Expr.h revision 1b78276a75a5a0f496a82429c1ff9604d622a76d
15f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===--- Expr.h - Classes for representing expressions ----------*- C++ -*-===//
25f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//
35f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//                     The LLVM Compiler Infrastructure
45f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//
50bc735ffcfb223c0186419547abaa5c84482663eChris Lattner// This file is distributed under the University of Illinois Open Source
60bc735ffcfb223c0186419547abaa5c84482663eChris Lattner// License. See LICENSE.TXT for details.
75f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//
85f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===//
95f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//
105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//  This file defines the Expr interface and subclasses.
115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//
125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===//
135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#ifndef LLVM_CLANG_AST_EXPR_H
155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#define LLVM_CLANG_AST_EXPR_H
165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1794deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson#include "clang/AST/APValue.h"
185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include "clang/AST/Stmt.h"
195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include "clang/AST/Type.h"
205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include "llvm/ADT/APSInt.h"
21525a05093a4816af961fe2bc6b8a81c17e2e26c2Chris Lattner#include "llvm/ADT/APFloat.h"
223b8d116703db8018f855cbb4733ace426422623bNate Begeman#include "llvm/ADT/SmallVector.h"
23c5ae899b4bbf65488445316c63168079177db0edSteve Naroff#include <vector>
245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace clang {
26590b6646ef747d2f7b42e5f40487ff07642d7b6fChris Lattner  class ASTContext;
27c44eec6dd29ee9415cbd38a35deff4c8b67abb6aAnders Carlsson  class APValue;
28c4a1dea2dc56bd1357ec91b829a0b9e68229a13eDaniel Dunbar  class Decl;
29c4a1dea2dc56bd1357ec91b829a0b9e68229a13eDaniel Dunbar  class IdentifierInfo;
30c4a1dea2dc56bd1357ec91b829a0b9e68229a13eDaniel Dunbar  class ParmVarDecl;
318e9bebdea69c590dedfbf27374114cb76fe12fbdDouglas Gregor  class NamedDecl;
32c4a1dea2dc56bd1357ec91b829a0b9e68229a13eDaniel Dunbar  class ValueDecl;
3356ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff  class BlockDecl;
3488a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor  class CXXOperatorCallExpr;
3588a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor  class CXXMemberCallExpr;
3688a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor
375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Expr - This represents one expression.  Note that Expr's are subclasses of
385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Stmt.  This allows an expression to be transparently used any place a Stmt
395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// is required.
405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass Expr : public Stmt {
425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType TR;
43898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor
44898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// TypeDependent - Whether this expression is type-dependent
45898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// (C++ [temp.dep.expr]).
46898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  bool TypeDependent : 1;
47898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor
48898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// ValueDependent - Whether this expression is value-dependent
49898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// (C++ [temp.dep.constexpr]).
50898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  bool ValueDependent : 1;
51898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor
525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprotected:
53898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  // FIXME: Eventually, this constructor should go away and we should
54898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  // require every subclass to provide type/value-dependence
55898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  // information.
56898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  Expr(StmtClass SC, QualType T)
57b3eef68111ffc220e449be96da1747998c057790Douglas Gregor    : Stmt(SC), TypeDependent(false), ValueDependent(false) {
5883233a4b7c2bc7b531ffa3b33fdd1cd8138373b6Douglas Gregor    setType(T);
5983233a4b7c2bc7b531ffa3b33fdd1cd8138373b6Douglas Gregor  }
60898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor
61898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  Expr(StmtClass SC, QualType T, bool TD, bool VD)
62b3eef68111ffc220e449be96da1747998c057790Douglas Gregor    : Stmt(SC), TypeDependent(TD), ValueDependent(VD) {
63898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor    setType(T);
64898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  }
65898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor
66f7c2aa0b049272d8f318988c1965760dcb852578Douglas Gregorpublic:
67f7c2aa0b049272d8f318988c1965760dcb852578Douglas Gregor  QualType getType() const { return TR; }
68f7c2aa0b049272d8f318988c1965760dcb852578Douglas Gregor  void setType(QualType t) {
699d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor    // In C++, the type of an expression is always adjusted so that it
709d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor    // will not have reference type an expression will never have
719d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor    // reference type (C++ [expr]p6). Use
729d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor    // QualType::getNonReferenceType() to retrieve the non-reference
739d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor    // type. Additionally, inspect Expr::isLvalue to determine whether
749d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor    // an expression that is adjusted in this manner should be
759d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor    // considered an lvalue.
76f7c2aa0b049272d8f318988c1965760dcb852578Douglas Gregor    assert((TR.isNull() || !TR->isReferenceType()) &&
778320aaaa01d931aa234fc3bce05b399ef41898d5Daniel Dunbar           "Expressions can't have reference type");
78f7c2aa0b049272d8f318988c1965760dcb852578Douglas Gregor
79f7c2aa0b049272d8f318988c1965760dcb852578Douglas Gregor    TR = t;
809d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor  }
8177ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek
82898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// isValueDependent - Determines whether this expression is
83898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// value-dependent (C++ [temp.dep.constexpr]). For example, the
84898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// array bound of "Chars" in the following example is
85898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// value-dependent.
86898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// @code
87898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// template<int Size, char (&Chars)[Size]> struct meta_string;
88898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// @endcode
89898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  bool isValueDependent() const { return ValueDependent; }
90898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor
91898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// isTypeDependent - Determines whether this expression is
92898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// type-dependent (C++ [temp.dep.expr]), which means that its type
93898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// could change from one template instantiation to the next. For
94898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// example, the expressions "x" and "x + y" are type-dependent in
95898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// the following code, but "y" is not type-dependent:
96898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// @code
97898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// template<typename T>
98898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// void add(T x, int y) {
99898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  ///   x + y;
100898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// }
101898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// @endcode
102898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  bool isTypeDependent() const { return TypeDependent; }
103898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor
1045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// SourceLocation tokens are not useful in isolation - they are low level
1055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// value objects created/interpreted by SourceManager. We assume AST
1065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// clients will have a pointer to the respective SourceManager.
1075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  virtual SourceRange getSourceRange() const = 0;
1085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// getExprLoc - Return the preferred location for the arrow when diagnosing
1105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// a problem with a generic expression.
1115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  virtual SourceLocation getExprLoc() const { return getLocStart(); }
1125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
113026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner  /// isUnusedResultAWarning - Return true if this immediate expression should
114026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner  /// be warned about if the result is unused.  If so, fill in Loc and Ranges
115026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner  /// with location to warn on and the source range[s] to report with the
116026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner  /// warning.
117026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner  bool isUnusedResultAWarning(SourceLocation &Loc, SourceRange &R1,
118026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner                              SourceRange &R2) const;
1195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// isLvalue - C99 6.3.2.1: an lvalue is an expression with an object type or
1215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// incomplete type other than void. Nonarray expressions that can be lvalues:
1225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ///  - name, where name must be a variable
1235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ///  - e[i]
1245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ///  - (e), where e must be an lvalue
1255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ///  - e.name, where e must be an lvalue
1265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ///  - e->name
1275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ///  - *e, the type of e cannot be a function type
1285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ///  - string-constant
12908ad47cbd1f81fcb31dbc731c13b885a07e12704Bill Wendling  ///  - reference type [C++ [expr]]
1305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ///
1315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  enum isLvalueResult {
1325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    LV_Valid,
1335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    LV_NotObjectType,
1345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    LV_IncompleteVoidType,
135fec0b49c3fa621fbf63e420f3d54a5bb3a0265d2Steve Naroff    LV_DuplicateVectorComponents,
13686f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor    LV_InvalidExpression,
13786f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor    LV_MemberFunction
1385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  };
13928be73f74c9e241a23ea24fe5756623de6bf1084Chris Lattner  isLvalueResult isLvalue(ASTContext &Ctx) const;
1405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// isModifiableLvalue - C99 6.3.2.1: an lvalue that does not have array type,
1425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// does not have an incomplete type, does not have a const-qualified type,
1435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// and if it is a structure or union, does not have any member (including,
1445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// recursively, any member or element of all contained aggregates or unions)
1455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// with a const-qualified type.
1465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  enum isModifiableLvalueResult {
1475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    MLV_Valid,
1485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    MLV_NotObjectType,
1495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    MLV_IncompleteVoidType,
150fec0b49c3fa621fbf63e420f3d54a5bb3a0265d2Steve Naroff    MLV_DuplicateVectorComponents,
1515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    MLV_InvalidExpression,
152ca354faa7e9b99af17070c82b9662a5fca76422cChris Lattner    MLV_LValueCast,           // Specialized form of MLV_InvalidExpression.
1535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    MLV_IncompleteType,
1545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    MLV_ConstQualified,
1554f6a7d7ead09b439216c32f2de806a998aeb222aSteve Naroff    MLV_ArrayType,
1565daf570d0ce027e18ed5f9d66e6b2a14a40b720dFariborz Jahanian    MLV_NotBlockQualified,
157ba8d2d684e74a20bef03828c21c991d222c7e9e5Fariborz Jahanian    MLV_ReadonlyProperty,
15886f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor    MLV_NoSetterProperty,
15986f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor    MLV_MemberFunction
1605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  };
16128be73f74c9e241a23ea24fe5756623de6bf1084Chris Lattner  isModifiableLvalueResult isModifiableLvalue(ASTContext &Ctx) const;
1625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
16327c8dc06f65d7abcf6a7e7f64a7960c9a150ca01Douglas Gregor  bool isBitField();
1645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
165cd8f646eca128f52a7bce0103c51ff82ce96f374Daniel Dunbar  /// getIntegerConstantExprValue() - Return the value of an integer
166cd8f646eca128f52a7bce0103c51ff82ce96f374Daniel Dunbar  /// constant expression. The expression must be a valid integer
167cd8f646eca128f52a7bce0103c51ff82ce96f374Daniel Dunbar  /// constant expression as determined by isIntegerConstantExpr.
168cd8f646eca128f52a7bce0103c51ff82ce96f374Daniel Dunbar  llvm::APSInt getIntegerConstantExprValue(ASTContext &Ctx) const {
1698070a8497c0fb3e6f70a557f788405d8945b1208Daniel Dunbar    llvm::APSInt X;
170cd8f646eca128f52a7bce0103c51ff82ce96f374Daniel Dunbar    bool success = isIntegerConstantExpr(X, Ctx);
171a5d1cb7ef3f0780540e7fd7180399fd220ef0210Daniel Dunbar    success = success;
172cd8f646eca128f52a7bce0103c51ff82ce96f374Daniel Dunbar    assert(success && "Illegal argument to getIntegerConstantExpr");
173cd8f646eca128f52a7bce0103c51ff82ce96f374Daniel Dunbar    return X;
174cd8f646eca128f52a7bce0103c51ff82ce96f374Daniel Dunbar  }
175cd8f646eca128f52a7bce0103c51ff82ce96f374Daniel Dunbar
1765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// isIntegerConstantExpr - Return true if this expression is a valid integer
1775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// constant expression, and, if so, return its value in Result.  If not a
1785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// valid i-c-e, return false and fill in Loc (if specified) with the location
1795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// of the invalid expression.
180590b6646ef747d2f7b42e5f40487ff07642d7b6fChris Lattner  bool isIntegerConstantExpr(llvm::APSInt &Result, ASTContext &Ctx,
181590b6646ef747d2f7b42e5f40487ff07642d7b6fChris Lattner                             SourceLocation *Loc = 0,
1825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer                             bool isEvaluated = true) const;
1832d6744ff04c1690a1485178d550d2fab84a0270bDaniel Dunbar  bool isIntegerConstantExprInternal(llvm::APSInt &Result, ASTContext &Ctx,
1842d6744ff04c1690a1485178d550d2fab84a0270bDaniel Dunbar                             SourceLocation *Loc = 0,
1852d6744ff04c1690a1485178d550d2fab84a0270bDaniel Dunbar                             bool isEvaluated = true) const;
186590b6646ef747d2f7b42e5f40487ff07642d7b6fChris Lattner  bool isIntegerConstantExpr(ASTContext &Ctx, SourceLocation *Loc = 0) const {
1878070a8497c0fb3e6f70a557f788405d8945b1208Daniel Dunbar    llvm::APSInt X;
188590b6646ef747d2f7b42e5f40487ff07642d7b6fChris Lattner    return isIntegerConstantExpr(X, Ctx, Loc);
1895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
190c9e8f606787b0bc0c3b08e566b87cc1751694168Eli Friedman  /// isConstantInitializer - Returns true if this expression is a constant
191c9e8f606787b0bc0c3b08e566b87cc1751694168Eli Friedman  /// initializer, which can be emitted at compile-time.
192c9e8f606787b0bc0c3b08e566b87cc1751694168Eli Friedman  bool isConstantInitializer(ASTContext &Ctx) const;
1935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
19494deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson  /// EvalResult is a struct with detailed info about an evaluated expression.
19594deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson  struct EvalResult {
1962d6744ff04c1690a1485178d550d2fab84a0270bDaniel Dunbar    /// Val - This is the value the expression can be folded to.
19794deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson    APValue Val;
19894deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson
19994deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson    /// HasSideEffects - Whether the evaluated expression has side effects.
20094deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson    /// For example, (f() && 0) can be folded, but it still has side effects.
20194deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson    bool HasSideEffects;
20294deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson
20394deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson    /// Diag - If the expression is unfoldable, then Diag contains a note
20494deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson    /// diagnostic indicating why it's not foldable. DiagLoc indicates a caret
20594deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson    /// position for the error, and DiagExpr is the expression that caused
20694deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson    /// the error.
20794deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson    /// If the expression is foldable, but not an integer constant expression,
20894deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson    /// Diag contains a note diagnostic that describes why it isn't an integer
20994deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson    /// constant expression. If the expression *is* an integer constant
21094deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson    /// expression, then Diag will be zero.
21194deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson    unsigned Diag;
21294deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson    const Expr *DiagExpr;
21394deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson    SourceLocation DiagLoc;
21494deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson
21594deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson    EvalResult() : HasSideEffects(false), Diag(0), DiagExpr(0) {}
21694deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson  };
21794deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson
2186ee7aa154e8bbb21a21254293410b944f78b0bfeChris Lattner  /// Evaluate - Return true if this is a constant which we can fold using
219019f4e858e78587f2241ff1a76c747d7bcd7578cChris Lattner  /// any crazy technique (that has nothing to do with language standards) that
220019f4e858e78587f2241ff1a76c747d7bcd7578cChris Lattner  /// we want to.  If this function returns true, it returns the folded constant
221019f4e858e78587f2241ff1a76c747d7bcd7578cChris Lattner  /// in Result.
2225b45d4ef1ea3f04ec863daf8aa29be6c6e021750Anders Carlsson  bool Evaluate(EvalResult &Result, ASTContext &Ctx) const;
2235b45d4ef1ea3f04ec863daf8aa29be6c6e021750Anders Carlsson
2246ee7aa154e8bbb21a21254293410b944f78b0bfeChris Lattner  /// isEvaluatable - Call Evaluate to see if this expression can be constant
22545b6b9d080ac56917337d73d8f1cd6374b27b05dChris Lattner  /// folded, but discard the result.
22645b6b9d080ac56917337d73d8f1cd6374b27b05dChris Lattner  bool isEvaluatable(ASTContext &Ctx) const;
227c44eec6dd29ee9415cbd38a35deff4c8b67abb6aAnders Carlsson
22851fe996231b1d7199f76e4005ff4c943d5deeecdAnders Carlsson  /// EvaluateAsInt - Call Evaluate and return the folded integer. This
22951fe996231b1d7199f76e4005ff4c943d5deeecdAnders Carlsson  /// must be called on an expression that constant folds to an integer.
23051fe996231b1d7199f76e4005ff4c943d5deeecdAnders Carlsson  llvm::APSInt EvaluateAsInt(ASTContext &Ctx) const;
23151fe996231b1d7199f76e4005ff4c943d5deeecdAnders Carlsson
2321b78276a75a5a0f496a82429c1ff9604d622a76dAnders Carlsson  /// EvaluateAsLValue - Evaluate an expression to see if it's a valid LValue.
2331b78276a75a5a0f496a82429c1ff9604d622a76dAnders Carlsson  bool EvaluateAsLValue(EvalResult &Result, ASTContext &Ctx) const;
2341b78276a75a5a0f496a82429c1ff9604d622a76dAnders Carlsson
235efa9b3877ef298bcb792600ac33521827e1f7fafAnders Carlsson  /// isNullPointerConstant - C99 6.3.2.3p3 -  Return true if this is either an
236efa9b3877ef298bcb792600ac33521827e1f7fafAnders Carlsson  /// integer constant expression with the value zero, or if this is one that is
237efa9b3877ef298bcb792600ac33521827e1f7fafAnders Carlsson  /// cast to void*.
238efa9b3877ef298bcb792600ac33521827e1f7fafAnders Carlsson  bool isNullPointerConstant(ASTContext &Ctx) const;
239efa9b3877ef298bcb792600ac33521827e1f7fafAnders Carlsson
2402e5f54aa1dd15a62c34a9d1d24a5a0692f43934aTed Kremenek  /// hasGlobalStorage - Return true if this expression has static storage
2414cc627111453b75519d5130b57e06256da7b00e8Chris Lattner  /// duration.  This means that the address of this expression is a link-time
2424cc627111453b75519d5130b57e06256da7b00e8Chris Lattner  /// constant.
2432e5f54aa1dd15a62c34a9d1d24a5a0692f43934aTed Kremenek  bool hasGlobalStorage() const;
24444baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian
24544baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian  /// isOBJCGCCandidate - Return true if this expression may be used in a read/
24644baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian  /// write barrier.
24744baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian  bool isOBJCGCCandidate() const;
2484e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek
2494e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek  /// IgnoreParens - Ignore parentheses.  If this Expr is a ParenExpr, return
2504e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek  ///  its subexpression.  If that subexpression is also a ParenExpr,
2514e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek  ///  then this method recursively returns its subexpression, and so forth.
2524e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek  ///  Otherwise, the method returns the current Expr.
2534e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek  Expr* IgnoreParens();
25456f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner
25556f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner  /// IgnoreParenCasts - Ignore parentheses and casts.  Strip off any ParenExpr
25627c8dc06f65d7abcf6a7e7f64a7960c9a150ca01Douglas Gregor  /// or CastExprs, returning their operand.
25756f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner  Expr *IgnoreParenCasts();
2584e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek
259ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner  /// IgnoreParenNoopCasts - Ignore parentheses and casts that do not change the
260ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner  /// value (including ptr->int casts of the same size).  Strip off any
261ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner  /// ParenExpr or CastExprs, returning their operand.
262ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner  Expr *IgnoreParenNoopCasts(ASTContext &Ctx);
263ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner
2644e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek  const Expr* IgnoreParens() const {
2654e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek    return const_cast<Expr*>(this)->IgnoreParens();
2664e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek  }
26756f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner  const Expr *IgnoreParenCasts() const {
26856f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner    return const_cast<Expr*>(this)->IgnoreParenCasts();
26956f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner  }
270ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner  const Expr *IgnoreParenNoopCasts(ASTContext &Ctx) const {
271ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner    return const_cast<Expr*>(this)->IgnoreParenNoopCasts(Ctx);
272ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner  }
273ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner
274898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  static bool hasAnyTypeDependentArguments(Expr** Exprs, unsigned NumExprs);
275898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  static bool hasAnyValueDependentArguments(Expr** Exprs, unsigned NumExprs);
276898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor
2775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Stmt *T) {
2785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return T->getStmtClass() >= firstExprConstant &&
2795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer           T->getStmtClass() <= lastExprConstant;
2805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
2815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Expr *) { return true; }
2822e7d352dbec06755105237afba183492d31d03cbTed Kremenek
283e2563ca02a519c2ad6d64dfed87d6e86c5d3c072Sam Bishop  static inline Expr* Create(llvm::Deserializer& D, ASTContext& C) {
284e2563ca02a519c2ad6d64dfed87d6e86c5d3c072Sam Bishop    return cast<Expr>(Stmt::Create(D, C));
2852e7d352dbec06755105237afba183492d31d03cbTed Kremenek  }
2865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
2875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
2885549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek
2895549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek//===----------------------------------------------------------------------===//
2905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// Primary Expressions.
2915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===//
2925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
2935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// DeclRefExpr - [C99 6.5.1p2] - A reference to a declared variable, function,
2945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// enum, etc.
2955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass DeclRefExpr : public Expr {
2968e9bebdea69c590dedfbf27374114cb76fe12fbdDouglas Gregor  NamedDecl *D;
2975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation Loc;
2989e922b1663ecb95dc7eee03002fd66ed18fb3192Argyrios Kyrtzidis
2999e922b1663ecb95dc7eee03002fd66ed18fb3192Argyrios Kyrtzidisprotected:
3001a49af9681c350fef58e677f85ccb9a77e8e9d0aDouglas Gregor  // FIXME: Eventually, this constructor will go away and all subclasses
3011a49af9681c350fef58e677f85ccb9a77e8e9d0aDouglas Gregor  // will have to provide the type- and value-dependent flags.
3028e9bebdea69c590dedfbf27374114cb76fe12fbdDouglas Gregor  DeclRefExpr(StmtClass SC, NamedDecl *d, QualType t, SourceLocation l) :
3039e922b1663ecb95dc7eee03002fd66ed18fb3192Argyrios Kyrtzidis    Expr(SC, t), D(d), Loc(l) {}
3049e922b1663ecb95dc7eee03002fd66ed18fb3192Argyrios Kyrtzidis
3051a49af9681c350fef58e677f85ccb9a77e8e9d0aDouglas Gregor  DeclRefExpr(StmtClass SC, NamedDecl *d, QualType t, SourceLocation l, bool TD,
3061a49af9681c350fef58e677f85ccb9a77e8e9d0aDouglas Gregor              bool VD) :
3071a49af9681c350fef58e677f85ccb9a77e8e9d0aDouglas Gregor    Expr(SC, t, TD, VD), D(d), Loc(l) {}
3081a49af9681c350fef58e677f85ccb9a77e8e9d0aDouglas Gregor
3095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
310898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  // FIXME: Eventually, this constructor will go away and all clients
311898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  // will have to provide the type- and value-dependent flags.
3128e9bebdea69c590dedfbf27374114cb76fe12fbdDouglas Gregor  DeclRefExpr(NamedDecl *d, QualType t, SourceLocation l) :
3135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Expr(DeclRefExprClass, t), D(d), Loc(l) {}
314898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor
315898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  DeclRefExpr(NamedDecl *d, QualType t, SourceLocation l, bool TD, bool VD) :
316898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor    Expr(DeclRefExprClass, t, TD, VD), D(d), Loc(l) {}
3175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
3188e9bebdea69c590dedfbf27374114cb76fe12fbdDouglas Gregor  NamedDecl *getDecl() { return D; }
3198e9bebdea69c590dedfbf27374114cb76fe12fbdDouglas Gregor  const NamedDecl *getDecl() const { return D; }
320904eed3f6148758d39a2d3c88f3133274460d645Douglas Gregor  void setDecl(NamedDecl *NewD) { D = NewD; }
321904eed3f6148758d39a2d3c88f3133274460d645Douglas Gregor
3229e922b1663ecb95dc7eee03002fd66ed18fb3192Argyrios Kyrtzidis  SourceLocation getLocation() const { return Loc; }
3235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
3245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
3255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Stmt *T) {
3269e922b1663ecb95dc7eee03002fd66ed18fb3192Argyrios Kyrtzidis    return T->getStmtClass() == DeclRefExprClass ||
3271a49af9681c350fef58e677f85ccb9a77e8e9d0aDouglas Gregor           T->getStmtClass() == CXXConditionDeclExprClass ||
3281a49af9681c350fef58e677f85ccb9a77e8e9d0aDouglas Gregor           T->getStmtClass() == QualifiedDeclRefExprClass;
3295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
3305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const DeclRefExpr *) { return true; }
33177ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek
33277ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  // Iterators
33377ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_begin();
33477ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_end();
3352dc9ac73a8a34cabf261a81a1653d7379065ac61Ted Kremenek
336ec0aa78745f7b3bc96c20fffd1115bf26aaa0eadTed Kremenek  virtual void EmitImpl(llvm::Serializer& S) const;
337e2563ca02a519c2ad6d64dfed87d6e86c5d3c072Sam Bishop  static DeclRefExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C);
3385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
3395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
340d9f6910f4ef37c0e8eeee2a01287d9572c3176efChris Lattner/// PredefinedExpr - [C99 6.4.2.2] - A predefined identifier such as __func__.
341d9f6910f4ef37c0e8eeee2a01287d9572c3176efChris Lattnerclass PredefinedExpr : public Expr {
342227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlssonpublic:
343227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson  enum IdentType {
344227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson    Func,
345227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson    Function,
346cd9b46e5442a3ef17f83f75177d8545cb5b3e2b9Douglas Gregor    PrettyFunction
347227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson  };
348227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson
349227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlssonprivate:
350227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson  SourceLocation Loc;
351227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson  IdentType Type;
352227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlssonpublic:
353d9f6910f4ef37c0e8eeee2a01287d9572c3176efChris Lattner  PredefinedExpr(SourceLocation l, QualType type, IdentType IT)
354d9f6910f4ef37c0e8eeee2a01287d9572c3176efChris Lattner    : Expr(PredefinedExprClass, type), Loc(l), Type(IT) {}
355227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson
356227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson  IdentType getIdentType() const { return Type; }
357227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson
358227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson  virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
359227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson
360227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson  static bool classof(const Stmt *T) {
361d9f6910f4ef37c0e8eeee2a01287d9572c3176efChris Lattner    return T->getStmtClass() == PredefinedExprClass;
362227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson  }
363d9f6910f4ef37c0e8eeee2a01287d9572c3176efChris Lattner  static bool classof(const PredefinedExpr *) { return true; }
36477ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek
36577ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  // Iterators
36677ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_begin();
36777ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_end();
3681ba485e582edfc8636afc25a6d7453c869530688Ted Kremenek
369ec0aa78745f7b3bc96c20fffd1115bf26aaa0eadTed Kremenek  virtual void EmitImpl(llvm::Serializer& S) const;
370d9f6910f4ef37c0e8eeee2a01287d9572c3176efChris Lattner  static PredefinedExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C);
371227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson};
372227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson
3735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass IntegerLiteral : public Expr {
3745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  llvm::APInt Value;
3755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation Loc;
3765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
3775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // type should be IntTy, LongTy, LongLongTy, UnsignedIntTy, UnsignedLongTy,
3785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // or UnsignedLongLongTy
3795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  IntegerLiteral(const llvm::APInt &V, QualType type, SourceLocation l)
3805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    : Expr(IntegerLiteralClass, type), Value(V), Loc(l) {
3815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    assert(type->isIntegerType() && "Illegal type in IntegerLiteral");
3825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
383a135fb43eb94524a6529768596a4533eed9aa70dAnders Carlsson
384a135fb43eb94524a6529768596a4533eed9aa70dAnders Carlsson  IntegerLiteral* Clone(ASTContext &C) const;
385a135fb43eb94524a6529768596a4533eed9aa70dAnders Carlsson
3865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  const llvm::APInt &getValue() const { return Value; }
3875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
3885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
389313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor  /// \brief Retrieve the location of the literal.
390313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor  SourceLocation getLocation() const { return Loc; }
391313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor
3925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Stmt *T) {
3935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return T->getStmtClass() == IntegerLiteralClass;
3945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
3955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const IntegerLiteral *) { return true; }
39677ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek
39777ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  // Iterators
39877ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_begin();
39977ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_end();
4002dc9ac73a8a34cabf261a81a1653d7379065ac61Ted Kremenek
401ec0aa78745f7b3bc96c20fffd1115bf26aaa0eadTed Kremenek  virtual void EmitImpl(llvm::Serializer& S) const;
402e2563ca02a519c2ad6d64dfed87d6e86c5d3c072Sam Bishop  static IntegerLiteral* CreateImpl(llvm::Deserializer& D, ASTContext& C);
4035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
4045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
4055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass CharacterLiteral : public Expr {
4065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  unsigned Value;
4075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation Loc;
408c250aae4f645833aed3a6321bc8598f7330dce8dChris Lattner  bool IsWide;
4095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
4105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // type should be IntTy
411c250aae4f645833aed3a6321bc8598f7330dce8dChris Lattner  CharacterLiteral(unsigned value, bool iswide, QualType type, SourceLocation l)
412c250aae4f645833aed3a6321bc8598f7330dce8dChris Lattner    : Expr(CharacterLiteralClass, type), Value(value), Loc(l), IsWide(iswide) {
4135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
4142eadfb638eb1bb6ccfd6fd0453e764d47e27eed9Chris Lattner  SourceLocation getLoc() const { return Loc; }
415c250aae4f645833aed3a6321bc8598f7330dce8dChris Lattner  bool isWide() const { return IsWide; }
4162eadfb638eb1bb6ccfd6fd0453e764d47e27eed9Chris Lattner
4175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
4185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
4195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  unsigned getValue() const { return Value; }
4205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
4215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Stmt *T) {
4225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return T->getStmtClass() == CharacterLiteralClass;
4235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
4245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const CharacterLiteral *) { return true; }
42577ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek
42677ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  // Iterators
42777ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_begin();
42877ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_end();
4297338a8299ec393eaf6bb580b5ef9ab2b08b5bd11Ted Kremenek
430ec0aa78745f7b3bc96c20fffd1115bf26aaa0eadTed Kremenek  virtual void EmitImpl(llvm::Serializer& S) const;
431e2563ca02a519c2ad6d64dfed87d6e86c5d3c072Sam Bishop  static CharacterLiteral* CreateImpl(llvm::Deserializer& D, ASTContext& C);
4325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
4335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
4345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass FloatingLiteral : public Expr {
435525a05093a4816af961fe2bc6b8a81c17e2e26c2Chris Lattner  llvm::APFloat Value;
436720c4ec57b6110873cd533ad434853a27e7c3f4aTed Kremenek  bool IsExact : 1;
4375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation Loc;
4385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
439720c4ec57b6110873cd533ad434853a27e7c3f4aTed Kremenek  FloatingLiteral(const llvm::APFloat &V, bool* isexact,
440720c4ec57b6110873cd533ad434853a27e7c3f4aTed Kremenek                  QualType Type, SourceLocation L)
441720c4ec57b6110873cd533ad434853a27e7c3f4aTed Kremenek    : Expr(FloatingLiteralClass, Type), Value(V), IsExact(*isexact), Loc(L) {}
4425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
443c9bec4bfea9090a08dd83a7b213f0c8adf8d78ecChris Lattner  const llvm::APFloat &getValue() const { return Value; }
444720c4ec57b6110873cd533ad434853a27e7c3f4aTed Kremenek
445720c4ec57b6110873cd533ad434853a27e7c3f4aTed Kremenek  bool isExact() const { return IsExact; }
446c9bec4bfea9090a08dd83a7b213f0c8adf8d78ecChris Lattner
447da8249e57f3badecf925571881fe57243935c6c1Chris Lattner  /// getValueAsApproximateDouble - This returns the value as an inaccurate
448da8249e57f3badecf925571881fe57243935c6c1Chris Lattner  /// double.  Note that this may cause loss of precision, but is useful for
449da8249e57f3badecf925571881fe57243935c6c1Chris Lattner  /// debugging dumps, etc.
450da8249e57f3badecf925571881fe57243935c6c1Chris Lattner  double getValueAsApproximateDouble() const;
451da8249e57f3badecf925571881fe57243935c6c1Chris Lattner
4525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
4535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
4545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Stmt *T) {
4555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return T->getStmtClass() == FloatingLiteralClass;
4565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
4575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const FloatingLiteral *) { return true; }
45877ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek
45977ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  // Iterators
46077ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_begin();
46177ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_end();
462612c9b9ca73593b3194866c9e1a51554db9752e7Ted Kremenek
463ec0aa78745f7b3bc96c20fffd1115bf26aaa0eadTed Kremenek  virtual void EmitImpl(llvm::Serializer& S) const;
464e2563ca02a519c2ad6d64dfed87d6e86c5d3c072Sam Bishop  static FloatingLiteral* CreateImpl(llvm::Deserializer& D, ASTContext& C);
4655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
4665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
4675d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner/// ImaginaryLiteral - We support imaginary integer and floating point literals,
4685d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner/// like "1.0i".  We represent these as a wrapper around FloatingLiteral and
4695d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner/// IntegerLiteral classes.  Instances of this class always have a Complex type
4705d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner/// whose element type matches the subexpression.
4715d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner///
4725d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattnerclass ImaginaryLiteral : public Expr {
4735549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Stmt *Val;
4745d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattnerpublic:
4755d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner  ImaginaryLiteral(Expr *val, QualType Ty)
4765d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner    : Expr(ImaginaryLiteralClass, Ty), Val(val) {}
4775d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner
4785549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  const Expr *getSubExpr() const { return cast<Expr>(Val); }
4795549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getSubExpr() { return cast<Expr>(Val); }
4805d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner
4815d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner  virtual SourceRange getSourceRange() const { return Val->getSourceRange(); }
4825d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner  static bool classof(const Stmt *T) {
4835d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner    return T->getStmtClass() == ImaginaryLiteralClass;
4845d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner  }
4855d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner  static bool classof(const ImaginaryLiteral *) { return true; }
4865d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner
4875d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner  // Iterators
4885d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner  virtual child_iterator child_begin();
4895d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner  virtual child_iterator child_end();
4901c72de1be77fc43cc27e9bf1cbfe7bd25bee2f81Ted Kremenek
491ec0aa78745f7b3bc96c20fffd1115bf26aaa0eadTed Kremenek  virtual void EmitImpl(llvm::Serializer& S) const;
492e2563ca02a519c2ad6d64dfed87d6e86c5d3c072Sam Bishop  static ImaginaryLiteral* CreateImpl(llvm::Deserializer& D, ASTContext& C);
4935d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner};
4945d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner
495e6a82b2c29ad05534841e5f8fd033fb17b6f61e2Ted Kremenek/// StringLiteral - This represents a string literal expression, e.g. "foo"
496e6a82b2c29ad05534841e5f8fd033fb17b6f61e2Ted Kremenek/// or L"bar" (wide strings).  The actual string is returned by getStrData()
497e6a82b2c29ad05534841e5f8fd033fb17b6f61e2Ted Kremenek/// is NOT null-terminated, and the length of the string is determined by
498a7ad98ff0919d6a24ea7c46634ea29bea551c1a0Chris Lattner/// calling getByteLength().  The C type for a string is always a
499c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// ConstantArrayType.  In C++, the char type is const qualified, in C it is
500c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// not.
501690398188ea5b428f06aa13c7d4ce6eb741ad4f9Chris Lattner///
502690398188ea5b428f06aa13c7d4ce6eb741ad4f9Chris Lattner/// Note that strings in C can be formed by concatenation of multiple string
5038bea7c0ee44c71c817de7dc2be932b73bec90c9fChris Lattner/// literal pptokens in translation phase #6.  This keeps track of the locations
504690398188ea5b428f06aa13c7d4ce6eb741ad4f9Chris Lattner/// of each of these pieces.
505c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner///
506c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// Strings in C can also be truncated and extended by assigning into arrays,
507c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// e.g. with constructs like:
508c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner///   char X[2] = "foobar";
509c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// In this case, getByteLength() will return 6, but the string literal will
510c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// have type "char[2]".
5115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass StringLiteral : public Expr {
5125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  const char *StrData;
5135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  unsigned ByteLength;
5145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool IsWide;
515726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner  unsigned NumConcatenated;
516726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner  SourceLocation TokLocs[1];
5172085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner
5182085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner  StringLiteral(QualType Ty) : Expr(StringLiteralClass, Ty) {}
5195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
5202085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner  /// This is the "fully general" constructor that allows representation of
5212085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner  /// strings formed from multiple concatenated tokens.
5222085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner  static StringLiteral *Create(ASTContext &C, const char *StrData,
5232085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner                               unsigned ByteLength, bool Wide, QualType Ty,
524a135fb43eb94524a6529768596a4533eed9aa70dAnders Carlsson                               const SourceLocation *Loc, unsigned NumStrs);
5252085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner
5262085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner  /// Simple constructor for string literals made from one token.
5272085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner  static StringLiteral *Create(ASTContext &C, const char *StrData,
5282085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner                               unsigned ByteLength,
5292085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner                               bool Wide, QualType Ty, SourceLocation Loc) {
5302085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner    return Create(C, StrData, ByteLength, Wide, Ty, &Loc, 1);
5312085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner  }
532a135fb43eb94524a6529768596a4533eed9aa70dAnders Carlsson
533a135fb43eb94524a6529768596a4533eed9aa70dAnders Carlsson  StringLiteral* Clone(ASTContext &C) const;
534726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner  void Destroy(ASTContext &C);
5355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
5365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  const char *getStrData() const { return StrData; }
5375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  unsigned getByteLength() const { return ByteLength; }
5385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isWide() const { return IsWide; }
5398d4141f83d9de379547cf05bd75d4c6cf894b189Steve Naroff  bool containsNonAsciiOrNull() const {
54033fdb738a6c125f4c788733897021b7c1a062b0cSteve Naroff    for (unsigned i = 0; i < getByteLength(); ++i)
5418d4141f83d9de379547cf05bd75d4c6cf894b189Steve Naroff      if (!isascii(getStrData()[i]) || !getStrData()[i])
54233fdb738a6c125f4c788733897021b7c1a062b0cSteve Naroff        return true;
54333fdb738a6c125f4c788733897021b7c1a062b0cSteve Naroff    return false;
54433fdb738a6c125f4c788733897021b7c1a062b0cSteve Naroff  }
545726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner  /// getNumConcatenated - Get the number of string literal tokens that were
546726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner  /// concatenated in translation phase #6 to form this string literal.
547726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner  unsigned getNumConcatenated() const { return NumConcatenated; }
548726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner
549726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner  SourceLocation getStrTokenLoc(unsigned TokNum) const {
550726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner    assert(TokNum < NumConcatenated && "Invalid tok number");
551726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner    return TokLocs[TokNum];
552726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner  }
553b137299ce5bb6c36fbba651858600857fda4dd50Chris Lattner
554b137299ce5bb6c36fbba651858600857fda4dd50Chris Lattner  typedef const SourceLocation *tokloc_iterator;
555b137299ce5bb6c36fbba651858600857fda4dd50Chris Lattner  tokloc_iterator tokloc_begin() const { return TokLocs; }
556b137299ce5bb6c36fbba651858600857fda4dd50Chris Lattner  tokloc_iterator tokloc_end() const { return TokLocs+NumConcatenated; }
5575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
5585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  virtual SourceRange getSourceRange() const {
559726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner    return SourceRange(TokLocs[0], TokLocs[NumConcatenated-1]);
5605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
5615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Stmt *T) {
5625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return T->getStmtClass() == StringLiteralClass;
5635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
5645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const StringLiteral *) { return true; }
56577ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek
56677ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  // Iterators
56777ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_begin();
56877ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_end();
5697febad7377c04607aa2c744d58af61e1abea6250Ted Kremenek
570ec0aa78745f7b3bc96c20fffd1115bf26aaa0eadTed Kremenek  virtual void EmitImpl(llvm::Serializer& S) const;
571e2563ca02a519c2ad6d64dfed87d6e86c5d3c072Sam Bishop  static StringLiteral* CreateImpl(llvm::Deserializer& D, ASTContext& C);
5725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
5735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
5745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ParenExpr - This represents a parethesized expression, e.g. "(1)".  This
5755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// AST node is only formed if full location information is requested.
5765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass ParenExpr : public Expr {
5775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation L, R;
5785549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Stmt *Val;
5795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
5805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ParenExpr(SourceLocation l, SourceLocation r, Expr *val)
581898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor    : Expr(ParenExprClass, val->getType(),
582898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor           val->isTypeDependent(), val->isValueDependent()),
583898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor      L(l), R(r), Val(val) {}
5845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
5855549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  const Expr *getSubExpr() const { return cast<Expr>(Val); }
5865549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getSubExpr() { return cast<Expr>(Val); }
587866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek  virtual SourceRange getSourceRange() const { return SourceRange(L, R); }
5885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
589313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor  /// \brief Get the location of the left parentheses '('.
590313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor  SourceLocation getLParen() const { return L; }
591313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor
592313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor  /// \brief Get the location of the right parentheses ')'.
593313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor  SourceLocation getRParen() const { return R; }
594313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor
5955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Stmt *T) {
5965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return T->getStmtClass() == ParenExprClass;
5975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
5985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const ParenExpr *) { return true; }
59977ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek
60077ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  // Iterators
60177ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_begin();
60277ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_end();
6039eea2ca5f2cb5d77569274702b5b06273e426dc2Ted Kremenek
604ec0aa78745f7b3bc96c20fffd1115bf26aaa0eadTed Kremenek  virtual void EmitImpl(llvm::Serializer& S) const;
605e2563ca02a519c2ad6d64dfed87d6e86c5d3c072Sam Bishop  static ParenExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C);
6065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
6075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
6085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
6090518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl/// UnaryOperator - This represents the unary-expression's (except sizeof and
6100518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl/// alignof), the postinc/postdec operators from postfix-expression, and various
6115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// extensions.
612dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner///
613dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner/// Notes on various nodes:
614dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner///
615dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner/// Real/Imag - These return the real/imag part of a complex operand.  If
616dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner///   applied to a non-complex value, the former returns its operand and the
617dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner///   later returns zero in the type of the operand.
618dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner///
61973d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner/// __builtin_offsetof(type, a.b[10]) is represented as a unary operator whose
62073d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner///   subexpression is a compound literal with the various MemberExpr and
62173d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner///   ArraySubscriptExpr's applied to it.
62273d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner///
6235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass UnaryOperator : public Expr {
6245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
62513d130c3d225cdb5b1e6d9e86cea12eea718c707Chris Lattner  // Note that additions to this should also update the StmtVisitor class.
6265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  enum Opcode {
6275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    PostInc, PostDec, // [C99 6.5.2.4] Postfix increment and decrement operators
6285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    PreInc, PreDec,   // [C99 6.5.3.1] Prefix increment and decrement operators.
6295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    AddrOf, Deref,    // [C99 6.5.3.2] Address and indirection operators.
6305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Plus, Minus,      // [C99 6.5.3.3] Unary arithmetic operators.
6315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Not, LNot,        // [C99 6.5.3.3] Unary arithmetic operators.
6325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Real, Imag,       // "__real expr"/"__imag expr" Extension.
63373d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner    Extension,        // __extension__ marker.
63473d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner    OffsetOf          // __builtin_offsetof
6355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  };
6365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprivate:
6375549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Stmt *Val;
6385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  Opcode Opc;
6395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation Loc;
6405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
6415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
6425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  UnaryOperator(Expr *input, Opcode opc, QualType type, SourceLocation l)
6439103bb27f4eefa0e0d7935387750e3aca24abc49Douglas Gregor    : Expr(UnaryOperatorClass, type,
6449103bb27f4eefa0e0d7935387750e3aca24abc49Douglas Gregor           input->isTypeDependent() && opc != OffsetOf,
6459103bb27f4eefa0e0d7935387750e3aca24abc49Douglas Gregor           input->isValueDependent()),
6469103bb27f4eefa0e0d7935387750e3aca24abc49Douglas Gregor      Val(input), Opc(opc), Loc(l) {}
6475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
6485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  Opcode getOpcode() const { return Opc; }
6495549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getSubExpr() const { return cast<Expr>(Val); }
6505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
6515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// getOperatorLoc - Return the location of the operator.
6525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation getOperatorLoc() const { return Loc; }
6535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
6545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// isPostfix - Return true if this is a postfix operation, like x++.
6552085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner  static bool isPostfix(Opcode Op) {
6562085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner    return Op == PostInc || Op == PostDec;
6572085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner  }
6585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
6595a56ac30d04e8f0431a08980885662a47a6308aaTed Kremenek  /// isPostfix - Return true if this is a prefix operation, like --x.
6602085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner  static bool isPrefix(Opcode Op) {
6612085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner    return Op == PreInc || Op == PreDec;
6622085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner  }
6635a56ac30d04e8f0431a08980885662a47a6308aaTed Kremenek
6645a56ac30d04e8f0431a08980885662a47a6308aaTed Kremenek  bool isPrefix() const { return isPrefix(Opc); }
6655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isPostfix() const { return isPostfix(Opc); }
6665d826b82936beb2c32dd02460332ba8035192c65Ted Kremenek  bool isIncrementOp() const {return Opc==PreInc || Opc==PostInc; }
6675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isIncrementDecrementOp() const { return Opc>=PostInc && Opc<=PreDec; }
6685a1deb8d9c0722beae28d693fa137bbb942bd11fAnders Carlsson  bool isOffsetOfOp() const { return Opc == OffsetOf; }
6695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool isArithmeticOp(Opcode Op) { return Op >= Plus && Op <= LNot; }
6705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
6715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// getOpcodeStr - Turn an Opcode enum value into the punctuation char it
6725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// corresponds to, e.g. "sizeof" or "[pre]++"
6735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static const char *getOpcodeStr(Opcode Op);
6745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
675bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor  /// \brief Retrieve the unary opcode that corresponds to the given
676bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor  /// overloaded operator.
677bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor  static Opcode getOverloadedOpcode(OverloadedOperatorKind OO, bool Postfix);
678bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor
679bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor  /// \brief Retrieve the overloaded operator kind that corresponds to
680bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor  /// the given unary opcode.
681bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor  static OverloadedOperatorKind getOverloadedOperator(Opcode Opc);
682bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor
6835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  virtual SourceRange getSourceRange() const {
6845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    if (isPostfix())
6855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      return SourceRange(Val->getLocStart(), Loc);
6865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    else
6875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      return SourceRange(Loc, Val->getLocEnd());
6885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
6895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  virtual SourceLocation getExprLoc() const { return Loc; }
6905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
6915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Stmt *T) {
6925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return T->getStmtClass() == UnaryOperatorClass;
6935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
6945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const UnaryOperator *) { return true; }
69577ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek
69677ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  // Iterators
69777ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_begin();
69877ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_end();
6991049436d4b53d928b555f7381bc1639dd302bbc7Ted Kremenek
700ec0aa78745f7b3bc96c20fffd1115bf26aaa0eadTed Kremenek  virtual void EmitImpl(llvm::Serializer& S) const;
701e2563ca02a519c2ad6d64dfed87d6e86c5d3c072Sam Bishop  static UnaryOperator* CreateImpl(llvm::Deserializer& D, ASTContext& C);
7025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
7035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
7040518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl/// SizeOfAlignOfExpr - [C99 6.5.3.4] - This is for sizeof/alignof, both of
7050518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl/// types and expressions.
7060518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redlclass SizeOfAlignOfExpr : public Expr {
7070518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl  bool isSizeof : 1;  // true if sizeof, false if alignof.
7080518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl  bool isType : 1;    // true if operand is a type, false if an expression
709d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl  union {
710d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl    void *Ty;
711d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl    Stmt *Ex;
712d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl  } Argument;
7135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation OpLoc, RParenLoc;
7145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
715ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor  SizeOfAlignOfExpr(bool issizeof, QualType T,
7160518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl                    QualType resultType, SourceLocation op,
7170518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl                    SourceLocation rp) :
7182850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl      Expr(SizeOfAlignOfExprClass, resultType,
719ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor           false, // Never type-dependent (C++ [temp.dep.expr]p3).
7202850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl           // Value-dependent if the argument is type-dependent.
721ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor           T->isDependentType()),
722ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor      isSizeof(issizeof), isType(true), OpLoc(op), RParenLoc(rp) {
723ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor    Argument.Ty = T.getAsOpaquePtr();
724ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor  }
725ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor
726ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor  SizeOfAlignOfExpr(bool issizeof, Expr *E,
727ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor                    QualType resultType, SourceLocation op,
728ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor                    SourceLocation rp) :
729ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor      Expr(SizeOfAlignOfExprClass, resultType,
730ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor           false, // Never type-dependent (C++ [temp.dep.expr]p3).
731ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor           // Value-dependent if the argument is type-dependent.
732ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor           E->isTypeDependent()),
733ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor      isSizeof(issizeof), isType(false), OpLoc(op), RParenLoc(rp) {
734ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor    Argument.Ex = E;
735d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl  }
7360518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl
7379048891ff983d0681c116c6e8f1073aa31bdd6e8Daniel Dunbar  virtual void Destroy(ASTContext& C);
7389048891ff983d0681c116c6e8f1073aa31bdd6e8Daniel Dunbar
7395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isSizeOf() const { return isSizeof; }
7400518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl  bool isArgumentType() const { return isType; }
7410518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl  QualType getArgumentType() const {
7420518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl    assert(isArgumentType() && "calling getArgumentType() when arg is expr");
743d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl    return QualType::getFromOpaquePtr(Argument.Ty);
7440518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl  }
745caae7b099a0324b7c15dc89a9b70969d5d7ce996Chris Lattner  Expr *getArgumentExpr() {
7460518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl    assert(!isArgumentType() && "calling getArgumentExpr() when arg is type");
747d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl    return static_cast<Expr*>(Argument.Ex);
7480518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl  }
749caae7b099a0324b7c15dc89a9b70969d5d7ce996Chris Lattner  const Expr *getArgumentExpr() const {
750caae7b099a0324b7c15dc89a9b70969d5d7ce996Chris Lattner    return const_cast<SizeOfAlignOfExpr*>(this)->getArgumentExpr();
751caae7b099a0324b7c15dc89a9b70969d5d7ce996Chris Lattner  }
752caae7b099a0324b7c15dc89a9b70969d5d7ce996Chris Lattner
7530518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl  /// Gets the argument type, or the type of the argument expression, whichever
7540518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl  /// is appropriate.
7550518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl  QualType getTypeOfArgument() const {
7560518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl    return isArgumentType() ? getArgumentType() : getArgumentExpr()->getType();
7570518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl  }
7580518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl
75976e773a443be9f006610f46529e07d4c8d857680Chris Lattner  SourceLocation getOperatorLoc() const { return OpLoc; }
760866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek
761866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek  virtual SourceRange getSourceRange() const {
762866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek    return SourceRange(OpLoc, RParenLoc);
763866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek  }
7645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
7655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Stmt *T) {
7660518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl    return T->getStmtClass() == SizeOfAlignOfExprClass;
7675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
7680518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl  static bool classof(const SizeOfAlignOfExpr *) { return true; }
76977ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek
77077ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  // Iterators
77177ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_begin();
77277ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_end();
773ea2fe9b435e1b55135de32dcac97366554706ac4Ted Kremenek
774ea2fe9b435e1b55135de32dcac97366554706ac4Ted Kremenek  virtual void EmitImpl(llvm::Serializer& S) const;
7750518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl  static SizeOfAlignOfExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C);
7765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
7775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
7785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===//
7795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// Postfix Operators.
7805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===//
7815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
7825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ArraySubscriptExpr - [C99 6.5.2.1] Array Subscripting.
7835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass ArraySubscriptExpr : public Expr {
78477ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  enum { LHS, RHS, END_EXPR=2 };
7855549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Stmt* SubExprs[END_EXPR];
7865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation RBracketLoc;
7875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
7882324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek  ArraySubscriptExpr(Expr *lhs, Expr *rhs, QualType t,
78973d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner                     SourceLocation rbracketloc)
7902850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl  : Expr(ArraySubscriptExprClass, t,
7912850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl         lhs->isTypeDependent() || rhs->isTypeDependent(),
7922850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl         lhs->isValueDependent() || rhs->isValueDependent()),
7932850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl    RBracketLoc(rbracketloc) {
79473d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner    SubExprs[LHS] = lhs;
79573d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner    SubExprs[RHS] = rhs;
79673d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner  }
7975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
7982324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek  /// An array access can be written A[4] or 4[A] (both are equivalent).
7992324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek  /// - getBase() and getIdx() always present the normalized view: A[4].
8002324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek  ///    In this case getBase() returns "A" and getIdx() returns "4".
8012324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek  /// - getLHS() and getRHS() present the syntactic view. e.g. for
8022324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek  ///    4[A] getLHS() returns "4".
80333fd5c124aac15bab7cad95e4e0e7761356d2c06Christopher Lamb  /// Note: Because vector element access is also written A[4] we must
80433fd5c124aac15bab7cad95e4e0e7761356d2c06Christopher Lamb  /// predicate the format conversion in getBase and getIdx only on the
80533fd5c124aac15bab7cad95e4e0e7761356d2c06Christopher Lamb  /// the type of the RHS, as it is possible for the LHS to be a vector of
80633fd5c124aac15bab7cad95e4e0e7761356d2c06Christopher Lamb  /// integer type
8075549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getLHS() { return cast<Expr>(SubExprs[LHS]); }
8085549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  const Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); }
80977ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek
8105549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getRHS() { return cast<Expr>(SubExprs[RHS]); }
8115549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  const Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); }
8122324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek
81377ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  Expr *getBase() {
8145549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek    return cast<Expr>(getRHS()->getType()->isIntegerType() ? getLHS():getRHS());
81577ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  }
81677ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek
8172324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek  const Expr *getBase() const {
8185549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek    return cast<Expr>(getRHS()->getType()->isIntegerType() ? getLHS():getRHS());
8192324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek  }
8202324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek
82177ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  Expr *getIdx() {
8225549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek    return cast<Expr>(getRHS()->getType()->isIntegerType() ? getRHS():getLHS());
8232324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek  }
8242324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek
82577ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  const Expr *getIdx() const {
8265549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek    return cast<Expr>(getRHS()->getType()->isIntegerType() ? getRHS():getLHS());
82777ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  }
8285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
829866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek  virtual SourceRange getSourceRange() const {
83077ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek    return SourceRange(getLHS()->getLocStart(), RBracketLoc);
8315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
832866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek
833026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner  SourceLocation getRBracketLoc() const { return RBracketLoc; }
8345cd9d6daf3acd4cc87fecebd81d9495b9e4ba9cdChris Lattner  virtual SourceLocation getExprLoc() const { return getBase()->getExprLoc(); }
8355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
8365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Stmt *T) {
8375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return T->getStmtClass() == ArraySubscriptExprClass;
8385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
8395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const ArraySubscriptExpr *) { return true; }
84077ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek
84177ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  // Iterators
84277ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_begin();
84377ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_end();
84496fa54fc6dc7f4c8dad1fb22fc7fc4f4d775d6c0Ted Kremenek
845ec0aa78745f7b3bc96c20fffd1115bf26aaa0eadTed Kremenek  virtual void EmitImpl(llvm::Serializer& S) const;
846e2563ca02a519c2ad6d64dfed87d6e86c5d3c072Sam Bishop  static ArraySubscriptExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C);
8475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
8485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
8495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
850b4609806e9232593ece09ce08b630836e825865cDouglas Gregor/// CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
851b4609806e9232593ece09ce08b630836e825865cDouglas Gregor/// CallExpr itself represents a normal function call, e.g., "f(x, 2)",
852b4609806e9232593ece09ce08b630836e825865cDouglas Gregor/// while its subclasses may represent alternative syntax that (semantically)
853b4609806e9232593ece09ce08b630836e825865cDouglas Gregor/// results in a function call. For example, CXXOperatorCallExpr is
854b4609806e9232593ece09ce08b630836e825865cDouglas Gregor/// a subclass for overloaded operator calls that use operator syntax, e.g.,
855b4609806e9232593ece09ce08b630836e825865cDouglas Gregor/// "str1 + str2" to resolve to a function call.
8565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass CallExpr : public Expr {
85777ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  enum { FN=0, ARGS_START=1 };
8585549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Stmt **SubExprs;
8595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  unsigned NumArgs;
8605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation RParenLoc;
861d7fe4ea296646f049e4ff4cc37aa92ff4014a6b3Ted Kremenek
862d7fe4ea296646f049e4ff4cc37aa92ff4014a6b3Ted Kremenek  // This version of the ctor is for deserialization.
863b4609806e9232593ece09ce08b630836e825865cDouglas Gregor  CallExpr(StmtClass SC, Stmt** subexprs, unsigned numargs, QualType t,
864d7fe4ea296646f049e4ff4cc37aa92ff4014a6b3Ted Kremenek           SourceLocation rparenloc)
865b4609806e9232593ece09ce08b630836e825865cDouglas Gregor  : Expr(SC,t), SubExprs(subexprs),
866d7fe4ea296646f049e4ff4cc37aa92ff4014a6b3Ted Kremenek    NumArgs(numargs), RParenLoc(rparenloc) {}
867b4609806e9232593ece09ce08b630836e825865cDouglas Gregor
868b4609806e9232593ece09ce08b630836e825865cDouglas Gregorprotected:
869b4609806e9232593ece09ce08b630836e825865cDouglas Gregor  // This version of the constructor is for derived classes.
870668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek  CallExpr(ASTContext& C, StmtClass SC, Expr *fn, Expr **args, unsigned numargs,
871668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek           QualType t, SourceLocation rparenloc);
872d7fe4ea296646f049e4ff4cc37aa92ff4014a6b3Ted Kremenek
8735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
874668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek  CallExpr(ASTContext& C, Expr *fn, Expr **args, unsigned numargs, QualType t,
8755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer           SourceLocation rparenloc);
876668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek
877668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek  ~CallExpr() {}
878668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek
879668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek  void Destroy(ASTContext& C);
8805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
8815549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  const Expr *getCallee() const { return cast<Expr>(SubExprs[FN]); }
8825549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getCallee() { return cast<Expr>(SubExprs[FN]); }
88318b2515e1bf8c86a4900792692e42fe1296be28dChris Lattner  void setCallee(Expr *F) { SubExprs[FN] = F; }
8845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
8855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// getNumArgs - Return the number of actual arguments to this call.
8865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ///
8875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  unsigned getNumArgs() const { return NumArgs; }
8885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
8895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// getArg - Return the specified argument.
8905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  Expr *getArg(unsigned Arg) {
8915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    assert(Arg < NumArgs && "Arg access out of range!");
8925549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek    return cast<Expr>(SubExprs[Arg+ARGS_START]);
8935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
8945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  const Expr *getArg(unsigned Arg) const {
8955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    assert(Arg < NumArgs && "Arg access out of range!");
8965549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek    return cast<Expr>(SubExprs[Arg+ARGS_START]);
8975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
898668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek
899668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek  // FIXME: Why is this needed?  Why not just create the CallExpr with the
900668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek  // corect number of arguments?  It makes the ASTs less brittle.
901934f276cc5b45e19cd12ebb2d04fd7972a23865cSteve Naroff  /// setArg - Set the specified argument.
902934f276cc5b45e19cd12ebb2d04fd7972a23865cSteve Naroff  void setArg(unsigned Arg, Expr *ArgExpr) {
903934f276cc5b45e19cd12ebb2d04fd7972a23865cSteve Naroff    assert(Arg < NumArgs && "Arg access out of range!");
904934f276cc5b45e19cd12ebb2d04fd7972a23865cSteve Naroff    SubExprs[Arg+ARGS_START] = ArgExpr;
905934f276cc5b45e19cd12ebb2d04fd7972a23865cSteve Naroff  }
906d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner
907668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek  // FIXME: It would be great to just get rid of this.  There is only one
908668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek  // callee of this method, and it probably could be refactored to not use
909668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek  // this method and instead just create a CallExpr with the right number of
910668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek  // arguments.
911d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner  /// setNumArgs - This changes the number of arguments present in this call.
912d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner  /// Any orphaned expressions are deleted by this, and any new operands are set
913d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner  /// to null.
9148189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  void setNumArgs(ASTContext& C, unsigned NumArgs);
915d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner
9165549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  typedef ExprIterator arg_iterator;
9175549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  typedef ConstExprIterator const_arg_iterator;
9185549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek
919d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner  arg_iterator arg_begin() { return SubExprs+ARGS_START; }
920d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner  arg_iterator arg_end() { return SubExprs+ARGS_START+getNumArgs(); }
9215549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  const_arg_iterator arg_begin() const { return SubExprs+ARGS_START; }
9225549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  const_arg_iterator arg_end() const { return SubExprs+ARGS_START+getNumArgs();}
923d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner
9245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// getNumCommas - Return the number of commas that must have been present in
9255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// this function call.
9265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  unsigned getNumCommas() const { return NumArgs ? NumArgs - 1 : 0; }
9275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
928cb888967400a03504c88acedd5248d6778a82f46Chris Lattner  /// isBuiltinCall - If this is a call to a builtin, return the builtin ID.  If
929cb888967400a03504c88acedd5248d6778a82f46Chris Lattner  /// not, return 0.
9303c385e5f8d9008fff18597ca302be19fa86e51f6Douglas Gregor  unsigned isBuiltinCall(ASTContext &Context) const;
931cb888967400a03504c88acedd5248d6778a82f46Chris Lattner
932d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner  SourceLocation getRParenLoc() const { return RParenLoc; }
933866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek
934866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek  virtual SourceRange getSourceRange() const {
93577ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek    return SourceRange(getCallee()->getLocStart(), RParenLoc);
9365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
9375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
9385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Stmt *T) {
939b4609806e9232593ece09ce08b630836e825865cDouglas Gregor    return T->getStmtClass() == CallExprClass ||
94088a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor           T->getStmtClass() == CXXOperatorCallExprClass ||
94188a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor           T->getStmtClass() == CXXMemberCallExprClass;
9425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
9435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const CallExpr *) { return true; }
94488a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor  static bool classof(const CXXOperatorCallExpr *) { return true; }
94588a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor  static bool classof(const CXXMemberCallExpr *) { return true; }
94688a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor
94777ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  // Iterators
94877ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_begin();
94977ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  virtual child_iterator child_end();
950d7fe4ea296646f049e4ff4cc37aa92ff4014a6b3Ted Kremenek
951ec0aa78745f7b3bc96c20fffd1115bf26aaa0eadTed Kremenek  virtual void EmitImpl(llvm::Serializer& S) const;
952b4609806e9232593ece09ce08b630836e825865cDouglas Gregor  static CallExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C,
953b4609806e9232593ece09ce08b630836e825865cDouglas Gregor                              StmtClass SC);
9545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
9555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
956ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner/// MemberExpr - [C99 6.5.2.3] Structure and Union Members.  X->F and X.F.
9575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
9585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass MemberExpr : public Expr {
959ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner  /// Base - the expression for the base pointer or structure references.  In
960ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner  /// X.F, this is "X".
9615549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Stmt *Base;
962ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner
963ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner  /// MemberDecl - This is the decl being referenced by the field/member name.
964ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner  /// In X.F, this is the decl referenced by F.
96586f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor  NamedDecl *MemberDecl;
966ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner
967ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner  /// MemberLoc - This is the location of the member name.
9685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation MemberLoc;
969ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner
970ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner  /// IsArrow - True if this is "X->F", false if this is "X.F".
971ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner  bool IsArrow;
9725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
97386f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor  MemberExpr(Expr *base, bool isarrow, NamedDecl *memberdecl, SourceLocation l,
974510190777c4bd53e960eea4665b204778fec1b64Eli Friedman             QualType ty)
975510190777c4bd53e960eea4665b204778fec1b64Eli Friedman    : Expr(MemberExprClass, ty),
9765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      Base(base), MemberDecl(memberdecl), MemberLoc(l), IsArrow(isarrow) {}
977510190777c4bd53e960eea4665b204778fec1b64Eli Friedman
97888a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor  void setBase(Expr *E) { Base = E; }
9795549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getBase() const { return cast<Expr>(Base); }
98057e8b05fe9ba03d410db9c161e032cb79c9ab5baDouglas Gregor
98157e8b05fe9ba03d410db9c161e032cb79c9ab5baDouglas Gregor  /// \brief Retrieve the member declaration to which this expression refers.
98257e8b05fe9ba03d410db9c161e032cb79c9ab5baDouglas Gregor  ///
98357e8b05fe9ba03d410db9c161e032cb79c9ab5baDouglas Gregor  /// The returned declaration will either be a FieldDecl or (in C++)
98457e8b05fe9ba03d410db9c161e032cb79c9ab5baDouglas Gregor  /// a CXXMethodDecl.
98586f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor  NamedDecl *getMemberDecl() const { return MemberDecl; }
98688a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor  void setMemberDecl(NamedDecl *D) { MemberDecl = D; }
9875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isArrow() const { return IsArrow; }
988ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner
989ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner  /// getMemberLoc - Return the location of the "member", in X->F, it is the
990ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner  /// location of 'F'.
991026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner  SourceLocation getMemberLoc() const { return MemberLoc; }
9925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
9935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  virtual SourceRange getSourceRange() const {
9945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return SourceRange(getBase()->getLocStart(), MemberLoc);
9955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
996866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek
9975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  virtual SourceLocation getExprLoc() const { return MemberLoc; }
9985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
9995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Stmt *T) {
10005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return T->getStmtClass() == MemberExprClass;
10015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
10025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const MemberExpr *) { return true; }
10031237c673c07f9d827129ba02720108816abde562Ted Kremenek
10041237c673c07f9d827129ba02720108816abde562Ted Kremenek  // Iterators
10051237c673c07f9d827129ba02720108816abde562Ted Kremenek  virtual child_iterator child_begin();
10061237c673c07f9d827129ba02720108816abde562Ted Kremenek  virtual child_iterator child_end();
1007bd57e7c4754c0ce5d7d460041c8fd613e45c4319Ted Kremenek
1008bd57e7c4754c0ce5d7d460041c8fd613e45c4319Ted Kremenek  virtual void EmitImpl(llvm::Serializer& S) const;
1009e2563ca02a519c2ad6d64dfed87d6e86c5d3c072Sam Bishop  static MemberExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C);
10105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
10115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1012aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff/// CompoundLiteralExpr - [C99 6.5.2.5]
1013aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff///
1014aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroffclass CompoundLiteralExpr : public Expr {
10150fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner  /// LParenLoc - If non-null, this is the location of the left paren in a
10160fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner  /// compound literal like "(int){4}".  This can be null if this is a
10170fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner  /// synthesized compound expression.
10180fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner  SourceLocation LParenLoc;
10195549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Stmt *Init;
1020e9b12198c4cc7f5687960100351b4af006c14469Steve Naroff  bool FileScope;
1021aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroffpublic:
1022a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  CompoundLiteralExpr(SourceLocation lparenloc, QualType ty, Expr *init,
1023a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner                      bool fileScope)
1024a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner    : Expr(CompoundLiteralExprClass, ty), LParenLoc(lparenloc), Init(init),
1025a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner      FileScope(fileScope) {}
1026aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff
10275549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  const Expr *getInitializer() const { return cast<Expr>(Init); }
10285549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getInitializer() { return cast<Expr>(Init); }
1029e9b12198c4cc7f5687960100351b4af006c14469Steve Naroff
1030e9b12198c4cc7f5687960100351b4af006c14469Steve Naroff  bool isFileScope() const { return FileScope; }
1031aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff
10320fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner  SourceLocation getLParenLoc() const { return LParenLoc; }
10330fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner
103473d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner  virtual SourceRange getSourceRange() const {
10350fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner    // FIXME: Init should never be null.
10360fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner    if (!Init)
10370fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner      return SourceRange();
10380fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner    if (LParenLoc.isInvalid())
103973d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner      return Init->getSourceRange();
10400fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner    return SourceRange(LParenLoc, Init->getLocEnd());
104173d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner  }
1042aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff
1043aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff  static bool classof(const Stmt *T) {
1044aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff    return T->getStmtClass() == CompoundLiteralExprClass;
1045aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff  }
1046aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff  static bool classof(const CompoundLiteralExpr *) { return true; }
10471237c673c07f9d827129ba02720108816abde562Ted Kremenek
10481237c673c07f9d827129ba02720108816abde562Ted Kremenek  // Iterators
10491237c673c07f9d827129ba02720108816abde562Ted Kremenek  virtual child_iterator child_begin();
10501237c673c07f9d827129ba02720108816abde562Ted Kremenek  virtual child_iterator child_end();
10514b7d9ca9fd65a5a68e907b1b7effe33bf1e93629Ted Kremenek
10524b7d9ca9fd65a5a68e907b1b7effe33bf1e93629Ted Kremenek  virtual void EmitImpl(llvm::Serializer& S) const;
1053e2563ca02a519c2ad6d64dfed87d6e86c5d3c072Sam Bishop  static CompoundLiteralExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C);
1054aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff};
1055aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff
105649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// CastExpr - Base class for type casts, including both implicit
105749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// casts (ImplicitCastExpr) and explicit casts that have some
105849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// representation in the source code (ExplicitCastExpr's derived
105949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// classes).
10600835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidisclass CastExpr : public Expr {
10610835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis  Stmt *Op;
10620835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidisprotected:
10630835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis  CastExpr(StmtClass SC, QualType ty, Expr *op) :
1064898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor    Expr(SC, ty,
1065898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor         // Cast expressions are type-dependent if the type is
1066898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor         // dependent (C++ [temp.dep.expr]p3).
1067898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor         ty->isDependentType(),
1068898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor         // Cast expressions are value-dependent if the type is
1069898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor         // dependent or if the subexpression is value-dependent.
1070898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor         ty->isDependentType() || (op && op->isValueDependent())),
1071898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor    Op(op) {}
10720835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis
10730835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidispublic:
10740835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis  Expr *getSubExpr() { return cast<Expr>(Op); }
10750835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis  const Expr *getSubExpr() const { return cast<Expr>(Op); }
10760835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis
10770835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis  static bool classof(const Stmt *T) {
10789d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor    StmtClass SC = T->getStmtClass();
10799d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor    if (SC >= CXXNamedCastExprClass && SC <= CXXFunctionalCastExprClass)
10809d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor      return true;
10819d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor
10826eec8e883de118b431e3ead5b1e604a6ac68ff6bDouglas Gregor    if (SC >= ImplicitCastExprClass && SC <= CStyleCastExprClass)
10830835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis      return true;
10849d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor
10859d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor    return false;
10860835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis  }
10870835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis  static bool classof(const CastExpr *) { return true; }
10880835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis
10890835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis  // Iterators
10900835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis  virtual child_iterator child_begin();
10910835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis  virtual child_iterator child_end();
10920835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis};
10930835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis
109449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// ImplicitCastExpr - Allows us to explicitly represent implicit type
109549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// conversions, which have no direct representation in the original
109649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// source code. For example: converting T[]->T*, void f()->void
109749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// (*f)(), float->double, short->int, etc.
109849b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff///
1099bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// In C, implicit casts always produce rvalues. However, in C++, an
1100bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// implicit cast whose result is being bound to a reference will be
1101bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// an lvalue. For example:
1102bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor///
1103bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// @code
1104bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// class Base { };
1105bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// class Derived : public Base { };
1106bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// void f(Derived d) {
1107bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor///   Base& b = d; // initializer is an ImplicitCastExpr to an lvalue of type Base
1108bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// }
1109bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// @endcode
11100835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidisclass ImplicitCastExpr : public CastExpr {
1111eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor  /// LvalueCast - Whether this cast produces an lvalue.
1112eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor  bool LvalueCast;
1113eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor
111449b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroffpublic:
1115eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor  ImplicitCastExpr(QualType ty, Expr *op, bool Lvalue) :
1116b3eef68111ffc220e449be96da1747998c057790Douglas Gregor    CastExpr(ImplicitCastExprClass, ty, op), LvalueCast(Lvalue) { }
111790045e8ebabf50d6f1b3a67081a621b20b5e5341Steve Naroff
11180835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis  virtual SourceRange getSourceRange() const {
11190835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis    return getSubExpr()->getSourceRange();
11200835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis  }
112190045e8ebabf50d6f1b3a67081a621b20b5e5341Steve Naroff
1122eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor  /// isLvalueCast - Whether this cast produces an lvalue.
1123eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor  bool isLvalueCast() const { return LvalueCast; }
1124eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor
1125eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor  /// setLvalueCast - Set whether this cast produces an lvalue.
1126eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor  void setLvalueCast(bool Lvalue) { LvalueCast = Lvalue; }
1127eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor
112849b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff  static bool classof(const Stmt *T) {
112949b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff    return T->getStmtClass() == ImplicitCastExprClass;
113049b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff  }
113149b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff  static bool classof(const ImplicitCastExpr *) { return true; }
11321237c673c07f9d827129ba02720108816abde562Ted Kremenek
1133ec0aa78745f7b3bc96c20fffd1115bf26aaa0eadTed Kremenek  virtual void EmitImpl(llvm::Serializer& S) const;
1134e2563ca02a519c2ad6d64dfed87d6e86c5d3c072Sam Bishop  static ImplicitCastExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C);
113549b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff};
113649b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff
113749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// ExplicitCastExpr - An explicit cast written in the source
113849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// code.
113949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor///
114049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// This class is effectively an abstract class, because it provides
114149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// the basic representation of an explicitly-written cast without
114249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// specifying which kind of cast (C cast, functional cast, static
114349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// cast, etc.) was written; specific derived classes represent the
114449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// particular style of cast and its location information.
11455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
114649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// Unlike implicit casts, explicit cast nodes have two different
114749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// types: the type that was written into the source code, and the
114849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// actual type of the expression as determined by semantic
114949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// analysis. These types may differ slightly. For example, in C++ one
115049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// can cast to a reference type, which indicates that the resulting
115149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// expression will be an lvalue. The reference type, however, will
115249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// not be used as the type of the expression.
11530835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidisclass ExplicitCastExpr : public CastExpr {
115449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  /// TypeAsWritten - The type that this expression is casting to, as
115549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  /// written in the source code.
115649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  QualType TypeAsWritten;
115749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor
115849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregorprotected:
11598320aaaa01d931aa234fc3bce05b399ef41898d5Daniel Dunbar  ExplicitCastExpr(StmtClass SC, QualType exprTy, Expr *op, QualType writtenTy)
11608320aaaa01d931aa234fc3bce05b399ef41898d5Daniel Dunbar    : CastExpr(SC, exprTy, op), TypeAsWritten(writtenTy) {}
116149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor
116249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregorpublic:
116349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  /// getTypeAsWritten - Returns the type that this expression is
116449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  /// casting to, as written in the source code.
116549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  QualType getTypeAsWritten() const { return TypeAsWritten; }
116649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor
116749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  static bool classof(const Stmt *T) {
11689d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor    StmtClass SC = T->getStmtClass();
11696eec8e883de118b431e3ead5b1e604a6ac68ff6bDouglas Gregor    if (SC >= ExplicitCastExprClass && SC <= CStyleCastExprClass)
11709d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor      return true;
11719d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor    if (SC >= CXXNamedCastExprClass && SC <= CXXFunctionalCastExprClass)
117249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor      return true;
11739d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor
11749d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor    return false;
117549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  }
117649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  static bool classof(const ExplicitCastExpr *) { return true; }
117749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor};
117849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor
11796eec8e883de118b431e3ead5b1e604a6ac68ff6bDouglas Gregor/// CStyleCastExpr - An explicit cast in C (C99 6.5.4) or a C-style
118049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// cast in C++ (C++ [expr.cast]), which uses the syntax
118149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// (Type)expr. For example: @c (int)f.
11826eec8e883de118b431e3ead5b1e604a6ac68ff6bDouglas Gregorclass CStyleCastExpr : public ExplicitCastExpr {
1183b2f9e516327310d95840d442416084508f80c183Steve Naroff  SourceLocation LPLoc; // the location of the left paren
1184b2f9e516327310d95840d442416084508f80c183Steve Naroff  SourceLocation RPLoc; // the location of the right paren
11855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
11866eec8e883de118b431e3ead5b1e604a6ac68ff6bDouglas Gregor  CStyleCastExpr(QualType exprTy, Expr *op, QualType writtenTy,
1187b2f9e516327310d95840d442416084508f80c183Steve Naroff                    SourceLocation l, SourceLocation r) :
1188b2f9e516327310d95840d442416084508f80c183Steve Naroff    ExplicitCastExpr(CStyleCastExprClass, exprTy, op, writtenTy),
1189b2f9e516327310d95840d442416084508f80c183Steve Naroff    LPLoc(l), RPLoc(r) {}
119049b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff
1191b2f9e516327310d95840d442416084508f80c183Steve Naroff  SourceLocation getLParenLoc() const { return LPLoc; }
1192b2f9e516327310d95840d442416084508f80c183Steve Naroff  SourceLocation getRParenLoc() const { return RPLoc; }
11935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
11945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  virtual SourceRange getSourceRange() const {
1195b2f9e516327310d95840d442416084508f80c183Steve Naroff    return SourceRange(LPLoc, getSubExpr()->getSourceRange().getEnd());
11965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
11975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Stmt *T) {
11986eec8e883de118b431e3ead5b1e604a6ac68ff6bDouglas Gregor    return T->getStmtClass() == CStyleCastExprClass;
11995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
12006eec8e883de118b431e3ead5b1e604a6ac68ff6bDouglas Gregor  static bool classof(const CStyleCastExpr *) { return true; }
12019971c9ace70624987cd74645a75f4bfbc05afdf2Ted Kremenek
1202ec0aa78745f7b3bc96c20fffd1115bf26aaa0eadTed Kremenek  virtual void EmitImpl(llvm::Serializer& S) const;
12036eec8e883de118b431e3ead5b1e604a6ac68ff6bDouglas Gregor  static CStyleCastExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C);
12045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
12055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
12063fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// \brief A builtin binary operation expression such as "x + y" or "x <= y".
12073fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor///
12083fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// This expression node kind describes a builtin binary operation,
12093fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// such as "x + y" for integer values "x" and "y". The operands will
12103fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// already have been converted to appropriate types (e.g., by
12113fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// performing promotions or conversions).
12123fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor///
12133fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// In C++, where operators may be overloaded, a different kind of
12143fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// expression node (CXXOperatorCallExpr) is used to express the
12153fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// invocation of an overloaded operator with operator syntax. Within
12163fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// a C++ template, whether BinaryOperator or CXXOperatorCallExpr is
12173fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// used to store an expression "x + y" depends on the subexpressions
12183fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// for x and y. If neither x or y is type-dependent, and the "+"
12193fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// operator resolves to a built-in operation, BinaryOperator will be
12203fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// used to express the computation (x and y may still be
12213fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// value-dependent). If either x or y is type-dependent, or if the
12223fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// "+" resolves to an overloaded operator, CXXOperatorCallExpr will
12233fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// be used to express the computation.
12245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass BinaryOperator : public Expr {
12255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
12265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  enum Opcode {
12275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    // Operators listed in order of precedence.
122803d6fb99224c36935c9af9f4785cb33453c99b2bChris Lattner    // Note that additions to this should also update the StmtVisitor class.
1229224605064a4ef87d1c3d35ad1cb363f8b534012bSebastian Redl    PtrMemD, PtrMemI, // [C++ 5.5] Pointer-to-member operators.
12305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Mul, Div, Rem,    // [C99 6.5.5] Multiplicative operators.
12315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Add, Sub,         // [C99 6.5.6] Additive operators.
12325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Shl, Shr,         // [C99 6.5.7] Bitwise shift operators.
12335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    LT, GT, LE, GE,   // [C99 6.5.8] Relational operators.
12345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    EQ, NE,           // [C99 6.5.9] Equality operators.
12355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    And,              // [C99 6.5.10] Bitwise AND operator.
12365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Xor,              // [C99 6.5.11] Bitwise XOR operator.
12375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Or,               // [C99 6.5.12] Bitwise OR operator.
12385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    LAnd,             // [C99 6.5.13] Logical AND operator.
12395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    LOr,              // [C99 6.5.14] Logical OR operator.
12405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Assign, MulAssign,// [C99 6.5.16] Assignment operators.
12415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    DivAssign, RemAssign,
12425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    AddAssign, SubAssign,
12435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    ShlAssign, ShrAssign,
12445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    AndAssign, XorAssign,
12455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    OrAssign,
12465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Comma             // [C99 6.5.17] Comma operator.
12475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  };
124817d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattnerprivate:
124917d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner  enum { LHS, RHS, END_EXPR };
12505549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Stmt* SubExprs[END_EXPR];
125117d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner  Opcode Opc;
125217d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner  SourceLocation OpLoc;
125317d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattnerpublic:
12545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
125517d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner  BinaryOperator(Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy,
125617d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner                 SourceLocation opLoc)
1257898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor    : Expr(BinaryOperatorClass, ResTy,
1258898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor           lhs->isTypeDependent() || rhs->isTypeDependent(),
1259898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor           lhs->isValueDependent() || rhs->isValueDependent()),
1260898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor      Opc(opc), OpLoc(opLoc) {
12611237c673c07f9d827129ba02720108816abde562Ted Kremenek    SubExprs[LHS] = lhs;
12621237c673c07f9d827129ba02720108816abde562Ted Kremenek    SubExprs[RHS] = rhs;
12635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    assert(!isCompoundAssignmentOp() &&
12645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer           "Use ArithAssignBinaryOperator for compound assignments");
12655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
12665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
126717d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner  SourceLocation getOperatorLoc() const { return OpLoc; }
12685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  Opcode getOpcode() const { return Opc; }
12695549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); }
12705549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); }
12715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  virtual SourceRange getSourceRange() const {
12725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return SourceRange(getLHS()->getLocStart(), getRHS()->getLocEnd());
12735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
12745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
12755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// getOpcodeStr - Turn an Opcode enum value into the punctuation char it
12765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// corresponds to, e.g. "<<=".
12775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static const char *getOpcodeStr(Opcode Op);
12785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1279063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor  /// \brief Retrieve the binary opcode that corresponds to the given
1280063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor  /// overloaded operator.
1281063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor  static Opcode getOverloadedOpcode(OverloadedOperatorKind OO);
1282063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor
1283063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor  /// \brief Retrieve the overloaded operator kind that corresponds to
1284063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor  /// the given binary opcode.
1285063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor  static OverloadedOperatorKind getOverloadedOperator(Opcode Opc);
1286063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor
12875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// predicates to categorize the respective opcodes.
12885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isMultiplicativeOp() const { return Opc >= Mul && Opc <= Rem; }
12895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isAdditiveOp() const { return Opc == Add || Opc == Sub; }
12905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isShiftOp() const { return Opc == Shl || Opc == Shr; }
12915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isBitwiseOp() const { return Opc >= And && Opc <= Or; }
1292f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek
1293f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek  static bool isRelationalOp(Opcode Opc) { return Opc >= LT && Opc <= GE; }
1294f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek  bool isRelationalOp() const { return isRelationalOp(Opc); }
1295f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek
1296f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek  static bool isEqualityOp(Opcode Opc) { return Opc == EQ || Opc == NE; }
1297f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek  bool isEqualityOp() const { return isEqualityOp(Opc); }
1298f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek
1299f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek  static bool isLogicalOp(Opcode Opc) { return Opc == LAnd || Opc == LOr; }
1300f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek  bool isLogicalOp() const { return isLogicalOp(Opc); }
1301f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek
13025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isAssignmentOp() const { return Opc >= Assign && Opc <= OrAssign; }
13035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isCompoundAssignmentOp() const { return Opc > Assign && Opc <= OrAssign;}
13045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isShiftAssignOp() const { return Opc == ShlAssign || Opc == ShrAssign; }
13055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1306eb14fe839ec24c2ca14e5f094be147a34e3d3339Chris Lattner  static bool classof(const Stmt *S) {
1307eb14fe839ec24c2ca14e5f094be147a34e3d3339Chris Lattner    return S->getStmtClass() == BinaryOperatorClass ||
1308eb14fe839ec24c2ca14e5f094be147a34e3d3339Chris Lattner           S->getStmtClass() == CompoundAssignOperatorClass;
13095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
13105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const BinaryOperator *) { return true; }
13111237c673c07f9d827129ba02720108816abde562Ted Kremenek
13121237c673c07f9d827129ba02720108816abde562Ted Kremenek  // Iterators
13131237c673c07f9d827129ba02720108816abde562Ted Kremenek  virtual child_iterator child_begin();
13141237c673c07f9d827129ba02720108816abde562Ted Kremenek  virtual child_iterator child_end();
13152dc9ac73a8a34cabf261a81a1653d7379065ac61Ted Kremenek
1316ec0aa78745f7b3bc96c20fffd1115bf26aaa0eadTed Kremenek  virtual void EmitImpl(llvm::Serializer& S) const;
1317e2563ca02a519c2ad6d64dfed87d6e86c5d3c072Sam Bishop  static BinaryOperator* CreateImpl(llvm::Deserializer& D, ASTContext& C);
13181237c673c07f9d827129ba02720108816abde562Ted Kremenek
13195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprotected:
132017d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner  BinaryOperator(Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy,
132117d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner                 SourceLocation oploc, bool dead)
132217d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner    : Expr(CompoundAssignOperatorClass, ResTy), Opc(opc), OpLoc(oploc) {
13231237c673c07f9d827129ba02720108816abde562Ted Kremenek    SubExprs[LHS] = lhs;
13241237c673c07f9d827129ba02720108816abde562Ted Kremenek    SubExprs[RHS] = rhs;
13255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
13265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
13275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
13285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// CompoundAssignOperator - For compound assignments (e.g. +=), we keep
13295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// track of the type the operation is performed in.  Due to the semantics of
13305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// these operators, the operands are promoted, the aritmetic performed, an
13315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// implicit conversion back to the result type done, then the assignment takes
13325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// place.  This captures the intermediate type which the computation is done
13335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// in.
13345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass CompoundAssignOperator : public BinaryOperator {
1335ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman  QualType ComputationLHSType;
1336ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman  QualType ComputationResultType;
13375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
13385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  CompoundAssignOperator(Expr *lhs, Expr *rhs, Opcode opc,
1339ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman                         QualType ResType, QualType CompLHSType,
1340ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman                         QualType CompResultType,
134117d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner                         SourceLocation OpLoc)
134217d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner    : BinaryOperator(lhs, rhs, opc, ResType, OpLoc, true),
1343ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman      ComputationLHSType(CompLHSType),
1344ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman      ComputationResultType(CompResultType) {
13455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    assert(isCompoundAssignmentOp() &&
13465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer           "Only should be used for compound assignments");
13475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
13485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1349ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman  // The two computation types are the type the LHS is converted
1350ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman  // to for the computation and the type of the result; the two are
1351ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman  // distinct in a few cases (specifically, int+=ptr and ptr-=ptr).
1352ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman  QualType getComputationLHSType() const { return ComputationLHSType; }
1353ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman  QualType getComputationResultType() const { return ComputationResultType; }
13545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
13555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const CompoundAssignOperator *) { return true; }
13565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Stmt *S) {
1357eb14fe839ec24c2ca14e5f094be147a34e3d3339Chris Lattner    return S->getStmtClass() == CompoundAssignOperatorClass;
13585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
135983efb151a0c1df8cb8fb25d6dbb6c0f12f07f60aTed Kremenek
1360ec0aa78745f7b3bc96c20fffd1115bf26aaa0eadTed Kremenek  virtual void EmitImpl(llvm::Serializer& S) const;
1361e2563ca02a519c2ad6d64dfed87d6e86c5d3c072Sam Bishop  static CompoundAssignOperator* CreateImpl(llvm::Deserializer& D,
1362e2563ca02a519c2ad6d64dfed87d6e86c5d3c072Sam Bishop                                            ASTContext& C);
13635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
13645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
13655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ConditionalOperator - The ?: operator.  Note that LHS may be null when the
13665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// GNU "missing LHS" extension is in use.
13675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
13685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass ConditionalOperator : public Expr {
13691237c673c07f9d827129ba02720108816abde562Ted Kremenek  enum { COND, LHS, RHS, END_EXPR };
13705549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Stmt* SubExprs[END_EXPR]; // Left/Middle/Right hand sides.
13715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
13725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ConditionalOperator(Expr *cond, Expr *lhs, Expr *rhs, QualType t)
1373898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor    : Expr(ConditionalOperatorClass, t,
1374898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor           // FIXME: the type of the conditional operator doesn't
1375898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor           // depend on the type of the conditional, but the standard
1376898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor           // seems to imply that it could. File a bug!
1377898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor           ((lhs && lhs->isTypeDependent()) || (rhs && rhs->isTypeDependent())),
1378898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor           (cond->isValueDependent() ||
1379898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor            (lhs && lhs->isValueDependent()) ||
1380898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor            (rhs && rhs->isValueDependent()))) {
13811237c673c07f9d827129ba02720108816abde562Ted Kremenek    SubExprs[COND] = cond;
13821237c673c07f9d827129ba02720108816abde562Ted Kremenek    SubExprs[LHS] = lhs;
13831237c673c07f9d827129ba02720108816abde562Ted Kremenek    SubExprs[RHS] = rhs;
13841237c673c07f9d827129ba02720108816abde562Ted Kremenek  }
13855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1386395a2abf0028968d85958610e393e067885dc14fTed Kremenek  // getCond - Return the expression representing the condition for
1387395a2abf0028968d85958610e393e067885dc14fTed Kremenek  //  the ?: operator.
13885549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getCond() const { return cast<Expr>(SubExprs[COND]); }
1389395a2abf0028968d85958610e393e067885dc14fTed Kremenek
1390395a2abf0028968d85958610e393e067885dc14fTed Kremenek  // getTrueExpr - Return the subexpression representing the value of the ?:
1391395a2abf0028968d85958610e393e067885dc14fTed Kremenek  //  expression if the condition evaluates to true.  In most cases this value
1392395a2abf0028968d85958610e393e067885dc14fTed Kremenek  //  will be the same as getLHS() except a GCC extension allows the left
1393395a2abf0028968d85958610e393e067885dc14fTed Kremenek  //  subexpression to be omitted, and instead of the condition be returned.
1394395a2abf0028968d85958610e393e067885dc14fTed Kremenek  //  e.g: x ?: y is shorthand for x ? x : y, except that the expression "x"
1395395a2abf0028968d85958610e393e067885dc14fTed Kremenek  //  is only evaluated once.
1396395a2abf0028968d85958610e393e067885dc14fTed Kremenek  Expr *getTrueExpr() const {
13975549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek    return cast<Expr>(SubExprs[LHS] ? SubExprs[LHS] : SubExprs[COND]);
1398395a2abf0028968d85958610e393e067885dc14fTed Kremenek  }
1399395a2abf0028968d85958610e393e067885dc14fTed Kremenek
1400395a2abf0028968d85958610e393e067885dc14fTed Kremenek  // getTrueExpr - Return the subexpression representing the value of the ?:
1401395a2abf0028968d85958610e393e067885dc14fTed Kremenek  // expression if the condition evaluates to false. This is the same as getRHS.
14025549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getFalseExpr() const { return cast<Expr>(SubExprs[RHS]); }
1403395a2abf0028968d85958610e393e067885dc14fTed Kremenek
14045549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getLHS() const { return cast_or_null<Expr>(SubExprs[LHS]); }
14055549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); }
14065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
14075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  virtual SourceRange getSourceRange() const {
14085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return SourceRange(getCond()->getLocStart(), getRHS()->getLocEnd());
14095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
14105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Stmt *T) {
14115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return T->getStmtClass() == ConditionalOperatorClass;
14125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
14135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const ConditionalOperator *) { return true; }
14141237c673c07f9d827129ba02720108816abde562Ted Kremenek
14151237c673c07f9d827129ba02720108816abde562Ted Kremenek  // Iterators
14161237c673c07f9d827129ba02720108816abde562Ted Kremenek  virtual child_iterator child_begin();
14171237c673c07f9d827129ba02720108816abde562Ted Kremenek  virtual child_iterator child_end();
1418aa33763cc3dfa2fcb4fdb3c5b4be0c37f8d8f8e9Ted Kremenek
1419ec0aa78745f7b3bc96c20fffd1115bf26aaa0eadTed Kremenek  virtual void EmitImpl(llvm::Serializer& S) const;
1420e2563ca02a519c2ad6d64dfed87d6e86c5d3c072Sam Bishop  static ConditionalOperator* CreateImpl(llvm::Deserializer& D, ASTContext& C);
14215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
14225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
14236481a57fefbf1a313ff439028470fe4c27a3b7a3Chris Lattner/// AddrLabelExpr - The GNU address of label extension, representing &&label.
14246481a57fefbf1a313ff439028470fe4c27a3b7a3Chris Lattnerclass AddrLabelExpr : public Expr {
14255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation AmpAmpLoc, LabelLoc;
14265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  LabelStmt *Label;
14275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
14286481a57fefbf1a313ff439028470fe4c27a3b7a3Chris Lattner  AddrLabelExpr(SourceLocation AALoc, SourceLocation LLoc, LabelStmt *L,
14296481a57fefbf1a313ff439028470fe4c27a3b7a3Chris Lattner                QualType t)
14306481a57fefbf1a313ff439028470fe4c27a3b7a3Chris Lattner    : Expr(AddrLabelExprClass, t), AmpAmpLoc(AALoc), LabelLoc(LLoc), Label(L) {}
14315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
14325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  virtual SourceRange getSourceRange() const {
14335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return SourceRange(AmpAmpLoc, LabelLoc);
14345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
14355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
14365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  LabelStmt *getLabel() const { return Label; }
14375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
14385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Stmt *T) {
14396481a57fefbf1a313ff439028470fe4c27a3b7a3Chris Lattner    return T->getStmtClass() == AddrLabelExprClass;
14405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
14416481a57fefbf1a313ff439028470fe4c27a3b7a3Chris Lattner  static bool classof(const AddrLabelExpr *) { return true; }
14421237c673c07f9d827129ba02720108816abde562Ted Kremenek
14431237c673c07f9d827129ba02720108816abde562Ted Kremenek  // Iterators
14441237c673c07f9d827129ba02720108816abde562Ted Kremenek  virtual child_iterator child_begin();
14451237c673c07f9d827129ba02720108816abde562Ted Kremenek  virtual child_iterator child_end();
1446aa33763cc3dfa2fcb4fdb3c5b4be0c37f8d8f8e9Ted Kremenek
1447ec0aa78745f7b3bc96c20fffd1115bf26aaa0eadTed Kremenek  virtual void EmitImpl(llvm::Serializer& S) const;
1448e2563ca02a519c2ad6d64dfed87d6e86c5d3c072Sam Bishop  static AddrLabelExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C);
14495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
1450ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner
1451ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner/// StmtExpr - This is the GNU Statement Expression extension: ({int X=4; X;}).
1452ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner/// The StmtExpr contains a single CompoundStmt node, which it evaluates and
1453ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner/// takes the value of the last subexpression.
1454ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattnerclass StmtExpr : public Expr {
14555549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Stmt *SubStmt;
1456ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner  SourceLocation LParenLoc, RParenLoc;
1457ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattnerpublic:
1458d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff  StmtExpr(CompoundStmt *substmt, QualType T,
1459d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff           SourceLocation lp, SourceLocation rp) :
1460d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff    Expr(StmtExprClass, T), SubStmt(substmt),  LParenLoc(lp), RParenLoc(rp) { }
1461ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner
14625549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  CompoundStmt *getSubStmt() { return cast<CompoundStmt>(SubStmt); }
14635549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  const CompoundStmt *getSubStmt() const { return cast<CompoundStmt>(SubStmt); }
1464ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner
1465ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner  virtual SourceRange getSourceRange() const {
1466ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner    return SourceRange(LParenLoc, RParenLoc);
1467ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner  }
14685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1469026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner  SourceLocation getLParenLoc() const { return LParenLoc; }
1470026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner  SourceLocation getRParenLoc() const { return RParenLoc; }
1471026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner
1472ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner  static bool classof(const Stmt *T) {
1473ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner    return T->getStmtClass() == StmtExprClass;
1474ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner  }
1475ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner  static bool classof(const StmtExpr *) { return true; }
14761237c673c07f9d827129ba02720108816abde562Ted Kremenek
14771237c673c07f9d827129ba02720108816abde562Ted Kremenek  // Iterators
14781237c673c07f9d827129ba02720108816abde562Ted Kremenek  virtual child_iterator child_begin();
14791237c673c07f9d827129ba02720108816abde562Ted Kremenek  virtual child_iterator child_end();
1480aa33763cc3dfa2fcb4fdb3c5b4be0c37f8d8f8e9Ted Kremenek
1481ec0aa78745f7b3bc96c20fffd1115bf26aaa0eadTed Kremenek  virtual void EmitImpl(llvm::Serializer& S) const;
1482e2563ca02a519c2ad6d64dfed87d6e86c5d3c072Sam Bishop  static StmtExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C);
1483ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner};
1484ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner
1485d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff/// TypesCompatibleExpr - GNU builtin-in function __builtin_type_compatible_p.
1486d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff/// This AST node represents a function that returns 1 if two *types* (not
1487d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff/// expressions) are compatible. The result of this built-in function can be
1488d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff/// used in integer constant expressions.
1489d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroffclass TypesCompatibleExpr : public Expr {
1490d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff  QualType Type1;
1491d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff  QualType Type2;
1492363bcff47df2fda3cfcfcd994b7888157df58c43Steve Naroff  SourceLocation BuiltinLoc, RParenLoc;
1493d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroffpublic:
1494363bcff47df2fda3cfcfcd994b7888157df58c43Steve Naroff  TypesCompatibleExpr(QualType ReturnType, SourceLocation BLoc,
1495d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff                      QualType t1, QualType t2, SourceLocation RP) :
1496d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff    Expr(TypesCompatibleExprClass, ReturnType), Type1(t1), Type2(t2),
1497363bcff47df2fda3cfcfcd994b7888157df58c43Steve Naroff    BuiltinLoc(BLoc), RParenLoc(RP) {}
1498d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff
14997f28fe8e00ec4fac17977374d8da491f873a3b05Steve Naroff  QualType getArgType1() const { return Type1; }
15007f28fe8e00ec4fac17977374d8da491f873a3b05Steve Naroff  QualType getArgType2() const { return Type2; }
1501ec0550fa3653d46560bf4484a2e988329c228e39Steve Naroff
1502d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff  virtual SourceRange getSourceRange() const {
1503363bcff47df2fda3cfcfcd994b7888157df58c43Steve Naroff    return SourceRange(BuiltinLoc, RParenLoc);
1504d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff  }
1505d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff  static bool classof(const Stmt *T) {
1506d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff    return T->getStmtClass() == TypesCompatibleExprClass;
1507d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff  }
1508d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff  static bool classof(const TypesCompatibleExpr *) { return true; }
15091237c673c07f9d827129ba02720108816abde562Ted Kremenek
15101237c673c07f9d827129ba02720108816abde562Ted Kremenek  // Iterators
15111237c673c07f9d827129ba02720108816abde562Ted Kremenek  virtual child_iterator child_begin();
15121237c673c07f9d827129ba02720108816abde562Ted Kremenek  virtual child_iterator child_end();
1513d17c24ff8597fe0dee4210639d225bc4f7c5ac04Daniel Dunbar
1514d17c24ff8597fe0dee4210639d225bc4f7c5ac04Daniel Dunbar  virtual void EmitImpl(llvm::Serializer& S) const;
1515d17c24ff8597fe0dee4210639d225bc4f7c5ac04Daniel Dunbar  static TypesCompatibleExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C);
1516d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff};
1517d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff
1518d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// ShuffleVectorExpr - clang-specific builtin-in function
1519d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// __builtin_shufflevector.
1520d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// This AST node represents a operator that does a constant
1521d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// shuffle, similar to LLVM's shufflevector instruction. It takes
1522d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// two vectors and a variable number of constant indices,
1523d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// and returns the appropriately shuffled vector.
1524d38617c8a50f9729c254ab76cd359af797c6739bEli Friedmanclass ShuffleVectorExpr : public Expr {
1525d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  SourceLocation BuiltinLoc, RParenLoc;
1526d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman
1527d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  // SubExprs - the list of values passed to the __builtin_shufflevector
1528d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  // function. The first two are vectors, and the rest are constant
1529d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  // indices.  The number of values in this list is always
1530d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  // 2+the number of indices in the vector type.
15315549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Stmt **SubExprs;
1532d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  unsigned NumExprs;
1533d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman
1534d38617c8a50f9729c254ab76cd359af797c6739bEli Friedmanpublic:
1535d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  ShuffleVectorExpr(Expr **args, unsigned nexpr,
1536d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman                    QualType Type, SourceLocation BLoc,
1537d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman                    SourceLocation RP) :
1538d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman    Expr(ShuffleVectorExprClass, Type), BuiltinLoc(BLoc),
1539f809e3bd0c3d063f22ba34981072dae306ca9272Ted Kremenek    RParenLoc(RP), NumExprs(nexpr) {
1540f809e3bd0c3d063f22ba34981072dae306ca9272Ted Kremenek
15415549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek    SubExprs = new Stmt*[nexpr];
1542d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman    for (unsigned i = 0; i < nexpr; i++)
1543d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman      SubExprs[i] = args[i];
1544d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  }
1545d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman
1546d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  virtual SourceRange getSourceRange() const {
1547d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman    return SourceRange(BuiltinLoc, RParenLoc);
1548d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  }
1549d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  static bool classof(const Stmt *T) {
1550d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman    return T->getStmtClass() == ShuffleVectorExprClass;
1551d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  }
1552d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  static bool classof(const ShuffleVectorExpr *) { return true; }
1553d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman
1554d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  ~ShuffleVectorExpr() {
1555d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman    delete [] SubExprs;
1556d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  }
1557d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman
1558d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  /// getNumSubExprs - Return the size of the SubExprs array.  This includes the
1559d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  /// constant expression, the actual arguments passed in, and the function
1560d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  /// pointers.
1561d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  unsigned getNumSubExprs() const { return NumExprs; }
1562d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman
1563d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  /// getExpr - Return the Expr at the specified index.
1564d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  Expr *getExpr(unsigned Index) {
1565d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman    assert((Index < NumExprs) && "Arg access out of range!");
15665549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek    return cast<Expr>(SubExprs[Index]);
1567d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  }
1568d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  const Expr *getExpr(unsigned Index) const {
1569d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman    assert((Index < NumExprs) && "Arg access out of range!");
15705549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek    return cast<Expr>(SubExprs[Index]);
1571d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  }
1572d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman
1573dde8c94873976632e3ada4d8d067e1e244184d51Eli Friedman  unsigned getShuffleMaskIdx(ASTContext &Ctx, unsigned N) {
1574dde8c94873976632e3ada4d8d067e1e244184d51Eli Friedman    assert((N < NumExprs - 2) && "Shuffle idx out of range!");
1575a5d1cb7ef3f0780540e7fd7180399fd220ef0210Daniel Dunbar    return getExpr(N+2)->getIntegerConstantExprValue(Ctx).getZExtValue();
1576d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  }
1577d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman
1578d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  // Iterators
1579d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  virtual child_iterator child_begin();
1580d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  virtual child_iterator child_end();
1581d17c24ff8597fe0dee4210639d225bc4f7c5ac04Daniel Dunbar
1582d17c24ff8597fe0dee4210639d225bc4f7c5ac04Daniel Dunbar  virtual void EmitImpl(llvm::Serializer& S) const;
1583d17c24ff8597fe0dee4210639d225bc4f7c5ac04Daniel Dunbar  static ShuffleVectorExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C);
1584d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman};
1585d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman
1586d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff/// ChooseExpr - GNU builtin-in function __builtin_choose_expr.
1587d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff/// This AST node is similar to the conditional operator (?:) in C, with
1588d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff/// the following exceptions:
15897976932a1c256d447316ffac58e9821417725e34Eli Friedman/// - the test expression must be a integer constant expression.
15907976932a1c256d447316ffac58e9821417725e34Eli Friedman/// - the expression returned acts like the chosen subexpression in every
15917976932a1c256d447316ffac58e9821417725e34Eli Friedman///   visible way: the type is the same as that of the chosen subexpression,
15927976932a1c256d447316ffac58e9821417725e34Eli Friedman///   and all predicates (whether it's an l-value, whether it's an integer
15937976932a1c256d447316ffac58e9821417725e34Eli Friedman///   constant expression, etc.) return the same result as for the chosen
15947976932a1c256d447316ffac58e9821417725e34Eli Friedman///   sub-expression.
1595d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroffclass ChooseExpr : public Expr {
15961237c673c07f9d827129ba02720108816abde562Ted Kremenek  enum { COND, LHS, RHS, END_EXPR };
15975549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Stmt* SubExprs[END_EXPR]; // Left/Middle/Right hand sides.
1598d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff  SourceLocation BuiltinLoc, RParenLoc;
1599d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroffpublic:
1600d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff  ChooseExpr(SourceLocation BLoc, Expr *cond, Expr *lhs, Expr *rhs, QualType t,
1601d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff             SourceLocation RP)
1602d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff    : Expr(ChooseExprClass, t),
16031237c673c07f9d827129ba02720108816abde562Ted Kremenek      BuiltinLoc(BLoc), RParenLoc(RP) {
16041237c673c07f9d827129ba02720108816abde562Ted Kremenek      SubExprs[COND] = cond;
16051237c673c07f9d827129ba02720108816abde562Ted Kremenek      SubExprs[LHS] = lhs;
16061237c673c07f9d827129ba02720108816abde562Ted Kremenek      SubExprs[RHS] = rhs;
16071237c673c07f9d827129ba02720108816abde562Ted Kremenek    }
16087976932a1c256d447316ffac58e9821417725e34Eli Friedman
16097976932a1c256d447316ffac58e9821417725e34Eli Friedman  /// isConditionTrue - Return whether the condition is true (i.e. not
16107976932a1c256d447316ffac58e9821417725e34Eli Friedman  /// equal to zero).
161127437caadea35f84d550cd29f024fcf3ea240eecChris Lattner  bool isConditionTrue(ASTContext &C) const;
16127976932a1c256d447316ffac58e9821417725e34Eli Friedman
16137976932a1c256d447316ffac58e9821417725e34Eli Friedman  /// getChosenSubExpr - Return the subexpression chosen according to the
16147976932a1c256d447316ffac58e9821417725e34Eli Friedman  /// condition.
16157976932a1c256d447316ffac58e9821417725e34Eli Friedman  Expr *getChosenSubExpr(ASTContext &C) const {
16167976932a1c256d447316ffac58e9821417725e34Eli Friedman    return isConditionTrue(C) ? getLHS() : getRHS();
16177976932a1c256d447316ffac58e9821417725e34Eli Friedman  }
16187976932a1c256d447316ffac58e9821417725e34Eli Friedman
16195549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getCond() const { return cast<Expr>(SubExprs[COND]); }
16205549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); }
16215549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); }
16221237c673c07f9d827129ba02720108816abde562Ted Kremenek
1623d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff  virtual SourceRange getSourceRange() const {
1624d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff    return SourceRange(BuiltinLoc, RParenLoc);
1625d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff  }
1626d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff  static bool classof(const Stmt *T) {
1627d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff    return T->getStmtClass() == ChooseExprClass;
1628d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff  }
1629d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff  static bool classof(const ChooseExpr *) { return true; }
16301237c673c07f9d827129ba02720108816abde562Ted Kremenek
16311237c673c07f9d827129ba02720108816abde562Ted Kremenek  // Iterators
16321237c673c07f9d827129ba02720108816abde562Ted Kremenek  virtual child_iterator child_begin();
16331237c673c07f9d827129ba02720108816abde562Ted Kremenek  virtual child_iterator child_end();
1634d17c24ff8597fe0dee4210639d225bc4f7c5ac04Daniel Dunbar
1635d17c24ff8597fe0dee4210639d225bc4f7c5ac04Daniel Dunbar  virtual void EmitImpl(llvm::Serializer& S) const;
1636d17c24ff8597fe0dee4210639d225bc4f7c5ac04Daniel Dunbar  static ChooseExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C);
1637d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff};
1638d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff
16392d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// GNUNullExpr - Implements the GNU __null extension, which is a name
16402d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// for a null pointer constant that has integral type (e.g., int or
16412d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// long) and is the same size and alignment as a pointer. The __null
16422d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// extension is typically only used by system headers, which define
16432d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// NULL as __null in C++ rather than using 0 (which is an integer
16442d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// that may not match the size of a pointer).
16452d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregorclass GNUNullExpr : public Expr {
16462d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor  /// TokenLoc - The location of the __null keyword.
16472d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor  SourceLocation TokenLoc;
16482d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor
16492d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregorpublic:
16502d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor  GNUNullExpr(QualType Ty, SourceLocation Loc)
16512d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor    : Expr(GNUNullExprClass, Ty), TokenLoc(Loc) { }
16522d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor
16532d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor  /// getTokenLocation - The location of the __null token.
16542d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor  SourceLocation getTokenLocation() const { return TokenLoc; }
16552d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor
16562d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor  virtual SourceRange getSourceRange() const {
16572d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor    return SourceRange(TokenLoc);
16582d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor  }
16592d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor  static bool classof(const Stmt *T) {
16602d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor    return T->getStmtClass() == GNUNullExprClass;
16612d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor  }
16622d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor  static bool classof(const GNUNullExpr *) { return true; }
16632d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor
16642d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor  // Iterators
16652d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor  virtual child_iterator child_begin();
16662d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor  virtual child_iterator child_end();
16672d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor
16682d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor  virtual void EmitImpl(llvm::Serializer& S) const;
16692d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor  static GNUNullExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C);
16702d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor};
16712d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor
16727c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson/// VAArgExpr, used for the builtin function __builtin_va_start.
16737c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlssonclass VAArgExpr : public Expr {
16745549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Stmt *Val;
16757c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson  SourceLocation BuiltinLoc, RParenLoc;
16767c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlssonpublic:
16777c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson  VAArgExpr(SourceLocation BLoc, Expr* e, QualType t, SourceLocation RPLoc)
16787c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson    : Expr(VAArgExprClass, t),
16797c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson      Val(e),
16807c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson      BuiltinLoc(BLoc),
16817c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson      RParenLoc(RPLoc) { }
16827c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson
16835549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  const Expr *getSubExpr() const { return cast<Expr>(Val); }
16845549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getSubExpr() { return cast<Expr>(Val); }
16857c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson  virtual SourceRange getSourceRange() const {
16867c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson    return SourceRange(BuiltinLoc, RParenLoc);
16877c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson  }
16887c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson  static bool classof(const Stmt *T) {
16897c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson    return T->getStmtClass() == VAArgExprClass;
16907c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson  }
16917c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson  static bool classof(const VAArgExpr *) { return true; }
16927c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson
16937c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson  // Iterators
16947c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson  virtual child_iterator child_begin();
16957c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson  virtual child_iterator child_end();
1696d17c24ff8597fe0dee4210639d225bc4f7c5ac04Daniel Dunbar
1697d17c24ff8597fe0dee4210639d225bc4f7c5ac04Daniel Dunbar  virtual void EmitImpl(llvm::Serializer& S) const;
1698d17c24ff8597fe0dee4210639d225bc4f7c5ac04Daniel Dunbar  static VAArgExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C);
16997c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson};
17007c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson
17014c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// @brief Describes an C or C++ initializer list.
17024c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor///
17034c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// InitListExpr describes an initializer list, which can be used to
17044c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// initialize objects of different types, including
17054c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// struct/class/union types, arrays, and vectors. For example:
17064c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor///
17074c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// @code
17084c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// struct foo x = { 1, { 2, 3 } };
17094c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// @endcode
1710196ef51bc4d008ec1c69851fb3b0f8d036065931Chris Lattner///
17114c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// Prior to semantic analysis, an initializer list will represent the
17124c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// initializer list as written by the user, but will have the
17134c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// placeholder type "void". This initializer list is called the
17144c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// syntactic form of the initializer, and may contain C99 designated
17154c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// initializers (represented as DesignatedInitExprs), initializations
17164c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// of subobject members without explicit braces, and so on. Clients
17174c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// interested in the original syntax of the initializer list should
17184c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// use the syntactic form of the initializer list.
1719196ef51bc4d008ec1c69851fb3b0f8d036065931Chris Lattner///
17204c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// After semantic analysis, the initializer list will represent the
17214c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// semantic form of the initializer, where the initializations of all
17224c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// subobjects are made explicit with nested InitListExpr nodes and
17234c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// C99 designators have been eliminated by placing the designated
17244c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// initializations into the subobject they initialize. Additionally,
17254c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// any "holes" in the initialization, where no initializer has been
17264c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// specified for a particular subobject, will be replaced with
17273498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor/// implicitly-generated ImplicitValueInitExpr expressions that
17284c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// value-initialize the subobjects. Note, however, that the
17294c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// initializer lists may still have fewer initializers than there are
17304c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// elements to initialize within the object.
1731196ef51bc4d008ec1c69851fb3b0f8d036065931Chris Lattner///
17324c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// Given the semantic form of the initializer list, one can retrieve
17334c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// the original syntactic form of that initializer list (if it
17344c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// exists) using getSyntacticForm(). Since many initializer lists
17354c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// have the same syntactic and semantic forms, getSyntacticForm() may
17364c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// return NULL, indicating that the current initializer list also
17374c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// serves as its syntactic form.
173866b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlssonclass InitListExpr : public Expr {
17395549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  std::vector<Stmt *> InitExprs;
174066b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson  SourceLocation LBraceLoc, RBraceLoc;
1741418f6c7d142e5ff4607f70cd8431d008442bafe9Chris Lattner
17424c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  /// Contains the initializer list that describes the syntactic form
17434c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  /// written in the source code.
17444c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  InitListExpr *SyntacticForm;
17454c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor
17460bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor  /// If this initializer list initializes a union, specifies which
17470bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor  /// field within the union will be initialized.
17480bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor  FieldDecl *UnionFieldInit;
17490bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor
1750a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor  /// Whether this initializer list originally had a GNU array-range
1751a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor  /// designator in it. This is a temporary marker used by CodeGen.
1752a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor  bool HadArrayRangeDesignator;
1753a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor
175466b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlssonpublic:
175566b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson  InitListExpr(SourceLocation lbraceloc, Expr **initexprs, unsigned numinits,
17564c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor               SourceLocation rbraceloc);
175766b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson
1758c5ae899b4bbf65488445316c63168079177db0edSteve Naroff  unsigned getNumInits() const { return InitExprs.size(); }
175966b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson
176066b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson  const Expr* getInit(unsigned Init) const {
1761c5ae899b4bbf65488445316c63168079177db0edSteve Naroff    assert(Init < getNumInits() && "Initializer access out of range!");
17624c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor    return cast_or_null<Expr>(InitExprs[Init]);
176366b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson  }
176466b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson
176566b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson  Expr* getInit(unsigned Init) {
1766c5ae899b4bbf65488445316c63168079177db0edSteve Naroff    assert(Init < getNumInits() && "Initializer access out of range!");
17674c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor    return cast_or_null<Expr>(InitExprs[Init]);
176866b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson  }
176966b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson
17709e8925e72f53a9e2c4633b6b48e965ed01702fe4Steve Naroff  void setInit(unsigned Init, Expr *expr) {
1771c5ae899b4bbf65488445316c63168079177db0edSteve Naroff    assert(Init < getNumInits() && "Initializer access out of range!");
17729e8925e72f53a9e2c4633b6b48e965ed01702fe4Steve Naroff    InitExprs[Init] = expr;
17739e8925e72f53a9e2c4633b6b48e965ed01702fe4Steve Naroff  }
1774c5ae899b4bbf65488445316c63168079177db0edSteve Naroff
1775fa2192042f223b5122a9e17719930f77634fd31fDouglas Gregor  /// \brief Reserve space for some number of initializers.
1776fa2192042f223b5122a9e17719930f77634fd31fDouglas Gregor  void reserveInits(unsigned NumInits);
1777fa2192042f223b5122a9e17719930f77634fd31fDouglas Gregor
17784c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  /// @brief Specify the number of initializers
17794c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  ///
17804c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  /// If there are more than @p NumInits initializers, the remaining
17814c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  /// initializers will be destroyed. If there are fewer than @p
17824c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  /// NumInits initializers, NULL expressions will be added for the
17834c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  /// unknown initializers.
17844c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  void resizeInits(ASTContext &Context, unsigned NumInits);
17854c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor
17864c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  /// @brief Updates the initializer at index @p Init with the new
17874c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  /// expression @p expr, and returns the old expression at that
17884c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  /// location.
17894c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  ///
17904c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  /// When @p Init is out of range for this initializer list, the
17914c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  /// initializer list will be extended with NULL expressions to
17924c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  /// accomodate the new entry.
17934c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  Expr *updateInit(unsigned Init, Expr *expr);
1794c5ae899b4bbf65488445316c63168079177db0edSteve Naroff
17950bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor  /// \brief If this initializes a union, specifies which field in the
17960bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor  /// union to initialize.
17970bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor  ///
17980bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor  /// Typically, this field is the first named field within the
17990bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor  /// union. However, a designated initializer can specify the
18000bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor  /// initialization of a different field within the union.
18010bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor  FieldDecl *getInitializedFieldInUnion() { return UnionFieldInit; }
18020bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor  void setInitializedFieldInUnion(FieldDecl *FD) { UnionFieldInit = FD; }
18030bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor
1804c5ae899b4bbf65488445316c63168079177db0edSteve Naroff  // Explicit InitListExpr's originate from source code (and have valid source
1805c5ae899b4bbf65488445316c63168079177db0edSteve Naroff  // locations). Implicit InitListExpr's are created by the semantic analyzer.
1806b3eef68111ffc220e449be96da1747998c057790Douglas Gregor  bool isExplicit() {
1807b3eef68111ffc220e449be96da1747998c057790Douglas Gregor    return LBraceLoc.isValid() && RBraceLoc.isValid();
1808b3eef68111ffc220e449be96da1747998c057790Douglas Gregor  }
18099e8925e72f53a9e2c4633b6b48e965ed01702fe4Steve Naroff
181087fd703e097c27d63479cb83b687d4000a22bbb1Douglas Gregor  void setRBraceLoc(SourceLocation Loc) { RBraceLoc = Loc; }
181187fd703e097c27d63479cb83b687d4000a22bbb1Douglas Gregor
18124c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  /// @brief Retrieve the initializer list that describes the
18134c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  /// syntactic form of the initializer.
18144c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  ///
18154c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  ///
18164c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  InitListExpr *getSyntacticForm() const { return SyntacticForm; }
18174c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  void setSyntacticForm(InitListExpr *Init) { SyntacticForm = Init; }
18184c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor
1819a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor  bool hadArrayRangeDesignator() const { return HadArrayRangeDesignator; }
1820a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor  void sawArrayRangeDesignator() {
1821a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor    HadArrayRangeDesignator = true;
1822a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor  }
1823a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor
182466b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson  virtual SourceRange getSourceRange() const {
182566b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson    return SourceRange(LBraceLoc, RBraceLoc);
182666b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson  }
182766b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson  static bool classof(const Stmt *T) {
182866b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson    return T->getStmtClass() == InitListExprClass;
182966b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson  }
183066b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson  static bool classof(const InitListExpr *) { return true; }
183166b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson
183266b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson  // Iterators
183366b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson  virtual child_iterator child_begin();
183466b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson  virtual child_iterator child_end();
18356336f8dbae5145eb7b1429a8ec424c44e668f7cbTed Kremenek
18367fcfa4a9b5054bc2a3bc65093f9d2e9e67a70838Ted Kremenek  typedef std::vector<Stmt *>::iterator iterator;
18377fcfa4a9b5054bc2a3bc65093f9d2e9e67a70838Ted Kremenek  typedef std::vector<Stmt *>::reverse_iterator reverse_iterator;
18387fcfa4a9b5054bc2a3bc65093f9d2e9e67a70838Ted Kremenek
18397fcfa4a9b5054bc2a3bc65093f9d2e9e67a70838Ted Kremenek  iterator begin() { return InitExprs.begin(); }
18407fcfa4a9b5054bc2a3bc65093f9d2e9e67a70838Ted Kremenek  iterator end() { return InitExprs.end(); }
18417fcfa4a9b5054bc2a3bc65093f9d2e9e67a70838Ted Kremenek  reverse_iterator rbegin() { return InitExprs.rbegin(); }
18427fcfa4a9b5054bc2a3bc65093f9d2e9e67a70838Ted Kremenek  reverse_iterator rend() { return InitExprs.rend(); }
18437fcfa4a9b5054bc2a3bc65093f9d2e9e67a70838Ted Kremenek
18447fcfa4a9b5054bc2a3bc65093f9d2e9e67a70838Ted Kremenek  // Serailization.
18456336f8dbae5145eb7b1429a8ec424c44e668f7cbTed Kremenek  virtual void EmitImpl(llvm::Serializer& S) const;
1846e2563ca02a519c2ad6d64dfed87d6e86c5d3c072Sam Bishop  static InitListExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C);
18476336f8dbae5145eb7b1429a8ec424c44e668f7cbTed Kremenek
18486336f8dbae5145eb7b1429a8ec424c44e668f7cbTed Kremenekprivate:
18496336f8dbae5145eb7b1429a8ec424c44e668f7cbTed Kremenek  // Used by serializer.
185028a309e387a0a69b0c055c1565aa147fc695f906Chris Lattner  InitListExpr() : Expr(InitListExprClass, QualType()) {}
185166b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson};
185266b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson
185305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// @brief Represents a C99 designated initializer expression.
185405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor///
185505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// A designated initializer expression (C99 6.7.8) contains one or
185605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// more designators (which can be field designators, array
185705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// designators, or GNU array-range designators) followed by an
185805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// expression that initializes the field or element(s) that the
185905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// designators refer to. For example, given:
186005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor///
186105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// @code
186205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// struct point {
186305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor///   double x;
186405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor///   double y;
186505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// };
186605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// struct point ptarray[10] = { [2].y = 1.0, [2].x = 2.0, [0].x = 1.0 };
186705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// @endcode
186805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor///
186905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// The InitListExpr contains three DesignatedInitExprs, the first of
187005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// which covers @c [2].y=1.0. This DesignatedInitExpr will have two
187105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// designators, one array designator for @c [2] followed by one field
187205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// designator for @c .y. The initalization expression will be 1.0.
187305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregorclass DesignatedInitExpr : public Expr {
187405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// The location of the '=' or ':' prior to the actual initializer
187505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// expression.
187605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  SourceLocation EqualOrColonLoc;
187705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
1878eeae8f072748affce25ab4064982626361293390Douglas Gregor  /// Whether this designated initializer used the GNU deprecated
187905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// syntax rather than the C99 '=' syntax.
1880eeae8f072748affce25ab4064982626361293390Douglas Gregor  bool GNUSyntax : 1;
188105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
188205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// The number of designators in this initializer expression.
188305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  unsigned NumDesignators : 15;
188405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
188505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// The number of subexpressions of this initializer expression,
188605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// which contains both the initializer and any additional
188705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// expressions used by array and array-range designators.
188805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  unsigned NumSubExprs : 16;
188905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
189005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  DesignatedInitExpr(QualType Ty, unsigned NumDesignators,
1891eeae8f072748affce25ab4064982626361293390Douglas Gregor                     SourceLocation EqualOrColonLoc, bool GNUSyntax,
189205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor                     unsigned NumSubExprs)
189305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    : Expr(DesignatedInitExprClass, Ty),
1894eeae8f072748affce25ab4064982626361293390Douglas Gregor      EqualOrColonLoc(EqualOrColonLoc), GNUSyntax(GNUSyntax),
189505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      NumDesignators(NumDesignators), NumSubExprs(NumSubExprs) { }
189605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
189705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregorpublic:
189805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// A field designator, e.g., ".x".
189905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  struct FieldDesignator {
190005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// Refers to the field that is being initialized. The low bit
190105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// of this field determines whether this is actually a pointer
190205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// to an IdentifierInfo (if 1) or a FieldDecl (if 0). When
190305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// initially constructed, a field designator will store an
190405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// IdentifierInfo*. After semantic analysis has resolved that
190505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// name, the field designator will instead store a FieldDecl*.
190605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    uintptr_t NameOrField;
190705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
190805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// The location of the '.' in the designated initializer.
190905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    unsigned DotLoc;
191005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
191105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// The location of the field name in the designated initializer.
191205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    unsigned FieldLoc;
191305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  };
191405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
191505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// An array or GNU array-range designator, e.g., "[9]" or "[10..15]".
191605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  struct ArrayOrRangeDesignator {
191705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// Location of the first index expression within the designated
191805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// initializer expression's list of subexpressions.
191905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    unsigned Index;
192005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// The location of the '[' starting the array range designator.
192105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    unsigned LBracketLoc;
192205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// The location of the ellipsis separating the start and end
192305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// indices. Only valid for GNU array-range designators.
192405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    unsigned EllipsisLoc;
192505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// The location of the ']' terminating the array range designator.
192605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    unsigned RBracketLoc;
192705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  };
192805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
192905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// @brief Represents a single C99 designator.
193005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  ///
193105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// @todo This class is infuriatingly similar to clang::Designator,
193205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// but minor differences (storing indices vs. storing pointers)
193305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// keep us from reusing it. Try harder, later, to rectify these
193405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// differences.
193505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  class Designator {
193605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// @brief The kind of designator this describes.
193705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    enum {
193805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      FieldDesignator,
193905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      ArrayDesignator,
194005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      ArrayRangeDesignator
194105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    } Kind;
194205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
194305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    union {
194405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      /// A field designator, e.g., ".x".
194505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      struct FieldDesignator Field;
194605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      /// An array or GNU array-range designator, e.g., "[9]" or "[10..15]".
194705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      struct ArrayOrRangeDesignator ArrayOrRange;
194805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    };
194905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    friend class DesignatedInitExpr;
195005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
195105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  public:
195205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// @brief Initializes a field designator.
195305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    Designator(const IdentifierInfo *FieldName, SourceLocation DotLoc,
195405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor               SourceLocation FieldLoc)
195505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      : Kind(FieldDesignator) {
195605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      Field.NameOrField = reinterpret_cast<uintptr_t>(FieldName) | 0x01;
195705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      Field.DotLoc = DotLoc.getRawEncoding();
195805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      Field.FieldLoc = FieldLoc.getRawEncoding();
195905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    }
196005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
196105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// @brief Initializes an array designator.
196205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    Designator(unsigned Index, SourceLocation LBracketLoc,
196305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor               SourceLocation RBracketLoc)
196405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      : Kind(ArrayDesignator) {
196505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      ArrayOrRange.Index = Index;
196605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      ArrayOrRange.LBracketLoc = LBracketLoc.getRawEncoding();
196705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      ArrayOrRange.EllipsisLoc = SourceLocation().getRawEncoding();
196805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      ArrayOrRange.RBracketLoc = RBracketLoc.getRawEncoding();
196905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    }
197005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
197105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// @brief Initializes a GNU array-range designator.
197205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    Designator(unsigned Index, SourceLocation LBracketLoc,
197305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor               SourceLocation EllipsisLoc, SourceLocation RBracketLoc)
197405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      : Kind(ArrayRangeDesignator) {
197505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      ArrayOrRange.Index = Index;
197605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      ArrayOrRange.LBracketLoc = LBracketLoc.getRawEncoding();
197705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      ArrayOrRange.EllipsisLoc = EllipsisLoc.getRawEncoding();
197805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      ArrayOrRange.RBracketLoc = RBracketLoc.getRawEncoding();
197905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    }
198005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
198105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    bool isFieldDesignator() const { return Kind == FieldDesignator; }
198205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    bool isArrayDesignator() const { return Kind == ArrayDesignator; }
198305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    bool isArrayRangeDesignator() const { return Kind == ArrayRangeDesignator; }
198405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
198505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    IdentifierInfo * getFieldName();
198605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
198705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    FieldDecl *getField() {
198805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      assert(Kind == FieldDesignator && "Only valid on a field designator");
198905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      if (Field.NameOrField & 0x01)
199005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor        return 0;
199105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      else
199205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor        return reinterpret_cast<FieldDecl *>(Field.NameOrField);
199305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    }
199405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
199505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    void setField(FieldDecl *FD) {
199605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      assert(Kind == FieldDesignator && "Only valid on a field designator");
199705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      Field.NameOrField = reinterpret_cast<uintptr_t>(FD);
199805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    }
199905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
200087f55cf59e82f246d8605733e9300d0c5f6830a6Douglas Gregor    SourceLocation getDotLoc() const {
200187f55cf59e82f246d8605733e9300d0c5f6830a6Douglas Gregor      assert(Kind == FieldDesignator && "Only valid on a field designator");
200287f55cf59e82f246d8605733e9300d0c5f6830a6Douglas Gregor      return SourceLocation::getFromRawEncoding(Field.DotLoc);
200387f55cf59e82f246d8605733e9300d0c5f6830a6Douglas Gregor    }
200487f55cf59e82f246d8605733e9300d0c5f6830a6Douglas Gregor
200505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    SourceLocation getFieldLoc() const {
200605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      assert(Kind == FieldDesignator && "Only valid on a field designator");
200705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      return SourceLocation::getFromRawEncoding(Field.FieldLoc);
200805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    }
200905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
201005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    SourceLocation getLBracketLoc() const {
201105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      assert((Kind == ArrayDesignator || Kind == ArrayRangeDesignator) &&
201205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor             "Only valid on an array or array-range designator");
201305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      return SourceLocation::getFromRawEncoding(ArrayOrRange.LBracketLoc);
201405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    }
201505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
201605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    SourceLocation getRBracketLoc() const {
201705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      assert((Kind == ArrayDesignator || Kind == ArrayRangeDesignator) &&
201805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor             "Only valid on an array or array-range designator");
201905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      return SourceLocation::getFromRawEncoding(ArrayOrRange.RBracketLoc);
202005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    }
202105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
202205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    SourceLocation getEllipsisLoc() const {
202305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      assert(Kind == ArrayRangeDesignator &&
202405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor             "Only valid on an array-range designator");
202505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      return SourceLocation::getFromRawEncoding(ArrayOrRange.EllipsisLoc);
202605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    }
20274c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor
20284c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor    SourceLocation getStartLocation() const {
20294c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor      if (Kind == FieldDesignator)
20304c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor        return getDotLoc().isInvalid()? getFieldLoc() : getDotLoc();
20314c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor      else
20324c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor        return getLBracketLoc();
20334c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor    }
203405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  };
203505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
203605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  static DesignatedInitExpr *Create(ASTContext &C, Designator *Designators,
203705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor                                    unsigned NumDesignators,
203805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor                                    Expr **IndexExprs, unsigned NumIndexExprs,
203905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor                                    SourceLocation EqualOrColonLoc,
2040eeae8f072748affce25ab4064982626361293390Douglas Gregor                                    bool GNUSyntax, Expr *Init);
204105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
204205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// @brief Returns the number of designators in this initializer.
204305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  unsigned size() const { return NumDesignators; }
204405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
204505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  // Iterator access to the designators.
204605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  typedef Designator* designators_iterator;
204705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  designators_iterator designators_begin();
204805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  designators_iterator designators_end();
204905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
205005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  Expr *getArrayIndex(const Designator& D);
205105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  Expr *getArrayRangeStart(const Designator& D);
205205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  Expr *getArrayRangeEnd(const Designator& D);
205305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
205405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// @brief Retrieve the location of the '=' that precedes the
205505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// initializer value itself, if present.
205605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  SourceLocation getEqualOrColonLoc() const { return EqualOrColonLoc; }
205705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
205805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// @brief Determines whether this designated initializer used the
2059eeae8f072748affce25ab4064982626361293390Douglas Gregor  /// deprecated GNU syntax for designated initializers.
2060eeae8f072748affce25ab4064982626361293390Douglas Gregor  bool usesGNUSyntax() const { return GNUSyntax; }
206105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
206205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// @brief Retrieve the initializer value.
206305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  Expr *getInit() const {
206405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    return cast<Expr>(*const_cast<DesignatedInitExpr*>(this)->child_begin());
206505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  }
206605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
206705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  void setInit(Expr *init) {
206805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    *child_begin() = init;
206905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  }
207005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
207105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  virtual SourceRange getSourceRange() const;
207205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
207305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  static bool classof(const Stmt *T) {
207405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    return T->getStmtClass() == DesignatedInitExprClass;
207505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  }
207605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  static bool classof(const DesignatedInitExpr *) { return true; }
207705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
207805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  // Iterators
207905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  virtual child_iterator child_begin();
20803498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor  virtual child_iterator child_end();
20813498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor};
20823498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor
20833498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor/// \brief Represents an implicitly-generated value initialization of
20843498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor/// an object of a given type.
20853498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor///
20861a51b4a11b7db25cac2134249711ecaaf9d1c0a8Douglas Gregor/// Implicit value initializations occur within semantic initializer
20871a51b4a11b7db25cac2134249711ecaaf9d1c0a8Douglas Gregor/// list expressions (InitListExpr) as placeholders for subobject
20883498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor/// initializations not explicitly specified by the user.
20891a51b4a11b7db25cac2134249711ecaaf9d1c0a8Douglas Gregor///
20901a51b4a11b7db25cac2134249711ecaaf9d1c0a8Douglas Gregor/// \see InitListExpr
20913498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregorclass ImplicitValueInitExpr : public Expr {
20923498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregorpublic:
20933498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor  explicit ImplicitValueInitExpr(QualType ty)
20943498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor    : Expr(ImplicitValueInitExprClass, ty) { }
20953498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor
20963498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor  static bool classof(const Stmt *T) {
20973498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor    return T->getStmtClass() == ImplicitValueInitExprClass;
20983498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor  }
20993498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor  static bool classof(const ImplicitValueInitExpr *) { return true; }
21003498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor
21013498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor  virtual SourceRange getSourceRange() const {
21023498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor    return SourceRange();
21033498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor  }
21043498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor
21053498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor  // Iterators
21063498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor  virtual child_iterator child_begin();
210705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  virtual child_iterator child_end();
210805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor};
210905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
21104eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff//===----------------------------------------------------------------------===//
21114eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff// Clang Extensions
21124eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff//===----------------------------------------------------------------------===//
21134eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff
2114a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner
2115a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner/// ExtVectorElementExpr - This represents access to specific elements of a
2116a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner/// vector, and may occur on the left hand side or right hand side.  For example
2117a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner/// the following is legal:  "V.xy = V.zw" if V is a 4 element extended vector.
2118a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner///
211973525de7fd9bdd534382dc89a24f1f76db3e04b9Chris Lattner/// Note that the base may have either vector or pointer to vector type, just
212073525de7fd9bdd534382dc89a24f1f76db3e04b9Chris Lattner/// like a struct field reference.
212173525de7fd9bdd534382dc89a24f1f76db3e04b9Chris Lattner///
2122a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattnerclass ExtVectorElementExpr : public Expr {
2123a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  Stmt *Base;
2124a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  IdentifierInfo &Accessor;
2125a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  SourceLocation AccessorLoc;
2126a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattnerpublic:
2127a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  ExtVectorElementExpr(QualType ty, Expr *base, IdentifierInfo &accessor,
2128a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner                       SourceLocation loc)
2129a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner    : Expr(ExtVectorElementExprClass, ty),
2130a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner      Base(base), Accessor(accessor), AccessorLoc(loc) {}
2131a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner
2132a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  const Expr *getBase() const { return cast<Expr>(Base); }
2133a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  Expr *getBase() { return cast<Expr>(Base); }
2134a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner
2135a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  IdentifierInfo &getAccessor() const { return Accessor; }
2136a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner
2137a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  /// getNumElements - Get the number of components being selected.
2138a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  unsigned getNumElements() const;
2139a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner
2140a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  /// containsDuplicateElements - Return true if any element access is
2141a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  /// repeated.
2142a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  bool containsDuplicateElements() const;
2143a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner
2144a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  /// getEncodedElementAccess - Encode the elements accessed into an llvm
2145a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  /// aggregate Constant of ConstantInt(s).
2146a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  void getEncodedElementAccess(llvm::SmallVectorImpl<unsigned> &Elts) const;
2147a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner
2148a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  virtual SourceRange getSourceRange() const {
2149a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner    return SourceRange(getBase()->getLocStart(), AccessorLoc);
2150a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  }
2151a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner
21522140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner  /// isArrow - Return true if the base expression is a pointer to vector,
21532140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner  /// return false if the base expression is a vector.
21542140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner  bool isArrow() const;
21552140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner
2156a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  static bool classof(const Stmt *T) {
2157a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner    return T->getStmtClass() == ExtVectorElementExprClass;
2158a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  }
2159a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  static bool classof(const ExtVectorElementExpr *) { return true; }
2160a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner
2161a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  // Iterators
2162a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  virtual child_iterator child_begin();
2163a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  virtual child_iterator child_end();
2164d17c24ff8597fe0dee4210639d225bc4f7c5ac04Daniel Dunbar
2165d17c24ff8597fe0dee4210639d225bc4f7c5ac04Daniel Dunbar  virtual void EmitImpl(llvm::Serializer& S) const;
2166d17c24ff8597fe0dee4210639d225bc4f7c5ac04Daniel Dunbar  static ExtVectorElementExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C);
2167a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner};
2168a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner
2169a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner
217056ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff/// BlockExpr - Adaptor class for mixing a BlockDecl with expressions.
21719c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff/// ^{ statement-body }   or   ^(int arg1, float arg2){ statement-body }
21724eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroffclass BlockExpr : public Expr {
217356ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroffprotected:
217456ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff  BlockDecl *TheBlock;
2175b83d287bc7f47d36fb0751a481e2ef9308b37252Mike Stump  bool HasBlockDeclRefExprs;
21764eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroffpublic:
2177b83d287bc7f47d36fb0751a481e2ef9308b37252Mike Stump  BlockExpr(BlockDecl *BD, QualType ty, bool hasBlockDeclRefExprs)
2178b83d287bc7f47d36fb0751a481e2ef9308b37252Mike Stump    : Expr(BlockExprClass, ty),
2179b83d287bc7f47d36fb0751a481e2ef9308b37252Mike Stump      TheBlock(BD), HasBlockDeclRefExprs(hasBlockDeclRefExprs) {}
21809c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff
2181d5cab5435371b8cc74a9e05ebd40b5995ebad149Anders Carlsson  const BlockDecl *getBlockDecl() const { return TheBlock; }
218256ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff  BlockDecl *getBlockDecl() { return TheBlock; }
218356ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff
218456ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff  // Convenience functions for probing the underlying BlockDecl.
218556ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff  SourceLocation getCaretLocation() const;
218656ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff  const Stmt *getBody() const;
218756ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff  Stmt *getBody();
21889c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff
21899c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff  virtual SourceRange getSourceRange() const {
219056ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff    return SourceRange(getCaretLocation(), getBody()->getLocEnd());
21919c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff  }
21929c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff
219356ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff  /// getFunctionType - Return the underlying function type for this block.
219456ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff  const FunctionType *getFunctionType() const;
219556ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff
2196b83d287bc7f47d36fb0751a481e2ef9308b37252Mike Stump  /// hasBlockDeclRefExprs - Return true iff the block has BlockDeclRefExpr
2197b83d287bc7f47d36fb0751a481e2ef9308b37252Mike Stump  /// contained inside.
2198b83d287bc7f47d36fb0751a481e2ef9308b37252Mike Stump  bool hasBlockDeclRefExprs() const { return HasBlockDeclRefExprs; }
2199b83d287bc7f47d36fb0751a481e2ef9308b37252Mike Stump
22004eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  static bool classof(const Stmt *T) {
22019c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff    return T->getStmtClass() == BlockExprClass;
22024eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  }
22034eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  static bool classof(const BlockExpr *) { return true; }
22044eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff
22054eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  // Iterators
22064eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  virtual child_iterator child_begin();
22074eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  virtual child_iterator child_end();
220856ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff
22094eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  virtual void EmitImpl(llvm::Serializer& S) const;
22109c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff  static BlockExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C);
22114eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff};
22129c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff
22134eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff/// BlockDeclRefExpr - A reference to a declared variable, function,
22144eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff/// enum, etc.
22154eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroffclass BlockDeclRefExpr : public Expr {
22164eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  ValueDecl *D;
22174eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  SourceLocation Loc;
22184eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  bool IsByRef;
22194eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroffpublic:
22204eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  BlockDeclRefExpr(ValueDecl *d, QualType t, SourceLocation l, bool ByRef) :
22214eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff       Expr(BlockDeclRefExprClass, t), D(d), Loc(l), IsByRef(ByRef) {}
22224eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff
22234eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  ValueDecl *getDecl() { return D; }
22244eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  const ValueDecl *getDecl() const { return D; }
22254eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
22264eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff
22274eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  bool isByRef() const { return IsByRef; }
22284eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff
22294eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  static bool classof(const Stmt *T) {
22304eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff    return T->getStmtClass() == BlockDeclRefExprClass;
22314eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  }
22324eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  static bool classof(const BlockDeclRefExpr *) { return true; }
22334eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff
22344eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  // Iterators
22354eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  virtual child_iterator child_begin();
22364eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  virtual child_iterator child_end();
22374eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff
22384eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  virtual void EmitImpl(llvm::Serializer& S) const;
22394eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  static BlockDeclRefExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C);
22404eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff};
22414eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff
22425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}  // end namespace clang
22435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
22445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#endif
2245