Expr.h revision e17a6436b429e4b18a5e157061fb13bbc677b3b0
15f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===--- Expr.h - Classes for representing expressions ----------*- C++ -*-===//
25f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//
35f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//                     The LLVM Compiler Infrastructure
45f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//
50bc735ffcfb223c0186419547abaa5c84482663eChris Lattner// This file is distributed under the University of Illinois Open Source
60bc735ffcfb223c0186419547abaa5c84482663eChris Lattner// License. See LICENSE.TXT for details.
75f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//
85f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===//
95f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//
105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//  This file defines the Expr interface and subclasses.
115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//
125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===//
135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#ifndef LLVM_CLANG_AST_EXPR_H
155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#define LLVM_CLANG_AST_EXPR_H
165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1794deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson#include "clang/AST/APValue.h"
185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include "clang/AST/Stmt.h"
195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include "clang/AST/Type.h"
20161755a09898c95d21bfff33707da9ca41cd53c5John McCall#include "clang/AST/DeclAccessPair.h"
21709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek#include "clang/AST/ASTVector.h"
22409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson#include "clang/AST/UsuallyTinyPtrVector.h"
235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include "llvm/ADT/APSInt.h"
24525a05093a4816af961fe2bc6b8a81c17e2e26c2Chris Lattner#include "llvm/ADT/APFloat.h"
253b8d116703db8018f855cbb4733ace426422623bNate Begeman#include "llvm/ADT/SmallVector.h"
26b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar#include "llvm/ADT/StringRef.h"
27c5ae899b4bbf65488445316c63168079177db0edSteve Naroff#include <vector>
285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace clang {
30590b6646ef747d2f7b42e5f40487ff07642d7b6fChris Lattner  class ASTContext;
31c44eec6dd29ee9415cbd38a35deff4c8b67abb6aAnders Carlsson  class APValue;
32c4a1dea2dc56bd1357ec91b829a0b9e68229a13eDaniel Dunbar  class Decl;
33c4a1dea2dc56bd1357ec91b829a0b9e68229a13eDaniel Dunbar  class IdentifierInfo;
34c4a1dea2dc56bd1357ec91b829a0b9e68229a13eDaniel Dunbar  class ParmVarDecl;
358e9bebdea69c590dedfbf27374114cb76fe12fbdDouglas Gregor  class NamedDecl;
36c4a1dea2dc56bd1357ec91b829a0b9e68229a13eDaniel Dunbar  class ValueDecl;
3756ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff  class BlockDecl;
38409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson  class CXXBaseSpecifier;
3988a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor  class CXXOperatorCallExpr;
4088a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor  class CXXMemberCallExpr;
41833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  class TemplateArgumentLoc;
42d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  class TemplateArgumentListInfo;
4388a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor
447ab9d574d27ecee1f130e5755aa403e5ab529b6bAnders Carlsson/// \brief A simple array of base specifiers.
457ab9d574d27ecee1f130e5755aa403e5ab529b6bAnders Carlssontypedef UsuallyTinyPtrVector<const CXXBaseSpecifier> CXXBaseSpecifierArray;
467ab9d574d27ecee1f130e5755aa403e5ab529b6bAnders Carlsson
475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Expr - This represents one expression.  Note that Expr's are subclasses of
485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Stmt.  This allows an expression to be transparently used any place a Stmt
495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// is required.
505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass Expr : public Stmt {
525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType TR;
53898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor
54bef0efd11bc4430a3ee437a3213cec5c18af855aChris Lattner  virtual void ANCHOR(); // key function.
559ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregorprotected:
561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// TypeDependent - Whether this expression is type-dependent
57898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// (C++ [temp.dep.expr]).
58898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  bool TypeDependent : 1;
59898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor
601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// ValueDependent - Whether this expression is value-dependent
61898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// (C++ [temp.dep.constexpr]).
62898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  bool ValueDependent : 1;
63898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor
64898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  Expr(StmtClass SC, QualType T, bool TD, bool VD)
65b3eef68111ffc220e449be96da1747998c057790Douglas Gregor    : Stmt(SC), TypeDependent(TD), ValueDependent(VD) {
66898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor    setType(T);
67898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  }
68898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor
690b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor  /// \brief Construct an empty expression.
700b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor  explicit Expr(StmtClass SC, EmptyShell) : Stmt(SC) { }
710b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor
721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumppublic:
7343d9d9243329b1b75d1a6efdad9f16d6fb386b8eDouglas Gregor  /// \brief Increases the reference count for this expression.
7443d9d9243329b1b75d1a6efdad9f16d6fb386b8eDouglas Gregor  ///
7543d9d9243329b1b75d1a6efdad9f16d6fb386b8eDouglas Gregor  /// Invoke the Retain() operation when this expression
7643d9d9243329b1b75d1a6efdad9f16d6fb386b8eDouglas Gregor  /// is being shared by another owner.
7743d9d9243329b1b75d1a6efdad9f16d6fb386b8eDouglas Gregor  Expr *Retain() {
7843d9d9243329b1b75d1a6efdad9f16d6fb386b8eDouglas Gregor    Stmt::Retain();
7943d9d9243329b1b75d1a6efdad9f16d6fb386b8eDouglas Gregor    return this;
8043d9d9243329b1b75d1a6efdad9f16d6fb386b8eDouglas Gregor  }
811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
82f7c2aa0b049272d8f318988c1965760dcb852578Douglas Gregor  QualType getType() const { return TR; }
831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  void setType(QualType t) {
849d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor    // In C++, the type of an expression is always adjusted so that it
859d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor    // will not have reference type an expression will never have
869d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor    // reference type (C++ [expr]p6). Use
879d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor    // QualType::getNonReferenceType() to retrieve the non-reference
889d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor    // type. Additionally, inspect Expr::isLvalue to determine whether
899d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor    // an expression that is adjusted in this manner should be
909d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor    // considered an lvalue.
91905d11d53aeb6b26744f44fedc2b2820c7a62df6Douglas Gregor    assert((t.isNull() || !t->isReferenceType()) &&
928320aaaa01d931aa234fc3bce05b399ef41898d5Daniel Dunbar           "Expressions can't have reference type");
93f7c2aa0b049272d8f318988c1965760dcb852578Douglas Gregor
941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    TR = t;
959d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor  }
9677ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek
97898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// isValueDependent - Determines whether this expression is
98898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// value-dependent (C++ [temp.dep.constexpr]). For example, the
99898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// array bound of "Chars" in the following example is
1001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// value-dependent.
101898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// @code
102898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// template<int Size, char (&Chars)[Size]> struct meta_string;
103898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// @endcode
104898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  bool isValueDependent() const { return ValueDependent; }
105898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor
1060b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor  /// \brief Set whether this expression is value-dependent or not.
1070b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor  void setValueDependent(bool VD) { ValueDependent = VD; }
1080b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor
109898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// isTypeDependent - Determines whether this expression is
110898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// type-dependent (C++ [temp.dep.expr]), which means that its type
111898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// could change from one template instantiation to the next. For
112898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// example, the expressions "x" and "x + y" are type-dependent in
113898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// the following code, but "y" is not type-dependent:
114898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// @code
1151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// template<typename T>
116898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// void add(T x, int y) {
117898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  ///   x + y;
118898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// }
119898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// @endcode
120898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  bool isTypeDependent() const { return TypeDependent; }
121898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor
1220b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor  /// \brief Set whether this expression is type-dependent or not.
1230b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor  void setTypeDependent(bool TD) { TypeDependent = TD; }
1240b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor
1255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// SourceLocation tokens are not useful in isolation - they are low level
1265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// value objects created/interpreted by SourceManager. We assume AST
1275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// clients will have a pointer to the respective SourceManager.
1285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  virtual SourceRange getSourceRange() const = 0;
1295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// getExprLoc - Return the preferred location for the arrow when diagnosing
1315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// a problem with a generic expression.
1325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  virtual SourceLocation getExprLoc() const { return getLocStart(); }
1331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
134026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner  /// isUnusedResultAWarning - Return true if this immediate expression should
135026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner  /// be warned about if the result is unused.  If so, fill in Loc and Ranges
136026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner  /// with location to warn on and the source range[s] to report with the
137026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner  /// warning.
138026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner  bool isUnusedResultAWarning(SourceLocation &Loc, SourceRange &R1,
139df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump                              SourceRange &R2, ASTContext &Ctx) const;
1401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// isLvalue - C99 6.3.2.1: an lvalue is an expression with an object type or
1425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// incomplete type other than void. Nonarray expressions that can be lvalues:
1435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ///  - name, where name must be a variable
1445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ///  - e[i]
1455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ///  - (e), where e must be an lvalue
1465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ///  - e.name, where e must be an lvalue
1475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ///  - e->name
1485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ///  - *e, the type of e cannot be a function type
1495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ///  - string-constant
15008ad47cbd1f81fcb31dbc731c13b885a07e12704Bill Wendling  ///  - reference type [C++ [expr]]
15176458501a8963fa11b91c9337a487de6871169b4Sebastian Redl  ///  - b ? x : y, where x and y are lvalues of suitable types [C++]
1525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ///
1535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  enum isLvalueResult {
1545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    LV_Valid,
1555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    LV_NotObjectType,
1565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    LV_IncompleteVoidType,
157fec0b49c3fa621fbf63e420f3d54a5bb3a0265d2Steve Naroff    LV_DuplicateVectorComponents,
15886f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor    LV_InvalidExpression,
1592514a309204341798f96912ce7a90841bea59727Fariborz Jahanian    LV_MemberFunction,
160e9ff443040cb571ae2c5c2626c4dc9a9a812d84aFariborz Jahanian    LV_SubObjCPropertySetting,
161e873fb74219f48407ae0b8fa083aa7f0b6ff1427Douglas Gregor    LV_ClassTemporary
1625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  };
16328be73f74c9e241a23ea24fe5756623de6bf1084Chris Lattner  isLvalueResult isLvalue(ASTContext &Ctx) const;
16453202857c60214d80950a975e6e52aebf30bd16aEli Friedman
16553202857c60214d80950a975e6e52aebf30bd16aEli Friedman  // Same as above, but excluding checks for non-object and void types in C
16653202857c60214d80950a975e6e52aebf30bd16aEli Friedman  isLvalueResult isLvalueInternal(ASTContext &Ctx) const;
1671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// isModifiableLvalue - C99 6.3.2.1: an lvalue that does not have array type,
1695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// does not have an incomplete type, does not have a const-qualified type,
1701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// and if it is a structure or union, does not have any member (including,
1715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// recursively, any member or element of all contained aggregates or unions)
1725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// with a const-qualified type.
17344e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar  ///
17444e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar  /// \param Loc [in] [out] - A source location which *may* be filled
17544e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar  /// in with the location of the expression making this a
17644e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar  /// non-modifiable lvalue, if specified.
1775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  enum isModifiableLvalueResult {
1785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    MLV_Valid,
1795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    MLV_NotObjectType,
1805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    MLV_IncompleteVoidType,
181fec0b49c3fa621fbf63e420f3d54a5bb3a0265d2Steve Naroff    MLV_DuplicateVectorComponents,
1825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    MLV_InvalidExpression,
183ca354faa7e9b99af17070c82b9662a5fca76422cChris Lattner    MLV_LValueCast,           // Specialized form of MLV_InvalidExpression.
1845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    MLV_IncompleteType,
1855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    MLV_ConstQualified,
1864f6a7d7ead09b439216c32f2de806a998aeb222aSteve Naroff    MLV_ArrayType,
1875daf570d0ce027e18ed5f9d66e6b2a14a40b720dFariborz Jahanian    MLV_NotBlockQualified,
188ba8d2d684e74a20bef03828c21c991d222c7e9e5Fariborz Jahanian    MLV_ReadonlyProperty,
18986f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor    MLV_NoSetterProperty,
1902514a309204341798f96912ce7a90841bea59727Fariborz Jahanian    MLV_MemberFunction,
191e9ff443040cb571ae2c5c2626c4dc9a9a812d84aFariborz Jahanian    MLV_SubObjCPropertySetting,
192e873fb74219f48407ae0b8fa083aa7f0b6ff1427Douglas Gregor    MLV_ClassTemporary
1935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  };
19444e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar  isModifiableLvalueResult isModifiableLvalue(ASTContext &Ctx,
19544e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar                                              SourceLocation *Loc = 0) const;
1961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
19733bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor  /// \brief If this expression refers to a bit-field, retrieve the
19833bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor  /// declaration of that bit-field.
19933bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor  FieldDecl *getBitField();
2005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
20138d068e8f13a119b89a3b8b0f79f35cab1ffd09aAnders Carlsson  const FieldDecl *getBitField() const {
20238d068e8f13a119b89a3b8b0f79f35cab1ffd09aAnders Carlsson    return const_cast<Expr*>(this)->getBitField();
20338d068e8f13a119b89a3b8b0f79f35cab1ffd09aAnders Carlsson  }
2041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
205093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson  /// \brief Returns whether this expression refers to a vector element.
206093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson  bool refersToVectorElement() const;
207c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
2082b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner  /// isKnownToHaveBooleanValue - Return true if this is an integer expression
2092b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner  /// that is known to return 0 or 1.  This happens for _Bool/bool expressions
2102b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner  /// but also int expressions which are produced by things like comparisons in
2112b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner  /// C.
2122b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner  bool isKnownToHaveBooleanValue() const;
213c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
2145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// isIntegerConstantExpr - Return true if this expression is a valid integer
2155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// constant expression, and, if so, return its value in Result.  If not a
2165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// valid i-c-e, return false and fill in Loc (if specified) with the location
2175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// of the invalid expression.
218590b6646ef747d2f7b42e5f40487ff07642d7b6fChris Lattner  bool isIntegerConstantExpr(llvm::APSInt &Result, ASTContext &Ctx,
219590b6646ef747d2f7b42e5f40487ff07642d7b6fChris Lattner                             SourceLocation *Loc = 0,
2205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer                             bool isEvaluated = true) const;
221590b6646ef747d2f7b42e5f40487ff07642d7b6fChris Lattner  bool isIntegerConstantExpr(ASTContext &Ctx, SourceLocation *Loc = 0) const {
2228070a8497c0fb3e6f70a557f788405d8945b1208Daniel Dunbar    llvm::APSInt X;
223590b6646ef747d2f7b42e5f40487ff07642d7b6fChris Lattner    return isIntegerConstantExpr(X, Ctx, Loc);
2245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
225c9e8f606787b0bc0c3b08e566b87cc1751694168Eli Friedman  /// isConstantInitializer - Returns true if this expression is a constant
226c9e8f606787b0bc0c3b08e566b87cc1751694168Eli Friedman  /// initializer, which can be emitted at compile-time.
227c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  bool isConstantInitializer(ASTContext &Ctx) const;
2281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
22994deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson  /// EvalResult is a struct with detailed info about an evaluated expression.
23094deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson  struct EvalResult {
2312d6744ff04c1690a1485178d550d2fab84a0270bDaniel Dunbar    /// Val - This is the value the expression can be folded to.
23294deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson    APValue Val;
2331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
23494deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson    /// HasSideEffects - Whether the evaluated expression has side effects.
23594deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson    /// For example, (f() && 0) can be folded, but it still has side effects.
23694deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson    bool HasSideEffects;
2371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
23894deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson    /// Diag - If the expression is unfoldable, then Diag contains a note
23994deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson    /// diagnostic indicating why it's not foldable. DiagLoc indicates a caret
24094deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson    /// position for the error, and DiagExpr is the expression that caused
24194deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson    /// the error.
24294deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson    /// If the expression is foldable, but not an integer constant expression,
24394deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson    /// Diag contains a note diagnostic that describes why it isn't an integer
24494deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson    /// constant expression. If the expression *is* an integer constant
24594deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson    /// expression, then Diag will be zero.
24694deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson    unsigned Diag;
24794deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson    const Expr *DiagExpr;
24894deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson    SourceLocation DiagLoc;
2491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
25094deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson    EvalResult() : HasSideEffects(false), Diag(0), DiagExpr(0) {}
251e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara
252e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara    // isGlobalLValue - Return true if the evaluated lvalue expression
253e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara    // is global.
254e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara    bool isGlobalLValue() const;
255e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara    // hasSideEffects - Return true if the evaluated expression has
256e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara    // side effects.
257e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara    bool hasSideEffects() const {
258e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara      return HasSideEffects;
259e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara    }
26094deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson  };
26194deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson
2626ee7aa154e8bbb21a21254293410b944f78b0bfeChris Lattner  /// Evaluate - Return true if this is a constant which we can fold using
263019f4e858e78587f2241ff1a76c747d7bcd7578cChris Lattner  /// any crazy technique (that has nothing to do with language standards) that
264019f4e858e78587f2241ff1a76c747d7bcd7578cChris Lattner  /// we want to.  If this function returns true, it returns the folded constant
265019f4e858e78587f2241ff1a76c747d7bcd7578cChris Lattner  /// in Result.
2665b45d4ef1ea3f04ec863daf8aa29be6c6e021750Anders Carlsson  bool Evaluate(EvalResult &Result, ASTContext &Ctx) const;
2675b45d4ef1ea3f04ec863daf8aa29be6c6e021750Anders Carlsson
268cd7a445c6b46c5585580dfb652300c8483c0cb6bJohn McCall  /// EvaluateAsBooleanCondition - Return true if this is a constant
269cd7a445c6b46c5585580dfb652300c8483c0cb6bJohn McCall  /// which we we can fold and convert to a boolean condition using
270cd7a445c6b46c5585580dfb652300c8483c0cb6bJohn McCall  /// any crazy technique that we want to.
271cd7a445c6b46c5585580dfb652300c8483c0cb6bJohn McCall  bool EvaluateAsBooleanCondition(bool &Result, ASTContext &Ctx) const;
272cd7a445c6b46c5585580dfb652300c8483c0cb6bJohn McCall
2736ee7aa154e8bbb21a21254293410b944f78b0bfeChris Lattner  /// isEvaluatable - Call Evaluate to see if this expression can be constant
27445b6b9d080ac56917337d73d8f1cd6374b27b05dChris Lattner  /// folded, but discard the result.
27545b6b9d080ac56917337d73d8f1cd6374b27b05dChris Lattner  bool isEvaluatable(ASTContext &Ctx) const;
276c44eec6dd29ee9415cbd38a35deff4c8b67abb6aAnders Carlsson
2776ddf4784a22b994b954ed74c6061d4603d474639Fariborz Jahanian  /// HasSideEffects - This routine returns true for all those expressions
278c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  /// which must be evaluated each time and must not be optimization away
2796ddf4784a22b994b954ed74c6061d4603d474639Fariborz Jahanian  /// or evaluated at compile time. Example is a function call, volatile
2806ddf4784a22b994b954ed74c6061d4603d474639Fariborz Jahanian  /// variable read.
281393c247fe025ccb5f914e37e948192ea86faef8cFariborz Jahanian  bool HasSideEffects(ASTContext &Ctx) const;
282c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
28351fe996231b1d7199f76e4005ff4c943d5deeecdAnders Carlsson  /// EvaluateAsInt - Call Evaluate and return the folded integer. This
28451fe996231b1d7199f76e4005ff4c943d5deeecdAnders Carlsson  /// must be called on an expression that constant folds to an integer.
28551fe996231b1d7199f76e4005ff4c943d5deeecdAnders Carlsson  llvm::APSInt EvaluateAsInt(ASTContext &Ctx) const;
28651fe996231b1d7199f76e4005ff4c943d5deeecdAnders Carlsson
287b2f295c8050fb8c141bf2cf38eed0a56e99d0092Eli Friedman  /// EvaluateAsLValue - Evaluate an expression to see if it's a lvalue
288b2f295c8050fb8c141bf2cf38eed0a56e99d0092Eli Friedman  /// with link time known address.
2891b78276a75a5a0f496a82429c1ff9604d622a76dAnders Carlsson  bool EvaluateAsLValue(EvalResult &Result, ASTContext &Ctx) const;
2901b78276a75a5a0f496a82429c1ff9604d622a76dAnders Carlsson
291e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara  /// EvaluateAsLValue - Evaluate an expression to see if it's a lvalue.
292e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara  bool EvaluateAsAnyLValue(EvalResult &Result, ASTContext &Ctx) const;
293e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara
294ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor  /// \brief Enumeration used to describe how \c isNullPointerConstant()
295ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor  /// should cope with value-dependent expressions.
296ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor  enum NullPointerConstantValueDependence {
297ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor    /// \brief Specifies that the expression should never be value-dependent.
298ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor    NPC_NeverValueDependent = 0,
299c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
300ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor    /// \brief Specifies that a value-dependent expression of integral or
301ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor    /// dependent type should be considered a null pointer constant.
302ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor    NPC_ValueDependentIsNull,
303c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
304ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor    /// \brief Specifies that a value-dependent expression should be considered
305ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor    /// to never be a null pointer constant.
306ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor    NPC_ValueDependentIsNotNull
307ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor  };
308c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
309efa9b3877ef298bcb792600ac33521827e1f7fafAnders Carlsson  /// isNullPointerConstant - C99 6.3.2.3p3 -  Return true if this is either an
310efa9b3877ef298bcb792600ac33521827e1f7fafAnders Carlsson  /// integer constant expression with the value zero, or if this is one that is
311efa9b3877ef298bcb792600ac33521827e1f7fafAnders Carlsson  /// cast to void*.
312ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor  bool isNullPointerConstant(ASTContext &Ctx,
313ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor                             NullPointerConstantValueDependence NPC) const;
314efa9b3877ef298bcb792600ac33521827e1f7fafAnders Carlsson
31544baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian  /// isOBJCGCCandidate - Return true if this expression may be used in a read/
3161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// write barrier.
317102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanian  bool isOBJCGCCandidate(ASTContext &Ctx) const;
3181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3194e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek  /// IgnoreParens - Ignore parentheses.  If this Expr is a ParenExpr, return
3201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///  its subexpression.  If that subexpression is also a ParenExpr,
3214e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek  ///  then this method recursively returns its subexpression, and so forth.
3224e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek  ///  Otherwise, the method returns the current Expr.
3232b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner  Expr *IgnoreParens();
32456f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner
32556f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner  /// IgnoreParenCasts - Ignore parentheses and casts.  Strip off any ParenExpr
32627c8dc06f65d7abcf6a7e7f64a7960c9a150ca01Douglas Gregor  /// or CastExprs, returning their operand.
32756f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner  Expr *IgnoreParenCasts();
3281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3292fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCall  /// IgnoreParenImpCasts - Ignore parentheses and implicit casts.  Strip off any
3302fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCall  /// ParenExpr or ImplicitCastExprs, returning their operand.
3312fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCall  Expr *IgnoreParenImpCasts();
3322fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCall
333ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner  /// IgnoreParenNoopCasts - Ignore parentheses and casts that do not change the
334ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner  /// value (including ptr->int casts of the same size).  Strip off any
335ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner  /// ParenExpr or CastExprs, returning their operand.
336ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner  Expr *IgnoreParenNoopCasts(ASTContext &Ctx);
3371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3386eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor  /// \brief Determine whether this expression is a default function argument.
3396eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor  ///
3406eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor  /// Default arguments are implicitly generated in the abstract syntax tree
341c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  /// by semantic analysis for function calls, object constructions, etc. in
3426eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor  /// C++. Default arguments are represented by \c CXXDefaultArgExpr nodes;
3436eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor  /// this routine also looks through any implicit casts to determine whether
3446eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor  /// the expression is a default argument.
3456eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor  bool isDefaultArgument() const;
346c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
3472f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor  /// \brief Determine whether this expression directly creates a
3482f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor  /// temporary object (of class type).
3492f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor  bool isTemporaryObject() const { return getTemporaryObject() != 0; }
3502f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor
3512f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor  /// \brief If this expression directly creates a temporary object of
3522f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor  /// class type, return the expression that actually constructs that
3532f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor  /// temporary object.
3542f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor  const Expr *getTemporaryObject() const;
3552f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor
3562b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner  const Expr *IgnoreParens() const {
3574e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek    return const_cast<Expr*>(this)->IgnoreParens();
3584e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek  }
35956f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner  const Expr *IgnoreParenCasts() const {
36056f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner    return const_cast<Expr*>(this)->IgnoreParenCasts();
36156f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner  }
362ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner  const Expr *IgnoreParenNoopCasts(ASTContext &Ctx) const {
363ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner    return const_cast<Expr*>(this)->IgnoreParenNoopCasts(Ctx);
364ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner  }
3651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
366898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  static bool hasAnyTypeDependentArguments(Expr** Exprs, unsigned NumExprs);
367898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  static bool hasAnyValueDependentArguments(Expr** Exprs, unsigned NumExprs);
368898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor
3691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
3705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return T->getStmtClass() >= firstExprConstant &&
3711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump           T->getStmtClass() <= lastExprConstant;
3725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
3735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Expr *) { return true; }
3745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
3755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
3761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3775549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek//===----------------------------------------------------------------------===//
3785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// Primary Expressions.
3795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===//
3805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
381a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor/// \brief Represents the qualifier that may precede a C++ name, e.g., the
382a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor/// "std::" in "std::sort".
383a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregorstruct NameQualifier {
384a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// \brief The nested name specifier.
385a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  NestedNameSpecifier *NNS;
386c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
387a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// \brief The source range covered by the nested name specifier.
388a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  SourceRange Range;
389a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor};
390a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor
391a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor/// \brief Represents an explicit template argument list in C++, e.g.,
392a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor/// the "<int>" in "sort<int>".
393a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregorstruct ExplicitTemplateArgumentList {
394a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// \brief The source location of the left angle bracket ('<');
395a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  SourceLocation LAngleLoc;
396c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
397a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// \brief The source location of the right angle bracket ('>');
398a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  SourceLocation RAngleLoc;
399c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
400a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// \brief The number of template arguments in TemplateArgs.
401a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// The actual template arguments (if any) are stored after the
402a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// ExplicitTemplateArgumentList structure.
403a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  unsigned NumTemplateArgs;
404c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
405a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// \brief Retrieve the template arguments
406833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  TemplateArgumentLoc *getTemplateArgs() {
407833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    return reinterpret_cast<TemplateArgumentLoc *> (this + 1);
408a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  }
409c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
410a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// \brief Retrieve the template arguments
411833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  const TemplateArgumentLoc *getTemplateArgs() const {
412833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    return reinterpret_cast<const TemplateArgumentLoc *> (this + 1);
413a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  }
414d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall
415d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  void initializeFrom(const TemplateArgumentListInfo &List);
416d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  void copyInto(TemplateArgumentListInfo &List) const;
417d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  static std::size_t sizeFor(const TemplateArgumentListInfo &List);
418a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor};
419c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
4205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// DeclRefExpr - [C99 6.5.1p2] - A reference to a declared variable, function,
4215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// enum, etc.
4225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass DeclRefExpr : public Expr {
423a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  enum {
424c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    // Flag on DecoratedD that specifies when this declaration reference
425a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor    // expression has a C++ nested-name-specifier.
426a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor    HasQualifierFlag = 0x01,
427c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    // Flag on DecoratedD that specifies when this declaration reference
428a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor    // expression has an explicit C++ template argument list.
429a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor    HasExplicitTemplateArgumentListFlag = 0x02
430a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  };
431c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
432c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  // DecoratedD - The declaration that we are referencing, plus two bits to
433a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  // indicate whether (1) the declaration's name was explicitly qualified and
434c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  // (2) the declaration's name was followed by an explicit template
435a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  // argument list.
436dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall  llvm::PointerIntPair<ValueDecl *, 2> DecoratedD;
437c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
438a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  // Loc - The location of the declaration name itself.
4395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation Loc;
4409e922b1663ecb95dc7eee03002fd66ed18fb3192Argyrios Kyrtzidis
441a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// \brief Retrieve the qualifier that preceded the declaration name, if any.
442a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  NameQualifier *getNameQualifier() {
4432cf719c3c3d805f630dfc6b1255e52647820888eSebastian Redl    if ((DecoratedD.getInt() & HasQualifierFlag) == 0)
444a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor      return 0;
445c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
446a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor    return reinterpret_cast<NameQualifier *> (this + 1);
447a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  }
448c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
449a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// \brief Retrieve the qualifier that preceded the member name, if any.
450a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  const NameQualifier *getNameQualifier() const {
451a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor    return const_cast<DeclRefExpr *>(this)->getNameQualifier();
452a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  }
453c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
454a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// \brief Retrieve the explicit template argument list that followed the
455a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// member template name, if any.
456a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  ExplicitTemplateArgumentList *getExplicitTemplateArgumentList() {
4572cf719c3c3d805f630dfc6b1255e52647820888eSebastian Redl    if ((DecoratedD.getInt() & HasExplicitTemplateArgumentListFlag) == 0)
458a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor      return 0;
459c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
4602cf719c3c3d805f630dfc6b1255e52647820888eSebastian Redl    if ((DecoratedD.getInt() & HasQualifierFlag) == 0)
461a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor      return reinterpret_cast<ExplicitTemplateArgumentList *>(this + 1);
462c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
463a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor    return reinterpret_cast<ExplicitTemplateArgumentList *>(
464a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor                                                      getNameQualifier() + 1);
465a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  }
466c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
467a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// \brief Retrieve the explicit template argument list that followed the
468a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// member template name, if any.
469a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  const ExplicitTemplateArgumentList *getExplicitTemplateArgumentList() const {
470a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor    return const_cast<DeclRefExpr *>(this)->getExplicitTemplateArgumentList();
471a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  }
472c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
473a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  DeclRefExpr(NestedNameSpecifier *Qualifier, SourceRange QualifierRange,
474dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall              ValueDecl *D, SourceLocation NameLoc,
475d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall              const TemplateArgumentListInfo *TemplateArgs,
4760da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor              QualType T);
477c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
4789e922b1663ecb95dc7eee03002fd66ed18fb3192Argyrios Kyrtzidisprotected:
4790da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor  /// \brief Computes the type- and value-dependence flags for this
4800da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor  /// declaration reference expression.
4810da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor  void computeDependence();
4829e922b1663ecb95dc7eee03002fd66ed18fb3192Argyrios Kyrtzidis
483dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall  DeclRefExpr(StmtClass SC, ValueDecl *d, QualType t, SourceLocation l) :
4840da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor    Expr(SC, t, false, false), DecoratedD(d, 0), Loc(l) {
4850da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor    computeDependence();
4860da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor  }
4871a49af9681c350fef58e677f85ccb9a77e8e9d0aDouglas Gregor
4885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
489dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall  DeclRefExpr(ValueDecl *d, QualType t, SourceLocation l) :
4900da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor    Expr(DeclRefExprClass, t, false, false), DecoratedD(d, 0), Loc(l) {
4910da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor    computeDependence();
4920da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor  }
4931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4940b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor  /// \brief Construct an empty declaration reference expression.
4951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  explicit DeclRefExpr(EmptyShell Empty)
4960b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor    : Expr(DeclRefExprClass, Empty) { }
4970b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor
498a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  static DeclRefExpr *Create(ASTContext &Context,
499a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor                             NestedNameSpecifier *Qualifier,
500a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor                             SourceRange QualifierRange,
501dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall                             ValueDecl *D,
502a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor                             SourceLocation NameLoc,
5030da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor                             QualType T,
5040da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor                             const TemplateArgumentListInfo *TemplateArgs = 0);
505c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
506dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall  ValueDecl *getDecl() { return DecoratedD.getPointer(); }
507dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall  const ValueDecl *getDecl() const { return DecoratedD.getPointer(); }
508dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall  void setDecl(ValueDecl *NewD) { DecoratedD.setPointer(NewD); }
509904eed3f6148758d39a2d3c88f3133274460d645Douglas Gregor
5109e922b1663ecb95dc7eee03002fd66ed18fb3192Argyrios Kyrtzidis  SourceLocation getLocation() const { return Loc; }
5110b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor  void setLocation(SourceLocation L) { Loc = L; }
512a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  virtual SourceRange getSourceRange() const;
5131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
514a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// \brief Determine whether this declaration reference was preceded by a
515a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// C++ nested-name-specifier, e.g., \c N::foo.
516a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  bool hasQualifier() const { return DecoratedD.getInt() & HasQualifierFlag; }
517c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
518a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// \brief If the name was qualified, retrieves the source range of
519a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// the nested-name-specifier that precedes the name. Otherwise,
520a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// returns an empty source range.
521a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  SourceRange getQualifierRange() const {
522a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor    if (!hasQualifier())
523a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor      return SourceRange();
524c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
525a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor    return getNameQualifier()->Range;
526a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  }
527c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
528c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  /// \brief If the name was qualified, retrieves the nested-name-specifier
529a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// that precedes the name. Otherwise, returns NULL.
530a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  NestedNameSpecifier *getQualifier() const {
531a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor    if (!hasQualifier())
532a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor      return 0;
533c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
534a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor    return getNameQualifier()->NNS;
535a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  }
536c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
537a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// \brief Determines whether this member expression actually had a C++
538a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// template argument list explicitly specified, e.g., x.f<int>.
539a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  bool hasExplicitTemplateArgumentList() const {
540a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor    return DecoratedD.getInt() & HasExplicitTemplateArgumentListFlag;
541a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  }
542d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall
543d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  /// \brief Copies the template arguments (if present) into the given
544d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  /// structure.
545d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
546d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall    if (hasExplicitTemplateArgumentList())
547d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall      getExplicitTemplateArgumentList()->copyInto(List);
548d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  }
549c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
550a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// \brief Retrieve the location of the left angle bracket following the
551a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// member name ('<'), if any.
552a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  SourceLocation getLAngleLoc() const {
553a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor    if (!hasExplicitTemplateArgumentList())
554a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor      return SourceLocation();
555c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
556a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor    return getExplicitTemplateArgumentList()->LAngleLoc;
557a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  }
558c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
559a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// \brief Retrieve the template arguments provided as part of this
560a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// template-id.
561833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  const TemplateArgumentLoc *getTemplateArgs() const {
562a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor    if (!hasExplicitTemplateArgumentList())
563a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor      return 0;
564c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
565a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor    return getExplicitTemplateArgumentList()->getTemplateArgs();
566a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  }
567c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
568a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// \brief Retrieve the number of template arguments provided as part of this
569a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// template-id.
570a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  unsigned getNumTemplateArgs() const {
571a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor    if (!hasExplicitTemplateArgumentList())
572a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor      return 0;
573c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
574a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor    return getExplicitTemplateArgumentList()->NumTemplateArgs;
575a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  }
576c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
577a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// \brief Retrieve the location of the right angle bracket following the
578a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// template arguments ('>').
579a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  SourceLocation getRAngleLoc() const {
580a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor    if (!hasExplicitTemplateArgumentList())
581a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor      return SourceLocation();
582c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
583a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor    return getExplicitTemplateArgumentList()->RAngleLoc;
584a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  }
585c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
5861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
58799e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor    return T->getStmtClass() == DeclRefExprClass;
5885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
5895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const DeclRefExpr *) { return true; }
5901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
59177ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  // Iterators
59277ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_begin();
59377ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_end();
5945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
5955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
596d9f6910f4ef37c0e8eeee2a01287d9572c3176efChris Lattner/// PredefinedExpr - [C99 6.4.2.2] - A predefined identifier such as __func__.
597d9f6910f4ef37c0e8eeee2a01287d9572c3176efChris Lattnerclass PredefinedExpr : public Expr {
598227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlssonpublic:
599227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson  enum IdentType {
600227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson    Func,
601227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson    Function,
602848fa64143fbe5ae62a601ad61277f741e54dfabAnders Carlsson    PrettyFunction,
603848fa64143fbe5ae62a601ad61277f741e54dfabAnders Carlsson    /// PrettyFunctionNoVirtual - The same as PrettyFunction, except that the
604848fa64143fbe5ae62a601ad61277f741e54dfabAnders Carlsson    /// 'virtual' keyword is omitted for virtual member functions.
605848fa64143fbe5ae62a601ad61277f741e54dfabAnders Carlsson    PrettyFunctionNoVirtual
606227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson  };
6071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
608227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlssonprivate:
609227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson  SourceLocation Loc;
610227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson  IdentType Type;
611227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlssonpublic:
6121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  PredefinedExpr(SourceLocation l, QualType type, IdentType IT)
613c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    : Expr(PredefinedExprClass, type, type->isDependentType(),
614773f3973cf5e2b6b8788e895967dcb3c1e6ffe79Anders Carlsson           type->isDependentType()), Loc(l), Type(IT) {}
6151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
61617fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor  /// \brief Construct an empty predefined expression.
6171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  explicit PredefinedExpr(EmptyShell Empty)
61817fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor    : Expr(PredefinedExprClass, Empty) { }
61917fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor
620227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson  IdentType getIdentType() const { return Type; }
62117fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor  void setIdentType(IdentType IT) { Type = IT; }
62217fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor
62317fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor  SourceLocation getLocation() const { return Loc; }
62417fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor  void setLocation(SourceLocation L) { Loc = L; }
62517fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor
626848fa64143fbe5ae62a601ad61277f741e54dfabAnders Carlsson  static std::string ComputeName(IdentType IT, const Decl *CurrentDecl);
6273a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson
628227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson  virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
629227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson
6301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
6311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == PredefinedExprClass;
632227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson  }
633d9f6910f4ef37c0e8eeee2a01287d9572c3176efChris Lattner  static bool classof(const PredefinedExpr *) { return true; }
6341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
63577ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  // Iterators
63677ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_begin();
63777ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_end();
638227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson};
639227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson
6405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass IntegerLiteral : public Expr {
6415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  llvm::APInt Value;
6425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation Loc;
6435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
6441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  // type should be IntTy, LongTy, LongLongTy, UnsignedIntTy, UnsignedLongTy,
6455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // or UnsignedLongLongTy
6465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  IntegerLiteral(const llvm::APInt &V, QualType type, SourceLocation l)
6472333f7727f97018d6742e1e0938133bcfad967abEli Friedman    : Expr(IntegerLiteralClass, type, false, false), Value(V), Loc(l) {
6485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    assert(type->isIntegerType() && "Illegal type in IntegerLiteral");
6495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
650a135fb43eb94524a6529768596a4533eed9aa70dAnders Carlsson
6510b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor  /// \brief Construct an empty integer literal.
6521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  explicit IntegerLiteral(EmptyShell Empty)
6530b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor    : Expr(IntegerLiteralClass, Empty) { }
6540b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor
6555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  const llvm::APInt &getValue() const { return Value; }
6565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
6575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
658313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor  /// \brief Retrieve the location of the literal.
659313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor  SourceLocation getLocation() const { return Loc; }
660313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor
6610b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor  void setValue(const llvm::APInt &Val) { Value = Val; }
6620b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor  void setLocation(SourceLocation Location) { Loc = Location; }
6630b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor
6641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
6651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == IntegerLiteralClass;
6665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
6675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const IntegerLiteral *) { return true; }
6681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
66977ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  // Iterators
67077ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_begin();
67177ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_end();
6725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
6735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
6745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass CharacterLiteral : public Expr {
6755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  unsigned Value;
6765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation Loc;
677c250aae4f645833aed3a6321bc8598f7330dce8dChris Lattner  bool IsWide;
6785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
6795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // type should be IntTy
680c250aae4f645833aed3a6321bc8598f7330dce8dChris Lattner  CharacterLiteral(unsigned value, bool iswide, QualType type, SourceLocation l)
6812333f7727f97018d6742e1e0938133bcfad967abEli Friedman    : Expr(CharacterLiteralClass, type, false, false), Value(value), Loc(l),
6822333f7727f97018d6742e1e0938133bcfad967abEli Friedman      IsWide(iswide) {
6835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
6840b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor
6850b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor  /// \brief Construct an empty character literal.
6860b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor  CharacterLiteral(EmptyShell Empty) : Expr(CharacterLiteralClass, Empty) { }
6870b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor
688018d8e0596dd57401eeddcf11ac84ff0a065fbbeChris Lattner  SourceLocation getLocation() const { return Loc; }
689c250aae4f645833aed3a6321bc8598f7330dce8dChris Lattner  bool isWide() const { return IsWide; }
6901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
6921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  unsigned getValue() const { return Value; }
6945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
6950b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor  void setLocation(SourceLocation Location) { Loc = Location; }
6960b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor  void setWide(bool W) { IsWide = W; }
6970b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor  void setValue(unsigned Val) { Value = Val; }
6980b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor
6991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
7001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == CharacterLiteralClass;
7015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
7025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const CharacterLiteral *) { return true; }
70377ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek
70477ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  // Iterators
70577ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_begin();
70677ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_end();
7075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
7085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
7095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass FloatingLiteral : public Expr {
710525a05093a4816af961fe2bc6b8a81c17e2e26c2Chris Lattner  llvm::APFloat Value;
711720c4ec57b6110873cd533ad434853a27e7c3f4aTed Kremenek  bool IsExact : 1;
7125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation Loc;
7135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
7141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  FloatingLiteral(const llvm::APFloat &V, bool isexact,
715720c4ec57b6110873cd533ad434853a27e7c3f4aTed Kremenek                  QualType Type, SourceLocation L)
7162333f7727f97018d6742e1e0938133bcfad967abEli Friedman    : Expr(FloatingLiteralClass, Type, false, false), Value(V),
7172333f7727f97018d6742e1e0938133bcfad967abEli Friedman      IsExact(isexact), Loc(L) {}
7185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
71917fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor  /// \brief Construct an empty floating-point literal.
7201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  explicit FloatingLiteral(EmptyShell Empty)
72117fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor    : Expr(FloatingLiteralClass, Empty), Value(0.0) { }
72217fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor
723c9bec4bfea9090a08dd83a7b213f0c8adf8d78ecChris Lattner  const llvm::APFloat &getValue() const { return Value; }
72417fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor  void setValue(const llvm::APFloat &Val) { Value = Val; }
72517fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor
726720c4ec57b6110873cd533ad434853a27e7c3f4aTed Kremenek  bool isExact() const { return IsExact; }
72717fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor  void setExact(bool E) { IsExact = E; }
728c9bec4bfea9090a08dd83a7b213f0c8adf8d78ecChris Lattner
729da8249e57f3badecf925571881fe57243935c6c1Chris Lattner  /// getValueAsApproximateDouble - This returns the value as an inaccurate
730da8249e57f3badecf925571881fe57243935c6c1Chris Lattner  /// double.  Note that this may cause loss of precision, but is useful for
731da8249e57f3badecf925571881fe57243935c6c1Chris Lattner  /// debugging dumps, etc.
732da8249e57f3badecf925571881fe57243935c6c1Chris Lattner  double getValueAsApproximateDouble() const;
7331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
73417fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor  SourceLocation getLocation() const { return Loc; }
73517fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor  void setLocation(SourceLocation L) { Loc = L; }
73617fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor
7375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
7385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
7391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
7401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == FloatingLiteralClass;
7415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
7425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const FloatingLiteral *) { return true; }
7431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
74477ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  // Iterators
74577ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_begin();
74677ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_end();
7475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
7485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
7495d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner/// ImaginaryLiteral - We support imaginary integer and floating point literals,
7505d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner/// like "1.0i".  We represent these as a wrapper around FloatingLiteral and
7515d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner/// IntegerLiteral classes.  Instances of this class always have a Complex type
7525d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner/// whose element type matches the subexpression.
7535d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner///
7545d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattnerclass ImaginaryLiteral : public Expr {
7555549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Stmt *Val;
7565d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattnerpublic:
7575d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner  ImaginaryLiteral(Expr *val, QualType Ty)
7582333f7727f97018d6742e1e0938133bcfad967abEli Friedman    : Expr(ImaginaryLiteralClass, Ty, false, false), Val(val) {}
7591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
760cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor  /// \brief Build an empty imaginary literal.
7611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  explicit ImaginaryLiteral(EmptyShell Empty)
762cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor    : Expr(ImaginaryLiteralClass, Empty) { }
763cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor
7645549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  const Expr *getSubExpr() const { return cast<Expr>(Val); }
7655549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getSubExpr() { return cast<Expr>(Val); }
766cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor  void setSubExpr(Expr *E) { Val = E; }
767cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor
7685d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner  virtual SourceRange getSourceRange() const { return Val->getSourceRange(); }
7691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
7701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == ImaginaryLiteralClass;
7715d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner  }
7725d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner  static bool classof(const ImaginaryLiteral *) { return true; }
7731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7745d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner  // Iterators
7755d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner  virtual child_iterator child_begin();
7765d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner  virtual child_iterator child_end();
7775d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner};
7785d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner
779e6a82b2c29ad05534841e5f8fd033fb17b6f61e2Ted Kremenek/// StringLiteral - This represents a string literal expression, e.g. "foo"
780e6a82b2c29ad05534841e5f8fd033fb17b6f61e2Ted Kremenek/// or L"bar" (wide strings).  The actual string is returned by getStrData()
781e6a82b2c29ad05534841e5f8fd033fb17b6f61e2Ted Kremenek/// is NOT null-terminated, and the length of the string is determined by
782a7ad98ff0919d6a24ea7c46634ea29bea551c1a0Chris Lattner/// calling getByteLength().  The C type for a string is always a
783c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// ConstantArrayType.  In C++, the char type is const qualified, in C it is
784c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// not.
785690398188ea5b428f06aa13c7d4ce6eb741ad4f9Chris Lattner///
786690398188ea5b428f06aa13c7d4ce6eb741ad4f9Chris Lattner/// Note that strings in C can be formed by concatenation of multiple string
7878bea7c0ee44c71c817de7dc2be932b73bec90c9fChris Lattner/// literal pptokens in translation phase #6.  This keeps track of the locations
788690398188ea5b428f06aa13c7d4ce6eb741ad4f9Chris Lattner/// of each of these pieces.
789c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner///
790c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// Strings in C can also be truncated and extended by assigning into arrays,
791c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// e.g. with constructs like:
792c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner///   char X[2] = "foobar";
793c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// In this case, getByteLength() will return 6, but the string literal will
794c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// have type "char[2]".
7955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass StringLiteral : public Expr {
7965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  const char *StrData;
7975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  unsigned ByteLength;
7985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool IsWide;
799726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner  unsigned NumConcatenated;
800726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner  SourceLocation TokLocs[1];
8012085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner
8022333f7727f97018d6742e1e0938133bcfad967abEli Friedman  StringLiteral(QualType Ty) : Expr(StringLiteralClass, Ty, false, false) {}
8031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
80442602bb40aefcc2751d4078ba88aacf4d965c9bdDouglas Gregorprotected:
80542602bb40aefcc2751d4078ba88aacf4d965c9bdDouglas Gregor  virtual void DoDestroy(ASTContext &C);
80642602bb40aefcc2751d4078ba88aacf4d965c9bdDouglas Gregor
8075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
8082085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner  /// This is the "fully general" constructor that allows representation of
8092085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner  /// strings formed from multiple concatenated tokens.
8102085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner  static StringLiteral *Create(ASTContext &C, const char *StrData,
8112085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner                               unsigned ByteLength, bool Wide, QualType Ty,
812a135fb43eb94524a6529768596a4533eed9aa70dAnders Carlsson                               const SourceLocation *Loc, unsigned NumStrs);
8132085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner
8142085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner  /// Simple constructor for string literals made from one token.
8151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static StringLiteral *Create(ASTContext &C, const char *StrData,
8162085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner                               unsigned ByteLength,
8172085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner                               bool Wide, QualType Ty, SourceLocation Loc) {
8182085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner    return Create(C, StrData, ByteLength, Wide, Ty, &Loc, 1);
8192085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner  }
820a135fb43eb94524a6529768596a4533eed9aa70dAnders Carlsson
821673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor  /// \brief Construct an empty string literal.
822673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor  static StringLiteral *CreateEmpty(ASTContext &C, unsigned NumStrs);
823673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor
824b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar  llvm::StringRef getString() const {
825b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar    return llvm::StringRef(StrData, ByteLength);
826b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar  }
827b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar  // FIXME: These are deprecated, replace with StringRef.
8285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  const char *getStrData() const { return StrData; }
8295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  unsigned getByteLength() const { return ByteLength; }
830673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor
831673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor  /// \brief Sets the string data to the given string data.
832b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar  void setString(ASTContext &C, llvm::StringRef Str);
833673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor
8345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isWide() const { return IsWide; }
835673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor  void setWide(bool W) { IsWide = W; }
836673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor
8378d4141f83d9de379547cf05bd75d4c6cf894b189Steve Naroff  bool containsNonAsciiOrNull() const {
838b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar    llvm::StringRef Str = getString();
839b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar    for (unsigned i = 0, e = Str.size(); i != e; ++i)
840b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar      if (!isascii(Str[i]) || !Str[i])
84133fdb738a6c125f4c788733897021b7c1a062b0cSteve Naroff        return true;
84233fdb738a6c125f4c788733897021b7c1a062b0cSteve Naroff    return false;
84333fdb738a6c125f4c788733897021b7c1a062b0cSteve Naroff  }
844726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner  /// getNumConcatenated - Get the number of string literal tokens that were
845726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner  /// concatenated in translation phase #6 to form this string literal.
846726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner  unsigned getNumConcatenated() const { return NumConcatenated; }
8471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
848726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner  SourceLocation getStrTokenLoc(unsigned TokNum) const {
849726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner    assert(TokNum < NumConcatenated && "Invalid tok number");
850726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner    return TokLocs[TokNum];
851726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner  }
8521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  void setStrTokenLoc(unsigned TokNum, SourceLocation L) {
853673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor    assert(TokNum < NumConcatenated && "Invalid tok number");
854673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor    TokLocs[TokNum] = L;
855673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor  }
856673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor
857b137299ce5bb6c36fbba651858600857fda4dd50Chris Lattner  typedef const SourceLocation *tokloc_iterator;
858b137299ce5bb6c36fbba651858600857fda4dd50Chris Lattner  tokloc_iterator tokloc_begin() const { return TokLocs; }
859b137299ce5bb6c36fbba651858600857fda4dd50Chris Lattner  tokloc_iterator tokloc_end() const { return TokLocs+NumConcatenated; }
8605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
8611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  virtual SourceRange getSourceRange() const {
8621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return SourceRange(TokLocs[0], TokLocs[NumConcatenated-1]);
8635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
8641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
8651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == StringLiteralClass;
8665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
8675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const StringLiteral *) { return true; }
8681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
86977ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  // Iterators
87077ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_begin();
87177ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_end();
8725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
8735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
8745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ParenExpr - This represents a parethesized expression, e.g. "(1)".  This
8755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// AST node is only formed if full location information is requested.
8765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass ParenExpr : public Expr {
8775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation L, R;
8785549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Stmt *Val;
8795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
8805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ParenExpr(SourceLocation l, SourceLocation r, Expr *val)
881898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor    : Expr(ParenExprClass, val->getType(),
8821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump           val->isTypeDependent(), val->isValueDependent()),
883898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor      L(l), R(r), Val(val) {}
8841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
885c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor  /// \brief Construct an empty parenthesized expression.
8861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  explicit ParenExpr(EmptyShell Empty)
887c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor    : Expr(ParenExprClass, Empty) { }
888c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor
8895549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  const Expr *getSubExpr() const { return cast<Expr>(Val); }
8905549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getSubExpr() { return cast<Expr>(Val); }
891c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor  void setSubExpr(Expr *E) { Val = E; }
892c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor
893866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek  virtual SourceRange getSourceRange() const { return SourceRange(L, R); }
8945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
895313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor  /// \brief Get the location of the left parentheses '('.
896313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor  SourceLocation getLParen() const { return L; }
897c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor  void setLParen(SourceLocation Loc) { L = Loc; }
898313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor
899313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor  /// \brief Get the location of the right parentheses ')'.
900313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor  SourceLocation getRParen() const { return R; }
901c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor  void setRParen(SourceLocation Loc) { R = Loc; }
902313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor
9031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
9041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == ParenExprClass;
9055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
9065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const ParenExpr *) { return true; }
9071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
90877ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  // Iterators
90977ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_begin();
91077ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_end();
9115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
9125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
9135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
9140518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl/// UnaryOperator - This represents the unary-expression's (except sizeof and
9150518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl/// alignof), the postinc/postdec operators from postfix-expression, and various
9165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// extensions.
917dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner///
918dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner/// Notes on various nodes:
919dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner///
920dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner/// Real/Imag - These return the real/imag part of a complex operand.  If
921dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner///   applied to a non-complex value, the former returns its operand and the
922dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner///   later returns zero in the type of the operand.
923dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner///
92473d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner/// __builtin_offsetof(type, a.b[10]) is represented as a unary operator whose
9251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump///   subexpression is a compound literal with the various MemberExpr and
9268ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor///   ArraySubscriptExpr's applied to it. (This is only used in C)
92773d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner///
9285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass UnaryOperator : public Expr {
9295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
93013d130c3d225cdb5b1e6d9e86cea12eea718c707Chris Lattner  // Note that additions to this should also update the StmtVisitor class.
9315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  enum Opcode {
9325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    PostInc, PostDec, // [C99 6.5.2.4] Postfix increment and decrement operators
9335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    PreInc, PreDec,   // [C99 6.5.3.1] Prefix increment and decrement operators.
9345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    AddrOf, Deref,    // [C99 6.5.3.2] Address and indirection operators.
9355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Plus, Minus,      // [C99 6.5.3.3] Unary arithmetic operators.
9365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Not, LNot,        // [C99 6.5.3.3] Unary arithmetic operators.
9375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Real, Imag,       // "__real expr"/"__imag expr" Extension.
93873d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner    Extension,        // __extension__ marker.
93973d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner    OffsetOf          // __builtin_offsetof
9405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  };
9415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprivate:
9425549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Stmt *Val;
9435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  Opcode Opc;
9445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation Loc;
9451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumppublic:
9465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
9475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  UnaryOperator(Expr *input, Opcode opc, QualType type, SourceLocation l)
9489103bb27f4eefa0e0d7935387750e3aca24abc49Douglas Gregor    : Expr(UnaryOperatorClass, type,
9499103bb27f4eefa0e0d7935387750e3aca24abc49Douglas Gregor           input->isTypeDependent() && opc != OffsetOf,
9501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump           input->isValueDependent()),
9519103bb27f4eefa0e0d7935387750e3aca24abc49Douglas Gregor      Val(input), Opc(opc), Loc(l) {}
9525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
9530b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor  /// \brief Build an empty unary operator.
9541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  explicit UnaryOperator(EmptyShell Empty)
9550b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor    : Expr(UnaryOperatorClass, Empty), Opc(AddrOf) { }
9560b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor
9575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  Opcode getOpcode() const { return Opc; }
9580b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor  void setOpcode(Opcode O) { Opc = O; }
9590b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor
9605549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getSubExpr() const { return cast<Expr>(Val); }
9610b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor  void setSubExpr(Expr *E) { Val = E; }
9620b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor
9635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// getOperatorLoc - Return the location of the operator.
9645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation getOperatorLoc() const { return Loc; }
9650b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor  void setOperatorLoc(SourceLocation L) { Loc = L; }
9660b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor
9675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// isPostfix - Return true if this is a postfix operation, like x++.
9682085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner  static bool isPostfix(Opcode Op) {
9692085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner    return Op == PostInc || Op == PostDec;
9702085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner  }
9715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
9725a56ac30d04e8f0431a08980885662a47a6308aaTed Kremenek  /// isPostfix - Return true if this is a prefix operation, like --x.
9732085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner  static bool isPrefix(Opcode Op) {
9742085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner    return Op == PreInc || Op == PreDec;
9752085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner  }
9765a56ac30d04e8f0431a08980885662a47a6308aaTed Kremenek
9775a56ac30d04e8f0431a08980885662a47a6308aaTed Kremenek  bool isPrefix() const { return isPrefix(Opc); }
9785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isPostfix() const { return isPostfix(Opc); }
9795d826b82936beb2c32dd02460332ba8035192c65Ted Kremenek  bool isIncrementOp() const {return Opc==PreInc || Opc==PostInc; }
9805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isIncrementDecrementOp() const { return Opc>=PostInc && Opc<=PreDec; }
9815a1deb8d9c0722beae28d693fa137bbb942bd11fAnders Carlsson  bool isOffsetOfOp() const { return Opc == OffsetOf; }
9825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool isArithmeticOp(Opcode Op) { return Op >= Plus && Op <= LNot; }
9831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  bool isArithmeticOp() const { return isArithmeticOp(Opc); }
9841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
9855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// getOpcodeStr - Turn an Opcode enum value into the punctuation char it
9865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// corresponds to, e.g. "sizeof" or "[pre]++"
9875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static const char *getOpcodeStr(Opcode Op);
9885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
989bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor  /// \brief Retrieve the unary opcode that corresponds to the given
990bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor  /// overloaded operator.
991bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor  static Opcode getOverloadedOpcode(OverloadedOperatorKind OO, bool Postfix);
992bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor
993bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor  /// \brief Retrieve the overloaded operator kind that corresponds to
994bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor  /// the given unary opcode.
995bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor  static OverloadedOperatorKind getOverloadedOperator(Opcode Opc);
996bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor
9975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  virtual SourceRange getSourceRange() const {
9985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    if (isPostfix())
9995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      return SourceRange(Val->getLocStart(), Loc);
10005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    else
10015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      return SourceRange(Loc, Val->getLocEnd());
10025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
10035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  virtual SourceLocation getExprLoc() const { return Loc; }
10041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
10051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
10061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == UnaryOperatorClass;
10075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
10085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const UnaryOperator *) { return true; }
10091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
101077ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  // Iterators
101177ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_begin();
101277ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_end();
10135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
10145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
10158ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// OffsetOfExpr - [C99 7.17] - This represents an expression of the form
10168ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// offsetof(record-type, member-designator). For example, given:
10178ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// @code
10188ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// struct S {
10198ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor///   float f;
1020c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt///   double d;
10218ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// };
10228ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// struct T {
10238ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor///   int i;
10248ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor///   struct S s[10];
10258ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// };
10268ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// @endcode
1027c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt/// we can represent and evaluate the expression @c offsetof(struct T, s[2].d).
10288ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor
10298ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregorclass OffsetOfExpr : public Expr {
10308ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregorpublic:
10318ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  // __builtin_offsetof(type, identifier(.identifier|[expr])*)
10328ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  class OffsetOfNode {
10338ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  public:
10348ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    /// \brief The kind of offsetof node we have.
10358ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    enum Kind {
1036cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor      /// \brief An index into an array.
10378ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor      Array = 0x00,
1038cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor      /// \brief A field.
10398ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor      Field = 0x01,
1040cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor      /// \brief A field in a dependent type, known only by its name.
1041cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor      Identifier = 0x02,
1042cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor      /// \brief An implicit indirection through a C++ base class, when the
1043cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor      /// field found is in a base class.
1044cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor      Base = 0x03
10458ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    };
10468ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor
10478ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  private:
10488ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    enum { MaskBits = 2, Mask = 0x03 };
1049c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
10508ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    /// \brief The source range that covers this part of the designator.
10518ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    SourceRange Range;
1052c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
10538ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    /// \brief The data describing the designator, which comes in three
10548ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    /// different forms, depending on the lower two bits.
1055c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    ///   - An unsigned index into the array of Expr*'s stored after this node
10568ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    ///     in memory, for [constant-expression] designators.
10578ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    ///   - A FieldDecl*, for references to a known field.
10588ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    ///   - An IdentifierInfo*, for references to a field with a given name
10598ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    ///     when the class type is dependent.
1060c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    ///   - A CXXBaseSpecifier*, for references that look at a field in a
1061cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor    ///     base class.
10628ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    uintptr_t Data;
1063c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
10648ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  public:
10658ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    /// \brief Create an offsetof node that refers to an array element.
1066c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    OffsetOfNode(SourceLocation LBracketLoc, unsigned Index,
10678ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor                 SourceLocation RBracketLoc)
10688ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor      : Range(LBracketLoc, RBracketLoc), Data((Index << 2) | Array) { }
1069c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
10708ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    /// \brief Create an offsetof node that refers to a field.
1071c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    OffsetOfNode(SourceLocation DotLoc, FieldDecl *Field,
10728ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor                 SourceLocation NameLoc)
1073c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt      : Range(DotLoc.isValid()? DotLoc : NameLoc, NameLoc),
10748ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor        Data(reinterpret_cast<uintptr_t>(Field) | OffsetOfNode::Field) { }
1075c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
10768ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    /// \brief Create an offsetof node that refers to an identifier.
10778ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    OffsetOfNode(SourceLocation DotLoc, IdentifierInfo *Name,
10788ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor                 SourceLocation NameLoc)
1079c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt      : Range(DotLoc.isValid()? DotLoc : NameLoc, NameLoc),
10808ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor        Data(reinterpret_cast<uintptr_t>(Name) | Identifier) { }
1081cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor
1082cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor    /// \brief Create an offsetof node that refers into a C++ base class.
1083cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor    explicit OffsetOfNode(const CXXBaseSpecifier *Base)
1084cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor      : Range(), Data(reinterpret_cast<uintptr_t>(Base) | OffsetOfNode::Base) {}
1085c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
10868ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    /// \brief Determine what kind of offsetof node this is.
1087c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    Kind getKind() const {
10888ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor      return static_cast<Kind>(Data & Mask);
10898ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    }
1090c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
10918ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    /// \brief For an array element node, returns the index into the array
10928ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    /// of expressions.
10938ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    unsigned getArrayExprIndex() const {
10948ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor      assert(getKind() == Array);
10958ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor      return Data >> 2;
10968ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    }
10978ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor
10988ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    /// \brief For a field offsetof node, returns the field.
10998ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    FieldDecl *getField() const {
11008ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor      assert(getKind() == Field);
1101cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor      return reinterpret_cast<FieldDecl *>(Data & ~(uintptr_t)Mask);
11028ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    }
1103c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
11048ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    /// \brief For a field or identifier offsetof node, returns the name of
11058ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    /// the field.
11068ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    IdentifierInfo *getFieldName() const;
1107c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
1108cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor    /// \brief For a base class node, returns the base specifier.
1109cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor    CXXBaseSpecifier *getBase() const {
1110cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor      assert(getKind() == Base);
1111c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt      return reinterpret_cast<CXXBaseSpecifier *>(Data & ~(uintptr_t)Mask);
1112cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor    }
1113c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
11148ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    /// \brief Retrieve the source range that covers this offsetof node.
11158ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    ///
11168ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    /// For an array element node, the source range contains the locations of
11178ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    /// the square brackets. For a field or identifier node, the source range
1118c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    /// contains the location of the period (if there is one) and the
11198ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    /// identifier.
11208ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    SourceRange getRange() const { return Range; }
11218ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  };
11228ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor
11238ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregorprivate:
1124c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
11258ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  SourceLocation OperatorLoc, RParenLoc;
11268ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  // Base type;
11278ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  TypeSourceInfo *TSInfo;
11288ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  // Number of sub-components (i.e. instances of OffsetOfNode).
11298ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  unsigned NumComps;
11308ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  // Number of sub-expressions (i.e. array subscript expressions).
11318ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  unsigned NumExprs;
1132c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
1133c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  OffsetOfExpr(ASTContext &C, QualType type,
11348ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor               SourceLocation OperatorLoc, TypeSourceInfo *tsi,
1135c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt               OffsetOfNode* compsPtr, unsigned numComps,
11368ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor               Expr** exprsPtr, unsigned numExprs,
11378ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor               SourceLocation RParenLoc);
11388ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor
11398ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  explicit OffsetOfExpr(unsigned numComps, unsigned numExprs)
11408ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    : Expr(OffsetOfExprClass, EmptyShell()),
1141c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt      TSInfo(0), NumComps(numComps), NumExprs(numExprs) {}
11428ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor
11438ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregorpublic:
1144c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
1145c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  static OffsetOfExpr *Create(ASTContext &C, QualType type,
1146c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt                              SourceLocation OperatorLoc, TypeSourceInfo *tsi,
1147c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt                              OffsetOfNode* compsPtr, unsigned numComps,
11488ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor                              Expr** exprsPtr, unsigned numExprs,
11498ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor                              SourceLocation RParenLoc);
11508ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor
1151c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  static OffsetOfExpr *CreateEmpty(ASTContext &C,
11528ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor                                   unsigned NumComps, unsigned NumExprs);
11538ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor
11548ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  /// getOperatorLoc - Return the location of the operator.
11558ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  SourceLocation getOperatorLoc() const { return OperatorLoc; }
11568ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  void setOperatorLoc(SourceLocation L) { OperatorLoc = L; }
11578ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor
11588ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  /// \brief Return the location of the right parentheses.
11598ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  SourceLocation getRParenLoc() const { return RParenLoc; }
11608ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  void setRParenLoc(SourceLocation R) { RParenLoc = R; }
1161c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
11628ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  TypeSourceInfo *getTypeSourceInfo() const {
11638ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    return TSInfo;
11648ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  }
11658ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  void setTypeSourceInfo(TypeSourceInfo *tsi) {
11668ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    TSInfo = tsi;
11678ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  }
1168c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
11698ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  const OffsetOfNode &getComponent(unsigned Idx) {
11708ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    assert(Idx < NumComps && "Subscript out of range");
11718ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    return reinterpret_cast<OffsetOfNode *> (this + 1)[Idx];
11728ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  }
11738ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor
11748ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  void setComponent(unsigned Idx, OffsetOfNode ON) {
11758ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    assert(Idx < NumComps && "Subscript out of range");
11768ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    reinterpret_cast<OffsetOfNode *> (this + 1)[Idx] = ON;
11778ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  }
1178c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
11798ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  unsigned getNumComponents() const {
11808ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    return NumComps;
11818ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  }
11828ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor
11838ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  Expr* getIndexExpr(unsigned Idx) {
11848ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    assert(Idx < NumExprs && "Subscript out of range");
11858ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    return reinterpret_cast<Expr **>(
11868ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor                    reinterpret_cast<OffsetOfNode *>(this+1) + NumComps)[Idx];
11878ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  }
11888ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor
11898ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  void setIndexExpr(unsigned Idx, Expr* E) {
11908ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    assert(Idx < NumComps && "Subscript out of range");
11918ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    reinterpret_cast<Expr **>(
11928ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor                reinterpret_cast<OffsetOfNode *>(this+1) + NumComps)[Idx] = E;
11938ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  }
1194c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
11958ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  unsigned getNumExpressions() const {
11968ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    return NumExprs;
11978ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  }
11988ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor
11998ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  virtual SourceRange getSourceRange() const {
12008ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    return SourceRange(OperatorLoc, RParenLoc);
12018ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  }
12028ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor
12038ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  static bool classof(const Stmt *T) {
12048ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    return T->getStmtClass() == OffsetOfExprClass;
12058ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  }
12068ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor
12078ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  static bool classof(const OffsetOfExpr *) { return true; }
12088ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor
12098ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  // Iterators
12108ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  virtual child_iterator child_begin();
12118ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  virtual child_iterator child_end();
12128ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor};
12138ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor
12140518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl/// SizeOfAlignOfExpr - [C99 6.5.3.4] - This is for sizeof/alignof, both of
12150518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl/// types and expressions.
12160518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redlclass SizeOfAlignOfExpr : public Expr {
12170518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl  bool isSizeof : 1;  // true if sizeof, false if alignof.
12180518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl  bool isType : 1;    // true if operand is a type, false if an expression
1219d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl  union {
1220a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall    TypeSourceInfo *Ty;
1221d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl    Stmt *Ex;
1222d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl  } Argument;
12235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation OpLoc, RParenLoc;
122442602bb40aefcc2751d4078ba88aacf4d965c9bdDouglas Gregor
122542602bb40aefcc2751d4078ba88aacf4d965c9bdDouglas Gregorprotected:
122642602bb40aefcc2751d4078ba88aacf4d965c9bdDouglas Gregor  virtual void DoDestroy(ASTContext& C);
122742602bb40aefcc2751d4078ba88aacf4d965c9bdDouglas Gregor
12285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
1229a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall  SizeOfAlignOfExpr(bool issizeof, TypeSourceInfo *TInfo,
12300518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl                    QualType resultType, SourceLocation op,
12310518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl                    SourceLocation rp) :
12322850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl      Expr(SizeOfAlignOfExprClass, resultType,
1233ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor           false, // Never type-dependent (C++ [temp.dep.expr]p3).
12342850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl           // Value-dependent if the argument is type-dependent.
1235a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall           TInfo->getType()->isDependentType()),
1236ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor      isSizeof(issizeof), isType(true), OpLoc(op), RParenLoc(rp) {
1237a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall    Argument.Ty = TInfo;
1238ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor  }
1239ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor
12401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  SizeOfAlignOfExpr(bool issizeof, Expr *E,
1241ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor                    QualType resultType, SourceLocation op,
1242ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor                    SourceLocation rp) :
1243ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor      Expr(SizeOfAlignOfExprClass, resultType,
1244ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor           false, // Never type-dependent (C++ [temp.dep.expr]p3).
1245ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor           // Value-dependent if the argument is type-dependent.
1246ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor           E->isTypeDependent()),
1247ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor      isSizeof(issizeof), isType(false), OpLoc(op), RParenLoc(rp) {
1248ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor    Argument.Ex = E;
1249d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl  }
12500518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl
12510b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor  /// \brief Construct an empty sizeof/alignof expression.
12520b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor  explicit SizeOfAlignOfExpr(EmptyShell Empty)
12530b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor    : Expr(SizeOfAlignOfExprClass, Empty) { }
12540b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor
12555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isSizeOf() const { return isSizeof; }
12560b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor  void setSizeof(bool S) { isSizeof = S; }
12570b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor
12580518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl  bool isArgumentType() const { return isType; }
12590518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl  QualType getArgumentType() const {
12605ab75172051a6d2ea71a80a79e81c65519fd3462John McCall    return getArgumentTypeInfo()->getType();
12615ab75172051a6d2ea71a80a79e81c65519fd3462John McCall  }
1262a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall  TypeSourceInfo *getArgumentTypeInfo() const {
12630518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl    assert(isArgumentType() && "calling getArgumentType() when arg is expr");
12645ab75172051a6d2ea71a80a79e81c65519fd3462John McCall    return Argument.Ty;
12650518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl  }
1266caae7b099a0324b7c15dc89a9b70969d5d7ce996Chris Lattner  Expr *getArgumentExpr() {
12670518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl    assert(!isArgumentType() && "calling getArgumentExpr() when arg is type");
1268d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl    return static_cast<Expr*>(Argument.Ex);
12690518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl  }
1270caae7b099a0324b7c15dc89a9b70969d5d7ce996Chris Lattner  const Expr *getArgumentExpr() const {
1271caae7b099a0324b7c15dc89a9b70969d5d7ce996Chris Lattner    return const_cast<SizeOfAlignOfExpr*>(this)->getArgumentExpr();
1272caae7b099a0324b7c15dc89a9b70969d5d7ce996Chris Lattner  }
12730b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor
12740b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor  void setArgument(Expr *E) { Argument.Ex = E; isType = false; }
1275a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall  void setArgument(TypeSourceInfo *TInfo) {
1276a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall    Argument.Ty = TInfo;
12771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    isType = true;
12780b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor  }
12790b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor
12800518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl  /// Gets the argument type, or the type of the argument expression, whichever
12810518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl  /// is appropriate.
12820518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl  QualType getTypeOfArgument() const {
12830518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl    return isArgumentType() ? getArgumentType() : getArgumentExpr()->getType();
12840518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl  }
12850518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl
128676e773a443be9f006610f46529e07d4c8d857680Chris Lattner  SourceLocation getOperatorLoc() const { return OpLoc; }
12870b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor  void setOperatorLoc(SourceLocation L) { OpLoc = L; }
12880b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor
12890b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor  SourceLocation getRParenLoc() const { return RParenLoc; }
12900b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
1291866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek
1292866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek  virtual SourceRange getSourceRange() const {
1293866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek    return SourceRange(OpLoc, RParenLoc);
1294866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek  }
12955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
12961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
12971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == SizeOfAlignOfExprClass;
12985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
12990518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl  static bool classof(const SizeOfAlignOfExpr *) { return true; }
13001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
130177ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  // Iterators
130277ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_begin();
130377ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_end();
13045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
13055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
13065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===//
13075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// Postfix Operators.
13085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===//
13095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
13105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ArraySubscriptExpr - [C99 6.5.2.1] Array Subscripting.
13115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass ArraySubscriptExpr : public Expr {
131277ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  enum { LHS, RHS, END_EXPR=2 };
13131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  Stmt* SubExprs[END_EXPR];
13145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation RBracketLoc;
13155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
13162324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek  ArraySubscriptExpr(Expr *lhs, Expr *rhs, QualType t,
131773d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner                     SourceLocation rbracketloc)
13182850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl  : Expr(ArraySubscriptExprClass, t,
13192850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl         lhs->isTypeDependent() || rhs->isTypeDependent(),
13202850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl         lhs->isValueDependent() || rhs->isValueDependent()),
13212850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl    RBracketLoc(rbracketloc) {
132273d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner    SubExprs[LHS] = lhs;
132373d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner    SubExprs[RHS] = rhs;
132473d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner  }
13251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1326cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor  /// \brief Create an empty array subscript expression.
1327cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor  explicit ArraySubscriptExpr(EmptyShell Shell)
1328cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor    : Expr(ArraySubscriptExprClass, Shell) { }
1329cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor
13302324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek  /// An array access can be written A[4] or 4[A] (both are equivalent).
13312324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek  /// - getBase() and getIdx() always present the normalized view: A[4].
13322324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek  ///    In this case getBase() returns "A" and getIdx() returns "4".
13332324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek  /// - getLHS() and getRHS() present the syntactic view. e.g. for
13342324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek  ///    4[A] getLHS() returns "4".
133533fd5c124aac15bab7cad95e4e0e7761356d2c06Christopher Lamb  /// Note: Because vector element access is also written A[4] we must
133633fd5c124aac15bab7cad95e4e0e7761356d2c06Christopher Lamb  /// predicate the format conversion in getBase and getIdx only on the
133733fd5c124aac15bab7cad95e4e0e7761356d2c06Christopher Lamb  /// the type of the RHS, as it is possible for the LHS to be a vector of
133833fd5c124aac15bab7cad95e4e0e7761356d2c06Christopher Lamb  /// integer type
13395549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getLHS() { return cast<Expr>(SubExprs[LHS]); }
13405549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  const Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); }
1341cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor  void setLHS(Expr *E) { SubExprs[LHS] = E; }
1342cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor
13435549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getRHS() { return cast<Expr>(SubExprs[RHS]); }
13445549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  const Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); }
1345cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor  void setRHS(Expr *E) { SubExprs[RHS] = E; }
13461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
13471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  Expr *getBase() {
13485549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek    return cast<Expr>(getRHS()->getType()->isIntegerType() ? getLHS():getRHS());
134977ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  }
13501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
13511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  const Expr *getBase() const {
13525549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek    return cast<Expr>(getRHS()->getType()->isIntegerType() ? getLHS():getRHS());
13532324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek  }
13541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
13551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  Expr *getIdx() {
13565549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek    return cast<Expr>(getRHS()->getType()->isIntegerType() ? getRHS():getLHS());
13572324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek  }
13581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
135977ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  const Expr *getIdx() const {
13605549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek    return cast<Expr>(getRHS()->getType()->isIntegerType() ? getRHS():getLHS());
13611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  }
13621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
13631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  virtual SourceRange getSourceRange() const {
136477ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek    return SourceRange(getLHS()->getLocStart(), RBracketLoc);
13655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
13661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1367026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner  SourceLocation getRBracketLoc() const { return RBracketLoc; }
1368cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor  void setRBracketLoc(SourceLocation L) { RBracketLoc = L; }
1369cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor
13705cd9d6daf3acd4cc87fecebd81d9495b9e4ba9cdChris Lattner  virtual SourceLocation getExprLoc() const { return getBase()->getExprLoc(); }
13715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
13721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
13731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == ArraySubscriptExprClass;
13745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
13755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const ArraySubscriptExpr *) { return true; }
13761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
137777ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  // Iterators
137877ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_begin();
137977ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_end();
13805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
13815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
13825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1383b4609806e9232593ece09ce08b630836e825865cDouglas Gregor/// CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
13841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// CallExpr itself represents a normal function call, e.g., "f(x, 2)",
1385b4609806e9232593ece09ce08b630836e825865cDouglas Gregor/// while its subclasses may represent alternative syntax that (semantically)
13861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// results in a function call. For example, CXXOperatorCallExpr is
1387b4609806e9232593ece09ce08b630836e825865cDouglas Gregor/// a subclass for overloaded operator calls that use operator syntax, e.g.,
1388b4609806e9232593ece09ce08b630836e825865cDouglas Gregor/// "str1 + str2" to resolve to a function call.
13895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass CallExpr : public Expr {
139077ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  enum { FN=0, ARGS_START=1 };
13915549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Stmt **SubExprs;
13925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  unsigned NumArgs;
13935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation RParenLoc;
13941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1395b4609806e9232593ece09ce08b630836e825865cDouglas Gregorprotected:
1396b4609806e9232593ece09ce08b630836e825865cDouglas Gregor  // This version of the constructor is for derived classes.
1397668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek  CallExpr(ASTContext& C, StmtClass SC, Expr *fn, Expr **args, unsigned numargs,
1398668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek           QualType t, SourceLocation rparenloc);
139942602bb40aefcc2751d4078ba88aacf4d965c9bdDouglas Gregor
140042602bb40aefcc2751d4078ba88aacf4d965c9bdDouglas Gregor  virtual void DoDestroy(ASTContext& C);
14011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
14025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
14031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  CallExpr(ASTContext& C, Expr *fn, Expr **args, unsigned numargs, QualType t,
14045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer           SourceLocation rparenloc);
14051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
14061f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor  /// \brief Build an empty call expression.
1407ba0a9006dbc4814e1e35f82812cb5a1dad65e8b8Argyrios Kyrtzidis  CallExpr(ASTContext &C, StmtClass SC, EmptyShell Empty);
14081f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor
1409668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek  ~CallExpr() {}
14101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
14115549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  const Expr *getCallee() const { return cast<Expr>(SubExprs[FN]); }
14125549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getCallee() { return cast<Expr>(SubExprs[FN]); }
141318b2515e1bf8c86a4900792692e42fe1296be28dChris Lattner  void setCallee(Expr *F) { SubExprs[FN] = F; }
1414a00425414e8c209cabc25d1826b200aeb94259afZhongxing Xu
1415d20254f2875d0004c57ee766f258dbcee29f4841Nuno Lopes  Decl *getCalleeDecl();
1416d20254f2875d0004c57ee766f258dbcee29f4841Nuno Lopes  const Decl *getCalleeDecl() const {
1417d20254f2875d0004c57ee766f258dbcee29f4841Nuno Lopes    return const_cast<CallExpr*>(this)->getCalleeDecl();
1418d20254f2875d0004c57ee766f258dbcee29f4841Nuno Lopes  }
1419d20254f2875d0004c57ee766f258dbcee29f4841Nuno Lopes
1420a00425414e8c209cabc25d1826b200aeb94259afZhongxing Xu  /// \brief If the callee is a FunctionDecl, return it. Otherwise return 0.
1421a00425414e8c209cabc25d1826b200aeb94259afZhongxing Xu  FunctionDecl *getDirectCallee();
1422bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner  const FunctionDecl *getDirectCallee() const {
1423bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner    return const_cast<CallExpr*>(this)->getDirectCallee();
1424bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner  }
1425a00425414e8c209cabc25d1826b200aeb94259afZhongxing Xu
14265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// getNumArgs - Return the number of actual arguments to this call.
14275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ///
14285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  unsigned getNumArgs() const { return NumArgs; }
14291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
14305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// getArg - Return the specified argument.
14315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  Expr *getArg(unsigned Arg) {
14325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    assert(Arg < NumArgs && "Arg access out of range!");
14335549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek    return cast<Expr>(SubExprs[Arg+ARGS_START]);
14345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
14355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  const Expr *getArg(unsigned Arg) const {
14365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    assert(Arg < NumArgs && "Arg access out of range!");
14375549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek    return cast<Expr>(SubExprs[Arg+ARGS_START]);
14385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
14391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1440934f276cc5b45e19cd12ebb2d04fd7972a23865cSteve Naroff  /// setArg - Set the specified argument.
1441934f276cc5b45e19cd12ebb2d04fd7972a23865cSteve Naroff  void setArg(unsigned Arg, Expr *ArgExpr) {
1442934f276cc5b45e19cd12ebb2d04fd7972a23865cSteve Naroff    assert(Arg < NumArgs && "Arg access out of range!");
1443934f276cc5b45e19cd12ebb2d04fd7972a23865cSteve Naroff    SubExprs[Arg+ARGS_START] = ArgExpr;
1444934f276cc5b45e19cd12ebb2d04fd7972a23865cSteve Naroff  }
14451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1446d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner  /// setNumArgs - This changes the number of arguments present in this call.
1447d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner  /// Any orphaned expressions are deleted by this, and any new operands are set
1448d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner  /// to null.
14498189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  void setNumArgs(ASTContext& C, unsigned NumArgs);
14501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
14515549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  typedef ExprIterator arg_iterator;
14525549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  typedef ConstExprIterator const_arg_iterator;
14531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1454d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner  arg_iterator arg_begin() { return SubExprs+ARGS_START; }
1455d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner  arg_iterator arg_end() { return SubExprs+ARGS_START+getNumArgs(); }
14565549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  const_arg_iterator arg_begin() const { return SubExprs+ARGS_START; }
14575549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  const_arg_iterator arg_end() const { return SubExprs+ARGS_START+getNumArgs();}
14581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
14595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// getNumCommas - Return the number of commas that must have been present in
14605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// this function call.
14615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  unsigned getNumCommas() const { return NumArgs ? NumArgs - 1 : 0; }
14625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1463cb888967400a03504c88acedd5248d6778a82f46Chris Lattner  /// isBuiltinCall - If this is a call to a builtin, return the builtin ID.  If
1464cb888967400a03504c88acedd5248d6778a82f46Chris Lattner  /// not, return 0.
14653c385e5f8d9008fff18597ca302be19fa86e51f6Douglas Gregor  unsigned isBuiltinCall(ASTContext &Context) const;
14661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
14671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// getCallReturnType - Get the return type of the call expr. This is not
14681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// always the type of the expr itself, if the return type is a reference
14696dde78f744382a5627a04f984a97049e0c4b5e73Anders Carlsson  /// type.
14706dde78f744382a5627a04f984a97049e0c4b5e73Anders Carlsson  QualType getCallReturnType() const;
14711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1472d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner  SourceLocation getRParenLoc() const { return RParenLoc; }
14731f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
1474866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek
14751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  virtual SourceRange getSourceRange() const {
147677ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek    return SourceRange(getCallee()->getLocStart(), RParenLoc);
14775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
14781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
14791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
14804bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt    return T->getStmtClass() >= firstCallExprConstant &&
14814bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt           T->getStmtClass() <= lastCallExprConstant;
14825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
14835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const CallExpr *) { return true; }
148488a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor
148577ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  // Iterators
148677ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_begin();
148777ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_end();
14885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
14895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1490ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner/// MemberExpr - [C99 6.5.2.3] Structure and Union Members.  X->F and X.F.
14915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
14925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass MemberExpr : public Expr {
14936bb8017bb9e828d118e15e59d71c66bba323c364John McCall  /// Extra data stored in some member expressions.
14946bb8017bb9e828d118e15e59d71c66bba323c364John McCall  struct MemberNameQualifier : public NameQualifier {
1495161755a09898c95d21bfff33707da9ca41cd53c5John McCall    DeclAccessPair FoundDecl;
14966bb8017bb9e828d118e15e59d71c66bba323c364John McCall  };
14976bb8017bb9e828d118e15e59d71c66bba323c364John McCall
1498ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner  /// Base - the expression for the base pointer or structure references.  In
1499ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner  /// X.F, this is "X".
15005549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Stmt *Base;
15011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1502ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner  /// MemberDecl - This is the decl being referenced by the field/member name.
1503ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner  /// In X.F, this is the decl referenced by F.
1504f595cc41c4d95fe323f8a2b209523de9956f874dEli Friedman  ValueDecl *MemberDecl;
15051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1506ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner  /// MemberLoc - This is the location of the member name.
15075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation MemberLoc;
15081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1509ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner  /// IsArrow - True if this is "X->F", false if this is "X.F".
151083f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor  bool IsArrow : 1;
15111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
151283f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor  /// \brief True if this member expression used a nested-name-specifier to
15136bb8017bb9e828d118e15e59d71c66bba323c364John McCall  /// refer to the member, e.g., "x->Base::f", or found its member via a using
15146bb8017bb9e828d118e15e59d71c66bba323c364John McCall  /// declaration.  When true, a MemberNameQualifier
1515c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  /// structure is allocated immediately after the MemberExpr.
15166bb8017bb9e828d118e15e59d71c66bba323c364John McCall  bool HasQualifierOrFoundDecl : 1;
15171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1518c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  /// \brief True if this member expression specified a template argument list
1519c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  /// explicitly, e.g., x->f<int>. When true, an ExplicitTemplateArgumentList
1520c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  /// structure (and its TemplateArguments) are allocated immediately after
1521c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  /// the MemberExpr or, if the member expression also has a qualifier, after
15226bb8017bb9e828d118e15e59d71c66bba323c364John McCall  /// the MemberNameQualifier structure.
1523c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  bool HasExplicitTemplateArgumentList : 1;
15241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
152583f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor  /// \brief Retrieve the qualifier that preceded the member name, if any.
15266bb8017bb9e828d118e15e59d71c66bba323c364John McCall  MemberNameQualifier *getMemberQualifier() {
15276bb8017bb9e828d118e15e59d71c66bba323c364John McCall    assert(HasQualifierOrFoundDecl);
15286bb8017bb9e828d118e15e59d71c66bba323c364John McCall    return reinterpret_cast<MemberNameQualifier *> (this + 1);
152983f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor  }
153083f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor
153183f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor  /// \brief Retrieve the qualifier that preceded the member name, if any.
15326bb8017bb9e828d118e15e59d71c66bba323c364John McCall  const MemberNameQualifier *getMemberQualifier() const {
1533c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor    return const_cast<MemberExpr *>(this)->getMemberQualifier();
1534c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  }
15351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1536c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  /// \brief Retrieve the explicit template argument list that followed the
1537c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  /// member template name, if any.
1538c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  ExplicitTemplateArgumentList *getExplicitTemplateArgumentList() {
1539c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor    if (!HasExplicitTemplateArgumentList)
154083f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor      return 0;
15411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
15426bb8017bb9e828d118e15e59d71c66bba323c364John McCall    if (!HasQualifierOrFoundDecl)
1543c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor      return reinterpret_cast<ExplicitTemplateArgumentList *>(this + 1);
15441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1545c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor    return reinterpret_cast<ExplicitTemplateArgumentList *>(
1546c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor                                                      getMemberQualifier() + 1);
1547c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  }
15481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1549c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  /// \brief Retrieve the explicit template argument list that followed the
1550c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  /// member template name, if any.
1551c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  const ExplicitTemplateArgumentList *getExplicitTemplateArgumentList() const {
1552c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor    return const_cast<MemberExpr *>(this)->getExplicitTemplateArgumentList();
155383f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor  }
15541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
15555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
1556f595cc41c4d95fe323f8a2b209523de9956f874dEli Friedman  MemberExpr(Expr *base, bool isarrow, ValueDecl *memberdecl,
1557f595cc41c4d95fe323f8a2b209523de9956f874dEli Friedman             SourceLocation l, QualType ty)
15581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    : Expr(MemberExprClass, ty,
1559ffce2df6ae280d354d51371282a579df1eb86876Anders Carlsson           base->isTypeDependent(), base->isValueDependent()),
156083f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor      Base(base), MemberDecl(memberdecl), MemberLoc(l), IsArrow(isarrow),
15616bb8017bb9e828d118e15e59d71c66bba323c364John McCall      HasQualifierOrFoundDecl(false), HasExplicitTemplateArgumentList(false) {}
1562510190777c4bd53e960eea4665b204778fec1b64Eli Friedman
15631f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor  /// \brief Build an empty member reference expression.
15641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  explicit MemberExpr(EmptyShell Empty)
15656bb8017bb9e828d118e15e59d71c66bba323c364John McCall    : Expr(MemberExprClass, Empty), HasQualifierOrFoundDecl(false),
1566e6585a7d71510be00a625686153f48d496d3bbf1Douglas Gregor      HasExplicitTemplateArgumentList(false) { }
15671f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor
15681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static MemberExpr *Create(ASTContext &C, Expr *base, bool isarrow,
156983f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor                            NestedNameSpecifier *qual, SourceRange qualrange,
1570161755a09898c95d21bfff33707da9ca41cd53c5John McCall                            ValueDecl *memberdecl, DeclAccessPair founddecl,
1571c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor                            SourceLocation l,
1572d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall                            const TemplateArgumentListInfo *targs,
1573c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor                            QualType ty);
15741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
157588a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor  void setBase(Expr *E) { Base = E; }
15765549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getBase() const { return cast<Expr>(Base); }
157757e8b05fe9ba03d410db9c161e032cb79c9ab5baDouglas Gregor
157857e8b05fe9ba03d410db9c161e032cb79c9ab5baDouglas Gregor  /// \brief Retrieve the member declaration to which this expression refers.
157957e8b05fe9ba03d410db9c161e032cb79c9ab5baDouglas Gregor  ///
158057e8b05fe9ba03d410db9c161e032cb79c9ab5baDouglas Gregor  /// The returned declaration will either be a FieldDecl or (in C++)
158157e8b05fe9ba03d410db9c161e032cb79c9ab5baDouglas Gregor  /// a CXXMethodDecl.
1582f595cc41c4d95fe323f8a2b209523de9956f874dEli Friedman  ValueDecl *getMemberDecl() const { return MemberDecl; }
1583f595cc41c4d95fe323f8a2b209523de9956f874dEli Friedman  void setMemberDecl(ValueDecl *D) { MemberDecl = D; }
15841f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor
15856bb8017bb9e828d118e15e59d71c66bba323c364John McCall  /// \brief Retrieves the declaration found by lookup.
1586161755a09898c95d21bfff33707da9ca41cd53c5John McCall  DeclAccessPair getFoundDecl() const {
15876bb8017bb9e828d118e15e59d71c66bba323c364John McCall    if (!HasQualifierOrFoundDecl)
1588161755a09898c95d21bfff33707da9ca41cd53c5John McCall      return DeclAccessPair::make(getMemberDecl(),
1589161755a09898c95d21bfff33707da9ca41cd53c5John McCall                                  getMemberDecl()->getAccess());
15906bb8017bb9e828d118e15e59d71c66bba323c364John McCall    return getMemberQualifier()->FoundDecl;
15916bb8017bb9e828d118e15e59d71c66bba323c364John McCall  }
15926bb8017bb9e828d118e15e59d71c66bba323c364John McCall
15931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// \brief Determines whether this member expression actually had
15940979c805475d1ba49b5d6ef93c4d2ce6d2eab6edDouglas Gregor  /// a C++ nested-name-specifier prior to the name of the member, e.g.,
15950979c805475d1ba49b5d6ef93c4d2ce6d2eab6edDouglas Gregor  /// x->Base::foo.
15966bb8017bb9e828d118e15e59d71c66bba323c364John McCall  bool hasQualifier() const { return getQualifier() != 0; }
15971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
159883f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor  /// \brief If the member name was qualified, retrieves the source range of
159983f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor  /// the nested-name-specifier that precedes the member name. Otherwise,
160083f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor  /// returns an empty source range.
16011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  SourceRange getQualifierRange() const {
16026bb8017bb9e828d118e15e59d71c66bba323c364John McCall    if (!HasQualifierOrFoundDecl)
160383f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor      return SourceRange();
16041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
160583f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor    return getMemberQualifier()->Range;
160683f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor  }
16071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
16081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// \brief If the member name was qualified, retrieves the
160983f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor  /// nested-name-specifier that precedes the member name. Otherwise, returns
161083f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor  /// NULL.
16111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  NestedNameSpecifier *getQualifier() const {
16126bb8017bb9e828d118e15e59d71c66bba323c364John McCall    if (!HasQualifierOrFoundDecl)
161383f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor      return 0;
16141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
161583f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor    return getMemberQualifier()->NNS;
161683f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor  }
1617c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor
1618c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  /// \brief Determines whether this member expression actually had a C++
1619c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  /// template argument list explicitly specified, e.g., x.f<int>.
1620d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  bool hasExplicitTemplateArgumentList() const {
16211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return HasExplicitTemplateArgumentList;
1622c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  }
16231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1624d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  /// \brief Copies the template arguments (if present) into the given
1625d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  /// structure.
1626d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
1627d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall    if (hasExplicitTemplateArgumentList())
1628d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall      getExplicitTemplateArgumentList()->copyInto(List);
1629d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  }
1630c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
16311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// \brief Retrieve the location of the left angle bracket following the
1632c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  /// member name ('<'), if any.
16331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  SourceLocation getLAngleLoc() const {
1634c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor    if (!HasExplicitTemplateArgumentList)
1635c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor      return SourceLocation();
16361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1637c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor    return getExplicitTemplateArgumentList()->LAngleLoc;
1638c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  }
16391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1640c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  /// \brief Retrieve the template arguments provided as part of this
1641c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  /// template-id.
1642833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  const TemplateArgumentLoc *getTemplateArgs() const {
1643c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor    if (!HasExplicitTemplateArgumentList)
16441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump      return 0;
16451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1646c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor    return getExplicitTemplateArgumentList()->getTemplateArgs();
1647c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  }
16481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1649c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  /// \brief Retrieve the number of template arguments provided as part of this
1650c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  /// template-id.
16511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  unsigned getNumTemplateArgs() const {
1652c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor    if (!HasExplicitTemplateArgumentList)
16531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump      return 0;
16541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1655c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor    return getExplicitTemplateArgumentList()->NumTemplateArgs;
1656c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  }
16571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
16581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// \brief Retrieve the location of the right angle bracket following the
1659c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  /// template arguments ('>').
16601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  SourceLocation getRAngleLoc() const {
1661c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor    if (!HasExplicitTemplateArgumentList)
1662c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor      return SourceLocation();
16631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1664c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor    return getExplicitTemplateArgumentList()->RAngleLoc;
1665c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  }
16661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
16675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isArrow() const { return IsArrow; }
16681f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor  void setArrow(bool A) { IsArrow = A; }
16691f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor
1670ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner  /// getMemberLoc - Return the location of the "member", in X->F, it is the
1671ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner  /// location of 'F'.
1672026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner  SourceLocation getMemberLoc() const { return MemberLoc; }
16731f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor  void setMemberLoc(SourceLocation L) { MemberLoc = L; }
16745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
16755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  virtual SourceRange getSourceRange() const {
167672527137c521ad9330ecb81ccd841159719dc8cdEli Friedman    // If we have an implicit base (like a C++ implicit this),
167772527137c521ad9330ecb81ccd841159719dc8cdEli Friedman    // make sure not to return its location
1678c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor    SourceLocation EndLoc = MemberLoc;
1679c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor    if (HasExplicitTemplateArgumentList)
1680c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor      EndLoc = getRAngleLoc();
16811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
168272527137c521ad9330ecb81ccd841159719dc8cdEli Friedman    SourceLocation BaseLoc = getBase()->getLocStart();
168372527137c521ad9330ecb81ccd841159719dc8cdEli Friedman    if (BaseLoc.isInvalid())
1684c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor      return SourceRange(MemberLoc, EndLoc);
1685c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor    return SourceRange(BaseLoc, EndLoc);
16865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
16871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
16885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  virtual SourceLocation getExprLoc() const { return MemberLoc; }
16895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
16901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
169183f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor    return T->getStmtClass() == MemberExprClass;
16925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
16935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const MemberExpr *) { return true; }
16941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
16951237c673c07f9d827129ba02720108816abde562Ted Kremenek  // Iterators
16961237c673c07f9d827129ba02720108816abde562Ted Kremenek  virtual child_iterator child_begin();
16971237c673c07f9d827129ba02720108816abde562Ted Kremenek  virtual child_iterator child_end();
16985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
16995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
17001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// CompoundLiteralExpr - [C99 6.5.2.5]
1701aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff///
1702aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroffclass CompoundLiteralExpr : public Expr {
17030fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner  /// LParenLoc - If non-null, this is the location of the left paren in a
17040fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner  /// compound literal like "(int){4}".  This can be null if this is a
17050fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner  /// synthesized compound expression.
17060fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner  SourceLocation LParenLoc;
17071d7d8d66eff7ed0f3e957d330930cc9ab8047addJohn McCall
17081d7d8d66eff7ed0f3e957d330930cc9ab8047addJohn McCall  /// The type as written.  This can be an incomplete array type, in
17091d7d8d66eff7ed0f3e957d330930cc9ab8047addJohn McCall  /// which case the actual expression type will be different.
171042f56b50062cd3b3c6b23fdb9053578ae9145664John McCall  TypeSourceInfo *TInfo;
17115549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Stmt *Init;
1712e9b12198c4cc7f5687960100351b4af006c14469Steve Naroff  bool FileScope;
1713aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroffpublic:
17142333f7727f97018d6742e1e0938133bcfad967abEli Friedman  // FIXME: Can compound literals be value-dependent?
171542f56b50062cd3b3c6b23fdb9053578ae9145664John McCall  CompoundLiteralExpr(SourceLocation lparenloc, TypeSourceInfo *tinfo,
17161d7d8d66eff7ed0f3e957d330930cc9ab8047addJohn McCall                      QualType T, Expr *init, bool fileScope)
17171d7d8d66eff7ed0f3e957d330930cc9ab8047addJohn McCall    : Expr(CompoundLiteralExprClass, T,
171842f56b50062cd3b3c6b23fdb9053578ae9145664John McCall           tinfo->getType()->isDependentType(), false),
171942f56b50062cd3b3c6b23fdb9053578ae9145664John McCall      LParenLoc(lparenloc), TInfo(tinfo), Init(init), FileScope(fileScope) {}
17201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1721ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor  /// \brief Construct an empty compound literal.
1722ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor  explicit CompoundLiteralExpr(EmptyShell Empty)
1723ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor    : Expr(CompoundLiteralExprClass, Empty) { }
1724ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor
17255549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  const Expr *getInitializer() const { return cast<Expr>(Init); }
17265549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getInitializer() { return cast<Expr>(Init); }
1727ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor  void setInitializer(Expr *E) { Init = E; }
1728e9b12198c4cc7f5687960100351b4af006c14469Steve Naroff
1729e9b12198c4cc7f5687960100351b4af006c14469Steve Naroff  bool isFileScope() const { return FileScope; }
1730ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor  void setFileScope(bool FS) { FileScope = FS; }
1731ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor
17320fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner  SourceLocation getLParenLoc() const { return LParenLoc; }
1733ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor  void setLParenLoc(SourceLocation L) { LParenLoc = L; }
1734ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor
173542f56b50062cd3b3c6b23fdb9053578ae9145664John McCall  TypeSourceInfo *getTypeSourceInfo() const { return TInfo; }
173642f56b50062cd3b3c6b23fdb9053578ae9145664John McCall  void setTypeSourceInfo(TypeSourceInfo* tinfo) { TInfo = tinfo; }
173742f56b50062cd3b3c6b23fdb9053578ae9145664John McCall
173873d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner  virtual SourceRange getSourceRange() const {
17390fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner    // FIXME: Init should never be null.
17400fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner    if (!Init)
17410fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner      return SourceRange();
17420fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner    if (LParenLoc.isInvalid())
174373d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner      return Init->getSourceRange();
17440fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner    return SourceRange(LParenLoc, Init->getLocEnd());
174573d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner  }
1746aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff
17471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
17481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == CompoundLiteralExprClass;
1749aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff  }
1750aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff  static bool classof(const CompoundLiteralExpr *) { return true; }
17511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
17521237c673c07f9d827129ba02720108816abde562Ted Kremenek  // Iterators
17531237c673c07f9d827129ba02720108816abde562Ted Kremenek  virtual child_iterator child_begin();
17541237c673c07f9d827129ba02720108816abde562Ted Kremenek  virtual child_iterator child_end();
1755aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff};
1756aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff
175749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// CastExpr - Base class for type casts, including both implicit
175849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// casts (ImplicitCastExpr) and explicit casts that have some
175949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// representation in the source code (ExplicitCastExpr's derived
176049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// classes).
17610835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidisclass CastExpr : public Expr {
1762cdef2b75aa60cde1ca00e0aa3f89139ac89c6ae4Anders Carlssonpublic:
1763cdef2b75aa60cde1ca00e0aa3f89139ac89c6ae4Anders Carlsson  /// CastKind - the kind of cast this represents.
1764cdef2b75aa60cde1ca00e0aa3f89139ac89c6ae4Anders Carlsson  enum CastKind {
1765cdef2b75aa60cde1ca00e0aa3f89139ac89c6ae4Anders Carlsson    /// CK_Unknown - Unknown cast kind.
17661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    /// FIXME: The goal is to get rid of this and make all casts have a
1767cdef2b75aa60cde1ca00e0aa3f89139ac89c6ae4Anders Carlsson    /// kind so that the AST client doesn't have to try to figure out what's
1768cdef2b75aa60cde1ca00e0aa3f89139ac89c6ae4Anders Carlsson    /// going on.
1769cdef2b75aa60cde1ca00e0aa3f89139ac89c6ae4Anders Carlsson    CK_Unknown,
17701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1771cdef2b75aa60cde1ca00e0aa3f89139ac89c6ae4Anders Carlsson    /// CK_BitCast - Used for reinterpret_cast.
1772cdef2b75aa60cde1ca00e0aa3f89139ac89c6ae4Anders Carlsson    CK_BitCast,
17731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1774cdef2b75aa60cde1ca00e0aa3f89139ac89c6ae4Anders Carlsson    /// CK_NoOp - Used for const_cast.
17753503d041ca8a3535a1c1a30005a6b18ae7aed5dbAnders Carlsson    CK_NoOp,
17761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
177711de6de25a0110cd7be97eef761ef3b189781da6Anders Carlsson    /// CK_BaseToDerived - Base to derived class casts.
177811de6de25a0110cd7be97eef761ef3b189781da6Anders Carlsson    CK_BaseToDerived,
177911de6de25a0110cd7be97eef761ef3b189781da6Anders Carlsson
17803503d041ca8a3535a1c1a30005a6b18ae7aed5dbAnders Carlsson    /// CK_DerivedToBase - Derived to base class casts.
1781714179b179a31a0c3769a968ee18ba87b901b13fAnders Carlsson    CK_DerivedToBase,
17821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
178323cba801e11b03929c44f8cf54578305963a3476John McCall    /// CK_UncheckedDerivedToBase - Derived to base class casts that
178423cba801e11b03929c44f8cf54578305963a3476John McCall    /// assume that the derived pointer is not null.
178523cba801e11b03929c44f8cf54578305963a3476John McCall    CK_UncheckedDerivedToBase,
178623cba801e11b03929c44f8cf54578305963a3476John McCall
1787714179b179a31a0c3769a968ee18ba87b901b13fAnders Carlsson    /// CK_Dynamic - Dynamic cast.
17884d8673b645ad86e496b886a0f80b60763f67071dAnders Carlsson    CK_Dynamic,
17891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
17904d8673b645ad86e496b886a0f80b60763f67071dAnders Carlsson    /// CK_ToUnion - Cast to union (GCC extension).
1791112a0a8ddf23f6d25e0920002d5d4c1df0515f86Anders Carlsson    CK_ToUnion,
17921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1793112a0a8ddf23f6d25e0920002d5d4c1df0515f86Anders Carlsson    /// CK_ArrayToPointerDecay - Array to pointer decay.
179427a5b9b9babd1e4f8a19c5c9c0736c4b311c79b2Anders Carlsson    CK_ArrayToPointerDecay,
17951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1796b633c4ee622df81d4572ef57dac54ebed69bb9bfAnders Carlsson    // CK_FunctionToPointerDecay - Function to pointer decay.
1797b633c4ee622df81d4572ef57dac54ebed69bb9bfAnders Carlsson    CK_FunctionToPointerDecay,
17981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
179927a5b9b9babd1e4f8a19c5c9c0736c4b311c79b2Anders Carlsson    /// CK_NullToMemberPointer - Null pointer to member pointer.
180027a5b9b9babd1e4f8a19c5c9c0736c4b311c79b2Anders Carlsson    CK_NullToMemberPointer,
18011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
180227a5b9b9babd1e4f8a19c5c9c0736c4b311c79b2Anders Carlsson    /// CK_BaseToDerivedMemberPointer - Member pointer in base class to
180327a5b9b9babd1e4f8a19c5c9c0736c4b311c79b2Anders Carlsson    /// member pointer in derived class.
18049099ff0cf91ac9e0b2d5a142807fa384ce842fc4Fariborz Jahanian    CK_BaseToDerivedMemberPointer,
18059099ff0cf91ac9e0b2d5a142807fa384ce842fc4Fariborz Jahanian
18061a31a18db9d657751f38c724adc0d62e86852bd7Anders Carlsson    /// CK_DerivedToBaseMemberPointer - Member pointer in derived class to
18071a31a18db9d657751f38c724adc0d62e86852bd7Anders Carlsson    /// member pointer in base class.
18081a31a18db9d657751f38c724adc0d62e86852bd7Anders Carlsson    CK_DerivedToBaseMemberPointer,
1809c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
18101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    /// CK_UserDefinedConversion - Conversion using a user defined type
181158d3f1af9b4efa426826816a16894986b78b2692Fariborz Jahanian    /// conversion function.
18127fe5d72fbc8605b60d42d32394248ea76cf763a0Fariborz Jahanian    CK_UserDefinedConversion,
18137fe5d72fbc8605b60d42d32394248ea76cf763a0Fariborz Jahanian
18147fe5d72fbc8605b60d42d32394248ea76cf763a0Fariborz Jahanian    /// CK_ConstructorConversion - Conversion by constructor
18157f9e646b7ed47bc8e9a60031ad0c2b55031e2077Anders Carlsson    CK_ConstructorConversion,
1816c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
18177f9e646b7ed47bc8e9a60031ad0c2b55031e2077Anders Carlsson    /// CK_IntegralToPointer - Integral to pointer
18187f9e646b7ed47bc8e9a60031ad0c2b55031e2077Anders Carlsson    CK_IntegralToPointer,
1819c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
18207f9e646b7ed47bc8e9a60031ad0c2b55031e2077Anders Carlsson    /// CK_PointerToIntegral - Pointer to integral
1821ebeaf2031c968143c531bfe232d7507f20c57347Anders Carlsson    CK_PointerToIntegral,
1822c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
1823ebeaf2031c968143c531bfe232d7507f20c57347Anders Carlsson    /// CK_ToVoid - Cast to void.
182416a8904f3f5ed19158657e1da95e5902fbee66f7Anders Carlsson    CK_ToVoid,
1825c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
182616a8904f3f5ed19158657e1da95e5902fbee66f7Anders Carlsson    /// CK_VectorSplat - Casting from an integer/floating type to an extended
1827c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    /// vector type with the same element type as the src type. Splats the
1828f67cea84bac1d3417f0baaf1fcbc86ee126e2d87Anders Carlsson    /// src expression into the destination expression.
182982debc7d282e723e58d183bfa89ddc2500a8daafAnders Carlsson    CK_VectorSplat,
1830c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
183182debc7d282e723e58d183bfa89ddc2500a8daafAnders Carlsson    /// CK_IntegralCast - Casting between integral types of different size.
183282debc7d282e723e58d183bfa89ddc2500a8daafAnders Carlsson    CK_IntegralCast,
183382debc7d282e723e58d183bfa89ddc2500a8daafAnders Carlsson
183482debc7d282e723e58d183bfa89ddc2500a8daafAnders Carlsson    /// CK_IntegralToFloating - Integral to floating point.
183582debc7d282e723e58d183bfa89ddc2500a8daafAnders Carlsson    CK_IntegralToFloating,
1836c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
183782debc7d282e723e58d183bfa89ddc2500a8daafAnders Carlsson    /// CK_FloatingToIntegral - Floating point to integral.
183882debc7d282e723e58d183bfa89ddc2500a8daafAnders Carlsson    CK_FloatingToIntegral,
1839c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
184082debc7d282e723e58d183bfa89ddc2500a8daafAnders Carlsson    /// CK_FloatingCast - Casting between floating types of different size.
1841bc0e0781da778bd5eb41a810419912893ae20448Anders Carlsson    CK_FloatingCast,
1842c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
1843bc0e0781da778bd5eb41a810419912893ae20448Anders Carlsson    /// CK_MemberPointerToBoolean - Member pointer to boolean
184492ef5d75720c032808181133e4d7c5f82230237eFariborz Jahanian    CK_MemberPointerToBoolean,
184592ef5d75720c032808181133e4d7c5f82230237eFariborz Jahanian
1846c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    /// CK_AnyPointerToObjCPointerCast - Casting any pointer to objective-c
184792ef5d75720c032808181133e4d7c5f82230237eFariborz Jahanian    /// pointer
18483b27f1a80e4e433b503efd344c909eeafaa9033cFariborz Jahanian    CK_AnyPointerToObjCPointerCast,
1849c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    /// CK_AnyPointerToBlockPointerCast - Casting any pointer to block
18503b27f1a80e4e433b503efd344c909eeafaa9033cFariborz Jahanian    /// pointer
18513b27f1a80e4e433b503efd344c909eeafaa9033cFariborz Jahanian    CK_AnyPointerToBlockPointerCast
1852bc0e0781da778bd5eb41a810419912893ae20448Anders Carlsson
1853cdef2b75aa60cde1ca00e0aa3f89139ac89c6ae4Anders Carlsson  };
18541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1855cdef2b75aa60cde1ca00e0aa3f89139ac89c6ae4Anders Carlssonprivate:
1856cdef2b75aa60cde1ca00e0aa3f89139ac89c6ae4Anders Carlsson  CastKind Kind;
18570835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis  Stmt *Op;
1858409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson
18597ab9d574d27ecee1f130e5755aa403e5ab529b6bAnders Carlsson  /// BasePath - For derived-to-base and base-to-derived casts, the base array
18607ab9d574d27ecee1f130e5755aa403e5ab529b6bAnders Carlsson  /// contains the inheritance path.
1861f1b48b7014992155286d58bb1676f9f51031d18bAnders Carlsson  CXXBaseSpecifierArray BasePath;
18627ab9d574d27ecee1f130e5755aa403e5ab529b6bAnders Carlsson
18637ab9d574d27ecee1f130e5755aa403e5ab529b6bAnders Carlsson  void CheckBasePath() const {
1864409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson#ifndef NDEBUG
1865409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson    switch (getCastKind()) {
18665cf86ba6b5a724bf91cb52feade1158f1fbeb605Anders Carlsson    case CK_DerivedToBase:
1867cee22421929c91b481f4d1bb85cd48c0f6b7510bAnders Carlsson    case CK_UncheckedDerivedToBase:
1868cee22421929c91b481f4d1bb85cd48c0f6b7510bAnders Carlsson    case CK_DerivedToBaseMemberPointer:
1869409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson    case CK_BaseToDerived:
1870409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson    case CK_BaseToDerivedMemberPointer:
1871f9d68e1dd015972318b2448f75115ff4fc3d5008Anders Carlsson      assert(!BasePath.empty() && "Cast kind should have a base path!");
1872f9d68e1dd015972318b2448f75115ff4fc3d5008Anders Carlsson      break;
1873409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson
1874409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson    // These should not have an inheritance path.
1875409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson    case CK_Unknown:
1876409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson    case CK_BitCast:
1877409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson    case CK_NoOp:
1878409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson    case CK_Dynamic:
1879409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson    case CK_ToUnion:
1880409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson    case CK_ArrayToPointerDecay:
1881409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson    case CK_FunctionToPointerDecay:
1882409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson    case CK_NullToMemberPointer:
1883409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson    case CK_UserDefinedConversion:
1884409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson    case CK_ConstructorConversion:
1885409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson    case CK_IntegralToPointer:
1886409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson    case CK_PointerToIntegral:
1887409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson    case CK_ToVoid:
1888409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson    case CK_VectorSplat:
1889409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson    case CK_IntegralCast:
1890409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson    case CK_IntegralToFloating:
1891409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson    case CK_FloatingToIntegral:
1892409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson    case CK_FloatingCast:
1893409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson    case CK_MemberPointerToBoolean:
1894409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson    case CK_AnyPointerToObjCPointerCast:
1895409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson    case CK_AnyPointerToBlockPointerCast:
18965cf86ba6b5a724bf91cb52feade1158f1fbeb605Anders Carlsson      assert(BasePath.empty() && "Cast kind should not have a base path!");
1897409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson      break;
1898409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson    }
1899409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson#endif
1900409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson  }
1901409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson
19020835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidisprotected:
1903409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson  CastExpr(StmtClass SC, QualType ty, const CastKind kind, Expr *op,
1904f1b48b7014992155286d58bb1676f9f51031d18bAnders Carlsson           CXXBaseSpecifierArray BasePath) :
1905898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor    Expr(SC, ty,
1906898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor         // Cast expressions are type-dependent if the type is
1907898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor         // dependent (C++ [temp.dep.expr]p3).
1908898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor         ty->isDependentType(),
1909898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor         // Cast expressions are value-dependent if the type is
1910898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor         // dependent or if the subexpression is value-dependent.
19111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump         ty->isDependentType() || (op && op->isValueDependent())),
19127ab9d574d27ecee1f130e5755aa403e5ab529b6bAnders Carlsson    Kind(kind), Op(op), BasePath(BasePath) {
19137ab9d574d27ecee1f130e5755aa403e5ab529b6bAnders Carlsson      CheckBasePath();
1914409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson    }
19151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1916087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor  /// \brief Construct an empty cast.
19171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  CastExpr(StmtClass SC, EmptyShell Empty)
1918087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor    : Expr(SC, Empty) { }
19191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1920a3bddeda81ca784bed5501d79e1e7c53befaa91dAnders Carlsson  virtual void DoDestroy(ASTContext &C);
1921a3bddeda81ca784bed5501d79e1e7c53befaa91dAnders Carlsson
19220835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidispublic:
1923cdef2b75aa60cde1ca00e0aa3f89139ac89c6ae4Anders Carlsson  CastKind getCastKind() const { return Kind; }
1924cdef2b75aa60cde1ca00e0aa3f89139ac89c6ae4Anders Carlsson  void setCastKind(CastKind K) { Kind = K; }
1925f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson  const char *getCastKindName() const;
1926f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson
19270835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis  Expr *getSubExpr() { return cast<Expr>(Op); }
19280835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis  const Expr *getSubExpr() const { return cast<Expr>(Op); }
1929087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor  void setSubExpr(Expr *E) { Op = E; }
1930087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor
19316eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor  /// \brief Retrieve the cast subexpression as it was written in the source
19326eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor  /// code, looking through any implicit casts or other intermediate nodes
19336eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor  /// introduced by semantic analysis.
19346eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor  Expr *getSubExprAsWritten();
19356eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor  const Expr *getSubExprAsWritten() const {
19366eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor    return const_cast<CastExpr *>(this)->getSubExprAsWritten();
19376eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor  }
193841b2dcd465f1e438502c420effc9d0c747f9db8fAnders Carlsson
1939fc89c31a329eb6b36c6dbd8b7cb945d1a831650eAnders Carlsson  const CXXBaseSpecifierArray& getBasePath() const { return BasePath; }
194041b2dcd465f1e438502c420effc9d0c747f9db8fAnders Carlsson
19411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
19424bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt    return T->getStmtClass() >= firstCastExprConstant &&
19434bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt           T->getStmtClass() <= lastCastExprConstant;
19440835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis  }
19450835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis  static bool classof(const CastExpr *) { return true; }
19461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
19470835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis  // Iterators
19480835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis  virtual child_iterator child_begin();
19490835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis  virtual child_iterator child_end();
19500835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis};
19510835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis
195249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// ImplicitCastExpr - Allows us to explicitly represent implicit type
195349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// conversions, which have no direct representation in the original
195449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// source code. For example: converting T[]->T*, void f()->void
195549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// (*f)(), float->double, short->int, etc.
195649b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff///
1957bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// In C, implicit casts always produce rvalues. However, in C++, an
1958bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// implicit cast whose result is being bound to a reference will be
1959bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// an lvalue. For example:
1960bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor///
1961bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// @code
1962bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// class Base { };
1963bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// class Derived : public Base { };
19641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// void f(Derived d) {
1965bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor///   Base& b = d; // initializer is an ImplicitCastExpr to an lvalue of type Base
1966bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// }
1967bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// @endcode
19680835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidisclass ImplicitCastExpr : public CastExpr {
1969eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor  /// LvalueCast - Whether this cast produces an lvalue.
1970eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor  bool LvalueCast;
1971eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor
197249b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroffpublic:
1973c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  ImplicitCastExpr(QualType ty, CastKind kind, Expr *op,
1974f1b48b7014992155286d58bb1676f9f51031d18bAnders Carlsson                   CXXBaseSpecifierArray BasePath, bool Lvalue)
1975c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    : CastExpr(ImplicitCastExprClass, ty, kind, op, BasePath),
19767ab9d574d27ecee1f130e5755aa403e5ab529b6bAnders Carlsson    LvalueCast(Lvalue) { }
197790045e8ebabf50d6f1b3a67081a621b20b5e5341Steve Naroff
1978087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor  /// \brief Construct an empty implicit cast.
19791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  explicit ImplicitCastExpr(EmptyShell Shell)
1980087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor    : CastExpr(ImplicitCastExprClass, Shell) { }
1981087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor
19820835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis  virtual SourceRange getSourceRange() const {
19830835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis    return getSubExpr()->getSourceRange();
19840835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis  }
198590045e8ebabf50d6f1b3a67081a621b20b5e5341Steve Naroff
1986eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor  /// isLvalueCast - Whether this cast produces an lvalue.
1987eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor  bool isLvalueCast() const { return LvalueCast; }
1988eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor
1989eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor  /// setLvalueCast - Set whether this cast produces an lvalue.
1990eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor  void setLvalueCast(bool Lvalue) { LvalueCast = Lvalue; }
1991eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor
19921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
19931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == ImplicitCastExprClass;
199449b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff  }
199549b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff  static bool classof(const ImplicitCastExpr *) { return true; }
199649b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff};
199749b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff
199849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// ExplicitCastExpr - An explicit cast written in the source
19991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// code.
200049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor///
200149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// This class is effectively an abstract class, because it provides
200249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// the basic representation of an explicitly-written cast without
200349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// specifying which kind of cast (C cast, functional cast, static
200449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// cast, etc.) was written; specific derived classes represent the
200549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// particular style of cast and its location information.
20065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
200749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// Unlike implicit casts, explicit cast nodes have two different
200849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// types: the type that was written into the source code, and the
200949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// actual type of the expression as determined by semantic
201049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// analysis. These types may differ slightly. For example, in C++ one
201149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// can cast to a reference type, which indicates that the resulting
201249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// expression will be an lvalue. The reference type, however, will
201349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// not be used as the type of the expression.
20140835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidisclass ExplicitCastExpr : public CastExpr {
20159d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall  /// TInfo - Source type info for the (written) type
20169d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall  /// this expression is casting to.
20179d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall  TypeSourceInfo *TInfo;
201849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor
201949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregorprotected:
2020c0a2fd8f092722c8f78b566ac4506a21437040e9Anders Carlsson  ExplicitCastExpr(StmtClass SC, QualType exprTy, CastKind kind,
202141b2dcd465f1e438502c420effc9d0c747f9db8fAnders Carlsson                   Expr *op, CXXBaseSpecifierArray BasePath,
202241b2dcd465f1e438502c420effc9d0c747f9db8fAnders Carlsson                   TypeSourceInfo *writtenTy)
202341b2dcd465f1e438502c420effc9d0c747f9db8fAnders Carlsson    : CastExpr(SC, exprTy, kind, op, BasePath), TInfo(writtenTy) {}
202449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor
2025db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor  /// \brief Construct an empty explicit cast.
20261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ExplicitCastExpr(StmtClass SC, EmptyShell Shell)
2027db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor    : CastExpr(SC, Shell) { }
2028db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor
202949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregorpublic:
20309d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall  /// getTypeInfoAsWritten - Returns the type source info for the type
20319d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall  /// that this expression is casting to.
20329d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall  TypeSourceInfo *getTypeInfoAsWritten() const { return TInfo; }
20339d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall  void setTypeInfoAsWritten(TypeSourceInfo *writtenTy) { TInfo = writtenTy; }
20349d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall
203549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  /// getTypeAsWritten - Returns the type that this expression is
203649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  /// casting to, as written in the source code.
20379d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall  QualType getTypeAsWritten() const { return TInfo->getType(); }
203849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor
20391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
20404bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt     return T->getStmtClass() >= firstExplicitCastExprConstant &&
20414bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt            T->getStmtClass() <= lastExplicitCastExprConstant;
204249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  }
204349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  static bool classof(const ExplicitCastExpr *) { return true; }
204449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor};
204549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor
20466eec8e883de118b431e3ead5b1e604a6ac68ff6bDouglas Gregor/// CStyleCastExpr - An explicit cast in C (C99 6.5.4) or a C-style
204749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// cast in C++ (C++ [expr.cast]), which uses the syntax
204849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// (Type)expr. For example: @c (int)f.
20496eec8e883de118b431e3ead5b1e604a6ac68ff6bDouglas Gregorclass CStyleCastExpr : public ExplicitCastExpr {
2050b2f9e516327310d95840d442416084508f80c183Steve Naroff  SourceLocation LPLoc; // the location of the left paren
2051b2f9e516327310d95840d442416084508f80c183Steve Naroff  SourceLocation RPLoc; // the location of the right paren
20525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
20539d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall  CStyleCastExpr(QualType exprTy, CastKind kind, Expr *op,
205441b2dcd465f1e438502c420effc9d0c747f9db8fAnders Carlsson                 CXXBaseSpecifierArray BasePath, TypeSourceInfo *writtenTy,
205541b2dcd465f1e438502c420effc9d0c747f9db8fAnders Carlsson                 SourceLocation l, SourceLocation r)
205641b2dcd465f1e438502c420effc9d0c747f9db8fAnders Carlsson    : ExplicitCastExpr(CStyleCastExprClass, exprTy, kind, op, BasePath,
205741b2dcd465f1e438502c420effc9d0c747f9db8fAnders Carlsson                       writtenTy), LPLoc(l), RPLoc(r) {}
205849b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff
2059db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor  /// \brief Construct an empty C-style explicit cast.
20601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  explicit CStyleCastExpr(EmptyShell Shell)
2061db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor    : ExplicitCastExpr(CStyleCastExprClass, Shell) { }
2062db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor
2063b2f9e516327310d95840d442416084508f80c183Steve Naroff  SourceLocation getLParenLoc() const { return LPLoc; }
2064db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor  void setLParenLoc(SourceLocation L) { LPLoc = L; }
2065db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor
2066b2f9e516327310d95840d442416084508f80c183Steve Naroff  SourceLocation getRParenLoc() const { return RPLoc; }
2067db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor  void setRParenLoc(SourceLocation L) { RPLoc = L; }
2068db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor
20695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  virtual SourceRange getSourceRange() const {
2070b2f9e516327310d95840d442416084508f80c183Steve Naroff    return SourceRange(LPLoc, getSubExpr()->getSourceRange().getEnd());
20715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
20721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
20731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == CStyleCastExprClass;
20745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
20756eec8e883de118b431e3ead5b1e604a6ac68ff6bDouglas Gregor  static bool classof(const CStyleCastExpr *) { return true; }
20765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
20775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
20783fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// \brief A builtin binary operation expression such as "x + y" or "x <= y".
20793fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor///
20803fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// This expression node kind describes a builtin binary operation,
20813fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// such as "x + y" for integer values "x" and "y". The operands will
20823fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// already have been converted to appropriate types (e.g., by
20833fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// performing promotions or conversions).
20843fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor///
20853fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// In C++, where operators may be overloaded, a different kind of
20863fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// expression node (CXXOperatorCallExpr) is used to express the
20873fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// invocation of an overloaded operator with operator syntax. Within
20883fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// a C++ template, whether BinaryOperator or CXXOperatorCallExpr is
20893fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// used to store an expression "x + y" depends on the subexpressions
20903fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// for x and y. If neither x or y is type-dependent, and the "+"
20913fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// operator resolves to a built-in operation, BinaryOperator will be
20923fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// used to express the computation (x and y may still be
20933fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// value-dependent). If either x or y is type-dependent, or if the
20943fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// "+" resolves to an overloaded operator, CXXOperatorCallExpr will
20953fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// be used to express the computation.
20965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass BinaryOperator : public Expr {
20975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
20985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  enum Opcode {
20995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    // Operators listed in order of precedence.
210003d6fb99224c36935c9af9f4785cb33453c99b2bChris Lattner    // Note that additions to this should also update the StmtVisitor class.
2101224605064a4ef87d1c3d35ad1cb363f8b534012bSebastian Redl    PtrMemD, PtrMemI, // [C++ 5.5] Pointer-to-member operators.
21025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Mul, Div, Rem,    // [C99 6.5.5] Multiplicative operators.
21035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Add, Sub,         // [C99 6.5.6] Additive operators.
21045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Shl, Shr,         // [C99 6.5.7] Bitwise shift operators.
21055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    LT, GT, LE, GE,   // [C99 6.5.8] Relational operators.
21065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    EQ, NE,           // [C99 6.5.9] Equality operators.
21075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    And,              // [C99 6.5.10] Bitwise AND operator.
21085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Xor,              // [C99 6.5.11] Bitwise XOR operator.
21095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Or,               // [C99 6.5.12] Bitwise OR operator.
21105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    LAnd,             // [C99 6.5.13] Logical AND operator.
21115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    LOr,              // [C99 6.5.14] Logical OR operator.
21125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Assign, MulAssign,// [C99 6.5.16] Assignment operators.
21135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    DivAssign, RemAssign,
21145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    AddAssign, SubAssign,
21155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    ShlAssign, ShrAssign,
21165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    AndAssign, XorAssign,
21175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    OrAssign,
21185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Comma             // [C99 6.5.17] Comma operator.
21195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  };
212017d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattnerprivate:
212117d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner  enum { LHS, RHS, END_EXPR };
21225549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Stmt* SubExprs[END_EXPR];
212317d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner  Opcode Opc;
212417d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner  SourceLocation OpLoc;
21251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumppublic:
21261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
212717d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner  BinaryOperator(Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy,
212817d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner                 SourceLocation opLoc)
2129898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor    : Expr(BinaryOperatorClass, ResTy,
2130898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor           lhs->isTypeDependent() || rhs->isTypeDependent(),
21311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump           lhs->isValueDependent() || rhs->isValueDependent()),
2132898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor      Opc(opc), OpLoc(opLoc) {
21331237c673c07f9d827129ba02720108816abde562Ted Kremenek    SubExprs[LHS] = lhs;
21341237c673c07f9d827129ba02720108816abde562Ted Kremenek    SubExprs[RHS] = rhs;
21351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    assert(!isCompoundAssignmentOp() &&
21365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer           "Use ArithAssignBinaryOperator for compound assignments");
21375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
21385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
2139db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor  /// \brief Construct an empty binary operator.
21401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  explicit BinaryOperator(EmptyShell Empty)
2141db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor    : Expr(BinaryOperatorClass, Empty), Opc(Comma) { }
2142db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor
214317d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner  SourceLocation getOperatorLoc() const { return OpLoc; }
2144db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor  void setOperatorLoc(SourceLocation L) { OpLoc = L; }
2145db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor
21465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  Opcode getOpcode() const { return Opc; }
2147db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor  void setOpcode(Opcode O) { Opc = O; }
2148db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor
21495549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); }
2150db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor  void setLHS(Expr *E) { SubExprs[LHS] = E; }
21515549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); }
2152db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor  void setRHS(Expr *E) { SubExprs[RHS] = E; }
2153db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor
21545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  virtual SourceRange getSourceRange() const {
21555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return SourceRange(getLHS()->getLocStart(), getRHS()->getLocEnd());
21565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
21571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
21585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// getOpcodeStr - Turn an Opcode enum value into the punctuation char it
21595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// corresponds to, e.g. "<<=".
21605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static const char *getOpcodeStr(Opcode Op);
21615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
2162063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor  /// \brief Retrieve the binary opcode that corresponds to the given
2163063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor  /// overloaded operator.
2164063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor  static Opcode getOverloadedOpcode(OverloadedOperatorKind OO);
2165063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor
2166063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor  /// \brief Retrieve the overloaded operator kind that corresponds to
2167063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor  /// the given binary opcode.
2168063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor  static OverloadedOperatorKind getOverloadedOperator(Opcode Opc);
2169063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor
21705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// predicates to categorize the respective opcodes.
21715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isMultiplicativeOp() const { return Opc >= Mul && Opc <= Rem; }
21725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isAdditiveOp() const { return Opc == Add || Opc == Sub; }
217340a5ef90ac8d3f29bc8fe4ff80e00eaf3ef5b79fTed Kremenek  static bool isShiftOp(Opcode Opc) { return Opc == Shl || Opc == Shr; }
217440a5ef90ac8d3f29bc8fe4ff80e00eaf3ef5b79fTed Kremenek  bool isShiftOp() const { return isShiftOp(Opc); }
2175aee3c9375f97a49edef2a36f15df6abd9748e2a1Sebastian Redl
2176aee3c9375f97a49edef2a36f15df6abd9748e2a1Sebastian Redl  static bool isBitwiseOp(Opcode Opc) { return Opc >= And && Opc <= Or; }
2177aee3c9375f97a49edef2a36f15df6abd9748e2a1Sebastian Redl  bool isBitwiseOp() const { return isBitwiseOp(Opc); }
2178f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek
2179f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek  static bool isRelationalOp(Opcode Opc) { return Opc >= LT && Opc <= GE; }
2180f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek  bool isRelationalOp() const { return isRelationalOp(Opc); }
2181f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek
21821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool isEqualityOp(Opcode Opc) { return Opc == EQ || Opc == NE; }
2183f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek  bool isEqualityOp() const { return isEqualityOp(Opc); }
21841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2185aee3c9375f97a49edef2a36f15df6abd9748e2a1Sebastian Redl  static bool isComparisonOp(Opcode Opc) { return Opc >= LT && Opc <= NE; }
2186aee3c9375f97a49edef2a36f15df6abd9748e2a1Sebastian Redl  bool isComparisonOp() const { return isComparisonOp(Opc); }
2187aee3c9375f97a49edef2a36f15df6abd9748e2a1Sebastian Redl
2188f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek  static bool isLogicalOp(Opcode Opc) { return Opc == LAnd || Opc == LOr; }
2189f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek  bool isLogicalOp() const { return isLogicalOp(Opc); }
2190f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek
21915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isAssignmentOp() const { return Opc >= Assign && Opc <= OrAssign; }
21925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isCompoundAssignmentOp() const { return Opc > Assign && Opc <= OrAssign;}
21935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isShiftAssignOp() const { return Opc == ShlAssign || Opc == ShrAssign; }
21941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
21951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *S) {
21964bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt    return S->getStmtClass() >= firstBinaryOperatorConstant &&
21974bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt           S->getStmtClass() <= lastBinaryOperatorConstant;
21985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
21995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const BinaryOperator *) { return true; }
22001237c673c07f9d827129ba02720108816abde562Ted Kremenek
22011237c673c07f9d827129ba02720108816abde562Ted Kremenek  // Iterators
22021237c673c07f9d827129ba02720108816abde562Ted Kremenek  virtual child_iterator child_begin();
22031237c673c07f9d827129ba02720108816abde562Ted Kremenek  virtual child_iterator child_end();
22041237c673c07f9d827129ba02720108816abde562Ted Kremenek
22055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprotected:
220617d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner  BinaryOperator(Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy,
22072333f7727f97018d6742e1e0938133bcfad967abEli Friedman                 SourceLocation opLoc, bool dead)
22082333f7727f97018d6742e1e0938133bcfad967abEli Friedman    : Expr(CompoundAssignOperatorClass, ResTy,
22092333f7727f97018d6742e1e0938133bcfad967abEli Friedman           lhs->isTypeDependent() || rhs->isTypeDependent(),
22102333f7727f97018d6742e1e0938133bcfad967abEli Friedman           lhs->isValueDependent() || rhs->isValueDependent()),
22112333f7727f97018d6742e1e0938133bcfad967abEli Friedman      Opc(opc), OpLoc(opLoc) {
22121237c673c07f9d827129ba02720108816abde562Ted Kremenek    SubExprs[LHS] = lhs;
22131237c673c07f9d827129ba02720108816abde562Ted Kremenek    SubExprs[RHS] = rhs;
22145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
2215ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor
22161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  BinaryOperator(StmtClass SC, EmptyShell Empty)
2217ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor    : Expr(SC, Empty), Opc(MulAssign) { }
22185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
22195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
22205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// CompoundAssignOperator - For compound assignments (e.g. +=), we keep
22215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// track of the type the operation is performed in.  Due to the semantics of
22225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// these operators, the operands are promoted, the aritmetic performed, an
22235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// implicit conversion back to the result type done, then the assignment takes
22245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// place.  This captures the intermediate type which the computation is done
22255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// in.
22265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass CompoundAssignOperator : public BinaryOperator {
2227ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman  QualType ComputationLHSType;
2228ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman  QualType ComputationResultType;
22295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
22305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  CompoundAssignOperator(Expr *lhs, Expr *rhs, Opcode opc,
2231ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman                         QualType ResType, QualType CompLHSType,
2232ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman                         QualType CompResultType,
223317d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner                         SourceLocation OpLoc)
223417d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner    : BinaryOperator(lhs, rhs, opc, ResType, OpLoc, true),
2235ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman      ComputationLHSType(CompLHSType),
2236ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman      ComputationResultType(CompResultType) {
22371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    assert(isCompoundAssignmentOp() &&
22385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer           "Only should be used for compound assignments");
22395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
22405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
2241ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor  /// \brief Build an empty compound assignment operator expression.
2242ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor  explicit CompoundAssignOperator(EmptyShell Empty)
2243ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor    : BinaryOperator(CompoundAssignOperatorClass, Empty) { }
2244ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor
2245ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman  // The two computation types are the type the LHS is converted
2246ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman  // to for the computation and the type of the result; the two are
2247ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman  // distinct in a few cases (specifically, int+=ptr and ptr-=ptr).
2248ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman  QualType getComputationLHSType() const { return ComputationLHSType; }
2249ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor  void setComputationLHSType(QualType T) { ComputationLHSType = T; }
2250ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor
2251ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman  QualType getComputationResultType() const { return ComputationResultType; }
2252ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor  void setComputationResultType(QualType T) { ComputationResultType = T; }
2253ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor
22545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const CompoundAssignOperator *) { return true; }
22551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *S) {
22561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return S->getStmtClass() == CompoundAssignOperatorClass;
22575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
22585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
22595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
22605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ConditionalOperator - The ?: operator.  Note that LHS may be null when the
22615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// GNU "missing LHS" extension is in use.
22625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
22635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass ConditionalOperator : public Expr {
22641237c673c07f9d827129ba02720108816abde562Ted Kremenek  enum { COND, LHS, RHS, END_EXPR };
22655549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Stmt* SubExprs[END_EXPR]; // Left/Middle/Right hand sides.
226647e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor  SourceLocation QuestionLoc, ColonLoc;
22675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
226847e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor  ConditionalOperator(Expr *cond, SourceLocation QLoc, Expr *lhs,
226947e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor                      SourceLocation CLoc, Expr *rhs, QualType t)
2270898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor    : Expr(ConditionalOperatorClass, t,
2271898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor           // FIXME: the type of the conditional operator doesn't
2272898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor           // depend on the type of the conditional, but the standard
2273898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor           // seems to imply that it could. File a bug!
2274898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor           ((lhs && lhs->isTypeDependent()) || (rhs && rhs->isTypeDependent())),
22751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump           (cond->isValueDependent() ||
2276898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor            (lhs && lhs->isValueDependent()) ||
227747e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor            (rhs && rhs->isValueDependent()))),
227847e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor      QuestionLoc(QLoc),
227947e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor      ColonLoc(CLoc) {
22801237c673c07f9d827129ba02720108816abde562Ted Kremenek    SubExprs[COND] = cond;
22811237c673c07f9d827129ba02720108816abde562Ted Kremenek    SubExprs[LHS] = lhs;
22821237c673c07f9d827129ba02720108816abde562Ted Kremenek    SubExprs[RHS] = rhs;
22831237c673c07f9d827129ba02720108816abde562Ted Kremenek  }
22845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
2285ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor  /// \brief Build an empty conditional operator.
2286ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor  explicit ConditionalOperator(EmptyShell Empty)
2287ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor    : Expr(ConditionalOperatorClass, Empty) { }
2288ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor
2289395a2abf0028968d85958610e393e067885dc14fTed Kremenek  // getCond - Return the expression representing the condition for
2290395a2abf0028968d85958610e393e067885dc14fTed Kremenek  //  the ?: operator.
22915549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getCond() const { return cast<Expr>(SubExprs[COND]); }
2292ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor  void setCond(Expr *E) { SubExprs[COND] = E; }
2293395a2abf0028968d85958610e393e067885dc14fTed Kremenek
2294395a2abf0028968d85958610e393e067885dc14fTed Kremenek  // getTrueExpr - Return the subexpression representing the value of the ?:
2295395a2abf0028968d85958610e393e067885dc14fTed Kremenek  //  expression if the condition evaluates to true.  In most cases this value
2296395a2abf0028968d85958610e393e067885dc14fTed Kremenek  //  will be the same as getLHS() except a GCC extension allows the left
2297395a2abf0028968d85958610e393e067885dc14fTed Kremenek  //  subexpression to be omitted, and instead of the condition be returned.
2298395a2abf0028968d85958610e393e067885dc14fTed Kremenek  //  e.g: x ?: y is shorthand for x ? x : y, except that the expression "x"
22991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  //  is only evaluated once.
2300395a2abf0028968d85958610e393e067885dc14fTed Kremenek  Expr *getTrueExpr() const {
23015549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek    return cast<Expr>(SubExprs[LHS] ? SubExprs[LHS] : SubExprs[COND]);
2302395a2abf0028968d85958610e393e067885dc14fTed Kremenek  }
23031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2304395a2abf0028968d85958610e393e067885dc14fTed Kremenek  // getTrueExpr - Return the subexpression representing the value of the ?:
2305395a2abf0028968d85958610e393e067885dc14fTed Kremenek  // expression if the condition evaluates to false. This is the same as getRHS.
23065549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getFalseExpr() const { return cast<Expr>(SubExprs[RHS]); }
23071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
23085549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getLHS() const { return cast_or_null<Expr>(SubExprs[LHS]); }
2309ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor  void setLHS(Expr *E) { SubExprs[LHS] = E; }
2310ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor
23115549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); }
2312ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor  void setRHS(Expr *E) { SubExprs[RHS] = E; }
23135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
231447e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor  SourceLocation getQuestionLoc() const { return QuestionLoc; }
231547e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor  void setQuestionLoc(SourceLocation L) { QuestionLoc = L; }
231647e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor
231747e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor  SourceLocation getColonLoc() const { return ColonLoc; }
231847e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor  void setColonLoc(SourceLocation L) { ColonLoc = L; }
231947e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor
23205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  virtual SourceRange getSourceRange() const {
23215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return SourceRange(getCond()->getLocStart(), getRHS()->getLocEnd());
23225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
23231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
23241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == ConditionalOperatorClass;
23255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
23265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const ConditionalOperator *) { return true; }
23271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
23281237c673c07f9d827129ba02720108816abde562Ted Kremenek  // Iterators
23291237c673c07f9d827129ba02720108816abde562Ted Kremenek  virtual child_iterator child_begin();
23301237c673c07f9d827129ba02720108816abde562Ted Kremenek  virtual child_iterator child_end();
23315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
23325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
23336481a57fefbf1a313ff439028470fe4c27a3b7a3Chris Lattner/// AddrLabelExpr - The GNU address of label extension, representing &&label.
23346481a57fefbf1a313ff439028470fe4c27a3b7a3Chris Lattnerclass AddrLabelExpr : public Expr {
23355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation AmpAmpLoc, LabelLoc;
23365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  LabelStmt *Label;
23375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
23386481a57fefbf1a313ff439028470fe4c27a3b7a3Chris Lattner  AddrLabelExpr(SourceLocation AALoc, SourceLocation LLoc, LabelStmt *L,
23396481a57fefbf1a313ff439028470fe4c27a3b7a3Chris Lattner                QualType t)
23402333f7727f97018d6742e1e0938133bcfad967abEli Friedman    : Expr(AddrLabelExprClass, t, false, false),
23412333f7727f97018d6742e1e0938133bcfad967abEli Friedman      AmpAmpLoc(AALoc), LabelLoc(LLoc), Label(L) {}
23421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
23437d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor  /// \brief Build an empty address of a label expression.
23441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  explicit AddrLabelExpr(EmptyShell Empty)
23457d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor    : Expr(AddrLabelExprClass, Empty) { }
23467d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor
23477d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor  SourceLocation getAmpAmpLoc() const { return AmpAmpLoc; }
23487d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor  void setAmpAmpLoc(SourceLocation L) { AmpAmpLoc = L; }
23497d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor  SourceLocation getLabelLoc() const { return LabelLoc; }
23507d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor  void setLabelLoc(SourceLocation L) { LabelLoc = L; }
23517d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor
23525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  virtual SourceRange getSourceRange() const {
23535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return SourceRange(AmpAmpLoc, LabelLoc);
23545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
23551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
23565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  LabelStmt *getLabel() const { return Label; }
23577d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor  void setLabel(LabelStmt *S) { Label = S; }
23587d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor
23595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Stmt *T) {
23601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == AddrLabelExprClass;
23615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
23626481a57fefbf1a313ff439028470fe4c27a3b7a3Chris Lattner  static bool classof(const AddrLabelExpr *) { return true; }
23631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
23641237c673c07f9d827129ba02720108816abde562Ted Kremenek  // Iterators
23651237c673c07f9d827129ba02720108816abde562Ted Kremenek  virtual child_iterator child_begin();
23661237c673c07f9d827129ba02720108816abde562Ted Kremenek  virtual child_iterator child_end();
23675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
2368ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner
2369ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner/// StmtExpr - This is the GNU Statement Expression extension: ({int X=4; X;}).
2370ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner/// The StmtExpr contains a single CompoundStmt node, which it evaluates and
2371ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner/// takes the value of the last subexpression.
2372ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattnerclass StmtExpr : public Expr {
23735549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Stmt *SubStmt;
2374ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner  SourceLocation LParenLoc, RParenLoc;
2375ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattnerpublic:
23762333f7727f97018d6742e1e0938133bcfad967abEli Friedman  // FIXME: Does type-dependence need to be computed differently?
2377d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff  StmtExpr(CompoundStmt *substmt, QualType T,
2378d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff           SourceLocation lp, SourceLocation rp) :
23792333f7727f97018d6742e1e0938133bcfad967abEli Friedman    Expr(StmtExprClass, T, T->isDependentType(), false),
23802333f7727f97018d6742e1e0938133bcfad967abEli Friedman    SubStmt(substmt), LParenLoc(lp), RParenLoc(rp) { }
23811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
23826a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor  /// \brief Build an empty statement expression.
23836a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor  explicit StmtExpr(EmptyShell Empty) : Expr(StmtExprClass, Empty) { }
23846a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor
23855549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  CompoundStmt *getSubStmt() { return cast<CompoundStmt>(SubStmt); }
23865549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  const CompoundStmt *getSubStmt() const { return cast<CompoundStmt>(SubStmt); }
23876a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor  void setSubStmt(CompoundStmt *S) { SubStmt = S; }
23886a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor
2389ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner  virtual SourceRange getSourceRange() const {
2390ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner    return SourceRange(LParenLoc, RParenLoc);
2391ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner  }
23921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2393026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner  SourceLocation getLParenLoc() const { return LParenLoc; }
23946a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor  void setLParenLoc(SourceLocation L) { LParenLoc = L; }
2395026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner  SourceLocation getRParenLoc() const { return RParenLoc; }
23966a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
23971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2398ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner  static bool classof(const Stmt *T) {
23991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == StmtExprClass;
2400ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner  }
2401ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner  static bool classof(const StmtExpr *) { return true; }
24021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
24031237c673c07f9d827129ba02720108816abde562Ted Kremenek  // Iterators
24041237c673c07f9d827129ba02720108816abde562Ted Kremenek  virtual child_iterator child_begin();
24051237c673c07f9d827129ba02720108816abde562Ted Kremenek  virtual child_iterator child_end();
2406ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner};
2407ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner
2408dc241b42c7588f99027b035a09b71557a6db219eDouglas Gregor/// TypesCompatibleExpr - GNU builtin-in function __builtin_types_compatible_p.
2409d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff/// This AST node represents a function that returns 1 if two *types* (not
2410d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff/// expressions) are compatible. The result of this built-in function can be
2411d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff/// used in integer constant expressions.
2412d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroffclass TypesCompatibleExpr : public Expr {
2413d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff  QualType Type1;
2414d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff  QualType Type2;
2415363bcff47df2fda3cfcfcd994b7888157df58c43Steve Naroff  SourceLocation BuiltinLoc, RParenLoc;
2416d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroffpublic:
24171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  TypesCompatibleExpr(QualType ReturnType, SourceLocation BLoc,
24181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                      QualType t1, QualType t2, SourceLocation RP) :
24192333f7727f97018d6742e1e0938133bcfad967abEli Friedman    Expr(TypesCompatibleExprClass, ReturnType, false, false),
24202333f7727f97018d6742e1e0938133bcfad967abEli Friedman    Type1(t1), Type2(t2), BuiltinLoc(BLoc), RParenLoc(RP) {}
2421d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff
242244cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  /// \brief Build an empty __builtin_type_compatible_p expression.
242344cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  explicit TypesCompatibleExpr(EmptyShell Empty)
242444cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor    : Expr(TypesCompatibleExprClass, Empty) { }
242544cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor
24267f28fe8e00ec4fac17977374d8da491f873a3b05Steve Naroff  QualType getArgType1() const { return Type1; }
242744cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  void setArgType1(QualType T) { Type1 = T; }
24287f28fe8e00ec4fac17977374d8da491f873a3b05Steve Naroff  QualType getArgType2() const { return Type2; }
242944cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  void setArgType2(QualType T) { Type2 = T; }
24301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
243144cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  SourceLocation getBuiltinLoc() const { return BuiltinLoc; }
243244cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  void setBuiltinLoc(SourceLocation L) { BuiltinLoc = L; }
24331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
243444cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  SourceLocation getRParenLoc() const { return RParenLoc; }
243544cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
24361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2437d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff  virtual SourceRange getSourceRange() const {
2438363bcff47df2fda3cfcfcd994b7888157df58c43Steve Naroff    return SourceRange(BuiltinLoc, RParenLoc);
2439d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff  }
2440d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff  static bool classof(const Stmt *T) {
24411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == TypesCompatibleExprClass;
2442d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff  }
2443d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff  static bool classof(const TypesCompatibleExpr *) { return true; }
24441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
24451237c673c07f9d827129ba02720108816abde562Ted Kremenek  // Iterators
24461237c673c07f9d827129ba02720108816abde562Ted Kremenek  virtual child_iterator child_begin();
24471237c673c07f9d827129ba02720108816abde562Ted Kremenek  virtual child_iterator child_end();
2448d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff};
2449d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff
2450d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// ShuffleVectorExpr - clang-specific builtin-in function
2451d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// __builtin_shufflevector.
2452d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// This AST node represents a operator that does a constant
2453d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// shuffle, similar to LLVM's shufflevector instruction. It takes
2454d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// two vectors and a variable number of constant indices,
2455d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// and returns the appropriately shuffled vector.
2456d38617c8a50f9729c254ab76cd359af797c6739bEli Friedmanclass ShuffleVectorExpr : public Expr {
2457d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  SourceLocation BuiltinLoc, RParenLoc;
2458d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman
2459d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  // SubExprs - the list of values passed to the __builtin_shufflevector
2460d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  // function. The first two are vectors, and the rest are constant
2461d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  // indices.  The number of values in this list is always
2462d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  // 2+the number of indices in the vector type.
24635549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Stmt **SubExprs;
2464d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  unsigned NumExprs;
2465d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman
2466888376a2bbcfc2f047902249f8455918e2489ae1Nate Begemanprotected:
24671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  virtual void DoDestroy(ASTContext &C);
2468888376a2bbcfc2f047902249f8455918e2489ae1Nate Begeman
2469d38617c8a50f9729c254ab76cd359af797c6739bEli Friedmanpublic:
24702333f7727f97018d6742e1e0938133bcfad967abEli Friedman  // FIXME: Can a shufflevector be value-dependent?  Does type-dependence need
24712333f7727f97018d6742e1e0938133bcfad967abEli Friedman  // to be computed differently?
2472a88dc3079bedf70a5cfc39791727e43a10383006Nate Begeman  ShuffleVectorExpr(ASTContext &C, Expr **args, unsigned nexpr,
24731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                    QualType Type, SourceLocation BLoc,
24741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                    SourceLocation RP) :
24752333f7727f97018d6742e1e0938133bcfad967abEli Friedman    Expr(ShuffleVectorExprClass, Type, Type->isDependentType(), false),
24762333f7727f97018d6742e1e0938133bcfad967abEli Friedman    BuiltinLoc(BLoc), RParenLoc(RP), NumExprs(nexpr) {
24771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2478a88dc3079bedf70a5cfc39791727e43a10383006Nate Begeman    SubExprs = new (C) Stmt*[nexpr];
2479d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman    for (unsigned i = 0; i < nexpr; i++)
2480d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman      SubExprs[i] = args[i];
2481d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  }
248294cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor
248394cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor  /// \brief Build an empty vector-shuffle expression.
24841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  explicit ShuffleVectorExpr(EmptyShell Empty)
248594cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor    : Expr(ShuffleVectorExprClass, Empty), SubExprs(0) { }
248694cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor
248794cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor  SourceLocation getBuiltinLoc() const { return BuiltinLoc; }
248894cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor  void setBuiltinLoc(SourceLocation L) { BuiltinLoc = L; }
24891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
249094cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor  SourceLocation getRParenLoc() const { return RParenLoc; }
249194cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
249294cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor
2493d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  virtual SourceRange getSourceRange() const {
2494d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman    return SourceRange(BuiltinLoc, RParenLoc);
2495d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  }
2496d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  static bool classof(const Stmt *T) {
24971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == ShuffleVectorExprClass;
2498d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  }
2499d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  static bool classof(const ShuffleVectorExpr *) { return true; }
25001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2501888376a2bbcfc2f047902249f8455918e2489ae1Nate Begeman  ~ShuffleVectorExpr() {}
25021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2503d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  /// getNumSubExprs - Return the size of the SubExprs array.  This includes the
2504d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  /// constant expression, the actual arguments passed in, and the function
2505d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  /// pointers.
2506d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  unsigned getNumSubExprs() const { return NumExprs; }
25071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2508d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  /// getExpr - Return the Expr at the specified index.
2509d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  Expr *getExpr(unsigned Index) {
2510d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman    assert((Index < NumExprs) && "Arg access out of range!");
25115549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek    return cast<Expr>(SubExprs[Index]);
2512d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  }
2513d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  const Expr *getExpr(unsigned Index) const {
2514d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman    assert((Index < NumExprs) && "Arg access out of range!");
25155549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek    return cast<Expr>(SubExprs[Index]);
2516d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  }
25171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2518888376a2bbcfc2f047902249f8455918e2489ae1Nate Begeman  void setExprs(ASTContext &C, Expr ** Exprs, unsigned NumExprs);
251994cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor
2520dde8c94873976632e3ada4d8d067e1e244184d51Eli Friedman  unsigned getShuffleMaskIdx(ASTContext &Ctx, unsigned N) {
2521dde8c94873976632e3ada4d8d067e1e244184d51Eli Friedman    assert((N < NumExprs - 2) && "Shuffle idx out of range!");
25229a901bb63990574ff0bcc12ff851d7a71cff8ddbEli Friedman    return getExpr(N+2)->EvaluateAsInt(Ctx).getZExtValue();
2523d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  }
25241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2525d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  // Iterators
2526d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  virtual child_iterator child_begin();
2527d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  virtual child_iterator child_end();
2528d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman};
2529d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman
2530d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff/// ChooseExpr - GNU builtin-in function __builtin_choose_expr.
25311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// This AST node is similar to the conditional operator (?:) in C, with
2532d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff/// the following exceptions:
25337976932a1c256d447316ffac58e9821417725e34Eli Friedman/// - the test expression must be a integer constant expression.
25347976932a1c256d447316ffac58e9821417725e34Eli Friedman/// - the expression returned acts like the chosen subexpression in every
25357976932a1c256d447316ffac58e9821417725e34Eli Friedman///   visible way: the type is the same as that of the chosen subexpression,
25367976932a1c256d447316ffac58e9821417725e34Eli Friedman///   and all predicates (whether it's an l-value, whether it's an integer
25377976932a1c256d447316ffac58e9821417725e34Eli Friedman///   constant expression, etc.) return the same result as for the chosen
25387976932a1c256d447316ffac58e9821417725e34Eli Friedman///   sub-expression.
2539d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroffclass ChooseExpr : public Expr {
25401237c673c07f9d827129ba02720108816abde562Ted Kremenek  enum { COND, LHS, RHS, END_EXPR };
25415549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Stmt* SubExprs[END_EXPR]; // Left/Middle/Right hand sides.
2542d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff  SourceLocation BuiltinLoc, RParenLoc;
2543d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroffpublic:
2544d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff  ChooseExpr(SourceLocation BLoc, Expr *cond, Expr *lhs, Expr *rhs, QualType t,
2545ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor             SourceLocation RP, bool TypeDependent, bool ValueDependent)
2546ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor    : Expr(ChooseExprClass, t, TypeDependent, ValueDependent),
25471237c673c07f9d827129ba02720108816abde562Ted Kremenek      BuiltinLoc(BLoc), RParenLoc(RP) {
25481237c673c07f9d827129ba02720108816abde562Ted Kremenek      SubExprs[COND] = cond;
25491237c673c07f9d827129ba02720108816abde562Ted Kremenek      SubExprs[LHS] = lhs;
25501237c673c07f9d827129ba02720108816abde562Ted Kremenek      SubExprs[RHS] = rhs;
25511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    }
25527976932a1c256d447316ffac58e9821417725e34Eli Friedman
255344cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  /// \brief Build an empty __builtin_choose_expr.
255444cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  explicit ChooseExpr(EmptyShell Empty) : Expr(ChooseExprClass, Empty) { }
255544cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor
25567976932a1c256d447316ffac58e9821417725e34Eli Friedman  /// isConditionTrue - Return whether the condition is true (i.e. not
25577976932a1c256d447316ffac58e9821417725e34Eli Friedman  /// equal to zero).
255827437caadea35f84d550cd29f024fcf3ea240eecChris Lattner  bool isConditionTrue(ASTContext &C) const;
25597976932a1c256d447316ffac58e9821417725e34Eli Friedman
25607976932a1c256d447316ffac58e9821417725e34Eli Friedman  /// getChosenSubExpr - Return the subexpression chosen according to the
25617976932a1c256d447316ffac58e9821417725e34Eli Friedman  /// condition.
25627976932a1c256d447316ffac58e9821417725e34Eli Friedman  Expr *getChosenSubExpr(ASTContext &C) const {
25637976932a1c256d447316ffac58e9821417725e34Eli Friedman    return isConditionTrue(C) ? getLHS() : getRHS();
25647976932a1c256d447316ffac58e9821417725e34Eli Friedman  }
25657976932a1c256d447316ffac58e9821417725e34Eli Friedman
25665549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getCond() const { return cast<Expr>(SubExprs[COND]); }
256744cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  void setCond(Expr *E) { SubExprs[COND] = E; }
25685549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); }
256944cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  void setLHS(Expr *E) { SubExprs[LHS] = E; }
25705549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); }
257144cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  void setRHS(Expr *E) { SubExprs[RHS] = E; }
257244cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor
257344cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  SourceLocation getBuiltinLoc() const { return BuiltinLoc; }
257444cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  void setBuiltinLoc(SourceLocation L) { BuiltinLoc = L; }
25751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
257644cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  SourceLocation getRParenLoc() const { return RParenLoc; }
257744cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
25781237c673c07f9d827129ba02720108816abde562Ted Kremenek
2579d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff  virtual SourceRange getSourceRange() const {
2580d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff    return SourceRange(BuiltinLoc, RParenLoc);
2581d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff  }
2582d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff  static bool classof(const Stmt *T) {
25831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == ChooseExprClass;
2584d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff  }
2585d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff  static bool classof(const ChooseExpr *) { return true; }
25861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
25871237c673c07f9d827129ba02720108816abde562Ted Kremenek  // Iterators
25881237c673c07f9d827129ba02720108816abde562Ted Kremenek  virtual child_iterator child_begin();
25891237c673c07f9d827129ba02720108816abde562Ted Kremenek  virtual child_iterator child_end();
2590d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff};
2591d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff
25922d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// GNUNullExpr - Implements the GNU __null extension, which is a name
25932d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// for a null pointer constant that has integral type (e.g., int or
25942d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// long) and is the same size and alignment as a pointer. The __null
25952d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// extension is typically only used by system headers, which define
25962d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// NULL as __null in C++ rather than using 0 (which is an integer
25972d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// that may not match the size of a pointer).
25982d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregorclass GNUNullExpr : public Expr {
25992d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor  /// TokenLoc - The location of the __null keyword.
26002d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor  SourceLocation TokenLoc;
26012d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor
26022d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregorpublic:
26031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  GNUNullExpr(QualType Ty, SourceLocation Loc)
26042333f7727f97018d6742e1e0938133bcfad967abEli Friedman    : Expr(GNUNullExprClass, Ty, false, false), TokenLoc(Loc) { }
26052d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor
260644cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  /// \brief Build an empty GNU __null expression.
260744cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  explicit GNUNullExpr(EmptyShell Empty) : Expr(GNUNullExprClass, Empty) { }
260844cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor
26092d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor  /// getTokenLocation - The location of the __null token.
26102d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor  SourceLocation getTokenLocation() const { return TokenLoc; }
261144cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  void setTokenLocation(SourceLocation L) { TokenLoc = L; }
26122d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor
26132d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor  virtual SourceRange getSourceRange() const {
26142d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor    return SourceRange(TokenLoc);
26152d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor  }
26162d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor  static bool classof(const Stmt *T) {
26171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == GNUNullExprClass;
26182d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor  }
26192d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor  static bool classof(const GNUNullExpr *) { return true; }
26201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
26212d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor  // Iterators
26222d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor  virtual child_iterator child_begin();
26232d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor  virtual child_iterator child_end();
26242d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor};
26252d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor
262674626d6ef2e194fcc911e071556660ff331eb4a8Zhongxing Xu/// VAArgExpr, used for the builtin function __builtin_va_arg.
26277c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlssonclass VAArgExpr : public Expr {
26285549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Stmt *Val;
26297c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson  SourceLocation BuiltinLoc, RParenLoc;
26307c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlssonpublic:
26317c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson  VAArgExpr(SourceLocation BLoc, Expr* e, QualType t, SourceLocation RPLoc)
26322333f7727f97018d6742e1e0938133bcfad967abEli Friedman    : Expr(VAArgExprClass, t, t->isDependentType(), false),
26337c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson      Val(e),
26347c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson      BuiltinLoc(BLoc),
26357c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson      RParenLoc(RPLoc) { }
26361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
263774626d6ef2e194fcc911e071556660ff331eb4a8Zhongxing Xu  /// \brief Create an empty __builtin_va_arg expression.
2638d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor  explicit VAArgExpr(EmptyShell Empty) : Expr(VAArgExprClass, Empty) { }
2639d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor
26405549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  const Expr *getSubExpr() const { return cast<Expr>(Val); }
26415549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getSubExpr() { return cast<Expr>(Val); }
2642d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor  void setSubExpr(Expr *E) { Val = E; }
2643d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor
2644d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor  SourceLocation getBuiltinLoc() const { return BuiltinLoc; }
2645d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor  void setBuiltinLoc(SourceLocation L) { BuiltinLoc = L; }
26461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2647d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor  SourceLocation getRParenLoc() const { return RParenLoc; }
2648d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
2649d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor
26507c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson  virtual SourceRange getSourceRange() const {
26517c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson    return SourceRange(BuiltinLoc, RParenLoc);
26521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  }
26537c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson  static bool classof(const Stmt *T) {
26547c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson    return T->getStmtClass() == VAArgExprClass;
26557c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson  }
26567c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson  static bool classof(const VAArgExpr *) { return true; }
26571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
26587c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson  // Iterators
26597c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson  virtual child_iterator child_begin();
26601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  virtual child_iterator child_end();
26617c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson};
26621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
26634c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// @brief Describes an C or C++ initializer list.
26644c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor///
26654c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// InitListExpr describes an initializer list, which can be used to
26664c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// initialize objects of different types, including
26674c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// struct/class/union types, arrays, and vectors. For example:
26684c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor///
26694c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// @code
26704c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// struct foo x = { 1, { 2, 3 } };
26714c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// @endcode
2672196ef51bc4d008ec1c69851fb3b0f8d036065931Chris Lattner///
26734c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// Prior to semantic analysis, an initializer list will represent the
26744c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// initializer list as written by the user, but will have the
26754c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// placeholder type "void". This initializer list is called the
26764c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// syntactic form of the initializer, and may contain C99 designated
26774c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// initializers (represented as DesignatedInitExprs), initializations
26784c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// of subobject members without explicit braces, and so on. Clients
26794c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// interested in the original syntax of the initializer list should
26804c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// use the syntactic form of the initializer list.
2681196ef51bc4d008ec1c69851fb3b0f8d036065931Chris Lattner///
26824c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// After semantic analysis, the initializer list will represent the
26834c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// semantic form of the initializer, where the initializations of all
26844c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// subobjects are made explicit with nested InitListExpr nodes and
26854c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// C99 designators have been eliminated by placing the designated
26864c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// initializations into the subobject they initialize. Additionally,
26874c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// any "holes" in the initialization, where no initializer has been
26884c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// specified for a particular subobject, will be replaced with
26893498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor/// implicitly-generated ImplicitValueInitExpr expressions that
26904c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// value-initialize the subobjects. Note, however, that the
26914c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// initializer lists may still have fewer initializers than there are
26924c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// elements to initialize within the object.
2693196ef51bc4d008ec1c69851fb3b0f8d036065931Chris Lattner///
26944c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// Given the semantic form of the initializer list, one can retrieve
26954c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// the original syntactic form of that initializer list (if it
26964c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// exists) using getSyntacticForm(). Since many initializer lists
26974c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// have the same syntactic and semantic forms, getSyntacticForm() may
26984c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// return NULL, indicating that the current initializer list also
26994c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// serves as its syntactic form.
270066b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlssonclass InitListExpr : public Expr {
2701ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek  // FIXME: Eliminate this vector in favor of ASTContext allocation
2702709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek  typedef ASTVector<Stmt *> InitExprsTy;
2703709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek  InitExprsTy InitExprs;
270466b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson  SourceLocation LBraceLoc, RBraceLoc;
27051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
27064c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  /// Contains the initializer list that describes the syntactic form
27074c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  /// written in the source code.
27084c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  InitListExpr *SyntacticForm;
27094c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor
27100bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor  /// If this initializer list initializes a union, specifies which
27110bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor  /// field within the union will be initialized.
27120bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor  FieldDecl *UnionFieldInit;
27130bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor
2714a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor  /// Whether this initializer list originally had a GNU array-range
2715a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor  /// designator in it. This is a temporary marker used by CodeGen.
2716a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor  bool HadArrayRangeDesignator;
2717a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor
271866b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlssonpublic:
2719709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek  InitListExpr(ASTContext &C, SourceLocation lbraceloc,
2720709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek               Expr **initexprs, unsigned numinits,
2721ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek               SourceLocation rbraceloc);
2722d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor
2723d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  /// \brief Build an empty initializer list.
2724709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek  explicit InitListExpr(ASTContext &C, EmptyShell Empty)
2725709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek    : Expr(InitListExprClass, Empty), InitExprs(C) { }
27261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2727ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek  unsigned getNumInits() const { return InitExprs.size(); }
27281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
27291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  const Expr* getInit(unsigned Init) const {
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  Expr* getInit(unsigned Init) {
2735c5ae899b4bbf65488445316c63168079177db0edSteve Naroff    assert(Init < getNumInits() && "Initializer access out of range!");
27364c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor    return cast_or_null<Expr>(InitExprs[Init]);
273766b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson  }
27381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
27391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  void setInit(unsigned Init, Expr *expr) {
2740c5ae899b4bbf65488445316c63168079177db0edSteve Naroff    assert(Init < getNumInits() && "Initializer access out of range!");
27419e8925e72f53a9e2c4633b6b48e965ed01702fe4Steve Naroff    InitExprs[Init] = expr;
27429e8925e72f53a9e2c4633b6b48e965ed01702fe4Steve Naroff  }
2743c5ae899b4bbf65488445316c63168079177db0edSteve Naroff
2744fa2192042f223b5122a9e17719930f77634fd31fDouglas Gregor  /// \brief Reserve space for some number of initializers.
2745709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek  void reserveInits(ASTContext &C, unsigned NumInits);
27461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
27474c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  /// @brief Specify the number of initializers
27484c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  ///
27494c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  /// If there are more than @p NumInits initializers, the remaining
27504c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  /// initializers will be destroyed. If there are fewer than @p
27514c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  /// NumInits initializers, NULL expressions will be added for the
27524c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  /// unknown initializers.
27534c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  void resizeInits(ASTContext &Context, unsigned NumInits);
27544c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor
27554c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  /// @brief Updates the initializer at index @p Init with the new
27564c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  /// expression @p expr, and returns the old expression at that
27574c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  /// location.
27584c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  ///
27594c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  /// When @p Init is out of range for this initializer list, the
27604c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  /// initializer list will be extended with NULL expressions to
27614c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  /// accomodate the new entry.
2762709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek  Expr *updateInit(ASTContext &C, unsigned Init, Expr *expr);
2763c5ae899b4bbf65488445316c63168079177db0edSteve Naroff
27640bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor  /// \brief If this initializes a union, specifies which field in the
27650bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor  /// union to initialize.
27660bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor  ///
27670bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor  /// Typically, this field is the first named field within the
27680bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor  /// union. However, a designated initializer can specify the
27690bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor  /// initialization of a different field within the union.
27700bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor  FieldDecl *getInitializedFieldInUnion() { return UnionFieldInit; }
27710bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor  void setInitializedFieldInUnion(FieldDecl *FD) { UnionFieldInit = FD; }
27720bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor
2773c5ae899b4bbf65488445316c63168079177db0edSteve Naroff  // Explicit InitListExpr's originate from source code (and have valid source
2774c5ae899b4bbf65488445316c63168079177db0edSteve Naroff  // locations). Implicit InitListExpr's are created by the semantic analyzer.
2775b3eef68111ffc220e449be96da1747998c057790Douglas Gregor  bool isExplicit() {
2776b3eef68111ffc220e449be96da1747998c057790Douglas Gregor    return LBraceLoc.isValid() && RBraceLoc.isValid();
2777b3eef68111ffc220e449be96da1747998c057790Douglas Gregor  }
27781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2779d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  SourceLocation getLBraceLoc() const { return LBraceLoc; }
2780d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  void setLBraceLoc(SourceLocation Loc) { LBraceLoc = Loc; }
2781d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  SourceLocation getRBraceLoc() const { return RBraceLoc; }
278287fd703e097c27d63479cb83b687d4000a22bbb1Douglas Gregor  void setRBraceLoc(SourceLocation Loc) { RBraceLoc = Loc; }
278387fd703e097c27d63479cb83b687d4000a22bbb1Douglas Gregor
27844c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  /// @brief Retrieve the initializer list that describes the
27854c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  /// syntactic form of the initializer.
27864c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  ///
27871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
27884c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  InitListExpr *getSyntacticForm() const { return SyntacticForm; }
27894c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  void setSyntacticForm(InitListExpr *Init) { SyntacticForm = Init; }
27904c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor
2791a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor  bool hadArrayRangeDesignator() const { return HadArrayRangeDesignator; }
27921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  void sawArrayRangeDesignator(bool ARD = true) {
2793d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor    HadArrayRangeDesignator = ARD;
2794a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor  }
2795a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor
279666b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson  virtual SourceRange getSourceRange() const {
279766b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson    return SourceRange(LBraceLoc, RBraceLoc);
27981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  }
279966b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson  static bool classof(const Stmt *T) {
28001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == InitListExprClass;
280166b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson  }
280266b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson  static bool classof(const InitListExpr *) { return true; }
28031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
280466b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson  // Iterators
280566b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson  virtual child_iterator child_begin();
280666b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson  virtual child_iterator child_end();
28071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2808709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek  typedef InitExprsTy::iterator iterator;
2809709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek  typedef InitExprsTy::reverse_iterator reverse_iterator;
28101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2811ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek  iterator begin() { return InitExprs.begin(); }
2812ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek  iterator end() { return InitExprs.end(); }
2813ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek  reverse_iterator rbegin() { return InitExprs.rbegin(); }
2814ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek  reverse_iterator rend() { return InitExprs.rend(); }
281566b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson};
281666b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson
281705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// @brief Represents a C99 designated initializer expression.
281805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor///
281905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// A designated initializer expression (C99 6.7.8) contains one or
282005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// more designators (which can be field designators, array
282105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// designators, or GNU array-range designators) followed by an
282205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// expression that initializes the field or element(s) that the
282305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// designators refer to. For example, given:
28241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump///
282505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// @code
282605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// struct point {
282705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor///   double x;
282805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor///   double y;
282905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// };
283005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// struct point ptarray[10] = { [2].y = 1.0, [2].x = 2.0, [0].x = 1.0 };
283105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// @endcode
283205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor///
283305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// The InitListExpr contains three DesignatedInitExprs, the first of
283405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// which covers @c [2].y=1.0. This DesignatedInitExpr will have two
283505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// designators, one array designator for @c [2] followed by one field
283605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// designator for @c .y. The initalization expression will be 1.0.
283705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregorclass DesignatedInitExpr : public Expr {
2838ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregorpublic:
2839ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor  /// \brief Forward declaration of the Designator class.
2840ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor  class Designator;
2841ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor
2842ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregorprivate:
284305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// The location of the '=' or ':' prior to the actual initializer
284405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// expression.
284505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  SourceLocation EqualOrColonLoc;
284605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
2847eeae8f072748affce25ab4064982626361293390Douglas Gregor  /// Whether this designated initializer used the GNU deprecated
284805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// syntax rather than the C99 '=' syntax.
2849eeae8f072748affce25ab4064982626361293390Douglas Gregor  bool GNUSyntax : 1;
285005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
285105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// The number of designators in this initializer expression.
285205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  unsigned NumDesignators : 15;
285305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
2854ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor  /// \brief The designators in this designated initialization
2855ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor  /// expression.
2856ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor  Designator *Designators;
2857ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor
285805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// The number of subexpressions of this initializer expression,
285905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// which contains both the initializer and any additional
286005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// expressions used by array and array-range designators.
286105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  unsigned NumSubExprs : 16;
286205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
2863ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor
2864319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregor  DesignatedInitExpr(ASTContext &C, QualType Ty, unsigned NumDesignators,
2865ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor                     const Designator *Designators,
2866eeae8f072748affce25ab4064982626361293390Douglas Gregor                     SourceLocation EqualOrColonLoc, bool GNUSyntax,
28679ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor                     Expr **IndexExprs, unsigned NumIndexExprs,
28689ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor                     Expr *Init);
286905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
2870d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  explicit DesignatedInitExpr(unsigned NumSubExprs)
2871d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor    : Expr(DesignatedInitExprClass, EmptyShell()),
2872d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor      NumDesignators(0), Designators(0), NumSubExprs(NumSubExprs) { }
2873d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor
287442602bb40aefcc2751d4078ba88aacf4d965c9bdDouglas Gregorprotected:
28751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  virtual void DoDestroy(ASTContext &C);
287642602bb40aefcc2751d4078ba88aacf4d965c9bdDouglas Gregor
2877319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregor  void DestroyDesignators(ASTContext &C);
2878c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
287905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregorpublic:
288005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// A field designator, e.g., ".x".
288105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  struct FieldDesignator {
288205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// Refers to the field that is being initialized. The low bit
288305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// of this field determines whether this is actually a pointer
288405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// to an IdentifierInfo (if 1) or a FieldDecl (if 0). When
288505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// initially constructed, a field designator will store an
288605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// IdentifierInfo*. After semantic analysis has resolved that
288705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// name, the field designator will instead store a FieldDecl*.
288805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    uintptr_t NameOrField;
28891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
289005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// The location of the '.' in the designated initializer.
289105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    unsigned DotLoc;
28921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
289305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// The location of the field name in the designated initializer.
289405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    unsigned FieldLoc;
289505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  };
289605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
289705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// An array or GNU array-range designator, e.g., "[9]" or "[10..15]".
289805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  struct ArrayOrRangeDesignator {
289905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// Location of the first index expression within the designated
290005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// initializer expression's list of subexpressions.
290105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    unsigned Index;
290205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// The location of the '[' starting the array range designator.
290305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    unsigned LBracketLoc;
290405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// The location of the ellipsis separating the start and end
290505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// indices. Only valid for GNU array-range designators.
290605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    unsigned EllipsisLoc;
290705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// The location of the ']' terminating the array range designator.
29081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    unsigned RBracketLoc;
290905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  };
291005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
291105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// @brief Represents a single C99 designator.
291205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  ///
291305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// @todo This class is infuriatingly similar to clang::Designator,
291405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// but minor differences (storing indices vs. storing pointers)
291505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// keep us from reusing it. Try harder, later, to rectify these
291605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// differences.
291705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  class Designator {
291805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// @brief The kind of designator this describes.
291905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    enum {
292005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      FieldDesignator,
292105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      ArrayDesignator,
292205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      ArrayRangeDesignator
292305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    } Kind;
292405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
292505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    union {
292605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      /// A field designator, e.g., ".x".
292705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      struct FieldDesignator Field;
292805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      /// An array or GNU array-range designator, e.g., "[9]" or "[10..15]".
292905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      struct ArrayOrRangeDesignator ArrayOrRange;
293005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    };
293105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    friend class DesignatedInitExpr;
293205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
293305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  public:
2934ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor    Designator() {}
2935ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor
293605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// @brief Initializes a field designator.
29371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    Designator(const IdentifierInfo *FieldName, SourceLocation DotLoc,
29381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump               SourceLocation FieldLoc)
293905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      : Kind(FieldDesignator) {
294005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      Field.NameOrField = reinterpret_cast<uintptr_t>(FieldName) | 0x01;
294105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      Field.DotLoc = DotLoc.getRawEncoding();
294205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      Field.FieldLoc = FieldLoc.getRawEncoding();
294305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    }
294405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
294505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// @brief Initializes an array designator.
29461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    Designator(unsigned Index, SourceLocation LBracketLoc,
294705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor               SourceLocation RBracketLoc)
294805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      : Kind(ArrayDesignator) {
294905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      ArrayOrRange.Index = Index;
295005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      ArrayOrRange.LBracketLoc = LBracketLoc.getRawEncoding();
295105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      ArrayOrRange.EllipsisLoc = SourceLocation().getRawEncoding();
295205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      ArrayOrRange.RBracketLoc = RBracketLoc.getRawEncoding();
295305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    }
295405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
295505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// @brief Initializes a GNU array-range designator.
29561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    Designator(unsigned Index, SourceLocation LBracketLoc,
295705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor               SourceLocation EllipsisLoc, SourceLocation RBracketLoc)
295805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      : Kind(ArrayRangeDesignator) {
295905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      ArrayOrRange.Index = Index;
296005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      ArrayOrRange.LBracketLoc = LBracketLoc.getRawEncoding();
296105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      ArrayOrRange.EllipsisLoc = EllipsisLoc.getRawEncoding();
296205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      ArrayOrRange.RBracketLoc = RBracketLoc.getRawEncoding();
296305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    }
296405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
296505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    bool isFieldDesignator() const { return Kind == FieldDesignator; }
296605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    bool isArrayDesignator() const { return Kind == ArrayDesignator; }
296705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    bool isArrayRangeDesignator() const { return Kind == ArrayRangeDesignator; }
296805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
296905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    IdentifierInfo * getFieldName();
297005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
297105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    FieldDecl *getField() {
297205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      assert(Kind == FieldDesignator && "Only valid on a field designator");
297305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      if (Field.NameOrField & 0x01)
297405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor        return 0;
297505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      else
297605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor        return reinterpret_cast<FieldDecl *>(Field.NameOrField);
297705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    }
297805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
297905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    void setField(FieldDecl *FD) {
298005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      assert(Kind == FieldDesignator && "Only valid on a field designator");
298105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      Field.NameOrField = reinterpret_cast<uintptr_t>(FD);
298205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    }
298305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
298487f55cf59e82f246d8605733e9300d0c5f6830a6Douglas Gregor    SourceLocation getDotLoc() const {
298587f55cf59e82f246d8605733e9300d0c5f6830a6Douglas Gregor      assert(Kind == FieldDesignator && "Only valid on a field designator");
298687f55cf59e82f246d8605733e9300d0c5f6830a6Douglas Gregor      return SourceLocation::getFromRawEncoding(Field.DotLoc);
298787f55cf59e82f246d8605733e9300d0c5f6830a6Douglas Gregor    }
298887f55cf59e82f246d8605733e9300d0c5f6830a6Douglas Gregor
298905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    SourceLocation getFieldLoc() const {
299005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      assert(Kind == FieldDesignator && "Only valid on a field designator");
299105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      return SourceLocation::getFromRawEncoding(Field.FieldLoc);
299205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    }
299305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
299405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    SourceLocation getLBracketLoc() const {
299505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      assert((Kind == ArrayDesignator || Kind == ArrayRangeDesignator) &&
299605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor             "Only valid on an array or array-range designator");
299705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      return SourceLocation::getFromRawEncoding(ArrayOrRange.LBracketLoc);
299805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    }
299905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
300005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    SourceLocation getRBracketLoc() const {
300105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      assert((Kind == ArrayDesignator || Kind == ArrayRangeDesignator) &&
300205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor             "Only valid on an array or array-range designator");
300305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      return SourceLocation::getFromRawEncoding(ArrayOrRange.RBracketLoc);
300405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    }
300505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
300605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    SourceLocation getEllipsisLoc() const {
300705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      assert(Kind == ArrayRangeDesignator &&
300805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor             "Only valid on an array-range designator");
300905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      return SourceLocation::getFromRawEncoding(ArrayOrRange.EllipsisLoc);
301005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    }
30114c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor
3012d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor    unsigned getFirstExprIndex() const {
3013d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor      assert((Kind == ArrayDesignator || Kind == ArrayRangeDesignator) &&
3014d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor             "Only valid on an array or array-range designator");
3015d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor      return ArrayOrRange.Index;
3016d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor    }
3017d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor
30184c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor    SourceLocation getStartLocation() const {
30194c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor      if (Kind == FieldDesignator)
30204c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor        return getDotLoc().isInvalid()? getFieldLoc() : getDotLoc();
30214c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor      else
30224c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor        return getLBracketLoc();
30234c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor    }
302405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  };
302505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
30261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static DesignatedInitExpr *Create(ASTContext &C, Designator *Designators,
302705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor                                    unsigned NumDesignators,
302805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor                                    Expr **IndexExprs, unsigned NumIndexExprs,
302905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor                                    SourceLocation EqualOrColonLoc,
3030eeae8f072748affce25ab4064982626361293390Douglas Gregor                                    bool GNUSyntax, Expr *Init);
303105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
3032d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  static DesignatedInitExpr *CreateEmpty(ASTContext &C, unsigned NumIndexExprs);
3033d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor
303405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// @brief Returns the number of designators in this initializer.
303505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  unsigned size() const { return NumDesignators; }
303605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
303705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  // Iterator access to the designators.
303805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  typedef Designator* designators_iterator;
3039ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor  designators_iterator designators_begin() { return Designators; }
30401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  designators_iterator designators_end() {
30411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return Designators + NumDesignators;
3042ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor  }
304305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
3044711997184366d584c9c437102cae1e9d9927b986Douglas Gregor  Designator *getDesignator(unsigned Idx) { return &designators_begin()[Idx]; }
3045711997184366d584c9c437102cae1e9d9927b986Douglas Gregor
3046c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  void setDesignators(ASTContext &C, const Designator *Desigs,
3047319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregor                      unsigned NumDesigs);
3048d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor
304905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  Expr *getArrayIndex(const Designator& D);
305005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  Expr *getArrayRangeStart(const Designator& D);
305105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  Expr *getArrayRangeEnd(const Designator& D);
305205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
305305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// @brief Retrieve the location of the '=' that precedes the
305405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// initializer value itself, if present.
305505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  SourceLocation getEqualOrColonLoc() const { return EqualOrColonLoc; }
3056d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  void setEqualOrColonLoc(SourceLocation L) { EqualOrColonLoc = L; }
305705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
305805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// @brief Determines whether this designated initializer used the
3059eeae8f072748affce25ab4064982626361293390Douglas Gregor  /// deprecated GNU syntax for designated initializers.
3060eeae8f072748affce25ab4064982626361293390Douglas Gregor  bool usesGNUSyntax() const { return GNUSyntax; }
3061d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  void setGNUSyntax(bool GNU) { GNUSyntax = GNU; }
306205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
306305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// @brief Retrieve the initializer value.
30641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  Expr *getInit() const {
306505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    return cast<Expr>(*const_cast<DesignatedInitExpr*>(this)->child_begin());
306605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  }
306705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
306805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  void setInit(Expr *init) {
306905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    *child_begin() = init;
307005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  }
307105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
3072d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  /// \brief Retrieve the total number of subexpressions in this
3073d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  /// designated initializer expression, including the actual
3074d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  /// initialized value and any expressions that occur within array
3075d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  /// and array-range designators.
3076d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  unsigned getNumSubExprs() const { return NumSubExprs; }
3077d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor
3078d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  Expr *getSubExpr(unsigned Idx) {
3079d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor    assert(Idx < NumSubExprs && "Subscript out of range");
3080d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor    char* Ptr = static_cast<char*>(static_cast<void *>(this));
3081d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor    Ptr += sizeof(DesignatedInitExpr);
3082d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor    return reinterpret_cast<Expr**>(reinterpret_cast<void**>(Ptr))[Idx];
3083d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  }
3084d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor
3085d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  void setSubExpr(unsigned Idx, Expr *E) {
3086d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor    assert(Idx < NumSubExprs && "Subscript out of range");
3087d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor    char* Ptr = static_cast<char*>(static_cast<void *>(this));
3088d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor    Ptr += sizeof(DesignatedInitExpr);
3089d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor    reinterpret_cast<Expr**>(reinterpret_cast<void**>(Ptr))[Idx] = E;
3090d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  }
3091d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor
3092ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor  /// \brief Replaces the designator at index @p Idx with the series
3093ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor  /// of designators in [First, Last).
3094319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregor  void ExpandDesignator(ASTContext &C, unsigned Idx, const Designator *First,
3095ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor                        const Designator *Last);
3096ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor
309705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  virtual SourceRange getSourceRange() const;
309805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
309905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  static bool classof(const Stmt *T) {
31001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == DesignatedInitExprClass;
310105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  }
310205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  static bool classof(const DesignatedInitExpr *) { return true; }
310305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
310405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  // Iterators
310505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  virtual child_iterator child_begin();
31061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  virtual child_iterator child_end();
31073498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor};
31083498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor
31093498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor/// \brief Represents an implicitly-generated value initialization of
31103498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor/// an object of a given type.
31113498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor///
31121a51b4a11b7db25cac2134249711ecaaf9d1c0a8Douglas Gregor/// Implicit value initializations occur within semantic initializer
31131a51b4a11b7db25cac2134249711ecaaf9d1c0a8Douglas Gregor/// list expressions (InitListExpr) as placeholders for subobject
31143498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor/// initializations not explicitly specified by the user.
31151a51b4a11b7db25cac2134249711ecaaf9d1c0a8Douglas Gregor///
31161a51b4a11b7db25cac2134249711ecaaf9d1c0a8Douglas Gregor/// \see InitListExpr
31171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpclass ImplicitValueInitExpr : public Expr {
31183498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregorpublic:
31191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  explicit ImplicitValueInitExpr(QualType ty)
31202333f7727f97018d6742e1e0938133bcfad967abEli Friedman    : Expr(ImplicitValueInitExprClass, ty, false, false) { }
31213498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor
3122d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  /// \brief Construct an empty implicit value initialization.
3123d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  explicit ImplicitValueInitExpr(EmptyShell Empty)
3124d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor    : Expr(ImplicitValueInitExprClass, Empty) { }
3125d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor
31261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
31273498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor    return T->getStmtClass() == ImplicitValueInitExprClass;
31283498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor  }
31293498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor  static bool classof(const ImplicitValueInitExpr *) { return true; }
31303498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor
31313498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor  virtual SourceRange getSourceRange() const {
31323498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor    return SourceRange();
31333498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor  }
31343498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor
31353498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor  // Iterators
31363498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor  virtual child_iterator child_begin();
31371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  virtual child_iterator child_end();
313805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor};
313905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
31402ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman
31412ef13e5abef0570a9f567b4671367275c05d4d34Nate Begemanclass ParenListExpr : public Expr {
31422ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman  Stmt **Exprs;
31432ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman  unsigned NumExprs;
31442ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman  SourceLocation LParenLoc, RParenLoc;
31452ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman
31461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpprotected:
31472ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman  virtual void DoDestroy(ASTContext& C);
31481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
31492ef13e5abef0570a9f567b4671367275c05d4d34Nate Begemanpublic:
31501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ParenListExpr(ASTContext& C, SourceLocation lparenloc, Expr **exprs,
31512ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman                unsigned numexprs, SourceLocation rparenloc);
31522ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman
31532ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman  ~ParenListExpr() {}
31542ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman
31552ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman  /// \brief Build an empty paren list.
31562ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman  //explicit ParenListExpr(EmptyShell Empty) : Expr(ParenListExprClass, Empty) { }
31571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
31582ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman  unsigned getNumExprs() const { return NumExprs; }
31591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
31601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  const Expr* getExpr(unsigned Init) const {
31612ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman    assert(Init < getNumExprs() && "Initializer access out of range!");
31622ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman    return cast_or_null<Expr>(Exprs[Init]);
31632ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman  }
31641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
31651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  Expr* getExpr(unsigned Init) {
31662ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman    assert(Init < getNumExprs() && "Initializer access out of range!");
31672ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman    return cast_or_null<Expr>(Exprs[Init]);
31682ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman  }
31692ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman
317083ddad3ab513f5d73698cf9fbeb4ed3f011bc3b9Douglas Gregor  Expr **getExprs() { return reinterpret_cast<Expr **>(Exprs); }
31711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
31722ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman  SourceLocation getLParenLoc() const { return LParenLoc; }
31732ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman  SourceLocation getRParenLoc() const { return RParenLoc; }
31742ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman
31752ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman  virtual SourceRange getSourceRange() const {
31762ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman    return SourceRange(LParenLoc, RParenLoc);
31771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  }
31782ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman  static bool classof(const Stmt *T) {
31791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == ParenListExprClass;
31802ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman  }
31812ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman  static bool classof(const ParenListExpr *) { return true; }
31821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
31832ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman  // Iterators
31842ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman  virtual child_iterator child_begin();
31852ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman  virtual child_iterator child_end();
31862ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman};
31872ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman
31881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
31894eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff//===----------------------------------------------------------------------===//
31904eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff// Clang Extensions
31914eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff//===----------------------------------------------------------------------===//
31924eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff
3193a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner
3194a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner/// ExtVectorElementExpr - This represents access to specific elements of a
3195a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner/// vector, and may occur on the left hand side or right hand side.  For example
3196a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner/// the following is legal:  "V.xy = V.zw" if V is a 4 element extended vector.
3197a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner///
319873525de7fd9bdd534382dc89a24f1f76db3e04b9Chris Lattner/// Note that the base may have either vector or pointer to vector type, just
319973525de7fd9bdd534382dc89a24f1f76db3e04b9Chris Lattner/// like a struct field reference.
320073525de7fd9bdd534382dc89a24f1f76db3e04b9Chris Lattner///
3201a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattnerclass ExtVectorElementExpr : public Expr {
3202a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  Stmt *Base;
3203d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor  IdentifierInfo *Accessor;
3204a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  SourceLocation AccessorLoc;
3205a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattnerpublic:
3206a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  ExtVectorElementExpr(QualType ty, Expr *base, IdentifierInfo &accessor,
3207a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner                       SourceLocation loc)
32082333f7727f97018d6742e1e0938133bcfad967abEli Friedman    : Expr(ExtVectorElementExprClass, ty, base->isTypeDependent(),
32092333f7727f97018d6742e1e0938133bcfad967abEli Friedman           base->isValueDependent()),
3210d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor      Base(base), Accessor(&accessor), AccessorLoc(loc) {}
32111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3212d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor  /// \brief Build an empty vector element expression.
3213d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor  explicit ExtVectorElementExpr(EmptyShell Empty)
3214d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor    : Expr(ExtVectorElementExprClass, Empty) { }
3215d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor
3216a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  const Expr *getBase() const { return cast<Expr>(Base); }
3217a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  Expr *getBase() { return cast<Expr>(Base); }
3218d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor  void setBase(Expr *E) { Base = E; }
3219d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor
3220d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor  IdentifierInfo &getAccessor() const { return *Accessor; }
3221d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor  void setAccessor(IdentifierInfo *II) { Accessor = II; }
3222d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor
3223d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor  SourceLocation getAccessorLoc() const { return AccessorLoc; }
3224d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor  void setAccessorLoc(SourceLocation L) { AccessorLoc = L; }
3225d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor
3226a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  /// getNumElements - Get the number of components being selected.
3227a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  unsigned getNumElements() const;
32281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3229a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  /// containsDuplicateElements - Return true if any element access is
3230a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  /// repeated.
3231a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  bool containsDuplicateElements() const;
32321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3233a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  /// getEncodedElementAccess - Encode the elements accessed into an llvm
3234a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  /// aggregate Constant of ConstantInt(s).
3235a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  void getEncodedElementAccess(llvm::SmallVectorImpl<unsigned> &Elts) const;
32361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3237a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  virtual SourceRange getSourceRange() const {
3238a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner    return SourceRange(getBase()->getLocStart(), AccessorLoc);
3239a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  }
32401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
32412140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner  /// isArrow - Return true if the base expression is a pointer to vector,
32422140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner  /// return false if the base expression is a vector.
32432140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner  bool isArrow() const;
32441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
32451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
32461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == ExtVectorElementExprClass;
3247a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  }
3248a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  static bool classof(const ExtVectorElementExpr *) { return true; }
32491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3250a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  // Iterators
3251a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  virtual child_iterator child_begin();
3252a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  virtual child_iterator child_end();
3253a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner};
3254a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner
3255a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner
325656ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff/// BlockExpr - Adaptor class for mixing a BlockDecl with expressions.
32579c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff/// ^{ statement-body }   or   ^(int arg1, float arg2){ statement-body }
32584eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroffclass BlockExpr : public Expr {
325956ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroffprotected:
326056ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff  BlockDecl *TheBlock;
3261b83d287bc7f47d36fb0751a481e2ef9308b37252Mike Stump  bool HasBlockDeclRefExprs;
32624eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroffpublic:
3263b83d287bc7f47d36fb0751a481e2ef9308b37252Mike Stump  BlockExpr(BlockDecl *BD, QualType ty, bool hasBlockDeclRefExprs)
32642333f7727f97018d6742e1e0938133bcfad967abEli Friedman    : Expr(BlockExprClass, ty, ty->isDependentType(), false),
3265b83d287bc7f47d36fb0751a481e2ef9308b37252Mike Stump      TheBlock(BD), HasBlockDeclRefExprs(hasBlockDeclRefExprs) {}
32669c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff
326784af7c27cdc615ff917a501d61256b4049383c97Douglas Gregor  /// \brief Build an empty block expression.
326884af7c27cdc615ff917a501d61256b4049383c97Douglas Gregor  explicit BlockExpr(EmptyShell Empty) : Expr(BlockExprClass, Empty) { }
326984af7c27cdc615ff917a501d61256b4049383c97Douglas Gregor
3270d5cab5435371b8cc74a9e05ebd40b5995ebad149Anders Carlsson  const BlockDecl *getBlockDecl() const { return TheBlock; }
327156ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff  BlockDecl *getBlockDecl() { return TheBlock; }
327284af7c27cdc615ff917a501d61256b4049383c97Douglas Gregor  void setBlockDecl(BlockDecl *BD) { TheBlock = BD; }
327384af7c27cdc615ff917a501d61256b4049383c97Douglas Gregor
327456ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff  // Convenience functions for probing the underlying BlockDecl.
327556ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff  SourceLocation getCaretLocation() const;
327656ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff  const Stmt *getBody() const;
327756ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff  Stmt *getBody();
32789c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff
32799c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff  virtual SourceRange getSourceRange() const {
328056ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff    return SourceRange(getCaretLocation(), getBody()->getLocEnd());
32819c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff  }
32829c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff
328356ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff  /// getFunctionType - Return the underlying function type for this block.
328456ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff  const FunctionType *getFunctionType() const;
328556ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff
3286b83d287bc7f47d36fb0751a481e2ef9308b37252Mike Stump  /// hasBlockDeclRefExprs - Return true iff the block has BlockDeclRefExpr
32875b54b88c4082bb81b8b341b622fda9a85cbd5fadChris Lattner  /// inside of the block that reference values outside the block.
3288b83d287bc7f47d36fb0751a481e2ef9308b37252Mike Stump  bool hasBlockDeclRefExprs() const { return HasBlockDeclRefExprs; }
328984af7c27cdc615ff917a501d61256b4049383c97Douglas Gregor  void setHasBlockDeclRefExprs(bool BDRE) { HasBlockDeclRefExprs = BDRE; }
3290b83d287bc7f47d36fb0751a481e2ef9308b37252Mike Stump
32911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
32929c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff    return T->getStmtClass() == BlockExprClass;
32934eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  }
32944eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  static bool classof(const BlockExpr *) { return true; }
32951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
32964eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  // Iterators
32974eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  virtual child_iterator child_begin();
32984eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  virtual child_iterator child_end();
32994eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff};
33001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
33014eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff/// BlockDeclRefExpr - A reference to a declared variable, function,
33024eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff/// enum, etc.
33034eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroffclass BlockDeclRefExpr : public Expr {
33041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ValueDecl *D;
33054eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  SourceLocation Loc;
33067d5c74ecbbd8719436c071f38657bc8e97ee4a24Fariborz Jahanian  bool IsByRef : 1;
33077d5c74ecbbd8719436c071f38657bc8e97ee4a24Fariborz Jahanian  bool ConstQualAdded : 1;
33084eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroffpublic:
33092333f7727f97018d6742e1e0938133bcfad967abEli Friedman  // FIXME: Fix type/value dependence!
33101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  BlockDeclRefExpr(ValueDecl *d, QualType t, SourceLocation l, bool ByRef,
33112333f7727f97018d6742e1e0938133bcfad967abEli Friedman                   bool constAdded = false)
33122333f7727f97018d6742e1e0938133bcfad967abEli Friedman  : Expr(BlockDeclRefExprClass, t, false, false), D(d), Loc(l), IsByRef(ByRef),
33132333f7727f97018d6742e1e0938133bcfad967abEli Friedman    ConstQualAdded(constAdded) {}
331494cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor
331594cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor  // \brief Build an empty reference to a declared variable in a
331694cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor  // block.
331794cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor  explicit BlockDeclRefExpr(EmptyShell Empty)
331894cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor    : Expr(BlockDeclRefExprClass, Empty) { }
33191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
33204eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  ValueDecl *getDecl() { return D; }
33214eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  const ValueDecl *getDecl() const { return D; }
332294cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor  void setDecl(ValueDecl *VD) { D = VD; }
332394cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor
332494cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor  SourceLocation getLocation() const { return Loc; }
332594cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor  void setLocation(SourceLocation L) { Loc = L; }
332694cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor
33274eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
33281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
33294eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  bool isByRef() const { return IsByRef; }
333094cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor  void setByRef(bool BR) { IsByRef = BR; }
33311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
33327d5c74ecbbd8719436c071f38657bc8e97ee4a24Fariborz Jahanian  bool isConstQualAdded() const { return ConstQualAdded; }
33337d5c74ecbbd8719436c071f38657bc8e97ee4a24Fariborz Jahanian  void setConstQualAdded(bool C) { ConstQualAdded = C; }
333494cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor
33351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
33361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == BlockDeclRefExprClass;
33374eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  }
33384eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  static bool classof(const BlockDeclRefExpr *) { return true; }
33391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
33404eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  // Iterators
33414eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  virtual child_iterator child_begin();
33424eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  virtual child_iterator child_end();
33434eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff};
33444eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff
33455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}  // end namespace clang
33465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
33475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#endif
3348