Expr.h revision 2fc46bf1a9bc31d50f82de37c70ea257d3cded27
15f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===--- Expr.h - Classes for representing expressions ----------*- C++ -*-===//
25f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//
35f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//                     The LLVM Compiler Infrastructure
45f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//
50bc735ffcfb223c0186419547abaa5c84482663eChris Lattner// This file is distributed under the University of Illinois Open Source
60bc735ffcfb223c0186419547abaa5c84482663eChris Lattner// License. See LICENSE.TXT for details.
75f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//
85f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===//
95f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//
105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//  This file defines the Expr interface and subclasses.
115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//
125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===//
135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#ifndef LLVM_CLANG_AST_EXPR_H
155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#define LLVM_CLANG_AST_EXPR_H
165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1794deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson#include "clang/AST/APValue.h"
185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include "clang/AST/Stmt.h"
195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include "clang/AST/Type.h"
20161755a09898c95d21bfff33707da9ca41cd53c5John McCall#include "clang/AST/DeclAccessPair.h"
21709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek#include "clang/AST/ASTVector.h"
22409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson#include "clang/AST/UsuallyTinyPtrVector.h"
235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include "llvm/ADT/APSInt.h"
24525a05093a4816af961fe2bc6b8a81c17e2e26c2Chris Lattner#include "llvm/ADT/APFloat.h"
253b8d116703db8018f855cbb4733ace426422623bNate Begeman#include "llvm/ADT/SmallVector.h"
26b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar#include "llvm/ADT/StringRef.h"
27c5ae899b4bbf65488445316c63168079177db0edSteve Naroff#include <vector>
285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace clang {
30590b6646ef747d2f7b42e5f40487ff07642d7b6fChris Lattner  class ASTContext;
31c44eec6dd29ee9415cbd38a35deff4c8b67abb6aAnders Carlsson  class APValue;
32c4a1dea2dc56bd1357ec91b829a0b9e68229a13eDaniel Dunbar  class Decl;
33c4a1dea2dc56bd1357ec91b829a0b9e68229a13eDaniel Dunbar  class IdentifierInfo;
34c4a1dea2dc56bd1357ec91b829a0b9e68229a13eDaniel Dunbar  class ParmVarDecl;
358e9bebdea69c590dedfbf27374114cb76fe12fbdDouglas Gregor  class NamedDecl;
36c4a1dea2dc56bd1357ec91b829a0b9e68229a13eDaniel Dunbar  class ValueDecl;
3756ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff  class BlockDecl;
38409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson  class CXXBaseSpecifier;
3988a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor  class CXXOperatorCallExpr;
4088a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor  class CXXMemberCallExpr;
41833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  class TemplateArgumentLoc;
42d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  class TemplateArgumentListInfo;
4388a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor
447ab9d574d27ecee1f130e5755aa403e5ab529b6bAnders Carlsson/// \brief A simple array of base specifiers.
457ab9d574d27ecee1f130e5755aa403e5ab529b6bAnders Carlssontypedef UsuallyTinyPtrVector<const CXXBaseSpecifier> CXXBaseSpecifierArray;
467ab9d574d27ecee1f130e5755aa403e5ab529b6bAnders Carlsson
475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Expr - This represents one expression.  Note that Expr's are subclasses of
485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Stmt.  This allows an expression to be transparently used any place a Stmt
495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// is required.
505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass Expr : public Stmt {
525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType TR;
53898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor
549ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregorprotected:
551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// TypeDependent - Whether this expression is type-dependent
56898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// (C++ [temp.dep.expr]).
57898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  bool TypeDependent : 1;
58898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor
591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// ValueDependent - Whether this expression is value-dependent
60898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// (C++ [temp.dep.constexpr]).
61898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  bool ValueDependent : 1;
62898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor
63898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  Expr(StmtClass SC, QualType T, bool TD, bool VD)
64b3eef68111ffc220e449be96da1747998c057790Douglas Gregor    : Stmt(SC), TypeDependent(TD), ValueDependent(VD) {
65898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor    setType(T);
66898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  }
67898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor
680b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor  /// \brief Construct an empty expression.
690b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor  explicit Expr(StmtClass SC, EmptyShell) : Stmt(SC) { }
700b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor
711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumppublic:
7243d9d9243329b1b75d1a6efdad9f16d6fb386b8eDouglas Gregor  /// \brief Increases the reference count for this expression.
7343d9d9243329b1b75d1a6efdad9f16d6fb386b8eDouglas Gregor  ///
7443d9d9243329b1b75d1a6efdad9f16d6fb386b8eDouglas Gregor  /// Invoke the Retain() operation when this expression
7543d9d9243329b1b75d1a6efdad9f16d6fb386b8eDouglas Gregor  /// is being shared by another owner.
7643d9d9243329b1b75d1a6efdad9f16d6fb386b8eDouglas Gregor  Expr *Retain() {
7743d9d9243329b1b75d1a6efdad9f16d6fb386b8eDouglas Gregor    Stmt::Retain();
7843d9d9243329b1b75d1a6efdad9f16d6fb386b8eDouglas Gregor    return this;
7943d9d9243329b1b75d1a6efdad9f16d6fb386b8eDouglas Gregor  }
801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
81f7c2aa0b049272d8f318988c1965760dcb852578Douglas Gregor  QualType getType() const { return TR; }
821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  void setType(QualType t) {
839d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor    // In C++, the type of an expression is always adjusted so that it
849d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor    // will not have reference type an expression will never have
859d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor    // reference type (C++ [expr]p6). Use
869d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor    // QualType::getNonReferenceType() to retrieve the non-reference
879d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor    // type. Additionally, inspect Expr::isLvalue to determine whether
889d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor    // an expression that is adjusted in this manner should be
899d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor    // considered an lvalue.
90905d11d53aeb6b26744f44fedc2b2820c7a62df6Douglas Gregor    assert((t.isNull() || !t->isReferenceType()) &&
918320aaaa01d931aa234fc3bce05b399ef41898d5Daniel Dunbar           "Expressions can't have reference type");
92f7c2aa0b049272d8f318988c1965760dcb852578Douglas Gregor
931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    TR = t;
949d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor  }
9577ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek
96898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// isValueDependent - Determines whether this expression is
97898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// value-dependent (C++ [temp.dep.constexpr]). For example, the
98898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// array bound of "Chars" in the following example is
991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// value-dependent.
100898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// @code
101898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// template<int Size, char (&Chars)[Size]> struct meta_string;
102898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// @endcode
103898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  bool isValueDependent() const { return ValueDependent; }
104898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor
1050b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor  /// \brief Set whether this expression is value-dependent or not.
1060b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor  void setValueDependent(bool VD) { ValueDependent = VD; }
1070b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor
108898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// isTypeDependent - Determines whether this expression is
109898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// type-dependent (C++ [temp.dep.expr]), which means that its type
110898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// could change from one template instantiation to the next. For
111898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// example, the expressions "x" and "x + y" are type-dependent in
112898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// the following code, but "y" is not type-dependent:
113898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// @code
1141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// template<typename T>
115898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// void add(T x, int y) {
116898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  ///   x + y;
117898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// }
118898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// @endcode
119898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  bool isTypeDependent() const { return TypeDependent; }
120898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor
1210b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor  /// \brief Set whether this expression is type-dependent or not.
1220b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor  void setTypeDependent(bool TD) { TypeDependent = TD; }
1230b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor
1245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// SourceLocation tokens are not useful in isolation - they are low level
1255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// value objects created/interpreted by SourceManager. We assume AST
1265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// clients will have a pointer to the respective SourceManager.
1275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  virtual SourceRange getSourceRange() const = 0;
1285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// getExprLoc - Return the preferred location for the arrow when diagnosing
1305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// a problem with a generic expression.
1315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  virtual SourceLocation getExprLoc() const { return getLocStart(); }
1321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
133026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner  /// isUnusedResultAWarning - Return true if this immediate expression should
134026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner  /// be warned about if the result is unused.  If so, fill in Loc and Ranges
135026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner  /// with location to warn on and the source range[s] to report with the
136026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner  /// warning.
137026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner  bool isUnusedResultAWarning(SourceLocation &Loc, SourceRange &R1,
138df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump                              SourceRange &R2, ASTContext &Ctx) const;
1391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// isLvalue - C99 6.3.2.1: an lvalue is an expression with an object type or
1415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// incomplete type other than void. Nonarray expressions that can be lvalues:
1425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ///  - name, where name must be a variable
1435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ///  - e[i]
1445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ///  - (e), where e must be an lvalue
1455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ///  - e.name, where e must be an lvalue
1465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ///  - e->name
1475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ///  - *e, the type of e cannot be a function type
1485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ///  - string-constant
14908ad47cbd1f81fcb31dbc731c13b885a07e12704Bill Wendling  ///  - reference type [C++ [expr]]
15076458501a8963fa11b91c9337a487de6871169b4Sebastian Redl  ///  - b ? x : y, where x and y are lvalues of suitable types [C++]
1515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ///
1525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  enum isLvalueResult {
1535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    LV_Valid,
1545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    LV_NotObjectType,
1555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    LV_IncompleteVoidType,
156fec0b49c3fa621fbf63e420f3d54a5bb3a0265d2Steve Naroff    LV_DuplicateVectorComponents,
15786f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor    LV_InvalidExpression,
1582514a309204341798f96912ce7a90841bea59727Fariborz Jahanian    LV_MemberFunction,
159e9ff443040cb571ae2c5c2626c4dc9a9a812d84aFariborz Jahanian    LV_SubObjCPropertySetting,
160e873fb74219f48407ae0b8fa083aa7f0b6ff1427Douglas Gregor    LV_ClassTemporary
1615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  };
16228be73f74c9e241a23ea24fe5756623de6bf1084Chris Lattner  isLvalueResult isLvalue(ASTContext &Ctx) const;
16353202857c60214d80950a975e6e52aebf30bd16aEli Friedman
16453202857c60214d80950a975e6e52aebf30bd16aEli Friedman  // Same as above, but excluding checks for non-object and void types in C
16553202857c60214d80950a975e6e52aebf30bd16aEli Friedman  isLvalueResult isLvalueInternal(ASTContext &Ctx) const;
1661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// isModifiableLvalue - C99 6.3.2.1: an lvalue that does not have array type,
1685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// does not have an incomplete type, does not have a const-qualified type,
1691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// and if it is a structure or union, does not have any member (including,
1705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// recursively, any member or element of all contained aggregates or unions)
1715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// with a const-qualified type.
17244e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar  ///
17344e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar  /// \param Loc [in] [out] - A source location which *may* be filled
17444e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar  /// in with the location of the expression making this a
17544e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar  /// non-modifiable lvalue, if specified.
1765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  enum isModifiableLvalueResult {
1775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    MLV_Valid,
1785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    MLV_NotObjectType,
1795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    MLV_IncompleteVoidType,
180fec0b49c3fa621fbf63e420f3d54a5bb3a0265d2Steve Naroff    MLV_DuplicateVectorComponents,
1815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    MLV_InvalidExpression,
182ca354faa7e9b99af17070c82b9662a5fca76422cChris Lattner    MLV_LValueCast,           // Specialized form of MLV_InvalidExpression.
1835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    MLV_IncompleteType,
1845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    MLV_ConstQualified,
1854f6a7d7ead09b439216c32f2de806a998aeb222aSteve Naroff    MLV_ArrayType,
1865daf570d0ce027e18ed5f9d66e6b2a14a40b720dFariborz Jahanian    MLV_NotBlockQualified,
187ba8d2d684e74a20bef03828c21c991d222c7e9e5Fariborz Jahanian    MLV_ReadonlyProperty,
18886f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor    MLV_NoSetterProperty,
1892514a309204341798f96912ce7a90841bea59727Fariborz Jahanian    MLV_MemberFunction,
190e9ff443040cb571ae2c5c2626c4dc9a9a812d84aFariborz Jahanian    MLV_SubObjCPropertySetting,
191e873fb74219f48407ae0b8fa083aa7f0b6ff1427Douglas Gregor    MLV_ClassTemporary
1925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  };
19344e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar  isModifiableLvalueResult isModifiableLvalue(ASTContext &Ctx,
19444e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar                                              SourceLocation *Loc = 0) const;
1951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
19633bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor  /// \brief If this expression refers to a bit-field, retrieve the
19733bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor  /// declaration of that bit-field.
19833bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor  FieldDecl *getBitField();
1995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
20038d068e8f13a119b89a3b8b0f79f35cab1ffd09aAnders Carlsson  const FieldDecl *getBitField() const {
20138d068e8f13a119b89a3b8b0f79f35cab1ffd09aAnders Carlsson    return const_cast<Expr*>(this)->getBitField();
20238d068e8f13a119b89a3b8b0f79f35cab1ffd09aAnders Carlsson  }
2031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
204093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson  /// \brief Returns whether this expression refers to a vector element.
205093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson  bool refersToVectorElement() const;
206c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
2072b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner  /// isKnownToHaveBooleanValue - Return true if this is an integer expression
2082b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner  /// that is known to return 0 or 1.  This happens for _Bool/bool expressions
2092b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner  /// but also int expressions which are produced by things like comparisons in
2102b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner  /// C.
2112b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner  bool isKnownToHaveBooleanValue() const;
212c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
2135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// isIntegerConstantExpr - Return true if this expression is a valid integer
2145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// constant expression, and, if so, return its value in Result.  If not a
2155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// valid i-c-e, return false and fill in Loc (if specified) with the location
2165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// of the invalid expression.
217590b6646ef747d2f7b42e5f40487ff07642d7b6fChris Lattner  bool isIntegerConstantExpr(llvm::APSInt &Result, ASTContext &Ctx,
218590b6646ef747d2f7b42e5f40487ff07642d7b6fChris Lattner                             SourceLocation *Loc = 0,
2195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer                             bool isEvaluated = true) const;
220590b6646ef747d2f7b42e5f40487ff07642d7b6fChris Lattner  bool isIntegerConstantExpr(ASTContext &Ctx, SourceLocation *Loc = 0) const {
2218070a8497c0fb3e6f70a557f788405d8945b1208Daniel Dunbar    llvm::APSInt X;
222590b6646ef747d2f7b42e5f40487ff07642d7b6fChris Lattner    return isIntegerConstantExpr(X, Ctx, Loc);
2235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
224c9e8f606787b0bc0c3b08e566b87cc1751694168Eli Friedman  /// isConstantInitializer - Returns true if this expression is a constant
225c9e8f606787b0bc0c3b08e566b87cc1751694168Eli Friedman  /// initializer, which can be emitted at compile-time.
226c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  bool isConstantInitializer(ASTContext &Ctx) const;
2271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
22894deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson  /// EvalResult is a struct with detailed info about an evaluated expression.
22994deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson  struct EvalResult {
2302d6744ff04c1690a1485178d550d2fab84a0270bDaniel Dunbar    /// Val - This is the value the expression can be folded to.
23194deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson    APValue Val;
2321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
23394deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson    /// HasSideEffects - Whether the evaluated expression has side effects.
23494deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson    /// For example, (f() && 0) can be folded, but it still has side effects.
23594deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson    bool HasSideEffects;
2361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
23794deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson    /// Diag - If the expression is unfoldable, then Diag contains a note
23894deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson    /// diagnostic indicating why it's not foldable. DiagLoc indicates a caret
23994deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson    /// position for the error, and DiagExpr is the expression that caused
24094deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson    /// the error.
24194deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson    /// If the expression is foldable, but not an integer constant expression,
24294deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson    /// Diag contains a note diagnostic that describes why it isn't an integer
24394deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson    /// constant expression. If the expression *is* an integer constant
24494deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson    /// expression, then Diag will be zero.
24594deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson    unsigned Diag;
24694deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson    const Expr *DiagExpr;
24794deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson    SourceLocation DiagLoc;
2481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
24994deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson    EvalResult() : HasSideEffects(false), Diag(0), DiagExpr(0) {}
25094deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson  };
25194deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson
2526ee7aa154e8bbb21a21254293410b944f78b0bfeChris Lattner  /// Evaluate - Return true if this is a constant which we can fold using
253019f4e858e78587f2241ff1a76c747d7bcd7578cChris Lattner  /// any crazy technique (that has nothing to do with language standards) that
254019f4e858e78587f2241ff1a76c747d7bcd7578cChris Lattner  /// we want to.  If this function returns true, it returns the folded constant
255019f4e858e78587f2241ff1a76c747d7bcd7578cChris Lattner  /// in Result.
2565b45d4ef1ea3f04ec863daf8aa29be6c6e021750Anders Carlsson  bool Evaluate(EvalResult &Result, ASTContext &Ctx) const;
2575b45d4ef1ea3f04ec863daf8aa29be6c6e021750Anders Carlsson
258660e6f79a138a30a437c02142f23e7ef4eb21b2eMike Stump  /// EvaluateAsAny - The same as Evaluate, except that it also succeeds on
259660e6f79a138a30a437c02142f23e7ef4eb21b2eMike Stump  /// stack based objects.
260660e6f79a138a30a437c02142f23e7ef4eb21b2eMike Stump  bool EvaluateAsAny(EvalResult &Result, ASTContext &Ctx) const;
261660e6f79a138a30a437c02142f23e7ef4eb21b2eMike Stump
262cd7a445c6b46c5585580dfb652300c8483c0cb6bJohn McCall  /// EvaluateAsBooleanCondition - Return true if this is a constant
263cd7a445c6b46c5585580dfb652300c8483c0cb6bJohn McCall  /// which we we can fold and convert to a boolean condition using
264cd7a445c6b46c5585580dfb652300c8483c0cb6bJohn McCall  /// any crazy technique that we want to.
265cd7a445c6b46c5585580dfb652300c8483c0cb6bJohn McCall  bool EvaluateAsBooleanCondition(bool &Result, ASTContext &Ctx) const;
266cd7a445c6b46c5585580dfb652300c8483c0cb6bJohn McCall
2676ee7aa154e8bbb21a21254293410b944f78b0bfeChris Lattner  /// isEvaluatable - Call Evaluate to see if this expression can be constant
26845b6b9d080ac56917337d73d8f1cd6374b27b05dChris Lattner  /// folded, but discard the result.
26945b6b9d080ac56917337d73d8f1cd6374b27b05dChris Lattner  bool isEvaluatable(ASTContext &Ctx) const;
270c44eec6dd29ee9415cbd38a35deff4c8b67abb6aAnders Carlsson
2716ddf4784a22b994b954ed74c6061d4603d474639Fariborz Jahanian  /// HasSideEffects - This routine returns true for all those expressions
272c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  /// which must be evaluated each time and must not be optimization away
2736ddf4784a22b994b954ed74c6061d4603d474639Fariborz Jahanian  /// or evaluated at compile time. Example is a function call, volatile
2746ddf4784a22b994b954ed74c6061d4603d474639Fariborz Jahanian  /// variable read.
275393c247fe025ccb5f914e37e948192ea86faef8cFariborz Jahanian  bool HasSideEffects(ASTContext &Ctx) const;
276c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
27751fe996231b1d7199f76e4005ff4c943d5deeecdAnders Carlsson  /// EvaluateAsInt - Call Evaluate and return the folded integer. This
27851fe996231b1d7199f76e4005ff4c943d5deeecdAnders Carlsson  /// must be called on an expression that constant folds to an integer.
27951fe996231b1d7199f76e4005ff4c943d5deeecdAnders Carlsson  llvm::APSInt EvaluateAsInt(ASTContext &Ctx) const;
28051fe996231b1d7199f76e4005ff4c943d5deeecdAnders Carlsson
281b2f295c8050fb8c141bf2cf38eed0a56e99d0092Eli Friedman  /// EvaluateAsLValue - Evaluate an expression to see if it's a lvalue
282b2f295c8050fb8c141bf2cf38eed0a56e99d0092Eli Friedman  /// with link time known address.
2831b78276a75a5a0f496a82429c1ff9604d622a76dAnders Carlsson  bool EvaluateAsLValue(EvalResult &Result, ASTContext &Ctx) const;
2841b78276a75a5a0f496a82429c1ff9604d622a76dAnders Carlsson
285b2f295c8050fb8c141bf2cf38eed0a56e99d0092Eli Friedman  /// EvaluateAsAnyLValue - The same as EvaluateAsLValue, except that it
286b2f295c8050fb8c141bf2cf38eed0a56e99d0092Eli Friedman  /// also succeeds on stack based, immutable address lvalues.
287b2f295c8050fb8c141bf2cf38eed0a56e99d0092Eli Friedman  bool EvaluateAsAnyLValue(EvalResult &Result, ASTContext &Ctx) const;
288b2f295c8050fb8c141bf2cf38eed0a56e99d0092Eli Friedman
289ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor  /// \brief Enumeration used to describe how \c isNullPointerConstant()
290ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor  /// should cope with value-dependent expressions.
291ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor  enum NullPointerConstantValueDependence {
292ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor    /// \brief Specifies that the expression should never be value-dependent.
293ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor    NPC_NeverValueDependent = 0,
294c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
295ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor    /// \brief Specifies that a value-dependent expression of integral or
296ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor    /// dependent type should be considered a null pointer constant.
297ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor    NPC_ValueDependentIsNull,
298c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
299ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor    /// \brief Specifies that a value-dependent expression should be considered
300ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor    /// to never be a null pointer constant.
301ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor    NPC_ValueDependentIsNotNull
302ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor  };
303c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
304efa9b3877ef298bcb792600ac33521827e1f7fafAnders Carlsson  /// isNullPointerConstant - C99 6.3.2.3p3 -  Return true if this is either an
305efa9b3877ef298bcb792600ac33521827e1f7fafAnders Carlsson  /// integer constant expression with the value zero, or if this is one that is
306efa9b3877ef298bcb792600ac33521827e1f7fafAnders Carlsson  /// cast to void*.
307ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor  bool isNullPointerConstant(ASTContext &Ctx,
308ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor                             NullPointerConstantValueDependence NPC) const;
309efa9b3877ef298bcb792600ac33521827e1f7fafAnders Carlsson
31044baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian  /// isOBJCGCCandidate - Return true if this expression may be used in a read/
3111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// write barrier.
312102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanian  bool isOBJCGCCandidate(ASTContext &Ctx) const;
3131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3144e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek  /// IgnoreParens - Ignore parentheses.  If this Expr is a ParenExpr, return
3151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///  its subexpression.  If that subexpression is also a ParenExpr,
3164e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek  ///  then this method recursively returns its subexpression, and so forth.
3174e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek  ///  Otherwise, the method returns the current Expr.
3182b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner  Expr *IgnoreParens();
31956f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner
32056f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner  /// IgnoreParenCasts - Ignore parentheses and casts.  Strip off any ParenExpr
32127c8dc06f65d7abcf6a7e7f64a7960c9a150ca01Douglas Gregor  /// or CastExprs, returning their operand.
32256f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner  Expr *IgnoreParenCasts();
3231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3242fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCall  /// IgnoreParenImpCasts - Ignore parentheses and implicit casts.  Strip off any
3252fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCall  /// ParenExpr or ImplicitCastExprs, returning their operand.
3262fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCall  Expr *IgnoreParenImpCasts();
3272fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCall
328ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner  /// IgnoreParenNoopCasts - Ignore parentheses and casts that do not change the
329ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner  /// value (including ptr->int casts of the same size).  Strip off any
330ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner  /// ParenExpr or CastExprs, returning their operand.
331ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner  Expr *IgnoreParenNoopCasts(ASTContext &Ctx);
3321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3336eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor  /// \brief Determine whether this expression is a default function argument.
3346eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor  ///
3356eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor  /// Default arguments are implicitly generated in the abstract syntax tree
336c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  /// by semantic analysis for function calls, object constructions, etc. in
3376eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor  /// C++. Default arguments are represented by \c CXXDefaultArgExpr nodes;
3386eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor  /// this routine also looks through any implicit casts to determine whether
3396eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor  /// the expression is a default argument.
3406eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor  bool isDefaultArgument() const;
341c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
3422f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor  /// \brief Determine whether this expression directly creates a
3432f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor  /// temporary object (of class type).
3442f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor  bool isTemporaryObject() const { return getTemporaryObject() != 0; }
3452f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor
3462f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor  /// \brief If this expression directly creates a temporary object of
3472f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor  /// class type, return the expression that actually constructs that
3482f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor  /// temporary object.
3492f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor  const Expr *getTemporaryObject() const;
3502f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor
3512b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner  const Expr *IgnoreParens() const {
3524e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek    return const_cast<Expr*>(this)->IgnoreParens();
3534e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek  }
35456f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner  const Expr *IgnoreParenCasts() const {
35556f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner    return const_cast<Expr*>(this)->IgnoreParenCasts();
35656f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner  }
357ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner  const Expr *IgnoreParenNoopCasts(ASTContext &Ctx) const {
358ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner    return const_cast<Expr*>(this)->IgnoreParenNoopCasts(Ctx);
359ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner  }
3601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
361898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  static bool hasAnyTypeDependentArguments(Expr** Exprs, unsigned NumExprs);
362898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  static bool hasAnyValueDependentArguments(Expr** Exprs, unsigned NumExprs);
363898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor
3641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
3655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return T->getStmtClass() >= firstExprConstant &&
3661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump           T->getStmtClass() <= lastExprConstant;
3675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
3685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Expr *) { return true; }
3695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
3705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
3711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3725549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek//===----------------------------------------------------------------------===//
3735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// Primary Expressions.
3745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===//
3755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
376a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor/// \brief Represents the qualifier that may precede a C++ name, e.g., the
377a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor/// "std::" in "std::sort".
378a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregorstruct NameQualifier {
379a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// \brief The nested name specifier.
380a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  NestedNameSpecifier *NNS;
381c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
382a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// \brief The source range covered by the nested name specifier.
383a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  SourceRange Range;
384a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor};
385a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor
386a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor/// \brief Represents an explicit template argument list in C++, e.g.,
387a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor/// the "<int>" in "sort<int>".
388a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregorstruct ExplicitTemplateArgumentList {
389a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// \brief The source location of the left angle bracket ('<');
390a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  SourceLocation LAngleLoc;
391c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
392a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// \brief The source location of the right angle bracket ('>');
393a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  SourceLocation RAngleLoc;
394c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
395a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// \brief The number of template arguments in TemplateArgs.
396a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// The actual template arguments (if any) are stored after the
397a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// ExplicitTemplateArgumentList structure.
398a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  unsigned NumTemplateArgs;
399c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
400a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// \brief Retrieve the template arguments
401833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  TemplateArgumentLoc *getTemplateArgs() {
402833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    return reinterpret_cast<TemplateArgumentLoc *> (this + 1);
403a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  }
404c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
405a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// \brief Retrieve the template arguments
406833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  const TemplateArgumentLoc *getTemplateArgs() const {
407833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    return reinterpret_cast<const TemplateArgumentLoc *> (this + 1);
408a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  }
409d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall
410d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  void initializeFrom(const TemplateArgumentListInfo &List);
411d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  void copyInto(TemplateArgumentListInfo &List) const;
412d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  static std::size_t sizeFor(const TemplateArgumentListInfo &List);
413a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor};
414c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
4155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// DeclRefExpr - [C99 6.5.1p2] - A reference to a declared variable, function,
4165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// enum, etc.
4175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass DeclRefExpr : public Expr {
418a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  enum {
419c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    // Flag on DecoratedD that specifies when this declaration reference
420a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor    // expression has a C++ nested-name-specifier.
421a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor    HasQualifierFlag = 0x01,
422c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    // Flag on DecoratedD that specifies when this declaration reference
423a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor    // expression has an explicit C++ template argument list.
424a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor    HasExplicitTemplateArgumentListFlag = 0x02
425a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  };
426c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
427c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  // DecoratedD - The declaration that we are referencing, plus two bits to
428a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  // indicate whether (1) the declaration's name was explicitly qualified and
429c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  // (2) the declaration's name was followed by an explicit template
430a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  // argument list.
431dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall  llvm::PointerIntPair<ValueDecl *, 2> DecoratedD;
432c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
433a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  // Loc - The location of the declaration name itself.
4345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation Loc;
4359e922b1663ecb95dc7eee03002fd66ed18fb3192Argyrios Kyrtzidis
436a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// \brief Retrieve the qualifier that preceded the declaration name, if any.
437a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  NameQualifier *getNameQualifier() {
4382cf719c3c3d805f630dfc6b1255e52647820888eSebastian Redl    if ((DecoratedD.getInt() & HasQualifierFlag) == 0)
439a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor      return 0;
440c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
441a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor    return reinterpret_cast<NameQualifier *> (this + 1);
442a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  }
443c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
444a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// \brief Retrieve the qualifier that preceded the member name, if any.
445a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  const NameQualifier *getNameQualifier() const {
446a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor    return const_cast<DeclRefExpr *>(this)->getNameQualifier();
447a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  }
448c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
449a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// \brief Retrieve the explicit template argument list that followed the
450a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// member template name, if any.
451a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  ExplicitTemplateArgumentList *getExplicitTemplateArgumentList() {
4522cf719c3c3d805f630dfc6b1255e52647820888eSebastian Redl    if ((DecoratedD.getInt() & HasExplicitTemplateArgumentListFlag) == 0)
453a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor      return 0;
454c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
4552cf719c3c3d805f630dfc6b1255e52647820888eSebastian Redl    if ((DecoratedD.getInt() & HasQualifierFlag) == 0)
456a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor      return reinterpret_cast<ExplicitTemplateArgumentList *>(this + 1);
457c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
458a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor    return reinterpret_cast<ExplicitTemplateArgumentList *>(
459a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor                                                      getNameQualifier() + 1);
460a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  }
461c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
462a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// \brief Retrieve the explicit template argument list that followed the
463a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// member template name, if any.
464a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  const ExplicitTemplateArgumentList *getExplicitTemplateArgumentList() const {
465a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor    return const_cast<DeclRefExpr *>(this)->getExplicitTemplateArgumentList();
466a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  }
467c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
468a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  DeclRefExpr(NestedNameSpecifier *Qualifier, SourceRange QualifierRange,
469dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall              ValueDecl *D, SourceLocation NameLoc,
470d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall              const TemplateArgumentListInfo *TemplateArgs,
4710da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor              QualType T);
472c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
4739e922b1663ecb95dc7eee03002fd66ed18fb3192Argyrios Kyrtzidisprotected:
4740da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor  /// \brief Computes the type- and value-dependence flags for this
4750da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor  /// declaration reference expression.
4760da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor  void computeDependence();
4779e922b1663ecb95dc7eee03002fd66ed18fb3192Argyrios Kyrtzidis
478dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall  DeclRefExpr(StmtClass SC, ValueDecl *d, QualType t, SourceLocation l) :
4790da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor    Expr(SC, t, false, false), DecoratedD(d, 0), Loc(l) {
4800da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor    computeDependence();
4810da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor  }
4821a49af9681c350fef58e677f85ccb9a77e8e9d0aDouglas Gregor
4835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
484dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall  DeclRefExpr(ValueDecl *d, QualType t, SourceLocation l) :
4850da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor    Expr(DeclRefExprClass, t, false, false), DecoratedD(d, 0), Loc(l) {
4860da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor    computeDependence();
4870da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor  }
4881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4890b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor  /// \brief Construct an empty declaration reference expression.
4901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  explicit DeclRefExpr(EmptyShell Empty)
4910b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor    : Expr(DeclRefExprClass, Empty) { }
4920b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor
493a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  static DeclRefExpr *Create(ASTContext &Context,
494a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor                             NestedNameSpecifier *Qualifier,
495a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor                             SourceRange QualifierRange,
496dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall                             ValueDecl *D,
497a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor                             SourceLocation NameLoc,
4980da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor                             QualType T,
4990da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor                             const TemplateArgumentListInfo *TemplateArgs = 0);
500c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
501dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall  ValueDecl *getDecl() { return DecoratedD.getPointer(); }
502dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall  const ValueDecl *getDecl() const { return DecoratedD.getPointer(); }
503dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall  void setDecl(ValueDecl *NewD) { DecoratedD.setPointer(NewD); }
504904eed3f6148758d39a2d3c88f3133274460d645Douglas Gregor
5059e922b1663ecb95dc7eee03002fd66ed18fb3192Argyrios Kyrtzidis  SourceLocation getLocation() const { return Loc; }
5060b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor  void setLocation(SourceLocation L) { Loc = L; }
507a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  virtual SourceRange getSourceRange() const;
5081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
509a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// \brief Determine whether this declaration reference was preceded by a
510a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// C++ nested-name-specifier, e.g., \c N::foo.
511a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  bool hasQualifier() const { return DecoratedD.getInt() & HasQualifierFlag; }
512c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
513a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// \brief If the name was qualified, retrieves the source range of
514a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// the nested-name-specifier that precedes the name. Otherwise,
515a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// returns an empty source range.
516a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  SourceRange getQualifierRange() const {
517a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor    if (!hasQualifier())
518a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor      return SourceRange();
519c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
520a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor    return getNameQualifier()->Range;
521a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  }
522c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
523c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  /// \brief If the name was qualified, retrieves the nested-name-specifier
524a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// that precedes the name. Otherwise, returns NULL.
525a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  NestedNameSpecifier *getQualifier() const {
526a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor    if (!hasQualifier())
527a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor      return 0;
528c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
529a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor    return getNameQualifier()->NNS;
530a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  }
531c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
532a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// \brief Determines whether this member expression actually had a C++
533a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// template argument list explicitly specified, e.g., x.f<int>.
534a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  bool hasExplicitTemplateArgumentList() const {
535a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor    return DecoratedD.getInt() & HasExplicitTemplateArgumentListFlag;
536a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  }
537d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall
538d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  /// \brief Copies the template arguments (if present) into the given
539d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  /// structure.
540d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
541d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall    if (hasExplicitTemplateArgumentList())
542d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall      getExplicitTemplateArgumentList()->copyInto(List);
543d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  }
544c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
545a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// \brief Retrieve the location of the left angle bracket following the
546a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// member name ('<'), if any.
547a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  SourceLocation getLAngleLoc() const {
548a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor    if (!hasExplicitTemplateArgumentList())
549a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor      return SourceLocation();
550c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
551a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor    return getExplicitTemplateArgumentList()->LAngleLoc;
552a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  }
553c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
554a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// \brief Retrieve the template arguments provided as part of this
555a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// template-id.
556833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  const TemplateArgumentLoc *getTemplateArgs() const {
557a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor    if (!hasExplicitTemplateArgumentList())
558a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor      return 0;
559c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
560a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor    return getExplicitTemplateArgumentList()->getTemplateArgs();
561a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  }
562c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
563a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// \brief Retrieve the number of template arguments provided as part of this
564a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// template-id.
565a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  unsigned getNumTemplateArgs() const {
566a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor    if (!hasExplicitTemplateArgumentList())
567a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor      return 0;
568c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
569a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor    return getExplicitTemplateArgumentList()->NumTemplateArgs;
570a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  }
571c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
572a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// \brief Retrieve the location of the right angle bracket following the
573a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// template arguments ('>').
574a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  SourceLocation getRAngleLoc() const {
575a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor    if (!hasExplicitTemplateArgumentList())
576a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor      return SourceLocation();
577c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
578a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor    return getExplicitTemplateArgumentList()->RAngleLoc;
579a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  }
580c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
5811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
58299e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor    return T->getStmtClass() == DeclRefExprClass;
5835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
5845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const DeclRefExpr *) { return true; }
5851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
58677ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  // Iterators
58777ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_begin();
58877ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_end();
5895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
5905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
591d9f6910f4ef37c0e8eeee2a01287d9572c3176efChris Lattner/// PredefinedExpr - [C99 6.4.2.2] - A predefined identifier such as __func__.
592d9f6910f4ef37c0e8eeee2a01287d9572c3176efChris Lattnerclass PredefinedExpr : public Expr {
593227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlssonpublic:
594227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson  enum IdentType {
595227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson    Func,
596227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson    Function,
597848fa64143fbe5ae62a601ad61277f741e54dfabAnders Carlsson    PrettyFunction,
598848fa64143fbe5ae62a601ad61277f741e54dfabAnders Carlsson    /// PrettyFunctionNoVirtual - The same as PrettyFunction, except that the
599848fa64143fbe5ae62a601ad61277f741e54dfabAnders Carlsson    /// 'virtual' keyword is omitted for virtual member functions.
600848fa64143fbe5ae62a601ad61277f741e54dfabAnders Carlsson    PrettyFunctionNoVirtual
601227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson  };
6021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
603227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlssonprivate:
604227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson  SourceLocation Loc;
605227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson  IdentType Type;
606227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlssonpublic:
6071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  PredefinedExpr(SourceLocation l, QualType type, IdentType IT)
608c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    : Expr(PredefinedExprClass, type, type->isDependentType(),
609773f3973cf5e2b6b8788e895967dcb3c1e6ffe79Anders Carlsson           type->isDependentType()), Loc(l), Type(IT) {}
6101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
61117fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor  /// \brief Construct an empty predefined expression.
6121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  explicit PredefinedExpr(EmptyShell Empty)
61317fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor    : Expr(PredefinedExprClass, Empty) { }
61417fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor
615227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson  IdentType getIdentType() const { return Type; }
61617fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor  void setIdentType(IdentType IT) { Type = IT; }
61717fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor
61817fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor  SourceLocation getLocation() const { return Loc; }
61917fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor  void setLocation(SourceLocation L) { Loc = L; }
62017fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor
621848fa64143fbe5ae62a601ad61277f741e54dfabAnders Carlsson  static std::string ComputeName(IdentType IT, const Decl *CurrentDecl);
6223a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson
623227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson  virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
624227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson
6251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
6261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == PredefinedExprClass;
627227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson  }
628d9f6910f4ef37c0e8eeee2a01287d9572c3176efChris Lattner  static bool classof(const PredefinedExpr *) { return true; }
6291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
63077ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  // Iterators
63177ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_begin();
63277ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_end();
633227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson};
634227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson
6355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass IntegerLiteral : public Expr {
6365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  llvm::APInt Value;
6375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation Loc;
6385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
6391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  // type should be IntTy, LongTy, LongLongTy, UnsignedIntTy, UnsignedLongTy,
6405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // or UnsignedLongLongTy
6415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  IntegerLiteral(const llvm::APInt &V, QualType type, SourceLocation l)
6422333f7727f97018d6742e1e0938133bcfad967abEli Friedman    : Expr(IntegerLiteralClass, type, false, false), Value(V), Loc(l) {
6435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    assert(type->isIntegerType() && "Illegal type in IntegerLiteral");
6445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
645a135fb43eb94524a6529768596a4533eed9aa70dAnders Carlsson
6460b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor  /// \brief Construct an empty integer literal.
6471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  explicit IntegerLiteral(EmptyShell Empty)
6480b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor    : Expr(IntegerLiteralClass, Empty) { }
6490b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor
6505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  const llvm::APInt &getValue() const { return Value; }
6515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
6525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
653313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor  /// \brief Retrieve the location of the literal.
654313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor  SourceLocation getLocation() const { return Loc; }
655313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor
6560b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor  void setValue(const llvm::APInt &Val) { Value = Val; }
6570b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor  void setLocation(SourceLocation Location) { Loc = Location; }
6580b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor
6591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
6601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == IntegerLiteralClass;
6615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
6625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const IntegerLiteral *) { return true; }
6631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
66477ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  // Iterators
66577ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_begin();
66677ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_end();
6675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
6685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
6695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass CharacterLiteral : public Expr {
6705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  unsigned Value;
6715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation Loc;
672c250aae4f645833aed3a6321bc8598f7330dce8dChris Lattner  bool IsWide;
6735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
6745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // type should be IntTy
675c250aae4f645833aed3a6321bc8598f7330dce8dChris Lattner  CharacterLiteral(unsigned value, bool iswide, QualType type, SourceLocation l)
6762333f7727f97018d6742e1e0938133bcfad967abEli Friedman    : Expr(CharacterLiteralClass, type, false, false), Value(value), Loc(l),
6772333f7727f97018d6742e1e0938133bcfad967abEli Friedman      IsWide(iswide) {
6785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
6790b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor
6800b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor  /// \brief Construct an empty character literal.
6810b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor  CharacterLiteral(EmptyShell Empty) : Expr(CharacterLiteralClass, Empty) { }
6820b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor
683018d8e0596dd57401eeddcf11ac84ff0a065fbbeChris Lattner  SourceLocation getLocation() const { return Loc; }
684c250aae4f645833aed3a6321bc8598f7330dce8dChris Lattner  bool isWide() const { return IsWide; }
6851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
6871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  unsigned getValue() const { return Value; }
6895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
6900b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor  void setLocation(SourceLocation Location) { Loc = Location; }
6910b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor  void setWide(bool W) { IsWide = W; }
6920b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor  void setValue(unsigned Val) { Value = Val; }
6930b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor
6941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
6951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == CharacterLiteralClass;
6965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
6975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const CharacterLiteral *) { return true; }
69877ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek
69977ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  // Iterators
70077ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_begin();
70177ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_end();
7025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
7035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
7045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass FloatingLiteral : public Expr {
705525a05093a4816af961fe2bc6b8a81c17e2e26c2Chris Lattner  llvm::APFloat Value;
706720c4ec57b6110873cd533ad434853a27e7c3f4aTed Kremenek  bool IsExact : 1;
7075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation Loc;
7085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
7091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  FloatingLiteral(const llvm::APFloat &V, bool isexact,
710720c4ec57b6110873cd533ad434853a27e7c3f4aTed Kremenek                  QualType Type, SourceLocation L)
7112333f7727f97018d6742e1e0938133bcfad967abEli Friedman    : Expr(FloatingLiteralClass, Type, false, false), Value(V),
7122333f7727f97018d6742e1e0938133bcfad967abEli Friedman      IsExact(isexact), Loc(L) {}
7135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
71417fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor  /// \brief Construct an empty floating-point literal.
7151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  explicit FloatingLiteral(EmptyShell Empty)
71617fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor    : Expr(FloatingLiteralClass, Empty), Value(0.0) { }
71717fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor
718c9bec4bfea9090a08dd83a7b213f0c8adf8d78ecChris Lattner  const llvm::APFloat &getValue() const { return Value; }
71917fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor  void setValue(const llvm::APFloat &Val) { Value = Val; }
72017fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor
721720c4ec57b6110873cd533ad434853a27e7c3f4aTed Kremenek  bool isExact() const { return IsExact; }
72217fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor  void setExact(bool E) { IsExact = E; }
723c9bec4bfea9090a08dd83a7b213f0c8adf8d78ecChris Lattner
724da8249e57f3badecf925571881fe57243935c6c1Chris Lattner  /// getValueAsApproximateDouble - This returns the value as an inaccurate
725da8249e57f3badecf925571881fe57243935c6c1Chris Lattner  /// double.  Note that this may cause loss of precision, but is useful for
726da8249e57f3badecf925571881fe57243935c6c1Chris Lattner  /// debugging dumps, etc.
727da8249e57f3badecf925571881fe57243935c6c1Chris Lattner  double getValueAsApproximateDouble() const;
7281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
72917fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor  SourceLocation getLocation() const { return Loc; }
73017fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor  void setLocation(SourceLocation L) { Loc = L; }
73117fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor
7325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
7335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
7341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
7351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == FloatingLiteralClass;
7365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
7375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const FloatingLiteral *) { return true; }
7381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
73977ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  // Iterators
74077ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_begin();
74177ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_end();
7425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
7435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
7445d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner/// ImaginaryLiteral - We support imaginary integer and floating point literals,
7455d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner/// like "1.0i".  We represent these as a wrapper around FloatingLiteral and
7465d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner/// IntegerLiteral classes.  Instances of this class always have a Complex type
7475d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner/// whose element type matches the subexpression.
7485d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner///
7495d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattnerclass ImaginaryLiteral : public Expr {
7505549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Stmt *Val;
7515d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattnerpublic:
7525d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner  ImaginaryLiteral(Expr *val, QualType Ty)
7532333f7727f97018d6742e1e0938133bcfad967abEli Friedman    : Expr(ImaginaryLiteralClass, Ty, false, false), Val(val) {}
7541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
755cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor  /// \brief Build an empty imaginary literal.
7561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  explicit ImaginaryLiteral(EmptyShell Empty)
757cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor    : Expr(ImaginaryLiteralClass, Empty) { }
758cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor
7595549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  const Expr *getSubExpr() const { return cast<Expr>(Val); }
7605549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getSubExpr() { return cast<Expr>(Val); }
761cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor  void setSubExpr(Expr *E) { Val = E; }
762cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor
7635d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner  virtual SourceRange getSourceRange() const { return Val->getSourceRange(); }
7641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
7651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == ImaginaryLiteralClass;
7665d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner  }
7675d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner  static bool classof(const ImaginaryLiteral *) { return true; }
7681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7695d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner  // Iterators
7705d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner  virtual child_iterator child_begin();
7715d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner  virtual child_iterator child_end();
7725d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner};
7735d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner
774e6a82b2c29ad05534841e5f8fd033fb17b6f61e2Ted Kremenek/// StringLiteral - This represents a string literal expression, e.g. "foo"
775e6a82b2c29ad05534841e5f8fd033fb17b6f61e2Ted Kremenek/// or L"bar" (wide strings).  The actual string is returned by getStrData()
776e6a82b2c29ad05534841e5f8fd033fb17b6f61e2Ted Kremenek/// is NOT null-terminated, and the length of the string is determined by
777a7ad98ff0919d6a24ea7c46634ea29bea551c1a0Chris Lattner/// calling getByteLength().  The C type for a string is always a
778c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// ConstantArrayType.  In C++, the char type is const qualified, in C it is
779c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// not.
780690398188ea5b428f06aa13c7d4ce6eb741ad4f9Chris Lattner///
781690398188ea5b428f06aa13c7d4ce6eb741ad4f9Chris Lattner/// Note that strings in C can be formed by concatenation of multiple string
7828bea7c0ee44c71c817de7dc2be932b73bec90c9fChris Lattner/// literal pptokens in translation phase #6.  This keeps track of the locations
783690398188ea5b428f06aa13c7d4ce6eb741ad4f9Chris Lattner/// of each of these pieces.
784c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner///
785c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// Strings in C can also be truncated and extended by assigning into arrays,
786c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// e.g. with constructs like:
787c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner///   char X[2] = "foobar";
788c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// In this case, getByteLength() will return 6, but the string literal will
789c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// have type "char[2]".
7905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass StringLiteral : public Expr {
7915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  const char *StrData;
7925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  unsigned ByteLength;
7935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool IsWide;
794726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner  unsigned NumConcatenated;
795726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner  SourceLocation TokLocs[1];
7962085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner
7972333f7727f97018d6742e1e0938133bcfad967abEli Friedman  StringLiteral(QualType Ty) : Expr(StringLiteralClass, Ty, false, false) {}
7981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
79942602bb40aefcc2751d4078ba88aacf4d965c9bdDouglas Gregorprotected:
80042602bb40aefcc2751d4078ba88aacf4d965c9bdDouglas Gregor  virtual void DoDestroy(ASTContext &C);
80142602bb40aefcc2751d4078ba88aacf4d965c9bdDouglas Gregor
8025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
8032085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner  /// This is the "fully general" constructor that allows representation of
8042085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner  /// strings formed from multiple concatenated tokens.
8052085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner  static StringLiteral *Create(ASTContext &C, const char *StrData,
8062085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner                               unsigned ByteLength, bool Wide, QualType Ty,
807a135fb43eb94524a6529768596a4533eed9aa70dAnders Carlsson                               const SourceLocation *Loc, unsigned NumStrs);
8082085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner
8092085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner  /// Simple constructor for string literals made from one token.
8101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static StringLiteral *Create(ASTContext &C, const char *StrData,
8112085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner                               unsigned ByteLength,
8122085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner                               bool Wide, QualType Ty, SourceLocation Loc) {
8132085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner    return Create(C, StrData, ByteLength, Wide, Ty, &Loc, 1);
8142085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner  }
815a135fb43eb94524a6529768596a4533eed9aa70dAnders Carlsson
816673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor  /// \brief Construct an empty string literal.
817673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor  static StringLiteral *CreateEmpty(ASTContext &C, unsigned NumStrs);
818673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor
819b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar  llvm::StringRef getString() const {
820b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar    return llvm::StringRef(StrData, ByteLength);
821b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar  }
822b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar  // FIXME: These are deprecated, replace with StringRef.
8235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  const char *getStrData() const { return StrData; }
8245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  unsigned getByteLength() const { return ByteLength; }
825673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor
826673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor  /// \brief Sets the string data to the given string data.
827b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar  void setString(ASTContext &C, llvm::StringRef Str);
828673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor
8295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isWide() const { return IsWide; }
830673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor  void setWide(bool W) { IsWide = W; }
831673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor
8328d4141f83d9de379547cf05bd75d4c6cf894b189Steve Naroff  bool containsNonAsciiOrNull() const {
833b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar    llvm::StringRef Str = getString();
834b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar    for (unsigned i = 0, e = Str.size(); i != e; ++i)
835b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar      if (!isascii(Str[i]) || !Str[i])
83633fdb738a6c125f4c788733897021b7c1a062b0cSteve Naroff        return true;
83733fdb738a6c125f4c788733897021b7c1a062b0cSteve Naroff    return false;
83833fdb738a6c125f4c788733897021b7c1a062b0cSteve Naroff  }
839726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner  /// getNumConcatenated - Get the number of string literal tokens that were
840726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner  /// concatenated in translation phase #6 to form this string literal.
841726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner  unsigned getNumConcatenated() const { return NumConcatenated; }
8421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
843726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner  SourceLocation getStrTokenLoc(unsigned TokNum) const {
844726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner    assert(TokNum < NumConcatenated && "Invalid tok number");
845726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner    return TokLocs[TokNum];
846726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner  }
8471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  void setStrTokenLoc(unsigned TokNum, SourceLocation L) {
848673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor    assert(TokNum < NumConcatenated && "Invalid tok number");
849673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor    TokLocs[TokNum] = L;
850673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor  }
851673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor
852b137299ce5bb6c36fbba651858600857fda4dd50Chris Lattner  typedef const SourceLocation *tokloc_iterator;
853b137299ce5bb6c36fbba651858600857fda4dd50Chris Lattner  tokloc_iterator tokloc_begin() const { return TokLocs; }
854b137299ce5bb6c36fbba651858600857fda4dd50Chris Lattner  tokloc_iterator tokloc_end() const { return TokLocs+NumConcatenated; }
8555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
8561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  virtual SourceRange getSourceRange() const {
8571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return SourceRange(TokLocs[0], TokLocs[NumConcatenated-1]);
8585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
8591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
8601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == StringLiteralClass;
8615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
8625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const StringLiteral *) { return true; }
8631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
86477ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  // Iterators
86577ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_begin();
86677ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_end();
8675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
8685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
8695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ParenExpr - This represents a parethesized expression, e.g. "(1)".  This
8705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// AST node is only formed if full location information is requested.
8715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass ParenExpr : public Expr {
8725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation L, R;
8735549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Stmt *Val;
8745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
8755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ParenExpr(SourceLocation l, SourceLocation r, Expr *val)
876898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor    : Expr(ParenExprClass, val->getType(),
8771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump           val->isTypeDependent(), val->isValueDependent()),
878898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor      L(l), R(r), Val(val) {}
8791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
880c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor  /// \brief Construct an empty parenthesized expression.
8811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  explicit ParenExpr(EmptyShell Empty)
882c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor    : Expr(ParenExprClass, Empty) { }
883c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor
8845549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  const Expr *getSubExpr() const { return cast<Expr>(Val); }
8855549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getSubExpr() { return cast<Expr>(Val); }
886c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor  void setSubExpr(Expr *E) { Val = E; }
887c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor
888866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek  virtual SourceRange getSourceRange() const { return SourceRange(L, R); }
8895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
890313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor  /// \brief Get the location of the left parentheses '('.
891313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor  SourceLocation getLParen() const { return L; }
892c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor  void setLParen(SourceLocation Loc) { L = Loc; }
893313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor
894313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor  /// \brief Get the location of the right parentheses ')'.
895313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor  SourceLocation getRParen() const { return R; }
896c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor  void setRParen(SourceLocation Loc) { R = Loc; }
897313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor
8981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
8991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == ParenExprClass;
9005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
9015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const ParenExpr *) { return true; }
9021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
90377ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  // Iterators
90477ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_begin();
90577ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_end();
9065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
9075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
9085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
9090518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl/// UnaryOperator - This represents the unary-expression's (except sizeof and
9100518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl/// alignof), the postinc/postdec operators from postfix-expression, and various
9115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// extensions.
912dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner///
913dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner/// Notes on various nodes:
914dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner///
915dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner/// Real/Imag - These return the real/imag part of a complex operand.  If
916dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner///   applied to a non-complex value, the former returns its operand and the
917dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner///   later returns zero in the type of the operand.
918dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner///
91973d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner/// __builtin_offsetof(type, a.b[10]) is represented as a unary operator whose
9201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump///   subexpression is a compound literal with the various MemberExpr and
9218ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor///   ArraySubscriptExpr's applied to it. (This is only used in C)
92273d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner///
9235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass UnaryOperator : public Expr {
9245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
92513d130c3d225cdb5b1e6d9e86cea12eea718c707Chris Lattner  // Note that additions to this should also update the StmtVisitor class.
9265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  enum Opcode {
9275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    PostInc, PostDec, // [C99 6.5.2.4] Postfix increment and decrement operators
9285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    PreInc, PreDec,   // [C99 6.5.3.1] Prefix increment and decrement operators.
9295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    AddrOf, Deref,    // [C99 6.5.3.2] Address and indirection operators.
9305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Plus, Minus,      // [C99 6.5.3.3] Unary arithmetic operators.
9315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Not, LNot,        // [C99 6.5.3.3] Unary arithmetic operators.
9325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Real, Imag,       // "__real expr"/"__imag expr" Extension.
93373d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner    Extension,        // __extension__ marker.
93473d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner    OffsetOf          // __builtin_offsetof
9355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  };
9365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprivate:
9375549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Stmt *Val;
9385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  Opcode Opc;
9395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation Loc;
9401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumppublic:
9415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
9425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  UnaryOperator(Expr *input, Opcode opc, QualType type, SourceLocation l)
9439103bb27f4eefa0e0d7935387750e3aca24abc49Douglas Gregor    : Expr(UnaryOperatorClass, type,
9449103bb27f4eefa0e0d7935387750e3aca24abc49Douglas Gregor           input->isTypeDependent() && opc != OffsetOf,
9451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump           input->isValueDependent()),
9469103bb27f4eefa0e0d7935387750e3aca24abc49Douglas Gregor      Val(input), Opc(opc), Loc(l) {}
9475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
9480b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor  /// \brief Build an empty unary operator.
9491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  explicit UnaryOperator(EmptyShell Empty)
9500b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor    : Expr(UnaryOperatorClass, Empty), Opc(AddrOf) { }
9510b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor
9525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  Opcode getOpcode() const { return Opc; }
9530b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor  void setOpcode(Opcode O) { Opc = O; }
9540b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor
9555549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getSubExpr() const { return cast<Expr>(Val); }
9560b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor  void setSubExpr(Expr *E) { Val = E; }
9570b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor
9585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// getOperatorLoc - Return the location of the operator.
9595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation getOperatorLoc() const { return Loc; }
9600b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor  void setOperatorLoc(SourceLocation L) { Loc = L; }
9610b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor
9625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// isPostfix - Return true if this is a postfix operation, like x++.
9632085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner  static bool isPostfix(Opcode Op) {
9642085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner    return Op == PostInc || Op == PostDec;
9652085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner  }
9665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
9675a56ac30d04e8f0431a08980885662a47a6308aaTed Kremenek  /// isPostfix - Return true if this is a prefix operation, like --x.
9682085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner  static bool isPrefix(Opcode Op) {
9692085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner    return Op == PreInc || Op == PreDec;
9702085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner  }
9715a56ac30d04e8f0431a08980885662a47a6308aaTed Kremenek
9725a56ac30d04e8f0431a08980885662a47a6308aaTed Kremenek  bool isPrefix() const { return isPrefix(Opc); }
9735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isPostfix() const { return isPostfix(Opc); }
9745d826b82936beb2c32dd02460332ba8035192c65Ted Kremenek  bool isIncrementOp() const {return Opc==PreInc || Opc==PostInc; }
9755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isIncrementDecrementOp() const { return Opc>=PostInc && Opc<=PreDec; }
9765a1deb8d9c0722beae28d693fa137bbb942bd11fAnders Carlsson  bool isOffsetOfOp() const { return Opc == OffsetOf; }
9775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool isArithmeticOp(Opcode Op) { return Op >= Plus && Op <= LNot; }
9781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  bool isArithmeticOp() const { return isArithmeticOp(Opc); }
9791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
9805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// getOpcodeStr - Turn an Opcode enum value into the punctuation char it
9815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// corresponds to, e.g. "sizeof" or "[pre]++"
9825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static const char *getOpcodeStr(Opcode Op);
9835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
984bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor  /// \brief Retrieve the unary opcode that corresponds to the given
985bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor  /// overloaded operator.
986bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor  static Opcode getOverloadedOpcode(OverloadedOperatorKind OO, bool Postfix);
987bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor
988bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor  /// \brief Retrieve the overloaded operator kind that corresponds to
989bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor  /// the given unary opcode.
990bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor  static OverloadedOperatorKind getOverloadedOperator(Opcode Opc);
991bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor
9925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  virtual SourceRange getSourceRange() const {
9935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    if (isPostfix())
9945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      return SourceRange(Val->getLocStart(), Loc);
9955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    else
9965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      return SourceRange(Loc, Val->getLocEnd());
9975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
9985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  virtual SourceLocation getExprLoc() const { return Loc; }
9991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
10001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
10011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == UnaryOperatorClass;
10025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
10035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const UnaryOperator *) { return true; }
10041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
100577ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  // Iterators
100677ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_begin();
100777ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_end();
10085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
10095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
10108ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// OffsetOfExpr - [C99 7.17] - This represents an expression of the form
10118ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// offsetof(record-type, member-designator). For example, given:
10128ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// @code
10138ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// struct S {
10148ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor///   float f;
1015c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt///   double d;
10168ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// };
10178ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// struct T {
10188ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor///   int i;
10198ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor///   struct S s[10];
10208ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// };
10218ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// @endcode
1022c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt/// we can represent and evaluate the expression @c offsetof(struct T, s[2].d).
10238ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor
10248ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregorclass OffsetOfExpr : public Expr {
10258ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregorpublic:
10268ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  // __builtin_offsetof(type, identifier(.identifier|[expr])*)
10278ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  class OffsetOfNode {
10288ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  public:
10298ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    /// \brief The kind of offsetof node we have.
10308ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    enum Kind {
1031cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor      /// \brief An index into an array.
10328ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor      Array = 0x00,
1033cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor      /// \brief A field.
10348ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor      Field = 0x01,
1035cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor      /// \brief A field in a dependent type, known only by its name.
1036cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor      Identifier = 0x02,
1037cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor      /// \brief An implicit indirection through a C++ base class, when the
1038cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor      /// field found is in a base class.
1039cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor      Base = 0x03
10408ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    };
10418ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor
10428ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  private:
10438ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    enum { MaskBits = 2, Mask = 0x03 };
1044c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
10458ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    /// \brief The source range that covers this part of the designator.
10468ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    SourceRange Range;
1047c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
10488ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    /// \brief The data describing the designator, which comes in three
10498ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    /// different forms, depending on the lower two bits.
1050c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    ///   - An unsigned index into the array of Expr*'s stored after this node
10518ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    ///     in memory, for [constant-expression] designators.
10528ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    ///   - A FieldDecl*, for references to a known field.
10538ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    ///   - An IdentifierInfo*, for references to a field with a given name
10548ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    ///     when the class type is dependent.
1055c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    ///   - A CXXBaseSpecifier*, for references that look at a field in a
1056cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor    ///     base class.
10578ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    uintptr_t Data;
1058c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
10598ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  public:
10608ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    /// \brief Create an offsetof node that refers to an array element.
1061c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    OffsetOfNode(SourceLocation LBracketLoc, unsigned Index,
10628ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor                 SourceLocation RBracketLoc)
10638ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor      : Range(LBracketLoc, RBracketLoc), Data((Index << 2) | Array) { }
1064c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
10658ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    /// \brief Create an offsetof node that refers to a field.
1066c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    OffsetOfNode(SourceLocation DotLoc, FieldDecl *Field,
10678ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor                 SourceLocation NameLoc)
1068c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt      : Range(DotLoc.isValid()? DotLoc : NameLoc, NameLoc),
10698ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor        Data(reinterpret_cast<uintptr_t>(Field) | OffsetOfNode::Field) { }
1070c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
10718ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    /// \brief Create an offsetof node that refers to an identifier.
10728ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    OffsetOfNode(SourceLocation DotLoc, IdentifierInfo *Name,
10738ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor                 SourceLocation NameLoc)
1074c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt      : Range(DotLoc.isValid()? DotLoc : NameLoc, NameLoc),
10758ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor        Data(reinterpret_cast<uintptr_t>(Name) | Identifier) { }
1076cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor
1077cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor    /// \brief Create an offsetof node that refers into a C++ base class.
1078cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor    explicit OffsetOfNode(const CXXBaseSpecifier *Base)
1079cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor      : Range(), Data(reinterpret_cast<uintptr_t>(Base) | OffsetOfNode::Base) {}
1080c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
10818ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    /// \brief Determine what kind of offsetof node this is.
1082c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    Kind getKind() const {
10838ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor      return static_cast<Kind>(Data & Mask);
10848ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    }
1085c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
10868ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    /// \brief For an array element node, returns the index into the array
10878ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    /// of expressions.
10888ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    unsigned getArrayExprIndex() const {
10898ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor      assert(getKind() == Array);
10908ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor      return Data >> 2;
10918ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    }
10928ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor
10938ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    /// \brief For a field offsetof node, returns the field.
10948ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    FieldDecl *getField() const {
10958ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor      assert(getKind() == Field);
1096cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor      return reinterpret_cast<FieldDecl *>(Data & ~(uintptr_t)Mask);
10978ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    }
1098c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
10998ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    /// \brief For a field or identifier offsetof node, returns the name of
11008ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    /// the field.
11018ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    IdentifierInfo *getFieldName() const;
1102c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
1103cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor    /// \brief For a base class node, returns the base specifier.
1104cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor    CXXBaseSpecifier *getBase() const {
1105cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor      assert(getKind() == Base);
1106c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt      return reinterpret_cast<CXXBaseSpecifier *>(Data & ~(uintptr_t)Mask);
1107cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor    }
1108c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
11098ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    /// \brief Retrieve the source range that covers this offsetof node.
11108ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    ///
11118ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    /// For an array element node, the source range contains the locations of
11128ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    /// the square brackets. For a field or identifier node, the source range
1113c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    /// contains the location of the period (if there is one) and the
11148ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    /// identifier.
11158ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    SourceRange getRange() const { return Range; }
11168ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  };
11178ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor
11188ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregorprivate:
1119c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
11208ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  SourceLocation OperatorLoc, RParenLoc;
11218ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  // Base type;
11228ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  TypeSourceInfo *TSInfo;
11238ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  // Number of sub-components (i.e. instances of OffsetOfNode).
11248ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  unsigned NumComps;
11258ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  // Number of sub-expressions (i.e. array subscript expressions).
11268ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  unsigned NumExprs;
1127c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
1128c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  OffsetOfExpr(ASTContext &C, QualType type,
11298ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor               SourceLocation OperatorLoc, TypeSourceInfo *tsi,
1130c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt               OffsetOfNode* compsPtr, unsigned numComps,
11318ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor               Expr** exprsPtr, unsigned numExprs,
11328ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor               SourceLocation RParenLoc);
11338ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor
11348ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  explicit OffsetOfExpr(unsigned numComps, unsigned numExprs)
11358ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    : Expr(OffsetOfExprClass, EmptyShell()),
1136c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt      TSInfo(0), NumComps(numComps), NumExprs(numExprs) {}
11378ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor
11388ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregorpublic:
1139c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
1140c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  static OffsetOfExpr *Create(ASTContext &C, QualType type,
1141c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt                              SourceLocation OperatorLoc, TypeSourceInfo *tsi,
1142c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt                              OffsetOfNode* compsPtr, unsigned numComps,
11438ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor                              Expr** exprsPtr, unsigned numExprs,
11448ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor                              SourceLocation RParenLoc);
11458ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor
1146c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  static OffsetOfExpr *CreateEmpty(ASTContext &C,
11478ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor                                   unsigned NumComps, unsigned NumExprs);
11488ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor
11498ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  /// getOperatorLoc - Return the location of the operator.
11508ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  SourceLocation getOperatorLoc() const { return OperatorLoc; }
11518ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  void setOperatorLoc(SourceLocation L) { OperatorLoc = L; }
11528ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor
11538ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  /// \brief Return the location of the right parentheses.
11548ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  SourceLocation getRParenLoc() const { return RParenLoc; }
11558ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  void setRParenLoc(SourceLocation R) { RParenLoc = R; }
1156c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
11578ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  TypeSourceInfo *getTypeSourceInfo() const {
11588ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    return TSInfo;
11598ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  }
11608ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  void setTypeSourceInfo(TypeSourceInfo *tsi) {
11618ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    TSInfo = tsi;
11628ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  }
1163c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
11648ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  const OffsetOfNode &getComponent(unsigned Idx) {
11658ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    assert(Idx < NumComps && "Subscript out of range");
11668ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    return reinterpret_cast<OffsetOfNode *> (this + 1)[Idx];
11678ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  }
11688ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor
11698ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  void setComponent(unsigned Idx, OffsetOfNode ON) {
11708ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    assert(Idx < NumComps && "Subscript out of range");
11718ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    reinterpret_cast<OffsetOfNode *> (this + 1)[Idx] = ON;
11728ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  }
1173c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
11748ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  unsigned getNumComponents() const {
11758ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    return NumComps;
11768ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  }
11778ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor
11788ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  Expr* getIndexExpr(unsigned Idx) {
11798ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    assert(Idx < NumExprs && "Subscript out of range");
11808ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    return reinterpret_cast<Expr **>(
11818ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor                    reinterpret_cast<OffsetOfNode *>(this+1) + NumComps)[Idx];
11828ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  }
11838ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor
11848ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  void setIndexExpr(unsigned Idx, Expr* E) {
11858ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    assert(Idx < NumComps && "Subscript out of range");
11868ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    reinterpret_cast<Expr **>(
11878ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor                reinterpret_cast<OffsetOfNode *>(this+1) + NumComps)[Idx] = E;
11888ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  }
1189c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
11908ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  unsigned getNumExpressions() const {
11918ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    return NumExprs;
11928ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  }
11938ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor
11948ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  virtual SourceRange getSourceRange() const {
11958ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    return SourceRange(OperatorLoc, RParenLoc);
11968ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  }
11978ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor
11988ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  static bool classof(const Stmt *T) {
11998ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    return T->getStmtClass() == OffsetOfExprClass;
12008ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  }
12018ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor
12028ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  static bool classof(const OffsetOfExpr *) { return true; }
12038ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor
12048ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  // Iterators
12058ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  virtual child_iterator child_begin();
12068ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  virtual child_iterator child_end();
12078ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor};
12088ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor
12090518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl/// SizeOfAlignOfExpr - [C99 6.5.3.4] - This is for sizeof/alignof, both of
12100518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl/// types and expressions.
12110518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redlclass SizeOfAlignOfExpr : public Expr {
12120518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl  bool isSizeof : 1;  // true if sizeof, false if alignof.
12130518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl  bool isType : 1;    // true if operand is a type, false if an expression
1214d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl  union {
1215a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall    TypeSourceInfo *Ty;
1216d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl    Stmt *Ex;
1217d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl  } Argument;
12185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation OpLoc, RParenLoc;
121942602bb40aefcc2751d4078ba88aacf4d965c9bdDouglas Gregor
122042602bb40aefcc2751d4078ba88aacf4d965c9bdDouglas Gregorprotected:
122142602bb40aefcc2751d4078ba88aacf4d965c9bdDouglas Gregor  virtual void DoDestroy(ASTContext& C);
122242602bb40aefcc2751d4078ba88aacf4d965c9bdDouglas Gregor
12235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
1224a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall  SizeOfAlignOfExpr(bool issizeof, TypeSourceInfo *TInfo,
12250518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl                    QualType resultType, SourceLocation op,
12260518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl                    SourceLocation rp) :
12272850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl      Expr(SizeOfAlignOfExprClass, resultType,
1228ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor           false, // Never type-dependent (C++ [temp.dep.expr]p3).
12292850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl           // Value-dependent if the argument is type-dependent.
1230a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall           TInfo->getType()->isDependentType()),
1231ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor      isSizeof(issizeof), isType(true), OpLoc(op), RParenLoc(rp) {
1232a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall    Argument.Ty = TInfo;
1233ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor  }
1234ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor
12351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  SizeOfAlignOfExpr(bool issizeof, Expr *E,
1236ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor                    QualType resultType, SourceLocation op,
1237ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor                    SourceLocation rp) :
1238ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor      Expr(SizeOfAlignOfExprClass, resultType,
1239ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor           false, // Never type-dependent (C++ [temp.dep.expr]p3).
1240ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor           // Value-dependent if the argument is type-dependent.
1241ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor           E->isTypeDependent()),
1242ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor      isSizeof(issizeof), isType(false), OpLoc(op), RParenLoc(rp) {
1243ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor    Argument.Ex = E;
1244d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl  }
12450518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl
12460b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor  /// \brief Construct an empty sizeof/alignof expression.
12470b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor  explicit SizeOfAlignOfExpr(EmptyShell Empty)
12480b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor    : Expr(SizeOfAlignOfExprClass, Empty) { }
12490b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor
12505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isSizeOf() const { return isSizeof; }
12510b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor  void setSizeof(bool S) { isSizeof = S; }
12520b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor
12530518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl  bool isArgumentType() const { return isType; }
12540518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl  QualType getArgumentType() const {
12555ab75172051a6d2ea71a80a79e81c65519fd3462John McCall    return getArgumentTypeInfo()->getType();
12565ab75172051a6d2ea71a80a79e81c65519fd3462John McCall  }
1257a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall  TypeSourceInfo *getArgumentTypeInfo() const {
12580518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl    assert(isArgumentType() && "calling getArgumentType() when arg is expr");
12595ab75172051a6d2ea71a80a79e81c65519fd3462John McCall    return Argument.Ty;
12600518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl  }
1261caae7b099a0324b7c15dc89a9b70969d5d7ce996Chris Lattner  Expr *getArgumentExpr() {
12620518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl    assert(!isArgumentType() && "calling getArgumentExpr() when arg is type");
1263d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl    return static_cast<Expr*>(Argument.Ex);
12640518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl  }
1265caae7b099a0324b7c15dc89a9b70969d5d7ce996Chris Lattner  const Expr *getArgumentExpr() const {
1266caae7b099a0324b7c15dc89a9b70969d5d7ce996Chris Lattner    return const_cast<SizeOfAlignOfExpr*>(this)->getArgumentExpr();
1267caae7b099a0324b7c15dc89a9b70969d5d7ce996Chris Lattner  }
12680b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor
12690b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor  void setArgument(Expr *E) { Argument.Ex = E; isType = false; }
1270a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall  void setArgument(TypeSourceInfo *TInfo) {
1271a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall    Argument.Ty = TInfo;
12721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    isType = true;
12730b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor  }
12740b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor
12750518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl  /// Gets the argument type, or the type of the argument expression, whichever
12760518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl  /// is appropriate.
12770518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl  QualType getTypeOfArgument() const {
12780518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl    return isArgumentType() ? getArgumentType() : getArgumentExpr()->getType();
12790518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl  }
12800518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl
128176e773a443be9f006610f46529e07d4c8d857680Chris Lattner  SourceLocation getOperatorLoc() const { return OpLoc; }
12820b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor  void setOperatorLoc(SourceLocation L) { OpLoc = L; }
12830b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor
12840b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor  SourceLocation getRParenLoc() const { return RParenLoc; }
12850b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
1286866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek
1287866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek  virtual SourceRange getSourceRange() const {
1288866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek    return SourceRange(OpLoc, RParenLoc);
1289866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek  }
12905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
12911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
12921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == SizeOfAlignOfExprClass;
12935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
12940518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl  static bool classof(const SizeOfAlignOfExpr *) { return true; }
12951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
129677ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  // Iterators
129777ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_begin();
129877ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_end();
12995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
13005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
13015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===//
13025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// Postfix Operators.
13035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===//
13045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
13055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ArraySubscriptExpr - [C99 6.5.2.1] Array Subscripting.
13065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass ArraySubscriptExpr : public Expr {
130777ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  enum { LHS, RHS, END_EXPR=2 };
13081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  Stmt* SubExprs[END_EXPR];
13095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation RBracketLoc;
13105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
13112324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek  ArraySubscriptExpr(Expr *lhs, Expr *rhs, QualType t,
131273d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner                     SourceLocation rbracketloc)
13132850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl  : Expr(ArraySubscriptExprClass, t,
13142850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl         lhs->isTypeDependent() || rhs->isTypeDependent(),
13152850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl         lhs->isValueDependent() || rhs->isValueDependent()),
13162850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl    RBracketLoc(rbracketloc) {
131773d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner    SubExprs[LHS] = lhs;
131873d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner    SubExprs[RHS] = rhs;
131973d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner  }
13201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1321cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor  /// \brief Create an empty array subscript expression.
1322cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor  explicit ArraySubscriptExpr(EmptyShell Shell)
1323cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor    : Expr(ArraySubscriptExprClass, Shell) { }
1324cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor
13252324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek  /// An array access can be written A[4] or 4[A] (both are equivalent).
13262324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek  /// - getBase() and getIdx() always present the normalized view: A[4].
13272324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek  ///    In this case getBase() returns "A" and getIdx() returns "4".
13282324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek  /// - getLHS() and getRHS() present the syntactic view. e.g. for
13292324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek  ///    4[A] getLHS() returns "4".
133033fd5c124aac15bab7cad95e4e0e7761356d2c06Christopher Lamb  /// Note: Because vector element access is also written A[4] we must
133133fd5c124aac15bab7cad95e4e0e7761356d2c06Christopher Lamb  /// predicate the format conversion in getBase and getIdx only on the
133233fd5c124aac15bab7cad95e4e0e7761356d2c06Christopher Lamb  /// the type of the RHS, as it is possible for the LHS to be a vector of
133333fd5c124aac15bab7cad95e4e0e7761356d2c06Christopher Lamb  /// integer type
13345549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getLHS() { return cast<Expr>(SubExprs[LHS]); }
13355549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  const Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); }
1336cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor  void setLHS(Expr *E) { SubExprs[LHS] = E; }
1337cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor
13385549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getRHS() { return cast<Expr>(SubExprs[RHS]); }
13395549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  const Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); }
1340cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor  void setRHS(Expr *E) { SubExprs[RHS] = E; }
13411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
13421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  Expr *getBase() {
13435549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek    return cast<Expr>(getRHS()->getType()->isIntegerType() ? getLHS():getRHS());
134477ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  }
13451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
13461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  const Expr *getBase() const {
13475549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek    return cast<Expr>(getRHS()->getType()->isIntegerType() ? getLHS():getRHS());
13482324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek  }
13491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
13501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  Expr *getIdx() {
13515549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek    return cast<Expr>(getRHS()->getType()->isIntegerType() ? getRHS():getLHS());
13522324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek  }
13531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
135477ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  const Expr *getIdx() const {
13555549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek    return cast<Expr>(getRHS()->getType()->isIntegerType() ? getRHS():getLHS());
13561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  }
13571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
13581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  virtual SourceRange getSourceRange() const {
135977ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek    return SourceRange(getLHS()->getLocStart(), RBracketLoc);
13605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
13611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1362026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner  SourceLocation getRBracketLoc() const { return RBracketLoc; }
1363cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor  void setRBracketLoc(SourceLocation L) { RBracketLoc = L; }
1364cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor
13655cd9d6daf3acd4cc87fecebd81d9495b9e4ba9cdChris Lattner  virtual SourceLocation getExprLoc() const { return getBase()->getExprLoc(); }
13665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
13671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
13681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == ArraySubscriptExprClass;
13695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
13705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const ArraySubscriptExpr *) { return true; }
13711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
137277ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  // Iterators
137377ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_begin();
137477ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_end();
13755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
13765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
13775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1378b4609806e9232593ece09ce08b630836e825865cDouglas Gregor/// CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
13791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// CallExpr itself represents a normal function call, e.g., "f(x, 2)",
1380b4609806e9232593ece09ce08b630836e825865cDouglas Gregor/// while its subclasses may represent alternative syntax that (semantically)
13811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// results in a function call. For example, CXXOperatorCallExpr is
1382b4609806e9232593ece09ce08b630836e825865cDouglas Gregor/// a subclass for overloaded operator calls that use operator syntax, e.g.,
1383b4609806e9232593ece09ce08b630836e825865cDouglas Gregor/// "str1 + str2" to resolve to a function call.
13845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass CallExpr : public Expr {
138577ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  enum { FN=0, ARGS_START=1 };
13865549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Stmt **SubExprs;
13875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  unsigned NumArgs;
13885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation RParenLoc;
13891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1390b4609806e9232593ece09ce08b630836e825865cDouglas Gregorprotected:
1391b4609806e9232593ece09ce08b630836e825865cDouglas Gregor  // This version of the constructor is for derived classes.
1392668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek  CallExpr(ASTContext& C, StmtClass SC, Expr *fn, Expr **args, unsigned numargs,
1393668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek           QualType t, SourceLocation rparenloc);
139442602bb40aefcc2751d4078ba88aacf4d965c9bdDouglas Gregor
139542602bb40aefcc2751d4078ba88aacf4d965c9bdDouglas Gregor  virtual void DoDestroy(ASTContext& C);
13961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
13975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
13981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  CallExpr(ASTContext& C, Expr *fn, Expr **args, unsigned numargs, QualType t,
13995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer           SourceLocation rparenloc);
14001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
14011f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor  /// \brief Build an empty call expression.
1402ba0a9006dbc4814e1e35f82812cb5a1dad65e8b8Argyrios Kyrtzidis  CallExpr(ASTContext &C, StmtClass SC, EmptyShell Empty);
14031f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor
1404668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek  ~CallExpr() {}
14051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
14065549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  const Expr *getCallee() const { return cast<Expr>(SubExprs[FN]); }
14075549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getCallee() { return cast<Expr>(SubExprs[FN]); }
140818b2515e1bf8c86a4900792692e42fe1296be28dChris Lattner  void setCallee(Expr *F) { SubExprs[FN] = F; }
1409a00425414e8c209cabc25d1826b200aeb94259afZhongxing Xu
1410d20254f2875d0004c57ee766f258dbcee29f4841Nuno Lopes  Decl *getCalleeDecl();
1411d20254f2875d0004c57ee766f258dbcee29f4841Nuno Lopes  const Decl *getCalleeDecl() const {
1412d20254f2875d0004c57ee766f258dbcee29f4841Nuno Lopes    return const_cast<CallExpr*>(this)->getCalleeDecl();
1413d20254f2875d0004c57ee766f258dbcee29f4841Nuno Lopes  }
1414d20254f2875d0004c57ee766f258dbcee29f4841Nuno Lopes
1415a00425414e8c209cabc25d1826b200aeb94259afZhongxing Xu  /// \brief If the callee is a FunctionDecl, return it. Otherwise return 0.
1416a00425414e8c209cabc25d1826b200aeb94259afZhongxing Xu  FunctionDecl *getDirectCallee();
1417bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner  const FunctionDecl *getDirectCallee() const {
1418bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner    return const_cast<CallExpr*>(this)->getDirectCallee();
1419bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner  }
1420a00425414e8c209cabc25d1826b200aeb94259afZhongxing Xu
14215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// getNumArgs - Return the number of actual arguments to this call.
14225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ///
14235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  unsigned getNumArgs() const { return NumArgs; }
14241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
14255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// getArg - Return the specified argument.
14265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  Expr *getArg(unsigned Arg) {
14275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    assert(Arg < NumArgs && "Arg access out of range!");
14285549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek    return cast<Expr>(SubExprs[Arg+ARGS_START]);
14295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
14305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  const Expr *getArg(unsigned Arg) const {
14315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    assert(Arg < NumArgs && "Arg access out of range!");
14325549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek    return cast<Expr>(SubExprs[Arg+ARGS_START]);
14335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
14341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1435934f276cc5b45e19cd12ebb2d04fd7972a23865cSteve Naroff  /// setArg - Set the specified argument.
1436934f276cc5b45e19cd12ebb2d04fd7972a23865cSteve Naroff  void setArg(unsigned Arg, Expr *ArgExpr) {
1437934f276cc5b45e19cd12ebb2d04fd7972a23865cSteve Naroff    assert(Arg < NumArgs && "Arg access out of range!");
1438934f276cc5b45e19cd12ebb2d04fd7972a23865cSteve Naroff    SubExprs[Arg+ARGS_START] = ArgExpr;
1439934f276cc5b45e19cd12ebb2d04fd7972a23865cSteve Naroff  }
14401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1441d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner  /// setNumArgs - This changes the number of arguments present in this call.
1442d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner  /// Any orphaned expressions are deleted by this, and any new operands are set
1443d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner  /// to null.
14448189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  void setNumArgs(ASTContext& C, unsigned NumArgs);
14451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
14465549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  typedef ExprIterator arg_iterator;
14475549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  typedef ConstExprIterator const_arg_iterator;
14481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1449d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner  arg_iterator arg_begin() { return SubExprs+ARGS_START; }
1450d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner  arg_iterator arg_end() { return SubExprs+ARGS_START+getNumArgs(); }
14515549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  const_arg_iterator arg_begin() const { return SubExprs+ARGS_START; }
14525549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  const_arg_iterator arg_end() const { return SubExprs+ARGS_START+getNumArgs();}
14531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
14545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// getNumCommas - Return the number of commas that must have been present in
14555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// this function call.
14565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  unsigned getNumCommas() const { return NumArgs ? NumArgs - 1 : 0; }
14575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1458cb888967400a03504c88acedd5248d6778a82f46Chris Lattner  /// isBuiltinCall - If this is a call to a builtin, return the builtin ID.  If
1459cb888967400a03504c88acedd5248d6778a82f46Chris Lattner  /// not, return 0.
14603c385e5f8d9008fff18597ca302be19fa86e51f6Douglas Gregor  unsigned isBuiltinCall(ASTContext &Context) const;
14611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
14621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// getCallReturnType - Get the return type of the call expr. This is not
14631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// always the type of the expr itself, if the return type is a reference
14646dde78f744382a5627a04f984a97049e0c4b5e73Anders Carlsson  /// type.
14656dde78f744382a5627a04f984a97049e0c4b5e73Anders Carlsson  QualType getCallReturnType() const;
14661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1467d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner  SourceLocation getRParenLoc() const { return RParenLoc; }
14681f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
1469866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek
14701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  virtual SourceRange getSourceRange() const {
147177ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek    return SourceRange(getCallee()->getLocStart(), RParenLoc);
14725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
14731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
14741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
14754bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt    return T->getStmtClass() >= firstCallExprConstant &&
14764bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt           T->getStmtClass() <= lastCallExprConstant;
14775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
14785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const CallExpr *) { return true; }
147988a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor
148077ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  // Iterators
148177ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_begin();
148277ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_end();
14835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
14845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1485ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner/// MemberExpr - [C99 6.5.2.3] Structure and Union Members.  X->F and X.F.
14865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
14875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass MemberExpr : public Expr {
14886bb8017bb9e828d118e15e59d71c66bba323c364John McCall  /// Extra data stored in some member expressions.
14896bb8017bb9e828d118e15e59d71c66bba323c364John McCall  struct MemberNameQualifier : public NameQualifier {
1490161755a09898c95d21bfff33707da9ca41cd53c5John McCall    DeclAccessPair FoundDecl;
14916bb8017bb9e828d118e15e59d71c66bba323c364John McCall  };
14926bb8017bb9e828d118e15e59d71c66bba323c364John McCall
1493ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner  /// Base - the expression for the base pointer or structure references.  In
1494ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner  /// X.F, this is "X".
14955549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Stmt *Base;
14961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1497ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner  /// MemberDecl - This is the decl being referenced by the field/member name.
1498ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner  /// In X.F, this is the decl referenced by F.
1499f595cc41c4d95fe323f8a2b209523de9956f874dEli Friedman  ValueDecl *MemberDecl;
15001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1501ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner  /// MemberLoc - This is the location of the member name.
15025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation MemberLoc;
15031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1504ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner  /// IsArrow - True if this is "X->F", false if this is "X.F".
150583f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor  bool IsArrow : 1;
15061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
150783f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor  /// \brief True if this member expression used a nested-name-specifier to
15086bb8017bb9e828d118e15e59d71c66bba323c364John McCall  /// refer to the member, e.g., "x->Base::f", or found its member via a using
15096bb8017bb9e828d118e15e59d71c66bba323c364John McCall  /// declaration.  When true, a MemberNameQualifier
1510c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  /// structure is allocated immediately after the MemberExpr.
15116bb8017bb9e828d118e15e59d71c66bba323c364John McCall  bool HasQualifierOrFoundDecl : 1;
15121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1513c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  /// \brief True if this member expression specified a template argument list
1514c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  /// explicitly, e.g., x->f<int>. When true, an ExplicitTemplateArgumentList
1515c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  /// structure (and its TemplateArguments) are allocated immediately after
1516c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  /// the MemberExpr or, if the member expression also has a qualifier, after
15176bb8017bb9e828d118e15e59d71c66bba323c364John McCall  /// the MemberNameQualifier structure.
1518c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  bool HasExplicitTemplateArgumentList : 1;
15191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
152083f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor  /// \brief Retrieve the qualifier that preceded the member name, if any.
15216bb8017bb9e828d118e15e59d71c66bba323c364John McCall  MemberNameQualifier *getMemberQualifier() {
15226bb8017bb9e828d118e15e59d71c66bba323c364John McCall    assert(HasQualifierOrFoundDecl);
15236bb8017bb9e828d118e15e59d71c66bba323c364John McCall    return reinterpret_cast<MemberNameQualifier *> (this + 1);
152483f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor  }
152583f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor
152683f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor  /// \brief Retrieve the qualifier that preceded the member name, if any.
15276bb8017bb9e828d118e15e59d71c66bba323c364John McCall  const MemberNameQualifier *getMemberQualifier() const {
1528c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor    return const_cast<MemberExpr *>(this)->getMemberQualifier();
1529c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  }
15301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1531c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  /// \brief Retrieve the explicit template argument list that followed the
1532c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  /// member template name, if any.
1533c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  ExplicitTemplateArgumentList *getExplicitTemplateArgumentList() {
1534c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor    if (!HasExplicitTemplateArgumentList)
153583f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor      return 0;
15361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
15376bb8017bb9e828d118e15e59d71c66bba323c364John McCall    if (!HasQualifierOrFoundDecl)
1538c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor      return reinterpret_cast<ExplicitTemplateArgumentList *>(this + 1);
15391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1540c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor    return reinterpret_cast<ExplicitTemplateArgumentList *>(
1541c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor                                                      getMemberQualifier() + 1);
1542c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  }
15431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1544c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  /// \brief Retrieve the explicit template argument list that followed the
1545c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  /// member template name, if any.
1546c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  const ExplicitTemplateArgumentList *getExplicitTemplateArgumentList() const {
1547c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor    return const_cast<MemberExpr *>(this)->getExplicitTemplateArgumentList();
154883f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor  }
15491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
15505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
1551f595cc41c4d95fe323f8a2b209523de9956f874dEli Friedman  MemberExpr(Expr *base, bool isarrow, ValueDecl *memberdecl,
1552f595cc41c4d95fe323f8a2b209523de9956f874dEli Friedman             SourceLocation l, QualType ty)
15531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    : Expr(MemberExprClass, ty,
1554ffce2df6ae280d354d51371282a579df1eb86876Anders Carlsson           base->isTypeDependent(), base->isValueDependent()),
155583f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor      Base(base), MemberDecl(memberdecl), MemberLoc(l), IsArrow(isarrow),
15566bb8017bb9e828d118e15e59d71c66bba323c364John McCall      HasQualifierOrFoundDecl(false), HasExplicitTemplateArgumentList(false) {}
1557510190777c4bd53e960eea4665b204778fec1b64Eli Friedman
15581f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor  /// \brief Build an empty member reference expression.
15591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  explicit MemberExpr(EmptyShell Empty)
15606bb8017bb9e828d118e15e59d71c66bba323c364John McCall    : Expr(MemberExprClass, Empty), HasQualifierOrFoundDecl(false),
1561e6585a7d71510be00a625686153f48d496d3bbf1Douglas Gregor      HasExplicitTemplateArgumentList(false) { }
15621f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor
15631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static MemberExpr *Create(ASTContext &C, Expr *base, bool isarrow,
156483f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor                            NestedNameSpecifier *qual, SourceRange qualrange,
1565161755a09898c95d21bfff33707da9ca41cd53c5John McCall                            ValueDecl *memberdecl, DeclAccessPair founddecl,
1566c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor                            SourceLocation l,
1567d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall                            const TemplateArgumentListInfo *targs,
1568c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor                            QualType ty);
15691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
157088a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor  void setBase(Expr *E) { Base = E; }
15715549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getBase() const { return cast<Expr>(Base); }
157257e8b05fe9ba03d410db9c161e032cb79c9ab5baDouglas Gregor
157357e8b05fe9ba03d410db9c161e032cb79c9ab5baDouglas Gregor  /// \brief Retrieve the member declaration to which this expression refers.
157457e8b05fe9ba03d410db9c161e032cb79c9ab5baDouglas Gregor  ///
157557e8b05fe9ba03d410db9c161e032cb79c9ab5baDouglas Gregor  /// The returned declaration will either be a FieldDecl or (in C++)
157657e8b05fe9ba03d410db9c161e032cb79c9ab5baDouglas Gregor  /// a CXXMethodDecl.
1577f595cc41c4d95fe323f8a2b209523de9956f874dEli Friedman  ValueDecl *getMemberDecl() const { return MemberDecl; }
1578f595cc41c4d95fe323f8a2b209523de9956f874dEli Friedman  void setMemberDecl(ValueDecl *D) { MemberDecl = D; }
15791f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor
15806bb8017bb9e828d118e15e59d71c66bba323c364John McCall  /// \brief Retrieves the declaration found by lookup.
1581161755a09898c95d21bfff33707da9ca41cd53c5John McCall  DeclAccessPair getFoundDecl() const {
15826bb8017bb9e828d118e15e59d71c66bba323c364John McCall    if (!HasQualifierOrFoundDecl)
1583161755a09898c95d21bfff33707da9ca41cd53c5John McCall      return DeclAccessPair::make(getMemberDecl(),
1584161755a09898c95d21bfff33707da9ca41cd53c5John McCall                                  getMemberDecl()->getAccess());
15856bb8017bb9e828d118e15e59d71c66bba323c364John McCall    return getMemberQualifier()->FoundDecl;
15866bb8017bb9e828d118e15e59d71c66bba323c364John McCall  }
15876bb8017bb9e828d118e15e59d71c66bba323c364John McCall
15881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// \brief Determines whether this member expression actually had
15890979c805475d1ba49b5d6ef93c4d2ce6d2eab6edDouglas Gregor  /// a C++ nested-name-specifier prior to the name of the member, e.g.,
15900979c805475d1ba49b5d6ef93c4d2ce6d2eab6edDouglas Gregor  /// x->Base::foo.
15916bb8017bb9e828d118e15e59d71c66bba323c364John McCall  bool hasQualifier() const { return getQualifier() != 0; }
15921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
159383f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor  /// \brief If the member name was qualified, retrieves the source range of
159483f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor  /// the nested-name-specifier that precedes the member name. Otherwise,
159583f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor  /// returns an empty source range.
15961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  SourceRange getQualifierRange() const {
15976bb8017bb9e828d118e15e59d71c66bba323c364John McCall    if (!HasQualifierOrFoundDecl)
159883f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor      return SourceRange();
15991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
160083f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor    return getMemberQualifier()->Range;
160183f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor  }
16021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
16031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// \brief If the member name was qualified, retrieves the
160483f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor  /// nested-name-specifier that precedes the member name. Otherwise, returns
160583f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor  /// NULL.
16061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  NestedNameSpecifier *getQualifier() const {
16076bb8017bb9e828d118e15e59d71c66bba323c364John McCall    if (!HasQualifierOrFoundDecl)
160883f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor      return 0;
16091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
161083f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor    return getMemberQualifier()->NNS;
161183f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor  }
1612c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor
1613c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  /// \brief Determines whether this member expression actually had a C++
1614c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  /// template argument list explicitly specified, e.g., x.f<int>.
1615d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  bool hasExplicitTemplateArgumentList() const {
16161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return HasExplicitTemplateArgumentList;
1617c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  }
16181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1619d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  /// \brief Copies the template arguments (if present) into the given
1620d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  /// structure.
1621d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
1622d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall    if (hasExplicitTemplateArgumentList())
1623d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall      getExplicitTemplateArgumentList()->copyInto(List);
1624d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  }
1625c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
16261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// \brief Retrieve the location of the left angle bracket following the
1627c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  /// member name ('<'), if any.
16281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  SourceLocation getLAngleLoc() const {
1629c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor    if (!HasExplicitTemplateArgumentList)
1630c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor      return SourceLocation();
16311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1632c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor    return getExplicitTemplateArgumentList()->LAngleLoc;
1633c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  }
16341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1635c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  /// \brief Retrieve the template arguments provided as part of this
1636c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  /// template-id.
1637833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  const TemplateArgumentLoc *getTemplateArgs() const {
1638c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor    if (!HasExplicitTemplateArgumentList)
16391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump      return 0;
16401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1641c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor    return getExplicitTemplateArgumentList()->getTemplateArgs();
1642c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  }
16431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1644c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  /// \brief Retrieve the number of template arguments provided as part of this
1645c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  /// template-id.
16461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  unsigned getNumTemplateArgs() const {
1647c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor    if (!HasExplicitTemplateArgumentList)
16481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump      return 0;
16491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1650c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor    return getExplicitTemplateArgumentList()->NumTemplateArgs;
1651c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  }
16521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
16531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// \brief Retrieve the location of the right angle bracket following the
1654c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  /// template arguments ('>').
16551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  SourceLocation getRAngleLoc() const {
1656c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor    if (!HasExplicitTemplateArgumentList)
1657c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor      return SourceLocation();
16581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1659c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor    return getExplicitTemplateArgumentList()->RAngleLoc;
1660c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  }
16611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
16625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isArrow() const { return IsArrow; }
16631f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor  void setArrow(bool A) { IsArrow = A; }
16641f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor
1665ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner  /// getMemberLoc - Return the location of the "member", in X->F, it is the
1666ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner  /// location of 'F'.
1667026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner  SourceLocation getMemberLoc() const { return MemberLoc; }
16681f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor  void setMemberLoc(SourceLocation L) { MemberLoc = L; }
16695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
16705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  virtual SourceRange getSourceRange() const {
167172527137c521ad9330ecb81ccd841159719dc8cdEli Friedman    // If we have an implicit base (like a C++ implicit this),
167272527137c521ad9330ecb81ccd841159719dc8cdEli Friedman    // make sure not to return its location
1673c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor    SourceLocation EndLoc = MemberLoc;
1674c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor    if (HasExplicitTemplateArgumentList)
1675c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor      EndLoc = getRAngleLoc();
16761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
167772527137c521ad9330ecb81ccd841159719dc8cdEli Friedman    SourceLocation BaseLoc = getBase()->getLocStart();
167872527137c521ad9330ecb81ccd841159719dc8cdEli Friedman    if (BaseLoc.isInvalid())
1679c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor      return SourceRange(MemberLoc, EndLoc);
1680c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor    return SourceRange(BaseLoc, EndLoc);
16815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
16821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
16835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  virtual SourceLocation getExprLoc() const { return MemberLoc; }
16845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
16851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
168683f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor    return T->getStmtClass() == MemberExprClass;
16875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
16885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const MemberExpr *) { return true; }
16891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
16901237c673c07f9d827129ba02720108816abde562Ted Kremenek  // Iterators
16911237c673c07f9d827129ba02720108816abde562Ted Kremenek  virtual child_iterator child_begin();
16921237c673c07f9d827129ba02720108816abde562Ted Kremenek  virtual child_iterator child_end();
16935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
16945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
16951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// CompoundLiteralExpr - [C99 6.5.2.5]
1696aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff///
1697aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroffclass CompoundLiteralExpr : public Expr {
16980fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner  /// LParenLoc - If non-null, this is the location of the left paren in a
16990fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner  /// compound literal like "(int){4}".  This can be null if this is a
17000fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner  /// synthesized compound expression.
17010fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner  SourceLocation LParenLoc;
17021d7d8d66eff7ed0f3e957d330930cc9ab8047addJohn McCall
17031d7d8d66eff7ed0f3e957d330930cc9ab8047addJohn McCall  /// The type as written.  This can be an incomplete array type, in
17041d7d8d66eff7ed0f3e957d330930cc9ab8047addJohn McCall  /// which case the actual expression type will be different.
170542f56b50062cd3b3c6b23fdb9053578ae9145664John McCall  TypeSourceInfo *TInfo;
17065549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Stmt *Init;
1707e9b12198c4cc7f5687960100351b4af006c14469Steve Naroff  bool FileScope;
1708aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroffpublic:
17092333f7727f97018d6742e1e0938133bcfad967abEli Friedman  // FIXME: Can compound literals be value-dependent?
171042f56b50062cd3b3c6b23fdb9053578ae9145664John McCall  CompoundLiteralExpr(SourceLocation lparenloc, TypeSourceInfo *tinfo,
17111d7d8d66eff7ed0f3e957d330930cc9ab8047addJohn McCall                      QualType T, Expr *init, bool fileScope)
17121d7d8d66eff7ed0f3e957d330930cc9ab8047addJohn McCall    : Expr(CompoundLiteralExprClass, T,
171342f56b50062cd3b3c6b23fdb9053578ae9145664John McCall           tinfo->getType()->isDependentType(), false),
171442f56b50062cd3b3c6b23fdb9053578ae9145664John McCall      LParenLoc(lparenloc), TInfo(tinfo), Init(init), FileScope(fileScope) {}
17151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1716ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor  /// \brief Construct an empty compound literal.
1717ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor  explicit CompoundLiteralExpr(EmptyShell Empty)
1718ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor    : Expr(CompoundLiteralExprClass, Empty) { }
1719ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor
17205549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  const Expr *getInitializer() const { return cast<Expr>(Init); }
17215549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getInitializer() { return cast<Expr>(Init); }
1722ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor  void setInitializer(Expr *E) { Init = E; }
1723e9b12198c4cc7f5687960100351b4af006c14469Steve Naroff
1724e9b12198c4cc7f5687960100351b4af006c14469Steve Naroff  bool isFileScope() const { return FileScope; }
1725ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor  void setFileScope(bool FS) { FileScope = FS; }
1726ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor
17270fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner  SourceLocation getLParenLoc() const { return LParenLoc; }
1728ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor  void setLParenLoc(SourceLocation L) { LParenLoc = L; }
1729ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor
173042f56b50062cd3b3c6b23fdb9053578ae9145664John McCall  TypeSourceInfo *getTypeSourceInfo() const { return TInfo; }
173142f56b50062cd3b3c6b23fdb9053578ae9145664John McCall  void setTypeSourceInfo(TypeSourceInfo* tinfo) { TInfo = tinfo; }
173242f56b50062cd3b3c6b23fdb9053578ae9145664John McCall
173373d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner  virtual SourceRange getSourceRange() const {
17340fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner    // FIXME: Init should never be null.
17350fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner    if (!Init)
17360fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner      return SourceRange();
17370fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner    if (LParenLoc.isInvalid())
173873d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner      return Init->getSourceRange();
17390fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner    return SourceRange(LParenLoc, Init->getLocEnd());
174073d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner  }
1741aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff
17421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
17431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == CompoundLiteralExprClass;
1744aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff  }
1745aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff  static bool classof(const CompoundLiteralExpr *) { return true; }
17461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
17471237c673c07f9d827129ba02720108816abde562Ted Kremenek  // Iterators
17481237c673c07f9d827129ba02720108816abde562Ted Kremenek  virtual child_iterator child_begin();
17491237c673c07f9d827129ba02720108816abde562Ted Kremenek  virtual child_iterator child_end();
1750aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff};
1751aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff
175249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// CastExpr - Base class for type casts, including both implicit
175349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// casts (ImplicitCastExpr) and explicit casts that have some
175449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// representation in the source code (ExplicitCastExpr's derived
175549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// classes).
17560835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidisclass CastExpr : public Expr {
1757cdef2b75aa60cde1ca00e0aa3f89139ac89c6ae4Anders Carlssonpublic:
1758cdef2b75aa60cde1ca00e0aa3f89139ac89c6ae4Anders Carlsson  /// CastKind - the kind of cast this represents.
1759cdef2b75aa60cde1ca00e0aa3f89139ac89c6ae4Anders Carlsson  enum CastKind {
1760cdef2b75aa60cde1ca00e0aa3f89139ac89c6ae4Anders Carlsson    /// CK_Unknown - Unknown cast kind.
17611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    /// FIXME: The goal is to get rid of this and make all casts have a
1762cdef2b75aa60cde1ca00e0aa3f89139ac89c6ae4Anders Carlsson    /// kind so that the AST client doesn't have to try to figure out what's
1763cdef2b75aa60cde1ca00e0aa3f89139ac89c6ae4Anders Carlsson    /// going on.
1764cdef2b75aa60cde1ca00e0aa3f89139ac89c6ae4Anders Carlsson    CK_Unknown,
17651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1766cdef2b75aa60cde1ca00e0aa3f89139ac89c6ae4Anders Carlsson    /// CK_BitCast - Used for reinterpret_cast.
1767cdef2b75aa60cde1ca00e0aa3f89139ac89c6ae4Anders Carlsson    CK_BitCast,
17681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1769cdef2b75aa60cde1ca00e0aa3f89139ac89c6ae4Anders Carlsson    /// CK_NoOp - Used for const_cast.
17703503d041ca8a3535a1c1a30005a6b18ae7aed5dbAnders Carlsson    CK_NoOp,
17711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
177211de6de25a0110cd7be97eef761ef3b189781da6Anders Carlsson    /// CK_BaseToDerived - Base to derived class casts.
177311de6de25a0110cd7be97eef761ef3b189781da6Anders Carlsson    CK_BaseToDerived,
177411de6de25a0110cd7be97eef761ef3b189781da6Anders Carlsson
17753503d041ca8a3535a1c1a30005a6b18ae7aed5dbAnders Carlsson    /// CK_DerivedToBase - Derived to base class casts.
1776714179b179a31a0c3769a968ee18ba87b901b13fAnders Carlsson    CK_DerivedToBase,
17771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
177823cba801e11b03929c44f8cf54578305963a3476John McCall    /// CK_UncheckedDerivedToBase - Derived to base class casts that
177923cba801e11b03929c44f8cf54578305963a3476John McCall    /// assume that the derived pointer is not null.
178023cba801e11b03929c44f8cf54578305963a3476John McCall    CK_UncheckedDerivedToBase,
178123cba801e11b03929c44f8cf54578305963a3476John McCall
1782714179b179a31a0c3769a968ee18ba87b901b13fAnders Carlsson    /// CK_Dynamic - Dynamic cast.
17834d8673b645ad86e496b886a0f80b60763f67071dAnders Carlsson    CK_Dynamic,
17841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
17854d8673b645ad86e496b886a0f80b60763f67071dAnders Carlsson    /// CK_ToUnion - Cast to union (GCC extension).
1786112a0a8ddf23f6d25e0920002d5d4c1df0515f86Anders Carlsson    CK_ToUnion,
17871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1788112a0a8ddf23f6d25e0920002d5d4c1df0515f86Anders Carlsson    /// CK_ArrayToPointerDecay - Array to pointer decay.
178927a5b9b9babd1e4f8a19c5c9c0736c4b311c79b2Anders Carlsson    CK_ArrayToPointerDecay,
17901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1791b633c4ee622df81d4572ef57dac54ebed69bb9bfAnders Carlsson    // CK_FunctionToPointerDecay - Function to pointer decay.
1792b633c4ee622df81d4572ef57dac54ebed69bb9bfAnders Carlsson    CK_FunctionToPointerDecay,
17931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
179427a5b9b9babd1e4f8a19c5c9c0736c4b311c79b2Anders Carlsson    /// CK_NullToMemberPointer - Null pointer to member pointer.
179527a5b9b9babd1e4f8a19c5c9c0736c4b311c79b2Anders Carlsson    CK_NullToMemberPointer,
17961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
179727a5b9b9babd1e4f8a19c5c9c0736c4b311c79b2Anders Carlsson    /// CK_BaseToDerivedMemberPointer - Member pointer in base class to
179827a5b9b9babd1e4f8a19c5c9c0736c4b311c79b2Anders Carlsson    /// member pointer in derived class.
17999099ff0cf91ac9e0b2d5a142807fa384ce842fc4Fariborz Jahanian    CK_BaseToDerivedMemberPointer,
18009099ff0cf91ac9e0b2d5a142807fa384ce842fc4Fariborz Jahanian
18011a31a18db9d657751f38c724adc0d62e86852bd7Anders Carlsson    /// CK_DerivedToBaseMemberPointer - Member pointer in derived class to
18021a31a18db9d657751f38c724adc0d62e86852bd7Anders Carlsson    /// member pointer in base class.
18031a31a18db9d657751f38c724adc0d62e86852bd7Anders Carlsson    CK_DerivedToBaseMemberPointer,
1804c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
18051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    /// CK_UserDefinedConversion - Conversion using a user defined type
180658d3f1af9b4efa426826816a16894986b78b2692Fariborz Jahanian    /// conversion function.
18077fe5d72fbc8605b60d42d32394248ea76cf763a0Fariborz Jahanian    CK_UserDefinedConversion,
18087fe5d72fbc8605b60d42d32394248ea76cf763a0Fariborz Jahanian
18097fe5d72fbc8605b60d42d32394248ea76cf763a0Fariborz Jahanian    /// CK_ConstructorConversion - Conversion by constructor
18107f9e646b7ed47bc8e9a60031ad0c2b55031e2077Anders Carlsson    CK_ConstructorConversion,
1811c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
18127f9e646b7ed47bc8e9a60031ad0c2b55031e2077Anders Carlsson    /// CK_IntegralToPointer - Integral to pointer
18137f9e646b7ed47bc8e9a60031ad0c2b55031e2077Anders Carlsson    CK_IntegralToPointer,
1814c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
18157f9e646b7ed47bc8e9a60031ad0c2b55031e2077Anders Carlsson    /// CK_PointerToIntegral - Pointer to integral
1816ebeaf2031c968143c531bfe232d7507f20c57347Anders Carlsson    CK_PointerToIntegral,
1817c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
1818ebeaf2031c968143c531bfe232d7507f20c57347Anders Carlsson    /// CK_ToVoid - Cast to void.
181916a8904f3f5ed19158657e1da95e5902fbee66f7Anders Carlsson    CK_ToVoid,
1820c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
182116a8904f3f5ed19158657e1da95e5902fbee66f7Anders Carlsson    /// CK_VectorSplat - Casting from an integer/floating type to an extended
1822c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    /// vector type with the same element type as the src type. Splats the
1823f67cea84bac1d3417f0baaf1fcbc86ee126e2d87Anders Carlsson    /// src expression into the destination expression.
182482debc7d282e723e58d183bfa89ddc2500a8daafAnders Carlsson    CK_VectorSplat,
1825c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
182682debc7d282e723e58d183bfa89ddc2500a8daafAnders Carlsson    /// CK_IntegralCast - Casting between integral types of different size.
182782debc7d282e723e58d183bfa89ddc2500a8daafAnders Carlsson    CK_IntegralCast,
182882debc7d282e723e58d183bfa89ddc2500a8daafAnders Carlsson
182982debc7d282e723e58d183bfa89ddc2500a8daafAnders Carlsson    /// CK_IntegralToFloating - Integral to floating point.
183082debc7d282e723e58d183bfa89ddc2500a8daafAnders Carlsson    CK_IntegralToFloating,
1831c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
183282debc7d282e723e58d183bfa89ddc2500a8daafAnders Carlsson    /// CK_FloatingToIntegral - Floating point to integral.
183382debc7d282e723e58d183bfa89ddc2500a8daafAnders Carlsson    CK_FloatingToIntegral,
1834c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
183582debc7d282e723e58d183bfa89ddc2500a8daafAnders Carlsson    /// CK_FloatingCast - Casting between floating types of different size.
1836bc0e0781da778bd5eb41a810419912893ae20448Anders Carlsson    CK_FloatingCast,
1837c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
1838bc0e0781da778bd5eb41a810419912893ae20448Anders Carlsson    /// CK_MemberPointerToBoolean - Member pointer to boolean
183992ef5d75720c032808181133e4d7c5f82230237eFariborz Jahanian    CK_MemberPointerToBoolean,
184092ef5d75720c032808181133e4d7c5f82230237eFariborz Jahanian
1841c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    /// CK_AnyPointerToObjCPointerCast - Casting any pointer to objective-c
184292ef5d75720c032808181133e4d7c5f82230237eFariborz Jahanian    /// pointer
18433b27f1a80e4e433b503efd344c909eeafaa9033cFariborz Jahanian    CK_AnyPointerToObjCPointerCast,
1844c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    /// CK_AnyPointerToBlockPointerCast - Casting any pointer to block
18453b27f1a80e4e433b503efd344c909eeafaa9033cFariborz Jahanian    /// pointer
18463b27f1a80e4e433b503efd344c909eeafaa9033cFariborz Jahanian    CK_AnyPointerToBlockPointerCast
1847bc0e0781da778bd5eb41a810419912893ae20448Anders Carlsson
1848cdef2b75aa60cde1ca00e0aa3f89139ac89c6ae4Anders Carlsson  };
18491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1850cdef2b75aa60cde1ca00e0aa3f89139ac89c6ae4Anders Carlssonprivate:
1851cdef2b75aa60cde1ca00e0aa3f89139ac89c6ae4Anders Carlsson  CastKind Kind;
18520835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis  Stmt *Op;
1853409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson
18547ab9d574d27ecee1f130e5755aa403e5ab529b6bAnders Carlsson  /// BasePath - For derived-to-base and base-to-derived casts, the base array
18557ab9d574d27ecee1f130e5755aa403e5ab529b6bAnders Carlsson  /// contains the inheritance path.
1856f1b48b7014992155286d58bb1676f9f51031d18bAnders Carlsson  CXXBaseSpecifierArray BasePath;
18577ab9d574d27ecee1f130e5755aa403e5ab529b6bAnders Carlsson
18587ab9d574d27ecee1f130e5755aa403e5ab529b6bAnders Carlsson  void CheckBasePath() const {
1859409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson#ifndef NDEBUG
1860409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson    switch (getCastKind()) {
18615cf86ba6b5a724bf91cb52feade1158f1fbeb605Anders Carlsson    case CK_DerivedToBase:
1862cee22421929c91b481f4d1bb85cd48c0f6b7510bAnders Carlsson    case CK_UncheckedDerivedToBase:
1863cee22421929c91b481f4d1bb85cd48c0f6b7510bAnders Carlsson    case CK_DerivedToBaseMemberPointer:
1864409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson    case CK_BaseToDerived:
1865409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson    case CK_BaseToDerivedMemberPointer:
1866f9d68e1dd015972318b2448f75115ff4fc3d5008Anders Carlsson      assert(!BasePath.empty() && "Cast kind should have a base path!");
1867f9d68e1dd015972318b2448f75115ff4fc3d5008Anders Carlsson      break;
1868409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson
1869409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson    // These should not have an inheritance path.
1870409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson    case CK_Unknown:
1871409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson    case CK_BitCast:
1872409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson    case CK_NoOp:
1873409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson    case CK_Dynamic:
1874409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson    case CK_ToUnion:
1875409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson    case CK_ArrayToPointerDecay:
1876409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson    case CK_FunctionToPointerDecay:
1877409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson    case CK_NullToMemberPointer:
1878409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson    case CK_UserDefinedConversion:
1879409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson    case CK_ConstructorConversion:
1880409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson    case CK_IntegralToPointer:
1881409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson    case CK_PointerToIntegral:
1882409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson    case CK_ToVoid:
1883409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson    case CK_VectorSplat:
1884409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson    case CK_IntegralCast:
1885409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson    case CK_IntegralToFloating:
1886409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson    case CK_FloatingToIntegral:
1887409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson    case CK_FloatingCast:
1888409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson    case CK_MemberPointerToBoolean:
1889409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson    case CK_AnyPointerToObjCPointerCast:
1890409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson    case CK_AnyPointerToBlockPointerCast:
18915cf86ba6b5a724bf91cb52feade1158f1fbeb605Anders Carlsson      assert(BasePath.empty() && "Cast kind should not have a base path!");
1892409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson      break;
1893409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson    }
1894409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson#endif
1895409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson  }
1896409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson
18970835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidisprotected:
1898409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson  CastExpr(StmtClass SC, QualType ty, const CastKind kind, Expr *op,
1899f1b48b7014992155286d58bb1676f9f51031d18bAnders Carlsson           CXXBaseSpecifierArray BasePath) :
1900898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor    Expr(SC, ty,
1901898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor         // Cast expressions are type-dependent if the type is
1902898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor         // dependent (C++ [temp.dep.expr]p3).
1903898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor         ty->isDependentType(),
1904898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor         // Cast expressions are value-dependent if the type is
1905898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor         // dependent or if the subexpression is value-dependent.
19061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump         ty->isDependentType() || (op && op->isValueDependent())),
19077ab9d574d27ecee1f130e5755aa403e5ab529b6bAnders Carlsson    Kind(kind), Op(op), BasePath(BasePath) {
19087ab9d574d27ecee1f130e5755aa403e5ab529b6bAnders Carlsson      CheckBasePath();
1909409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson    }
19101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1911087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor  /// \brief Construct an empty cast.
19121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  CastExpr(StmtClass SC, EmptyShell Empty)
1913087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor    : Expr(SC, Empty) { }
19141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1915a3bddeda81ca784bed5501d79e1e7c53befaa91dAnders Carlsson  virtual void DoDestroy(ASTContext &C);
1916a3bddeda81ca784bed5501d79e1e7c53befaa91dAnders Carlsson
19170835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidispublic:
1918cdef2b75aa60cde1ca00e0aa3f89139ac89c6ae4Anders Carlsson  CastKind getCastKind() const { return Kind; }
1919cdef2b75aa60cde1ca00e0aa3f89139ac89c6ae4Anders Carlsson  void setCastKind(CastKind K) { Kind = K; }
1920f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson  const char *getCastKindName() const;
1921f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson
19220835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis  Expr *getSubExpr() { return cast<Expr>(Op); }
19230835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis  const Expr *getSubExpr() const { return cast<Expr>(Op); }
1924087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor  void setSubExpr(Expr *E) { Op = E; }
1925087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor
19266eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor  /// \brief Retrieve the cast subexpression as it was written in the source
19276eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor  /// code, looking through any implicit casts or other intermediate nodes
19286eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor  /// introduced by semantic analysis.
19296eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor  Expr *getSubExprAsWritten();
19306eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor  const Expr *getSubExprAsWritten() const {
19316eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor    return const_cast<CastExpr *>(this)->getSubExprAsWritten();
19326eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor  }
193341b2dcd465f1e438502c420effc9d0c747f9db8fAnders Carlsson
1934fc89c31a329eb6b36c6dbd8b7cb945d1a831650eAnders Carlsson  const CXXBaseSpecifierArray& getBasePath() const { return BasePath; }
193541b2dcd465f1e438502c420effc9d0c747f9db8fAnders Carlsson
19361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
19374bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt    return T->getStmtClass() >= firstCastExprConstant &&
19384bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt           T->getStmtClass() <= lastCastExprConstant;
19390835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis  }
19400835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis  static bool classof(const CastExpr *) { return true; }
19411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
19420835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis  // Iterators
19430835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis  virtual child_iterator child_begin();
19440835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis  virtual child_iterator child_end();
19450835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis};
19460835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis
194749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// ImplicitCastExpr - Allows us to explicitly represent implicit type
194849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// conversions, which have no direct representation in the original
194949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// source code. For example: converting T[]->T*, void f()->void
195049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// (*f)(), float->double, short->int, etc.
195149b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff///
1952bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// In C, implicit casts always produce rvalues. However, in C++, an
1953bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// implicit cast whose result is being bound to a reference will be
1954bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// an lvalue. For example:
1955bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor///
1956bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// @code
1957bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// class Base { };
1958bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// class Derived : public Base { };
19591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// void f(Derived d) {
1960bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor///   Base& b = d; // initializer is an ImplicitCastExpr to an lvalue of type Base
1961bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// }
1962bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// @endcode
19630835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidisclass ImplicitCastExpr : public CastExpr {
1964eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor  /// LvalueCast - Whether this cast produces an lvalue.
1965eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor  bool LvalueCast;
1966eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor
196749b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroffpublic:
1968c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  ImplicitCastExpr(QualType ty, CastKind kind, Expr *op,
1969f1b48b7014992155286d58bb1676f9f51031d18bAnders Carlsson                   CXXBaseSpecifierArray BasePath, bool Lvalue)
1970c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    : CastExpr(ImplicitCastExprClass, ty, kind, op, BasePath),
19717ab9d574d27ecee1f130e5755aa403e5ab529b6bAnders Carlsson    LvalueCast(Lvalue) { }
197290045e8ebabf50d6f1b3a67081a621b20b5e5341Steve Naroff
1973087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor  /// \brief Construct an empty implicit cast.
19741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  explicit ImplicitCastExpr(EmptyShell Shell)
1975087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor    : CastExpr(ImplicitCastExprClass, Shell) { }
1976087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor
19770835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis  virtual SourceRange getSourceRange() const {
19780835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis    return getSubExpr()->getSourceRange();
19790835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis  }
198090045e8ebabf50d6f1b3a67081a621b20b5e5341Steve Naroff
1981eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor  /// isLvalueCast - Whether this cast produces an lvalue.
1982eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor  bool isLvalueCast() const { return LvalueCast; }
1983eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor
1984eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor  /// setLvalueCast - Set whether this cast produces an lvalue.
1985eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor  void setLvalueCast(bool Lvalue) { LvalueCast = Lvalue; }
1986eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor
19871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
19881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == ImplicitCastExprClass;
198949b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff  }
199049b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff  static bool classof(const ImplicitCastExpr *) { return true; }
199149b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff};
199249b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff
199349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// ExplicitCastExpr - An explicit cast written in the source
19941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// code.
199549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor///
199649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// This class is effectively an abstract class, because it provides
199749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// the basic representation of an explicitly-written cast without
199849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// specifying which kind of cast (C cast, functional cast, static
199949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// cast, etc.) was written; specific derived classes represent the
200049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// particular style of cast and its location information.
20015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
200249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// Unlike implicit casts, explicit cast nodes have two different
200349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// types: the type that was written into the source code, and the
200449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// actual type of the expression as determined by semantic
200549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// analysis. These types may differ slightly. For example, in C++ one
200649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// can cast to a reference type, which indicates that the resulting
200749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// expression will be an lvalue. The reference type, however, will
200849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// not be used as the type of the expression.
20090835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidisclass ExplicitCastExpr : public CastExpr {
20109d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall  /// TInfo - Source type info for the (written) type
20119d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall  /// this expression is casting to.
20129d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall  TypeSourceInfo *TInfo;
201349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor
201449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregorprotected:
2015c0a2fd8f092722c8f78b566ac4506a21437040e9Anders Carlsson  ExplicitCastExpr(StmtClass SC, QualType exprTy, CastKind kind,
201641b2dcd465f1e438502c420effc9d0c747f9db8fAnders Carlsson                   Expr *op, CXXBaseSpecifierArray BasePath,
201741b2dcd465f1e438502c420effc9d0c747f9db8fAnders Carlsson                   TypeSourceInfo *writtenTy)
201841b2dcd465f1e438502c420effc9d0c747f9db8fAnders Carlsson    : CastExpr(SC, exprTy, kind, op, BasePath), TInfo(writtenTy) {}
201949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor
2020db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor  /// \brief Construct an empty explicit cast.
20211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ExplicitCastExpr(StmtClass SC, EmptyShell Shell)
2022db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor    : CastExpr(SC, Shell) { }
2023db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor
202449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregorpublic:
20259d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall  /// getTypeInfoAsWritten - Returns the type source info for the type
20269d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall  /// that this expression is casting to.
20279d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall  TypeSourceInfo *getTypeInfoAsWritten() const { return TInfo; }
20289d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall  void setTypeInfoAsWritten(TypeSourceInfo *writtenTy) { TInfo = writtenTy; }
20299d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall
203049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  /// getTypeAsWritten - Returns the type that this expression is
203149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  /// casting to, as written in the source code.
20329d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall  QualType getTypeAsWritten() const { return TInfo->getType(); }
203349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor
20341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
20354bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt     return T->getStmtClass() >= firstExplicitCastExprConstant &&
20364bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt            T->getStmtClass() <= lastExplicitCastExprConstant;
203749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  }
203849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  static bool classof(const ExplicitCastExpr *) { return true; }
203949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor};
204049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor
20416eec8e883de118b431e3ead5b1e604a6ac68ff6bDouglas Gregor/// CStyleCastExpr - An explicit cast in C (C99 6.5.4) or a C-style
204249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// cast in C++ (C++ [expr.cast]), which uses the syntax
204349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// (Type)expr. For example: @c (int)f.
20446eec8e883de118b431e3ead5b1e604a6ac68ff6bDouglas Gregorclass CStyleCastExpr : public ExplicitCastExpr {
2045b2f9e516327310d95840d442416084508f80c183Steve Naroff  SourceLocation LPLoc; // the location of the left paren
2046b2f9e516327310d95840d442416084508f80c183Steve Naroff  SourceLocation RPLoc; // the location of the right paren
20475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
20489d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall  CStyleCastExpr(QualType exprTy, CastKind kind, Expr *op,
204941b2dcd465f1e438502c420effc9d0c747f9db8fAnders Carlsson                 CXXBaseSpecifierArray BasePath, TypeSourceInfo *writtenTy,
205041b2dcd465f1e438502c420effc9d0c747f9db8fAnders Carlsson                 SourceLocation l, SourceLocation r)
205141b2dcd465f1e438502c420effc9d0c747f9db8fAnders Carlsson    : ExplicitCastExpr(CStyleCastExprClass, exprTy, kind, op, BasePath,
205241b2dcd465f1e438502c420effc9d0c747f9db8fAnders Carlsson                       writtenTy), LPLoc(l), RPLoc(r) {}
205349b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff
2054db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor  /// \brief Construct an empty C-style explicit cast.
20551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  explicit CStyleCastExpr(EmptyShell Shell)
2056db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor    : ExplicitCastExpr(CStyleCastExprClass, Shell) { }
2057db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor
2058b2f9e516327310d95840d442416084508f80c183Steve Naroff  SourceLocation getLParenLoc() const { return LPLoc; }
2059db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor  void setLParenLoc(SourceLocation L) { LPLoc = L; }
2060db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor
2061b2f9e516327310d95840d442416084508f80c183Steve Naroff  SourceLocation getRParenLoc() const { return RPLoc; }
2062db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor  void setRParenLoc(SourceLocation L) { RPLoc = L; }
2063db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor
20645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  virtual SourceRange getSourceRange() const {
2065b2f9e516327310d95840d442416084508f80c183Steve Naroff    return SourceRange(LPLoc, getSubExpr()->getSourceRange().getEnd());
20665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
20671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
20681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == CStyleCastExprClass;
20695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
20706eec8e883de118b431e3ead5b1e604a6ac68ff6bDouglas Gregor  static bool classof(const CStyleCastExpr *) { return true; }
20715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
20725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
20733fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// \brief A builtin binary operation expression such as "x + y" or "x <= y".
20743fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor///
20753fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// This expression node kind describes a builtin binary operation,
20763fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// such as "x + y" for integer values "x" and "y". The operands will
20773fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// already have been converted to appropriate types (e.g., by
20783fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// performing promotions or conversions).
20793fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor///
20803fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// In C++, where operators may be overloaded, a different kind of
20813fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// expression node (CXXOperatorCallExpr) is used to express the
20823fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// invocation of an overloaded operator with operator syntax. Within
20833fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// a C++ template, whether BinaryOperator or CXXOperatorCallExpr is
20843fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// used to store an expression "x + y" depends on the subexpressions
20853fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// for x and y. If neither x or y is type-dependent, and the "+"
20863fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// operator resolves to a built-in operation, BinaryOperator will be
20873fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// used to express the computation (x and y may still be
20883fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// value-dependent). If either x or y is type-dependent, or if the
20893fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// "+" resolves to an overloaded operator, CXXOperatorCallExpr will
20903fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// be used to express the computation.
20915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass BinaryOperator : public Expr {
20925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
20935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  enum Opcode {
20945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    // Operators listed in order of precedence.
209503d6fb99224c36935c9af9f4785cb33453c99b2bChris Lattner    // Note that additions to this should also update the StmtVisitor class.
2096224605064a4ef87d1c3d35ad1cb363f8b534012bSebastian Redl    PtrMemD, PtrMemI, // [C++ 5.5] Pointer-to-member operators.
20975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Mul, Div, Rem,    // [C99 6.5.5] Multiplicative operators.
20985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Add, Sub,         // [C99 6.5.6] Additive operators.
20995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Shl, Shr,         // [C99 6.5.7] Bitwise shift operators.
21005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    LT, GT, LE, GE,   // [C99 6.5.8] Relational operators.
21015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    EQ, NE,           // [C99 6.5.9] Equality operators.
21025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    And,              // [C99 6.5.10] Bitwise AND operator.
21035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Xor,              // [C99 6.5.11] Bitwise XOR operator.
21045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Or,               // [C99 6.5.12] Bitwise OR operator.
21055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    LAnd,             // [C99 6.5.13] Logical AND operator.
21065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    LOr,              // [C99 6.5.14] Logical OR operator.
21075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Assign, MulAssign,// [C99 6.5.16] Assignment operators.
21085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    DivAssign, RemAssign,
21095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    AddAssign, SubAssign,
21105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    ShlAssign, ShrAssign,
21115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    AndAssign, XorAssign,
21125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    OrAssign,
21135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Comma             // [C99 6.5.17] Comma operator.
21145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  };
211517d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattnerprivate:
211617d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner  enum { LHS, RHS, END_EXPR };
21175549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Stmt* SubExprs[END_EXPR];
211817d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner  Opcode Opc;
211917d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner  SourceLocation OpLoc;
21201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumppublic:
21211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
212217d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner  BinaryOperator(Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy,
212317d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner                 SourceLocation opLoc)
2124898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor    : Expr(BinaryOperatorClass, ResTy,
2125898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor           lhs->isTypeDependent() || rhs->isTypeDependent(),
21261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump           lhs->isValueDependent() || rhs->isValueDependent()),
2127898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor      Opc(opc), OpLoc(opLoc) {
21281237c673c07f9d827129ba02720108816abde562Ted Kremenek    SubExprs[LHS] = lhs;
21291237c673c07f9d827129ba02720108816abde562Ted Kremenek    SubExprs[RHS] = rhs;
21301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    assert(!isCompoundAssignmentOp() &&
21315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer           "Use ArithAssignBinaryOperator for compound assignments");
21325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
21335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
2134db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor  /// \brief Construct an empty binary operator.
21351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  explicit BinaryOperator(EmptyShell Empty)
2136db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor    : Expr(BinaryOperatorClass, Empty), Opc(Comma) { }
2137db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor
213817d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner  SourceLocation getOperatorLoc() const { return OpLoc; }
2139db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor  void setOperatorLoc(SourceLocation L) { OpLoc = L; }
2140db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor
21415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  Opcode getOpcode() const { return Opc; }
2142db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor  void setOpcode(Opcode O) { Opc = O; }
2143db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor
21445549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); }
2145db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor  void setLHS(Expr *E) { SubExprs[LHS] = E; }
21465549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); }
2147db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor  void setRHS(Expr *E) { SubExprs[RHS] = E; }
2148db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor
21495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  virtual SourceRange getSourceRange() const {
21505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return SourceRange(getLHS()->getLocStart(), getRHS()->getLocEnd());
21515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
21521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
21535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// getOpcodeStr - Turn an Opcode enum value into the punctuation char it
21545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// corresponds to, e.g. "<<=".
21555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static const char *getOpcodeStr(Opcode Op);
21565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
2157063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor  /// \brief Retrieve the binary opcode that corresponds to the given
2158063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor  /// overloaded operator.
2159063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor  static Opcode getOverloadedOpcode(OverloadedOperatorKind OO);
2160063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor
2161063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor  /// \brief Retrieve the overloaded operator kind that corresponds to
2162063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor  /// the given binary opcode.
2163063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor  static OverloadedOperatorKind getOverloadedOperator(Opcode Opc);
2164063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor
21655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// predicates to categorize the respective opcodes.
21665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isMultiplicativeOp() const { return Opc >= Mul && Opc <= Rem; }
21675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isAdditiveOp() const { return Opc == Add || Opc == Sub; }
216840a5ef90ac8d3f29bc8fe4ff80e00eaf3ef5b79fTed Kremenek  static bool isShiftOp(Opcode Opc) { return Opc == Shl || Opc == Shr; }
216940a5ef90ac8d3f29bc8fe4ff80e00eaf3ef5b79fTed Kremenek  bool isShiftOp() const { return isShiftOp(Opc); }
2170aee3c9375f97a49edef2a36f15df6abd9748e2a1Sebastian Redl
2171aee3c9375f97a49edef2a36f15df6abd9748e2a1Sebastian Redl  static bool isBitwiseOp(Opcode Opc) { return Opc >= And && Opc <= Or; }
2172aee3c9375f97a49edef2a36f15df6abd9748e2a1Sebastian Redl  bool isBitwiseOp() const { return isBitwiseOp(Opc); }
2173f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek
2174f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek  static bool isRelationalOp(Opcode Opc) { return Opc >= LT && Opc <= GE; }
2175f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek  bool isRelationalOp() const { return isRelationalOp(Opc); }
2176f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek
21771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool isEqualityOp(Opcode Opc) { return Opc == EQ || Opc == NE; }
2178f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek  bool isEqualityOp() const { return isEqualityOp(Opc); }
21791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2180aee3c9375f97a49edef2a36f15df6abd9748e2a1Sebastian Redl  static bool isComparisonOp(Opcode Opc) { return Opc >= LT && Opc <= NE; }
2181aee3c9375f97a49edef2a36f15df6abd9748e2a1Sebastian Redl  bool isComparisonOp() const { return isComparisonOp(Opc); }
2182aee3c9375f97a49edef2a36f15df6abd9748e2a1Sebastian Redl
2183f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek  static bool isLogicalOp(Opcode Opc) { return Opc == LAnd || Opc == LOr; }
2184f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek  bool isLogicalOp() const { return isLogicalOp(Opc); }
2185f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek
21865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isAssignmentOp() const { return Opc >= Assign && Opc <= OrAssign; }
21875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isCompoundAssignmentOp() const { return Opc > Assign && Opc <= OrAssign;}
21885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isShiftAssignOp() const { return Opc == ShlAssign || Opc == ShrAssign; }
21891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
21901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *S) {
21914bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt    return S->getStmtClass() >= firstBinaryOperatorConstant &&
21924bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt           S->getStmtClass() <= lastBinaryOperatorConstant;
21935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
21945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const BinaryOperator *) { return true; }
21951237c673c07f9d827129ba02720108816abde562Ted Kremenek
21961237c673c07f9d827129ba02720108816abde562Ted Kremenek  // Iterators
21971237c673c07f9d827129ba02720108816abde562Ted Kremenek  virtual child_iterator child_begin();
21981237c673c07f9d827129ba02720108816abde562Ted Kremenek  virtual child_iterator child_end();
21991237c673c07f9d827129ba02720108816abde562Ted Kremenek
22005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprotected:
220117d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner  BinaryOperator(Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy,
22022333f7727f97018d6742e1e0938133bcfad967abEli Friedman                 SourceLocation opLoc, bool dead)
22032333f7727f97018d6742e1e0938133bcfad967abEli Friedman    : Expr(CompoundAssignOperatorClass, ResTy,
22042333f7727f97018d6742e1e0938133bcfad967abEli Friedman           lhs->isTypeDependent() || rhs->isTypeDependent(),
22052333f7727f97018d6742e1e0938133bcfad967abEli Friedman           lhs->isValueDependent() || rhs->isValueDependent()),
22062333f7727f97018d6742e1e0938133bcfad967abEli Friedman      Opc(opc), OpLoc(opLoc) {
22071237c673c07f9d827129ba02720108816abde562Ted Kremenek    SubExprs[LHS] = lhs;
22081237c673c07f9d827129ba02720108816abde562Ted Kremenek    SubExprs[RHS] = rhs;
22095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
2210ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor
22111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  BinaryOperator(StmtClass SC, EmptyShell Empty)
2212ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor    : Expr(SC, Empty), Opc(MulAssign) { }
22135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
22145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
22155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// CompoundAssignOperator - For compound assignments (e.g. +=), we keep
22165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// track of the type the operation is performed in.  Due to the semantics of
22175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// these operators, the operands are promoted, the aritmetic performed, an
22185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// implicit conversion back to the result type done, then the assignment takes
22195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// place.  This captures the intermediate type which the computation is done
22205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// in.
22215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass CompoundAssignOperator : public BinaryOperator {
2222ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman  QualType ComputationLHSType;
2223ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman  QualType ComputationResultType;
22245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
22255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  CompoundAssignOperator(Expr *lhs, Expr *rhs, Opcode opc,
2226ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman                         QualType ResType, QualType CompLHSType,
2227ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman                         QualType CompResultType,
222817d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner                         SourceLocation OpLoc)
222917d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner    : BinaryOperator(lhs, rhs, opc, ResType, OpLoc, true),
2230ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman      ComputationLHSType(CompLHSType),
2231ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman      ComputationResultType(CompResultType) {
22321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    assert(isCompoundAssignmentOp() &&
22335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer           "Only should be used for compound assignments");
22345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
22355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
2236ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor  /// \brief Build an empty compound assignment operator expression.
2237ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor  explicit CompoundAssignOperator(EmptyShell Empty)
2238ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor    : BinaryOperator(CompoundAssignOperatorClass, Empty) { }
2239ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor
2240ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman  // The two computation types are the type the LHS is converted
2241ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman  // to for the computation and the type of the result; the two are
2242ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman  // distinct in a few cases (specifically, int+=ptr and ptr-=ptr).
2243ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman  QualType getComputationLHSType() const { return ComputationLHSType; }
2244ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor  void setComputationLHSType(QualType T) { ComputationLHSType = T; }
2245ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor
2246ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman  QualType getComputationResultType() const { return ComputationResultType; }
2247ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor  void setComputationResultType(QualType T) { ComputationResultType = T; }
2248ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor
22495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const CompoundAssignOperator *) { return true; }
22501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *S) {
22511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return S->getStmtClass() == CompoundAssignOperatorClass;
22525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
22535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
22545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
22555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ConditionalOperator - The ?: operator.  Note that LHS may be null when the
22565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// GNU "missing LHS" extension is in use.
22575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
22585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass ConditionalOperator : public Expr {
22591237c673c07f9d827129ba02720108816abde562Ted Kremenek  enum { COND, LHS, RHS, END_EXPR };
22605549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Stmt* SubExprs[END_EXPR]; // Left/Middle/Right hand sides.
226147e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor  SourceLocation QuestionLoc, ColonLoc;
22625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
226347e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor  ConditionalOperator(Expr *cond, SourceLocation QLoc, Expr *lhs,
226447e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor                      SourceLocation CLoc, Expr *rhs, QualType t)
2265898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor    : Expr(ConditionalOperatorClass, t,
2266898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor           // FIXME: the type of the conditional operator doesn't
2267898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor           // depend on the type of the conditional, but the standard
2268898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor           // seems to imply that it could. File a bug!
2269898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor           ((lhs && lhs->isTypeDependent()) || (rhs && rhs->isTypeDependent())),
22701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump           (cond->isValueDependent() ||
2271898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor            (lhs && lhs->isValueDependent()) ||
227247e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor            (rhs && rhs->isValueDependent()))),
227347e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor      QuestionLoc(QLoc),
227447e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor      ColonLoc(CLoc) {
22751237c673c07f9d827129ba02720108816abde562Ted Kremenek    SubExprs[COND] = cond;
22761237c673c07f9d827129ba02720108816abde562Ted Kremenek    SubExprs[LHS] = lhs;
22771237c673c07f9d827129ba02720108816abde562Ted Kremenek    SubExprs[RHS] = rhs;
22781237c673c07f9d827129ba02720108816abde562Ted Kremenek  }
22795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
2280ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor  /// \brief Build an empty conditional operator.
2281ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor  explicit ConditionalOperator(EmptyShell Empty)
2282ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor    : Expr(ConditionalOperatorClass, Empty) { }
2283ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor
2284395a2abf0028968d85958610e393e067885dc14fTed Kremenek  // getCond - Return the expression representing the condition for
2285395a2abf0028968d85958610e393e067885dc14fTed Kremenek  //  the ?: operator.
22865549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getCond() const { return cast<Expr>(SubExprs[COND]); }
2287ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor  void setCond(Expr *E) { SubExprs[COND] = E; }
2288395a2abf0028968d85958610e393e067885dc14fTed Kremenek
2289395a2abf0028968d85958610e393e067885dc14fTed Kremenek  // getTrueExpr - Return the subexpression representing the value of the ?:
2290395a2abf0028968d85958610e393e067885dc14fTed Kremenek  //  expression if the condition evaluates to true.  In most cases this value
2291395a2abf0028968d85958610e393e067885dc14fTed Kremenek  //  will be the same as getLHS() except a GCC extension allows the left
2292395a2abf0028968d85958610e393e067885dc14fTed Kremenek  //  subexpression to be omitted, and instead of the condition be returned.
2293395a2abf0028968d85958610e393e067885dc14fTed Kremenek  //  e.g: x ?: y is shorthand for x ? x : y, except that the expression "x"
22941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  //  is only evaluated once.
2295395a2abf0028968d85958610e393e067885dc14fTed Kremenek  Expr *getTrueExpr() const {
22965549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek    return cast<Expr>(SubExprs[LHS] ? SubExprs[LHS] : SubExprs[COND]);
2297395a2abf0028968d85958610e393e067885dc14fTed Kremenek  }
22981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2299395a2abf0028968d85958610e393e067885dc14fTed Kremenek  // getTrueExpr - Return the subexpression representing the value of the ?:
2300395a2abf0028968d85958610e393e067885dc14fTed Kremenek  // expression if the condition evaluates to false. This is the same as getRHS.
23015549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getFalseExpr() const { return cast<Expr>(SubExprs[RHS]); }
23021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
23035549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getLHS() const { return cast_or_null<Expr>(SubExprs[LHS]); }
2304ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor  void setLHS(Expr *E) { SubExprs[LHS] = E; }
2305ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor
23065549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); }
2307ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor  void setRHS(Expr *E) { SubExprs[RHS] = E; }
23085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
230947e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor  SourceLocation getQuestionLoc() const { return QuestionLoc; }
231047e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor  void setQuestionLoc(SourceLocation L) { QuestionLoc = L; }
231147e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor
231247e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor  SourceLocation getColonLoc() const { return ColonLoc; }
231347e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor  void setColonLoc(SourceLocation L) { ColonLoc = L; }
231447e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor
23155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  virtual SourceRange getSourceRange() const {
23165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return SourceRange(getCond()->getLocStart(), getRHS()->getLocEnd());
23175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
23181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
23191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == ConditionalOperatorClass;
23205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
23215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const ConditionalOperator *) { return true; }
23221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
23231237c673c07f9d827129ba02720108816abde562Ted Kremenek  // Iterators
23241237c673c07f9d827129ba02720108816abde562Ted Kremenek  virtual child_iterator child_begin();
23251237c673c07f9d827129ba02720108816abde562Ted Kremenek  virtual child_iterator child_end();
23265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
23275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
23286481a57fefbf1a313ff439028470fe4c27a3b7a3Chris Lattner/// AddrLabelExpr - The GNU address of label extension, representing &&label.
23296481a57fefbf1a313ff439028470fe4c27a3b7a3Chris Lattnerclass AddrLabelExpr : public Expr {
23305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation AmpAmpLoc, LabelLoc;
23315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  LabelStmt *Label;
23325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
23336481a57fefbf1a313ff439028470fe4c27a3b7a3Chris Lattner  AddrLabelExpr(SourceLocation AALoc, SourceLocation LLoc, LabelStmt *L,
23346481a57fefbf1a313ff439028470fe4c27a3b7a3Chris Lattner                QualType t)
23352333f7727f97018d6742e1e0938133bcfad967abEli Friedman    : Expr(AddrLabelExprClass, t, false, false),
23362333f7727f97018d6742e1e0938133bcfad967abEli Friedman      AmpAmpLoc(AALoc), LabelLoc(LLoc), Label(L) {}
23371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
23387d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor  /// \brief Build an empty address of a label expression.
23391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  explicit AddrLabelExpr(EmptyShell Empty)
23407d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor    : Expr(AddrLabelExprClass, Empty) { }
23417d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor
23427d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor  SourceLocation getAmpAmpLoc() const { return AmpAmpLoc; }
23437d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor  void setAmpAmpLoc(SourceLocation L) { AmpAmpLoc = L; }
23447d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor  SourceLocation getLabelLoc() const { return LabelLoc; }
23457d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor  void setLabelLoc(SourceLocation L) { LabelLoc = L; }
23467d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor
23475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  virtual SourceRange getSourceRange() const {
23485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return SourceRange(AmpAmpLoc, LabelLoc);
23495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
23501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
23515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  LabelStmt *getLabel() const { return Label; }
23527d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor  void setLabel(LabelStmt *S) { Label = S; }
23537d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor
23545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Stmt *T) {
23551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == AddrLabelExprClass;
23565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
23576481a57fefbf1a313ff439028470fe4c27a3b7a3Chris Lattner  static bool classof(const AddrLabelExpr *) { return true; }
23581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
23591237c673c07f9d827129ba02720108816abde562Ted Kremenek  // Iterators
23601237c673c07f9d827129ba02720108816abde562Ted Kremenek  virtual child_iterator child_begin();
23611237c673c07f9d827129ba02720108816abde562Ted Kremenek  virtual child_iterator child_end();
23625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
2363ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner
2364ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner/// StmtExpr - This is the GNU Statement Expression extension: ({int X=4; X;}).
2365ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner/// The StmtExpr contains a single CompoundStmt node, which it evaluates and
2366ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner/// takes the value of the last subexpression.
2367ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattnerclass StmtExpr : public Expr {
23685549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Stmt *SubStmt;
2369ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner  SourceLocation LParenLoc, RParenLoc;
2370ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattnerpublic:
23712333f7727f97018d6742e1e0938133bcfad967abEli Friedman  // FIXME: Does type-dependence need to be computed differently?
2372d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff  StmtExpr(CompoundStmt *substmt, QualType T,
2373d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff           SourceLocation lp, SourceLocation rp) :
23742333f7727f97018d6742e1e0938133bcfad967abEli Friedman    Expr(StmtExprClass, T, T->isDependentType(), false),
23752333f7727f97018d6742e1e0938133bcfad967abEli Friedman    SubStmt(substmt), LParenLoc(lp), RParenLoc(rp) { }
23761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
23776a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor  /// \brief Build an empty statement expression.
23786a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor  explicit StmtExpr(EmptyShell Empty) : Expr(StmtExprClass, Empty) { }
23796a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor
23805549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  CompoundStmt *getSubStmt() { return cast<CompoundStmt>(SubStmt); }
23815549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  const CompoundStmt *getSubStmt() const { return cast<CompoundStmt>(SubStmt); }
23826a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor  void setSubStmt(CompoundStmt *S) { SubStmt = S; }
23836a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor
2384ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner  virtual SourceRange getSourceRange() const {
2385ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner    return SourceRange(LParenLoc, RParenLoc);
2386ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner  }
23871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2388026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner  SourceLocation getLParenLoc() const { return LParenLoc; }
23896a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor  void setLParenLoc(SourceLocation L) { LParenLoc = L; }
2390026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner  SourceLocation getRParenLoc() const { return RParenLoc; }
23916a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
23921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2393ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner  static bool classof(const Stmt *T) {
23941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == StmtExprClass;
2395ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner  }
2396ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner  static bool classof(const StmtExpr *) { return true; }
23971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
23981237c673c07f9d827129ba02720108816abde562Ted Kremenek  // Iterators
23991237c673c07f9d827129ba02720108816abde562Ted Kremenek  virtual child_iterator child_begin();
24001237c673c07f9d827129ba02720108816abde562Ted Kremenek  virtual child_iterator child_end();
2401ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner};
2402ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner
2403dc241b42c7588f99027b035a09b71557a6db219eDouglas Gregor/// TypesCompatibleExpr - GNU builtin-in function __builtin_types_compatible_p.
2404d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff/// This AST node represents a function that returns 1 if two *types* (not
2405d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff/// expressions) are compatible. The result of this built-in function can be
2406d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff/// used in integer constant expressions.
2407d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroffclass TypesCompatibleExpr : public Expr {
2408d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff  QualType Type1;
2409d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff  QualType Type2;
2410363bcff47df2fda3cfcfcd994b7888157df58c43Steve Naroff  SourceLocation BuiltinLoc, RParenLoc;
2411d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroffpublic:
24121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  TypesCompatibleExpr(QualType ReturnType, SourceLocation BLoc,
24131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                      QualType t1, QualType t2, SourceLocation RP) :
24142333f7727f97018d6742e1e0938133bcfad967abEli Friedman    Expr(TypesCompatibleExprClass, ReturnType, false, false),
24152333f7727f97018d6742e1e0938133bcfad967abEli Friedman    Type1(t1), Type2(t2), BuiltinLoc(BLoc), RParenLoc(RP) {}
2416d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff
241744cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  /// \brief Build an empty __builtin_type_compatible_p expression.
241844cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  explicit TypesCompatibleExpr(EmptyShell Empty)
241944cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor    : Expr(TypesCompatibleExprClass, Empty) { }
242044cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor
24217f28fe8e00ec4fac17977374d8da491f873a3b05Steve Naroff  QualType getArgType1() const { return Type1; }
242244cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  void setArgType1(QualType T) { Type1 = T; }
24237f28fe8e00ec4fac17977374d8da491f873a3b05Steve Naroff  QualType getArgType2() const { return Type2; }
242444cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  void setArgType2(QualType T) { Type2 = T; }
24251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
242644cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  SourceLocation getBuiltinLoc() const { return BuiltinLoc; }
242744cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  void setBuiltinLoc(SourceLocation L) { BuiltinLoc = L; }
24281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
242944cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  SourceLocation getRParenLoc() const { return RParenLoc; }
243044cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
24311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2432d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff  virtual SourceRange getSourceRange() const {
2433363bcff47df2fda3cfcfcd994b7888157df58c43Steve Naroff    return SourceRange(BuiltinLoc, RParenLoc);
2434d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff  }
2435d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff  static bool classof(const Stmt *T) {
24361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == TypesCompatibleExprClass;
2437d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff  }
2438d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff  static bool classof(const TypesCompatibleExpr *) { return true; }
24391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
24401237c673c07f9d827129ba02720108816abde562Ted Kremenek  // Iterators
24411237c673c07f9d827129ba02720108816abde562Ted Kremenek  virtual child_iterator child_begin();
24421237c673c07f9d827129ba02720108816abde562Ted Kremenek  virtual child_iterator child_end();
2443d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff};
2444d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff
2445d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// ShuffleVectorExpr - clang-specific builtin-in function
2446d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// __builtin_shufflevector.
2447d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// This AST node represents a operator that does a constant
2448d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// shuffle, similar to LLVM's shufflevector instruction. It takes
2449d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// two vectors and a variable number of constant indices,
2450d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// and returns the appropriately shuffled vector.
2451d38617c8a50f9729c254ab76cd359af797c6739bEli Friedmanclass ShuffleVectorExpr : public Expr {
2452d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  SourceLocation BuiltinLoc, RParenLoc;
2453d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman
2454d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  // SubExprs - the list of values passed to the __builtin_shufflevector
2455d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  // function. The first two are vectors, and the rest are constant
2456d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  // indices.  The number of values in this list is always
2457d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  // 2+the number of indices in the vector type.
24585549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Stmt **SubExprs;
2459d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  unsigned NumExprs;
2460d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman
2461888376a2bbcfc2f047902249f8455918e2489ae1Nate Begemanprotected:
24621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  virtual void DoDestroy(ASTContext &C);
2463888376a2bbcfc2f047902249f8455918e2489ae1Nate Begeman
2464d38617c8a50f9729c254ab76cd359af797c6739bEli Friedmanpublic:
24652333f7727f97018d6742e1e0938133bcfad967abEli Friedman  // FIXME: Can a shufflevector be value-dependent?  Does type-dependence need
24662333f7727f97018d6742e1e0938133bcfad967abEli Friedman  // to be computed differently?
2467a88dc3079bedf70a5cfc39791727e43a10383006Nate Begeman  ShuffleVectorExpr(ASTContext &C, Expr **args, unsigned nexpr,
24681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                    QualType Type, SourceLocation BLoc,
24691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                    SourceLocation RP) :
24702333f7727f97018d6742e1e0938133bcfad967abEli Friedman    Expr(ShuffleVectorExprClass, Type, Type->isDependentType(), false),
24712333f7727f97018d6742e1e0938133bcfad967abEli Friedman    BuiltinLoc(BLoc), RParenLoc(RP), NumExprs(nexpr) {
24721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2473a88dc3079bedf70a5cfc39791727e43a10383006Nate Begeman    SubExprs = new (C) Stmt*[nexpr];
2474d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman    for (unsigned i = 0; i < nexpr; i++)
2475d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman      SubExprs[i] = args[i];
2476d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  }
247794cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor
247894cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor  /// \brief Build an empty vector-shuffle expression.
24791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  explicit ShuffleVectorExpr(EmptyShell Empty)
248094cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor    : Expr(ShuffleVectorExprClass, Empty), SubExprs(0) { }
248194cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor
248294cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor  SourceLocation getBuiltinLoc() const { return BuiltinLoc; }
248394cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor  void setBuiltinLoc(SourceLocation L) { BuiltinLoc = L; }
24841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
248594cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor  SourceLocation getRParenLoc() const { return RParenLoc; }
248694cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
248794cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor
2488d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  virtual SourceRange getSourceRange() const {
2489d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman    return SourceRange(BuiltinLoc, RParenLoc);
2490d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  }
2491d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  static bool classof(const Stmt *T) {
24921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == ShuffleVectorExprClass;
2493d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  }
2494d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  static bool classof(const ShuffleVectorExpr *) { return true; }
24951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2496888376a2bbcfc2f047902249f8455918e2489ae1Nate Begeman  ~ShuffleVectorExpr() {}
24971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2498d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  /// getNumSubExprs - Return the size of the SubExprs array.  This includes the
2499d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  /// constant expression, the actual arguments passed in, and the function
2500d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  /// pointers.
2501d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  unsigned getNumSubExprs() const { return NumExprs; }
25021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2503d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  /// getExpr - Return the Expr at the specified index.
2504d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  Expr *getExpr(unsigned Index) {
2505d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman    assert((Index < NumExprs) && "Arg access out of range!");
25065549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek    return cast<Expr>(SubExprs[Index]);
2507d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  }
2508d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  const Expr *getExpr(unsigned Index) const {
2509d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman    assert((Index < NumExprs) && "Arg access out of range!");
25105549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek    return cast<Expr>(SubExprs[Index]);
2511d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  }
25121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2513888376a2bbcfc2f047902249f8455918e2489ae1Nate Begeman  void setExprs(ASTContext &C, Expr ** Exprs, unsigned NumExprs);
251494cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor
2515dde8c94873976632e3ada4d8d067e1e244184d51Eli Friedman  unsigned getShuffleMaskIdx(ASTContext &Ctx, unsigned N) {
2516dde8c94873976632e3ada4d8d067e1e244184d51Eli Friedman    assert((N < NumExprs - 2) && "Shuffle idx out of range!");
25179a901bb63990574ff0bcc12ff851d7a71cff8ddbEli Friedman    return getExpr(N+2)->EvaluateAsInt(Ctx).getZExtValue();
2518d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  }
25191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2520d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  // Iterators
2521d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  virtual child_iterator child_begin();
2522d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  virtual child_iterator child_end();
2523d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman};
2524d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman
2525d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff/// ChooseExpr - GNU builtin-in function __builtin_choose_expr.
25261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// This AST node is similar to the conditional operator (?:) in C, with
2527d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff/// the following exceptions:
25287976932a1c256d447316ffac58e9821417725e34Eli Friedman/// - the test expression must be a integer constant expression.
25297976932a1c256d447316ffac58e9821417725e34Eli Friedman/// - the expression returned acts like the chosen subexpression in every
25307976932a1c256d447316ffac58e9821417725e34Eli Friedman///   visible way: the type is the same as that of the chosen subexpression,
25317976932a1c256d447316ffac58e9821417725e34Eli Friedman///   and all predicates (whether it's an l-value, whether it's an integer
25327976932a1c256d447316ffac58e9821417725e34Eli Friedman///   constant expression, etc.) return the same result as for the chosen
25337976932a1c256d447316ffac58e9821417725e34Eli Friedman///   sub-expression.
2534d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroffclass ChooseExpr : public Expr {
25351237c673c07f9d827129ba02720108816abde562Ted Kremenek  enum { COND, LHS, RHS, END_EXPR };
25365549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Stmt* SubExprs[END_EXPR]; // Left/Middle/Right hand sides.
2537d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff  SourceLocation BuiltinLoc, RParenLoc;
2538d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroffpublic:
2539d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff  ChooseExpr(SourceLocation BLoc, Expr *cond, Expr *lhs, Expr *rhs, QualType t,
2540ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor             SourceLocation RP, bool TypeDependent, bool ValueDependent)
2541ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor    : Expr(ChooseExprClass, t, TypeDependent, ValueDependent),
25421237c673c07f9d827129ba02720108816abde562Ted Kremenek      BuiltinLoc(BLoc), RParenLoc(RP) {
25431237c673c07f9d827129ba02720108816abde562Ted Kremenek      SubExprs[COND] = cond;
25441237c673c07f9d827129ba02720108816abde562Ted Kremenek      SubExprs[LHS] = lhs;
25451237c673c07f9d827129ba02720108816abde562Ted Kremenek      SubExprs[RHS] = rhs;
25461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    }
25477976932a1c256d447316ffac58e9821417725e34Eli Friedman
254844cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  /// \brief Build an empty __builtin_choose_expr.
254944cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  explicit ChooseExpr(EmptyShell Empty) : Expr(ChooseExprClass, Empty) { }
255044cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor
25517976932a1c256d447316ffac58e9821417725e34Eli Friedman  /// isConditionTrue - Return whether the condition is true (i.e. not
25527976932a1c256d447316ffac58e9821417725e34Eli Friedman  /// equal to zero).
255327437caadea35f84d550cd29f024fcf3ea240eecChris Lattner  bool isConditionTrue(ASTContext &C) const;
25547976932a1c256d447316ffac58e9821417725e34Eli Friedman
25557976932a1c256d447316ffac58e9821417725e34Eli Friedman  /// getChosenSubExpr - Return the subexpression chosen according to the
25567976932a1c256d447316ffac58e9821417725e34Eli Friedman  /// condition.
25577976932a1c256d447316ffac58e9821417725e34Eli Friedman  Expr *getChosenSubExpr(ASTContext &C) const {
25587976932a1c256d447316ffac58e9821417725e34Eli Friedman    return isConditionTrue(C) ? getLHS() : getRHS();
25597976932a1c256d447316ffac58e9821417725e34Eli Friedman  }
25607976932a1c256d447316ffac58e9821417725e34Eli Friedman
25615549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getCond() const { return cast<Expr>(SubExprs[COND]); }
256244cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  void setCond(Expr *E) { SubExprs[COND] = E; }
25635549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); }
256444cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  void setLHS(Expr *E) { SubExprs[LHS] = E; }
25655549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); }
256644cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  void setRHS(Expr *E) { SubExprs[RHS] = E; }
256744cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor
256844cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  SourceLocation getBuiltinLoc() const { return BuiltinLoc; }
256944cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  void setBuiltinLoc(SourceLocation L) { BuiltinLoc = L; }
25701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
257144cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  SourceLocation getRParenLoc() const { return RParenLoc; }
257244cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
25731237c673c07f9d827129ba02720108816abde562Ted Kremenek
2574d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff  virtual SourceRange getSourceRange() const {
2575d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff    return SourceRange(BuiltinLoc, RParenLoc);
2576d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff  }
2577d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff  static bool classof(const Stmt *T) {
25781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == ChooseExprClass;
2579d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff  }
2580d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff  static bool classof(const ChooseExpr *) { return true; }
25811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
25821237c673c07f9d827129ba02720108816abde562Ted Kremenek  // Iterators
25831237c673c07f9d827129ba02720108816abde562Ted Kremenek  virtual child_iterator child_begin();
25841237c673c07f9d827129ba02720108816abde562Ted Kremenek  virtual child_iterator child_end();
2585d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff};
2586d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff
25872d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// GNUNullExpr - Implements the GNU __null extension, which is a name
25882d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// for a null pointer constant that has integral type (e.g., int or
25892d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// long) and is the same size and alignment as a pointer. The __null
25902d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// extension is typically only used by system headers, which define
25912d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// NULL as __null in C++ rather than using 0 (which is an integer
25922d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// that may not match the size of a pointer).
25932d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregorclass GNUNullExpr : public Expr {
25942d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor  /// TokenLoc - The location of the __null keyword.
25952d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor  SourceLocation TokenLoc;
25962d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor
25972d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregorpublic:
25981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  GNUNullExpr(QualType Ty, SourceLocation Loc)
25992333f7727f97018d6742e1e0938133bcfad967abEli Friedman    : Expr(GNUNullExprClass, Ty, false, false), TokenLoc(Loc) { }
26002d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor
260144cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  /// \brief Build an empty GNU __null expression.
260244cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  explicit GNUNullExpr(EmptyShell Empty) : Expr(GNUNullExprClass, Empty) { }
260344cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor
26042d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor  /// getTokenLocation - The location of the __null token.
26052d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor  SourceLocation getTokenLocation() const { return TokenLoc; }
260644cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  void setTokenLocation(SourceLocation L) { TokenLoc = L; }
26072d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor
26082d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor  virtual SourceRange getSourceRange() const {
26092d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor    return SourceRange(TokenLoc);
26102d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor  }
26112d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor  static bool classof(const Stmt *T) {
26121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == GNUNullExprClass;
26132d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor  }
26142d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor  static bool classof(const GNUNullExpr *) { return true; }
26151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
26162d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor  // Iterators
26172d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor  virtual child_iterator child_begin();
26182d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor  virtual child_iterator child_end();
26192d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor};
26202d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor
262174626d6ef2e194fcc911e071556660ff331eb4a8Zhongxing Xu/// VAArgExpr, used for the builtin function __builtin_va_arg.
26227c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlssonclass VAArgExpr : public Expr {
26235549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Stmt *Val;
26247c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson  SourceLocation BuiltinLoc, RParenLoc;
26257c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlssonpublic:
26267c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson  VAArgExpr(SourceLocation BLoc, Expr* e, QualType t, SourceLocation RPLoc)
26272333f7727f97018d6742e1e0938133bcfad967abEli Friedman    : Expr(VAArgExprClass, t, t->isDependentType(), false),
26287c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson      Val(e),
26297c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson      BuiltinLoc(BLoc),
26307c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson      RParenLoc(RPLoc) { }
26311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
263274626d6ef2e194fcc911e071556660ff331eb4a8Zhongxing Xu  /// \brief Create an empty __builtin_va_arg expression.
2633d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor  explicit VAArgExpr(EmptyShell Empty) : Expr(VAArgExprClass, Empty) { }
2634d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor
26355549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  const Expr *getSubExpr() const { return cast<Expr>(Val); }
26365549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getSubExpr() { return cast<Expr>(Val); }
2637d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor  void setSubExpr(Expr *E) { Val = E; }
2638d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor
2639d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor  SourceLocation getBuiltinLoc() const { return BuiltinLoc; }
2640d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor  void setBuiltinLoc(SourceLocation L) { BuiltinLoc = L; }
26411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2642d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor  SourceLocation getRParenLoc() const { return RParenLoc; }
2643d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
2644d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor
26457c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson  virtual SourceRange getSourceRange() const {
26467c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson    return SourceRange(BuiltinLoc, RParenLoc);
26471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  }
26487c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson  static bool classof(const Stmt *T) {
26497c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson    return T->getStmtClass() == VAArgExprClass;
26507c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson  }
26517c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson  static bool classof(const VAArgExpr *) { return true; }
26521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
26537c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson  // Iterators
26547c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson  virtual child_iterator child_begin();
26551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  virtual child_iterator child_end();
26567c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson};
26571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
26584c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// @brief Describes an C or C++ initializer list.
26594c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor///
26604c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// InitListExpr describes an initializer list, which can be used to
26614c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// initialize objects of different types, including
26624c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// struct/class/union types, arrays, and vectors. For example:
26634c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor///
26644c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// @code
26654c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// struct foo x = { 1, { 2, 3 } };
26664c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// @endcode
2667196ef51bc4d008ec1c69851fb3b0f8d036065931Chris Lattner///
26684c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// Prior to semantic analysis, an initializer list will represent the
26694c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// initializer list as written by the user, but will have the
26704c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// placeholder type "void". This initializer list is called the
26714c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// syntactic form of the initializer, and may contain C99 designated
26724c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// initializers (represented as DesignatedInitExprs), initializations
26734c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// of subobject members without explicit braces, and so on. Clients
26744c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// interested in the original syntax of the initializer list should
26754c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// use the syntactic form of the initializer list.
2676196ef51bc4d008ec1c69851fb3b0f8d036065931Chris Lattner///
26774c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// After semantic analysis, the initializer list will represent the
26784c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// semantic form of the initializer, where the initializations of all
26794c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// subobjects are made explicit with nested InitListExpr nodes and
26804c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// C99 designators have been eliminated by placing the designated
26814c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// initializations into the subobject they initialize. Additionally,
26824c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// any "holes" in the initialization, where no initializer has been
26834c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// specified for a particular subobject, will be replaced with
26843498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor/// implicitly-generated ImplicitValueInitExpr expressions that
26854c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// value-initialize the subobjects. Note, however, that the
26864c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// initializer lists may still have fewer initializers than there are
26874c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// elements to initialize within the object.
2688196ef51bc4d008ec1c69851fb3b0f8d036065931Chris Lattner///
26894c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// Given the semantic form of the initializer list, one can retrieve
26904c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// the original syntactic form of that initializer list (if it
26914c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// exists) using getSyntacticForm(). Since many initializer lists
26924c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// have the same syntactic and semantic forms, getSyntacticForm() may
26934c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// return NULL, indicating that the current initializer list also
26944c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// serves as its syntactic form.
269566b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlssonclass InitListExpr : public Expr {
2696ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek  // FIXME: Eliminate this vector in favor of ASTContext allocation
2697709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek  typedef ASTVector<Stmt *> InitExprsTy;
2698709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek  InitExprsTy InitExprs;
269966b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson  SourceLocation LBraceLoc, RBraceLoc;
27001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
27014c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  /// Contains the initializer list that describes the syntactic form
27024c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  /// written in the source code.
27034c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  InitListExpr *SyntacticForm;
27044c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor
27050bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor  /// If this initializer list initializes a union, specifies which
27060bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor  /// field within the union will be initialized.
27070bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor  FieldDecl *UnionFieldInit;
27080bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor
2709a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor  /// Whether this initializer list originally had a GNU array-range
2710a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor  /// designator in it. This is a temporary marker used by CodeGen.
2711a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor  bool HadArrayRangeDesignator;
2712a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor
271366b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlssonpublic:
2714709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek  InitListExpr(ASTContext &C, SourceLocation lbraceloc,
2715709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek               Expr **initexprs, unsigned numinits,
2716ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek               SourceLocation rbraceloc);
2717d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor
2718d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  /// \brief Build an empty initializer list.
2719709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek  explicit InitListExpr(ASTContext &C, EmptyShell Empty)
2720709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek    : Expr(InitListExprClass, Empty), InitExprs(C) { }
27211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2722ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek  unsigned getNumInits() const { return InitExprs.size(); }
27231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
27241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  const Expr* getInit(unsigned Init) const {
2725c5ae899b4bbf65488445316c63168079177db0edSteve Naroff    assert(Init < getNumInits() && "Initializer access out of range!");
27264c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor    return cast_or_null<Expr>(InitExprs[Init]);
272766b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson  }
27281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
27291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  Expr* getInit(unsigned Init) {
2730c5ae899b4bbf65488445316c63168079177db0edSteve Naroff    assert(Init < getNumInits() && "Initializer access out of range!");
27314c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor    return cast_or_null<Expr>(InitExprs[Init]);
273266b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson  }
27331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
27341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  void setInit(unsigned Init, Expr *expr) {
2735c5ae899b4bbf65488445316c63168079177db0edSteve Naroff    assert(Init < getNumInits() && "Initializer access out of range!");
27369e8925e72f53a9e2c4633b6b48e965ed01702fe4Steve Naroff    InitExprs[Init] = expr;
27379e8925e72f53a9e2c4633b6b48e965ed01702fe4Steve Naroff  }
2738c5ae899b4bbf65488445316c63168079177db0edSteve Naroff
2739fa2192042f223b5122a9e17719930f77634fd31fDouglas Gregor  /// \brief Reserve space for some number of initializers.
2740709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek  void reserveInits(ASTContext &C, unsigned NumInits);
27411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
27424c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  /// @brief Specify the number of initializers
27434c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  ///
27444c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  /// If there are more than @p NumInits initializers, the remaining
27454c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  /// initializers will be destroyed. If there are fewer than @p
27464c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  /// NumInits initializers, NULL expressions will be added for the
27474c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  /// unknown initializers.
27484c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  void resizeInits(ASTContext &Context, unsigned NumInits);
27494c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor
27504c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  /// @brief Updates the initializer at index @p Init with the new
27514c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  /// expression @p expr, and returns the old expression at that
27524c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  /// location.
27534c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  ///
27544c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  /// When @p Init is out of range for this initializer list, the
27554c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  /// initializer list will be extended with NULL expressions to
27564c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  /// accomodate the new entry.
2757709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek  Expr *updateInit(ASTContext &C, unsigned Init, Expr *expr);
2758c5ae899b4bbf65488445316c63168079177db0edSteve Naroff
27590bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor  /// \brief If this initializes a union, specifies which field in the
27600bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor  /// union to initialize.
27610bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor  ///
27620bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor  /// Typically, this field is the first named field within the
27630bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor  /// union. However, a designated initializer can specify the
27640bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor  /// initialization of a different field within the union.
27650bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor  FieldDecl *getInitializedFieldInUnion() { return UnionFieldInit; }
27660bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor  void setInitializedFieldInUnion(FieldDecl *FD) { UnionFieldInit = FD; }
27670bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor
2768c5ae899b4bbf65488445316c63168079177db0edSteve Naroff  // Explicit InitListExpr's originate from source code (and have valid source
2769c5ae899b4bbf65488445316c63168079177db0edSteve Naroff  // locations). Implicit InitListExpr's are created by the semantic analyzer.
2770b3eef68111ffc220e449be96da1747998c057790Douglas Gregor  bool isExplicit() {
2771b3eef68111ffc220e449be96da1747998c057790Douglas Gregor    return LBraceLoc.isValid() && RBraceLoc.isValid();
2772b3eef68111ffc220e449be96da1747998c057790Douglas Gregor  }
27731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2774d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  SourceLocation getLBraceLoc() const { return LBraceLoc; }
2775d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  void setLBraceLoc(SourceLocation Loc) { LBraceLoc = Loc; }
2776d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  SourceLocation getRBraceLoc() const { return RBraceLoc; }
277787fd703e097c27d63479cb83b687d4000a22bbb1Douglas Gregor  void setRBraceLoc(SourceLocation Loc) { RBraceLoc = Loc; }
277887fd703e097c27d63479cb83b687d4000a22bbb1Douglas Gregor
27794c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  /// @brief Retrieve the initializer list that describes the
27804c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  /// syntactic form of the initializer.
27814c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  ///
27821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
27834c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  InitListExpr *getSyntacticForm() const { return SyntacticForm; }
27844c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  void setSyntacticForm(InitListExpr *Init) { SyntacticForm = Init; }
27854c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor
2786a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor  bool hadArrayRangeDesignator() const { return HadArrayRangeDesignator; }
27871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  void sawArrayRangeDesignator(bool ARD = true) {
2788d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor    HadArrayRangeDesignator = ARD;
2789a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor  }
2790a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor
279166b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson  virtual SourceRange getSourceRange() const {
279266b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson    return SourceRange(LBraceLoc, RBraceLoc);
27931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  }
279466b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson  static bool classof(const Stmt *T) {
27951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == InitListExprClass;
279666b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson  }
279766b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson  static bool classof(const InitListExpr *) { return true; }
27981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
279966b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson  // Iterators
280066b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson  virtual child_iterator child_begin();
280166b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson  virtual child_iterator child_end();
28021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2803709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek  typedef InitExprsTy::iterator iterator;
2804709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek  typedef InitExprsTy::reverse_iterator reverse_iterator;
28051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2806ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek  iterator begin() { return InitExprs.begin(); }
2807ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek  iterator end() { return InitExprs.end(); }
2808ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek  reverse_iterator rbegin() { return InitExprs.rbegin(); }
2809ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek  reverse_iterator rend() { return InitExprs.rend(); }
281066b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson};
281166b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson
281205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// @brief Represents a C99 designated initializer expression.
281305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor///
281405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// A designated initializer expression (C99 6.7.8) contains one or
281505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// more designators (which can be field designators, array
281605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// designators, or GNU array-range designators) followed by an
281705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// expression that initializes the field or element(s) that the
281805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// designators refer to. For example, given:
28191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump///
282005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// @code
282105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// struct point {
282205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor///   double x;
282305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor///   double y;
282405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// };
282505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// struct point ptarray[10] = { [2].y = 1.0, [2].x = 2.0, [0].x = 1.0 };
282605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// @endcode
282705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor///
282805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// The InitListExpr contains three DesignatedInitExprs, the first of
282905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// which covers @c [2].y=1.0. This DesignatedInitExpr will have two
283005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// designators, one array designator for @c [2] followed by one field
283105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// designator for @c .y. The initalization expression will be 1.0.
283205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregorclass DesignatedInitExpr : public Expr {
2833ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregorpublic:
2834ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor  /// \brief Forward declaration of the Designator class.
2835ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor  class Designator;
2836ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor
2837ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregorprivate:
283805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// The location of the '=' or ':' prior to the actual initializer
283905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// expression.
284005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  SourceLocation EqualOrColonLoc;
284105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
2842eeae8f072748affce25ab4064982626361293390Douglas Gregor  /// Whether this designated initializer used the GNU deprecated
284305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// syntax rather than the C99 '=' syntax.
2844eeae8f072748affce25ab4064982626361293390Douglas Gregor  bool GNUSyntax : 1;
284505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
284605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// The number of designators in this initializer expression.
284705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  unsigned NumDesignators : 15;
284805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
2849ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor  /// \brief The designators in this designated initialization
2850ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor  /// expression.
2851ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor  Designator *Designators;
2852ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor
285305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// The number of subexpressions of this initializer expression,
285405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// which contains both the initializer and any additional
285505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// expressions used by array and array-range designators.
285605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  unsigned NumSubExprs : 16;
285705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
2858ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor
2859319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregor  DesignatedInitExpr(ASTContext &C, QualType Ty, unsigned NumDesignators,
2860ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor                     const Designator *Designators,
2861eeae8f072748affce25ab4064982626361293390Douglas Gregor                     SourceLocation EqualOrColonLoc, bool GNUSyntax,
28629ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor                     Expr **IndexExprs, unsigned NumIndexExprs,
28639ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor                     Expr *Init);
286405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
2865d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  explicit DesignatedInitExpr(unsigned NumSubExprs)
2866d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor    : Expr(DesignatedInitExprClass, EmptyShell()),
2867d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor      NumDesignators(0), Designators(0), NumSubExprs(NumSubExprs) { }
2868d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor
286942602bb40aefcc2751d4078ba88aacf4d965c9bdDouglas Gregorprotected:
28701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  virtual void DoDestroy(ASTContext &C);
287142602bb40aefcc2751d4078ba88aacf4d965c9bdDouglas Gregor
2872319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregor  void DestroyDesignators(ASTContext &C);
2873c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
287405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregorpublic:
287505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// A field designator, e.g., ".x".
287605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  struct FieldDesignator {
287705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// Refers to the field that is being initialized. The low bit
287805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// of this field determines whether this is actually a pointer
287905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// to an IdentifierInfo (if 1) or a FieldDecl (if 0). When
288005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// initially constructed, a field designator will store an
288105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// IdentifierInfo*. After semantic analysis has resolved that
288205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// name, the field designator will instead store a FieldDecl*.
288305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    uintptr_t NameOrField;
28841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
288505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// The location of the '.' in the designated initializer.
288605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    unsigned DotLoc;
28871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
288805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// The location of the field name in the designated initializer.
288905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    unsigned FieldLoc;
289005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  };
289105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
289205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// An array or GNU array-range designator, e.g., "[9]" or "[10..15]".
289305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  struct ArrayOrRangeDesignator {
289405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// Location of the first index expression within the designated
289505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// initializer expression's list of subexpressions.
289605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    unsigned Index;
289705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// The location of the '[' starting the array range designator.
289805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    unsigned LBracketLoc;
289905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// The location of the ellipsis separating the start and end
290005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// indices. Only valid for GNU array-range designators.
290105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    unsigned EllipsisLoc;
290205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// The location of the ']' terminating the array range designator.
29031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    unsigned RBracketLoc;
290405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  };
290505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
290605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// @brief Represents a single C99 designator.
290705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  ///
290805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// @todo This class is infuriatingly similar to clang::Designator,
290905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// but minor differences (storing indices vs. storing pointers)
291005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// keep us from reusing it. Try harder, later, to rectify these
291105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// differences.
291205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  class Designator {
291305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// @brief The kind of designator this describes.
291405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    enum {
291505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      FieldDesignator,
291605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      ArrayDesignator,
291705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      ArrayRangeDesignator
291805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    } Kind;
291905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
292005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    union {
292105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      /// A field designator, e.g., ".x".
292205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      struct FieldDesignator Field;
292305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      /// An array or GNU array-range designator, e.g., "[9]" or "[10..15]".
292405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      struct ArrayOrRangeDesignator ArrayOrRange;
292505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    };
292605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    friend class DesignatedInitExpr;
292705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
292805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  public:
2929ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor    Designator() {}
2930ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor
293105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// @brief Initializes a field designator.
29321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    Designator(const IdentifierInfo *FieldName, SourceLocation DotLoc,
29331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump               SourceLocation FieldLoc)
293405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      : Kind(FieldDesignator) {
293505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      Field.NameOrField = reinterpret_cast<uintptr_t>(FieldName) | 0x01;
293605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      Field.DotLoc = DotLoc.getRawEncoding();
293705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      Field.FieldLoc = FieldLoc.getRawEncoding();
293805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    }
293905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
294005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// @brief Initializes an array designator.
29411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    Designator(unsigned Index, SourceLocation LBracketLoc,
294205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor               SourceLocation RBracketLoc)
294305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      : Kind(ArrayDesignator) {
294405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      ArrayOrRange.Index = Index;
294505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      ArrayOrRange.LBracketLoc = LBracketLoc.getRawEncoding();
294605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      ArrayOrRange.EllipsisLoc = SourceLocation().getRawEncoding();
294705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      ArrayOrRange.RBracketLoc = RBracketLoc.getRawEncoding();
294805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    }
294905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
295005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// @brief Initializes a GNU array-range designator.
29511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    Designator(unsigned Index, SourceLocation LBracketLoc,
295205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor               SourceLocation EllipsisLoc, SourceLocation RBracketLoc)
295305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      : Kind(ArrayRangeDesignator) {
295405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      ArrayOrRange.Index = Index;
295505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      ArrayOrRange.LBracketLoc = LBracketLoc.getRawEncoding();
295605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      ArrayOrRange.EllipsisLoc = EllipsisLoc.getRawEncoding();
295705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      ArrayOrRange.RBracketLoc = RBracketLoc.getRawEncoding();
295805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    }
295905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
296005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    bool isFieldDesignator() const { return Kind == FieldDesignator; }
296105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    bool isArrayDesignator() const { return Kind == ArrayDesignator; }
296205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    bool isArrayRangeDesignator() const { return Kind == ArrayRangeDesignator; }
296305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
296405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    IdentifierInfo * getFieldName();
296505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
296605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    FieldDecl *getField() {
296705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      assert(Kind == FieldDesignator && "Only valid on a field designator");
296805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      if (Field.NameOrField & 0x01)
296905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor        return 0;
297005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      else
297105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor        return reinterpret_cast<FieldDecl *>(Field.NameOrField);
297205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    }
297305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
297405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    void setField(FieldDecl *FD) {
297505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      assert(Kind == FieldDesignator && "Only valid on a field designator");
297605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      Field.NameOrField = reinterpret_cast<uintptr_t>(FD);
297705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    }
297805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
297987f55cf59e82f246d8605733e9300d0c5f6830a6Douglas Gregor    SourceLocation getDotLoc() const {
298087f55cf59e82f246d8605733e9300d0c5f6830a6Douglas Gregor      assert(Kind == FieldDesignator && "Only valid on a field designator");
298187f55cf59e82f246d8605733e9300d0c5f6830a6Douglas Gregor      return SourceLocation::getFromRawEncoding(Field.DotLoc);
298287f55cf59e82f246d8605733e9300d0c5f6830a6Douglas Gregor    }
298387f55cf59e82f246d8605733e9300d0c5f6830a6Douglas Gregor
298405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    SourceLocation getFieldLoc() const {
298505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      assert(Kind == FieldDesignator && "Only valid on a field designator");
298605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      return SourceLocation::getFromRawEncoding(Field.FieldLoc);
298705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    }
298805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
298905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    SourceLocation getLBracketLoc() const {
299005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      assert((Kind == ArrayDesignator || Kind == ArrayRangeDesignator) &&
299105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor             "Only valid on an array or array-range designator");
299205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      return SourceLocation::getFromRawEncoding(ArrayOrRange.LBracketLoc);
299305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    }
299405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
299505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    SourceLocation getRBracketLoc() const {
299605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      assert((Kind == ArrayDesignator || Kind == ArrayRangeDesignator) &&
299705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor             "Only valid on an array or array-range designator");
299805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      return SourceLocation::getFromRawEncoding(ArrayOrRange.RBracketLoc);
299905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    }
300005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
300105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    SourceLocation getEllipsisLoc() const {
300205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      assert(Kind == ArrayRangeDesignator &&
300305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor             "Only valid on an array-range designator");
300405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      return SourceLocation::getFromRawEncoding(ArrayOrRange.EllipsisLoc);
300505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    }
30064c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor
3007d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor    unsigned getFirstExprIndex() const {
3008d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor      assert((Kind == ArrayDesignator || Kind == ArrayRangeDesignator) &&
3009d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor             "Only valid on an array or array-range designator");
3010d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor      return ArrayOrRange.Index;
3011d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor    }
3012d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor
30134c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor    SourceLocation getStartLocation() const {
30144c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor      if (Kind == FieldDesignator)
30154c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor        return getDotLoc().isInvalid()? getFieldLoc() : getDotLoc();
30164c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor      else
30174c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor        return getLBracketLoc();
30184c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor    }
301905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  };
302005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
30211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static DesignatedInitExpr *Create(ASTContext &C, Designator *Designators,
302205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor                                    unsigned NumDesignators,
302305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor                                    Expr **IndexExprs, unsigned NumIndexExprs,
302405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor                                    SourceLocation EqualOrColonLoc,
3025eeae8f072748affce25ab4064982626361293390Douglas Gregor                                    bool GNUSyntax, Expr *Init);
302605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
3027d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  static DesignatedInitExpr *CreateEmpty(ASTContext &C, unsigned NumIndexExprs);
3028d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor
302905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// @brief Returns the number of designators in this initializer.
303005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  unsigned size() const { return NumDesignators; }
303105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
303205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  // Iterator access to the designators.
303305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  typedef Designator* designators_iterator;
3034ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor  designators_iterator designators_begin() { return Designators; }
30351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  designators_iterator designators_end() {
30361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return Designators + NumDesignators;
3037ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor  }
303805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
3039711997184366d584c9c437102cae1e9d9927b986Douglas Gregor  Designator *getDesignator(unsigned Idx) { return &designators_begin()[Idx]; }
3040711997184366d584c9c437102cae1e9d9927b986Douglas Gregor
3041c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  void setDesignators(ASTContext &C, const Designator *Desigs,
3042319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregor                      unsigned NumDesigs);
3043d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor
304405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  Expr *getArrayIndex(const Designator& D);
304505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  Expr *getArrayRangeStart(const Designator& D);
304605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  Expr *getArrayRangeEnd(const Designator& D);
304705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
304805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// @brief Retrieve the location of the '=' that precedes the
304905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// initializer value itself, if present.
305005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  SourceLocation getEqualOrColonLoc() const { return EqualOrColonLoc; }
3051d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  void setEqualOrColonLoc(SourceLocation L) { EqualOrColonLoc = L; }
305205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
305305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// @brief Determines whether this designated initializer used the
3054eeae8f072748affce25ab4064982626361293390Douglas Gregor  /// deprecated GNU syntax for designated initializers.
3055eeae8f072748affce25ab4064982626361293390Douglas Gregor  bool usesGNUSyntax() const { return GNUSyntax; }
3056d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  void setGNUSyntax(bool GNU) { GNUSyntax = GNU; }
305705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
305805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// @brief Retrieve the initializer value.
30591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  Expr *getInit() const {
306005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    return cast<Expr>(*const_cast<DesignatedInitExpr*>(this)->child_begin());
306105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  }
306205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
306305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  void setInit(Expr *init) {
306405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    *child_begin() = init;
306505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  }
306605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
3067d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  /// \brief Retrieve the total number of subexpressions in this
3068d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  /// designated initializer expression, including the actual
3069d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  /// initialized value and any expressions that occur within array
3070d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  /// and array-range designators.
3071d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  unsigned getNumSubExprs() const { return NumSubExprs; }
3072d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor
3073d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  Expr *getSubExpr(unsigned Idx) {
3074d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor    assert(Idx < NumSubExprs && "Subscript out of range");
3075d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor    char* Ptr = static_cast<char*>(static_cast<void *>(this));
3076d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor    Ptr += sizeof(DesignatedInitExpr);
3077d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor    return reinterpret_cast<Expr**>(reinterpret_cast<void**>(Ptr))[Idx];
3078d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  }
3079d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor
3080d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  void setSubExpr(unsigned Idx, Expr *E) {
3081d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor    assert(Idx < NumSubExprs && "Subscript out of range");
3082d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor    char* Ptr = static_cast<char*>(static_cast<void *>(this));
3083d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor    Ptr += sizeof(DesignatedInitExpr);
3084d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor    reinterpret_cast<Expr**>(reinterpret_cast<void**>(Ptr))[Idx] = E;
3085d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  }
3086d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor
3087ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor  /// \brief Replaces the designator at index @p Idx with the series
3088ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor  /// of designators in [First, Last).
3089319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregor  void ExpandDesignator(ASTContext &C, unsigned Idx, const Designator *First,
3090ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor                        const Designator *Last);
3091ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor
309205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  virtual SourceRange getSourceRange() const;
309305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
309405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  static bool classof(const Stmt *T) {
30951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == DesignatedInitExprClass;
309605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  }
309705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  static bool classof(const DesignatedInitExpr *) { return true; }
309805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
309905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  // Iterators
310005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  virtual child_iterator child_begin();
31011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  virtual child_iterator child_end();
31023498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor};
31033498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor
31043498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor/// \brief Represents an implicitly-generated value initialization of
31053498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor/// an object of a given type.
31063498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor///
31071a51b4a11b7db25cac2134249711ecaaf9d1c0a8Douglas Gregor/// Implicit value initializations occur within semantic initializer
31081a51b4a11b7db25cac2134249711ecaaf9d1c0a8Douglas Gregor/// list expressions (InitListExpr) as placeholders for subobject
31093498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor/// initializations not explicitly specified by the user.
31101a51b4a11b7db25cac2134249711ecaaf9d1c0a8Douglas Gregor///
31111a51b4a11b7db25cac2134249711ecaaf9d1c0a8Douglas Gregor/// \see InitListExpr
31121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpclass ImplicitValueInitExpr : public Expr {
31133498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregorpublic:
31141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  explicit ImplicitValueInitExpr(QualType ty)
31152333f7727f97018d6742e1e0938133bcfad967abEli Friedman    : Expr(ImplicitValueInitExprClass, ty, false, false) { }
31163498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor
3117d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  /// \brief Construct an empty implicit value initialization.
3118d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  explicit ImplicitValueInitExpr(EmptyShell Empty)
3119d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor    : Expr(ImplicitValueInitExprClass, Empty) { }
3120d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor
31211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
31223498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor    return T->getStmtClass() == ImplicitValueInitExprClass;
31233498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor  }
31243498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor  static bool classof(const ImplicitValueInitExpr *) { return true; }
31253498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor
31263498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor  virtual SourceRange getSourceRange() const {
31273498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor    return SourceRange();
31283498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor  }
31293498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor
31303498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor  // Iterators
31313498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor  virtual child_iterator child_begin();
31321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  virtual child_iterator child_end();
313305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor};
313405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
31352ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman
31362ef13e5abef0570a9f567b4671367275c05d4d34Nate Begemanclass ParenListExpr : public Expr {
31372ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman  Stmt **Exprs;
31382ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman  unsigned NumExprs;
31392ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman  SourceLocation LParenLoc, RParenLoc;
31402ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman
31411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpprotected:
31422ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman  virtual void DoDestroy(ASTContext& C);
31431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
31442ef13e5abef0570a9f567b4671367275c05d4d34Nate Begemanpublic:
31451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ParenListExpr(ASTContext& C, SourceLocation lparenloc, Expr **exprs,
31462ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman                unsigned numexprs, SourceLocation rparenloc);
31472ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman
31482ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman  ~ParenListExpr() {}
31492ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman
31502ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman  /// \brief Build an empty paren list.
31512ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman  //explicit ParenListExpr(EmptyShell Empty) : Expr(ParenListExprClass, Empty) { }
31521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
31532ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman  unsigned getNumExprs() const { return NumExprs; }
31541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
31551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  const Expr* getExpr(unsigned Init) const {
31562ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman    assert(Init < getNumExprs() && "Initializer access out of range!");
31572ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman    return cast_or_null<Expr>(Exprs[Init]);
31582ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman  }
31591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
31601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  Expr* getExpr(unsigned Init) {
31612ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman    assert(Init < getNumExprs() && "Initializer access out of range!");
31622ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman    return cast_or_null<Expr>(Exprs[Init]);
31632ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman  }
31642ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman
316583ddad3ab513f5d73698cf9fbeb4ed3f011bc3b9Douglas Gregor  Expr **getExprs() { return reinterpret_cast<Expr **>(Exprs); }
31661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
31672ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman  SourceLocation getLParenLoc() const { return LParenLoc; }
31682ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman  SourceLocation getRParenLoc() const { return RParenLoc; }
31692ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman
31702ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman  virtual SourceRange getSourceRange() const {
31712ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman    return SourceRange(LParenLoc, RParenLoc);
31721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  }
31732ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman  static bool classof(const Stmt *T) {
31741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == ParenListExprClass;
31752ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman  }
31762ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman  static bool classof(const ParenListExpr *) { return true; }
31771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
31782ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman  // Iterators
31792ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman  virtual child_iterator child_begin();
31802ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman  virtual child_iterator child_end();
31812ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman};
31822ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman
31831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
31844eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff//===----------------------------------------------------------------------===//
31854eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff// Clang Extensions
31864eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff//===----------------------------------------------------------------------===//
31874eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff
3188a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner
3189a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner/// ExtVectorElementExpr - This represents access to specific elements of a
3190a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner/// vector, and may occur on the left hand side or right hand side.  For example
3191a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner/// the following is legal:  "V.xy = V.zw" if V is a 4 element extended vector.
3192a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner///
319373525de7fd9bdd534382dc89a24f1f76db3e04b9Chris Lattner/// Note that the base may have either vector or pointer to vector type, just
319473525de7fd9bdd534382dc89a24f1f76db3e04b9Chris Lattner/// like a struct field reference.
319573525de7fd9bdd534382dc89a24f1f76db3e04b9Chris Lattner///
3196a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattnerclass ExtVectorElementExpr : public Expr {
3197a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  Stmt *Base;
3198d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor  IdentifierInfo *Accessor;
3199a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  SourceLocation AccessorLoc;
3200a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattnerpublic:
3201a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  ExtVectorElementExpr(QualType ty, Expr *base, IdentifierInfo &accessor,
3202a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner                       SourceLocation loc)
32032333f7727f97018d6742e1e0938133bcfad967abEli Friedman    : Expr(ExtVectorElementExprClass, ty, base->isTypeDependent(),
32042333f7727f97018d6742e1e0938133bcfad967abEli Friedman           base->isValueDependent()),
3205d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor      Base(base), Accessor(&accessor), AccessorLoc(loc) {}
32061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3207d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor  /// \brief Build an empty vector element expression.
3208d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor  explicit ExtVectorElementExpr(EmptyShell Empty)
3209d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor    : Expr(ExtVectorElementExprClass, Empty) { }
3210d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor
3211a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  const Expr *getBase() const { return cast<Expr>(Base); }
3212a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  Expr *getBase() { return cast<Expr>(Base); }
3213d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor  void setBase(Expr *E) { Base = E; }
3214d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor
3215d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor  IdentifierInfo &getAccessor() const { return *Accessor; }
3216d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor  void setAccessor(IdentifierInfo *II) { Accessor = II; }
3217d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor
3218d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor  SourceLocation getAccessorLoc() const { return AccessorLoc; }
3219d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor  void setAccessorLoc(SourceLocation L) { AccessorLoc = L; }
3220d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor
3221a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  /// getNumElements - Get the number of components being selected.
3222a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  unsigned getNumElements() const;
32231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3224a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  /// containsDuplicateElements - Return true if any element access is
3225a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  /// repeated.
3226a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  bool containsDuplicateElements() const;
32271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3228a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  /// getEncodedElementAccess - Encode the elements accessed into an llvm
3229a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  /// aggregate Constant of ConstantInt(s).
3230a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  void getEncodedElementAccess(llvm::SmallVectorImpl<unsigned> &Elts) const;
32311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3232a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  virtual SourceRange getSourceRange() const {
3233a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner    return SourceRange(getBase()->getLocStart(), AccessorLoc);
3234a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  }
32351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
32362140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner  /// isArrow - Return true if the base expression is a pointer to vector,
32372140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner  /// return false if the base expression is a vector.
32382140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner  bool isArrow() const;
32391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
32401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
32411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == ExtVectorElementExprClass;
3242a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  }
3243a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  static bool classof(const ExtVectorElementExpr *) { return true; }
32441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3245a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  // Iterators
3246a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  virtual child_iterator child_begin();
3247a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  virtual child_iterator child_end();
3248a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner};
3249a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner
3250a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner
325156ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff/// BlockExpr - Adaptor class for mixing a BlockDecl with expressions.
32529c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff/// ^{ statement-body }   or   ^(int arg1, float arg2){ statement-body }
32534eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroffclass BlockExpr : public Expr {
325456ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroffprotected:
325556ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff  BlockDecl *TheBlock;
3256b83d287bc7f47d36fb0751a481e2ef9308b37252Mike Stump  bool HasBlockDeclRefExprs;
32574eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroffpublic:
3258b83d287bc7f47d36fb0751a481e2ef9308b37252Mike Stump  BlockExpr(BlockDecl *BD, QualType ty, bool hasBlockDeclRefExprs)
32592333f7727f97018d6742e1e0938133bcfad967abEli Friedman    : Expr(BlockExprClass, ty, ty->isDependentType(), false),
3260b83d287bc7f47d36fb0751a481e2ef9308b37252Mike Stump      TheBlock(BD), HasBlockDeclRefExprs(hasBlockDeclRefExprs) {}
32619c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff
326284af7c27cdc615ff917a501d61256b4049383c97Douglas Gregor  /// \brief Build an empty block expression.
326384af7c27cdc615ff917a501d61256b4049383c97Douglas Gregor  explicit BlockExpr(EmptyShell Empty) : Expr(BlockExprClass, Empty) { }
326484af7c27cdc615ff917a501d61256b4049383c97Douglas Gregor
3265d5cab5435371b8cc74a9e05ebd40b5995ebad149Anders Carlsson  const BlockDecl *getBlockDecl() const { return TheBlock; }
326656ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff  BlockDecl *getBlockDecl() { return TheBlock; }
326784af7c27cdc615ff917a501d61256b4049383c97Douglas Gregor  void setBlockDecl(BlockDecl *BD) { TheBlock = BD; }
326884af7c27cdc615ff917a501d61256b4049383c97Douglas Gregor
326956ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff  // Convenience functions for probing the underlying BlockDecl.
327056ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff  SourceLocation getCaretLocation() const;
327156ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff  const Stmt *getBody() const;
327256ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff  Stmt *getBody();
32739c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff
32749c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff  virtual SourceRange getSourceRange() const {
327556ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff    return SourceRange(getCaretLocation(), getBody()->getLocEnd());
32769c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff  }
32779c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff
327856ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff  /// getFunctionType - Return the underlying function type for this block.
327956ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff  const FunctionType *getFunctionType() const;
328056ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff
3281b83d287bc7f47d36fb0751a481e2ef9308b37252Mike Stump  /// hasBlockDeclRefExprs - Return true iff the block has BlockDeclRefExpr
32825b54b88c4082bb81b8b341b622fda9a85cbd5fadChris Lattner  /// inside of the block that reference values outside the block.
3283b83d287bc7f47d36fb0751a481e2ef9308b37252Mike Stump  bool hasBlockDeclRefExprs() const { return HasBlockDeclRefExprs; }
328484af7c27cdc615ff917a501d61256b4049383c97Douglas Gregor  void setHasBlockDeclRefExprs(bool BDRE) { HasBlockDeclRefExprs = BDRE; }
3285b83d287bc7f47d36fb0751a481e2ef9308b37252Mike Stump
32861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
32879c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff    return T->getStmtClass() == BlockExprClass;
32884eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  }
32894eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  static bool classof(const BlockExpr *) { return true; }
32901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
32914eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  // Iterators
32924eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  virtual child_iterator child_begin();
32934eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  virtual child_iterator child_end();
32944eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff};
32951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
32964eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff/// BlockDeclRefExpr - A reference to a declared variable, function,
32974eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff/// enum, etc.
32984eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroffclass BlockDeclRefExpr : public Expr {
32991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ValueDecl *D;
33004eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  SourceLocation Loc;
33017d5c74ecbbd8719436c071f38657bc8e97ee4a24Fariborz Jahanian  bool IsByRef : 1;
33027d5c74ecbbd8719436c071f38657bc8e97ee4a24Fariborz Jahanian  bool ConstQualAdded : 1;
33034eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroffpublic:
33042333f7727f97018d6742e1e0938133bcfad967abEli Friedman  // FIXME: Fix type/value dependence!
33051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  BlockDeclRefExpr(ValueDecl *d, QualType t, SourceLocation l, bool ByRef,
33062333f7727f97018d6742e1e0938133bcfad967abEli Friedman                   bool constAdded = false)
33072333f7727f97018d6742e1e0938133bcfad967abEli Friedman  : Expr(BlockDeclRefExprClass, t, false, false), D(d), Loc(l), IsByRef(ByRef),
33082333f7727f97018d6742e1e0938133bcfad967abEli Friedman    ConstQualAdded(constAdded) {}
330994cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor
331094cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor  // \brief Build an empty reference to a declared variable in a
331194cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor  // block.
331294cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor  explicit BlockDeclRefExpr(EmptyShell Empty)
331394cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor    : Expr(BlockDeclRefExprClass, Empty) { }
33141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
33154eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  ValueDecl *getDecl() { return D; }
33164eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  const ValueDecl *getDecl() const { return D; }
331794cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor  void setDecl(ValueDecl *VD) { D = VD; }
331894cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor
331994cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor  SourceLocation getLocation() const { return Loc; }
332094cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor  void setLocation(SourceLocation L) { Loc = L; }
332194cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor
33224eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
33231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
33244eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  bool isByRef() const { return IsByRef; }
332594cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor  void setByRef(bool BR) { IsByRef = BR; }
33261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
33277d5c74ecbbd8719436c071f38657bc8e97ee4a24Fariborz Jahanian  bool isConstQualAdded() const { return ConstQualAdded; }
33287d5c74ecbbd8719436c071f38657bc8e97ee4a24Fariborz Jahanian  void setConstQualAdded(bool C) { ConstQualAdded = C; }
332994cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor
33301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
33311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == BlockDeclRefExprClass;
33324eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  }
33334eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  static bool classof(const BlockDeclRefExpr *) { return true; }
33341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
33354eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  // Iterators
33364eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  virtual child_iterator child_begin();
33374eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  virtual child_iterator child_end();
33384eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff};
33394eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff
33405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}  // end namespace clang
33415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
33425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#endif
3343