Expr.h revision ad0fe03b897f9486191e75c8d90c3ffa9b4fd6a5
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"
18478851c3ed6bd784e7377dffd8e57b200c1b9ba9Benjamin Kramer#include "clang/AST/Decl.h"
195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include "clang/AST/Stmt.h"
205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include "clang/AST/Type.h"
21161755a09898c95d21bfff33707da9ca41cd53c5John McCall#include "clang/AST/DeclAccessPair.h"
225baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall#include "clang/AST/OperationKinds.h"
23709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek#include "clang/AST/ASTVector.h"
2471a7605977113c795edd44fcbd2302ad49506653Argyrios Kyrtzidis#include "clang/AST/TemplateBase.h"
2531dfd642d5ac33c4ee0cfe1d7a1d4da455dcc7a4Akira Hatanaka#include "clang/Basic/TargetInfo.h"
26f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne#include "clang/Basic/TypeTraits.h"
275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include "llvm/ADT/APSInt.h"
28525a05093a4816af961fe2bc6b8a81c17e2e26c2Chris Lattner#include "llvm/ADT/APFloat.h"
293b8d116703db8018f855cbb4733ace426422623bNate Begeman#include "llvm/ADT/SmallVector.h"
30b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar#include "llvm/ADT/StringRef.h"
31aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar#include "llvm/Support/Compiler.h"
32403ba3522d1b1c97ae5fad81c1a2c4b3a754e1c1Nick Lewycky#include <cctype>
335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace clang {
35590b6646ef747d2f7b42e5f40487ff07642d7b6fChris Lattner  class ASTContext;
36c44eec6dd29ee9415cbd38a35deff4c8b67abb6aAnders Carlsson  class APValue;
37c4a1dea2dc56bd1357ec91b829a0b9e68229a13eDaniel Dunbar  class Decl;
38c4a1dea2dc56bd1357ec91b829a0b9e68229a13eDaniel Dunbar  class IdentifierInfo;
39c4a1dea2dc56bd1357ec91b829a0b9e68229a13eDaniel Dunbar  class ParmVarDecl;
408e9bebdea69c590dedfbf27374114cb76fe12fbdDouglas Gregor  class NamedDecl;
41c4a1dea2dc56bd1357ec91b829a0b9e68229a13eDaniel Dunbar  class ValueDecl;
4256ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff  class BlockDecl;
43409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson  class CXXBaseSpecifier;
4488a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor  class CXXOperatorCallExpr;
4588a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor  class CXXMemberCallExpr;
46f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall  class ObjCPropertyRefExpr;
4756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  class OpaqueValueExpr;
4888a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor
497ab9d574d27ecee1f130e5755aa403e5ab529b6bAnders Carlsson/// \brief A simple array of base specifiers.
50686775deca8b8685eb90801495880e3abdd844c2Chris Lattnertypedef SmallVector<CXXBaseSpecifier*, 4> CXXCastPath;
517ab9d574d27ecee1f130e5755aa403e5ab529b6bAnders Carlsson
525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Expr - This represents one expression.  Note that Expr's are subclasses of
535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Stmt.  This allows an expression to be transparently used any place a Stmt
545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// is required.
555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass Expr : public Stmt {
575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType TR;
58898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor
598e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCallprotected:
60f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall  Expr(StmtClass SC, QualType T, ExprValueKind VK, ExprObjectKind OK,
61ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie       bool TD, bool VD, bool ID, bool ContainsUnexpandedParameterPack)
62ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    : Stmt(SC)
63561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor  {
648e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    ExprBits.TypeDependent = TD;
658e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    ExprBits.ValueDependent = VD;
66561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor    ExprBits.InstantiationDependent = ID;
67f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    ExprBits.ValueKind = VK;
68f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    ExprBits.ObjectKind = OK;
69bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor    ExprBits.ContainsUnexpandedParameterPack = ContainsUnexpandedParameterPack;
70898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor    setType(T);
71898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  }
72898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor
730b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor  /// \brief Construct an empty expression.
740b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor  explicit Expr(StmtClass SC, EmptyShell) : Stmt(SC) { }
750b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor
761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumppublic:
77f7c2aa0b049272d8f318988c1965760dcb852578Douglas Gregor  QualType getType() const { return TR; }
781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  void setType(QualType t) {
799d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor    // In C++, the type of an expression is always adjusted so that it
809d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor    // will not have reference type an expression will never have
819d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor    // reference type (C++ [expr]p6). Use
829d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor    // QualType::getNonReferenceType() to retrieve the non-reference
839d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor    // type. Additionally, inspect Expr::isLvalue to determine whether
849d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor    // an expression that is adjusted in this manner should be
859d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor    // considered an lvalue.
86905d11d53aeb6b26744f44fedc2b2820c7a62df6Douglas Gregor    assert((t.isNull() || !t->isReferenceType()) &&
878320aaaa01d931aa234fc3bce05b399ef41898d5Daniel Dunbar           "Expressions can't have reference type");
88f7c2aa0b049272d8f318988c1965760dcb852578Douglas Gregor
891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    TR = t;
909d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor  }
9177ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek
92898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// isValueDependent - Determines whether this expression is
93898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// value-dependent (C++ [temp.dep.constexpr]). For example, the
94898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// array bound of "Chars" in the following example is
951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// value-dependent.
96898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// @code
97898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// template<int Size, char (&Chars)[Size]> struct meta_string;
98898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// @endcode
998e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  bool isValueDependent() const { return ExprBits.ValueDependent; }
100898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor
1010b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor  /// \brief Set whether this expression is value-dependent or not.
102ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  void setValueDependent(bool VD) {
103ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    ExprBits.ValueDependent = VD;
104561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor    if (VD)
105561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor      ExprBits.InstantiationDependent = true;
106561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor  }
1070b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor
108898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// isTypeDependent - Determines whether this expression is
109898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// type-dependent (C++ [temp.dep.expr]), which means that its type
110898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// could change from one template instantiation to the next. For
111898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// example, the expressions "x" and "x + y" are type-dependent in
112898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// the following code, but "y" is not type-dependent:
113898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// @code
1141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// template<typename T>
115898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// void add(T x, int y) {
116898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  ///   x + y;
117898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// }
118898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// @endcode
1198e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  bool isTypeDependent() const { return ExprBits.TypeDependent; }
120898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor
1210b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor  /// \brief Set whether this expression is type-dependent or not.
122ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  void setTypeDependent(bool TD) {
123ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    ExprBits.TypeDependent = TD;
124561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor    if (TD)
125561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor      ExprBits.InstantiationDependent = true;
126561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor  }
127561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor
128561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor  /// \brief Whether this expression is instantiation-dependent, meaning that
129561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor  /// it depends in some way on a template parameter, even if neither its type
130561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor  /// nor (constant) value can change due to the template instantiation.
131561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor  ///
132561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor  /// In the following example, the expression \c sizeof(sizeof(T() + T())) is
133561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor  /// instantiation-dependent (since it involves a template parameter \c T), but
134561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor  /// is neither type- nor value-dependent, since the type of the inner
135561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor  /// \c sizeof is known (\c std::size_t) and therefore the size of the outer
136561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor  /// \c sizeof is known.
137561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor  ///
138561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor  /// \code
139561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor  /// template<typename T>
140561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor  /// void f(T x, T y) {
141561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor  ///   sizeof(sizeof(T() + T());
142561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor  /// }
143561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor  /// \endcode
144561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor  ///
145ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  bool isInstantiationDependent() const {
146ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    return ExprBits.InstantiationDependent;
147561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor  }
148ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
149561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor  /// \brief Set whether this expression is instantiation-dependent or not.
150ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  void setInstantiationDependent(bool ID) {
151561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor    ExprBits.InstantiationDependent = ID;
152561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor  }
1530b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor
154d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  /// \brief Whether this expression contains an unexpanded parameter
155d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  /// pack (for C++0x variadic templates).
156d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  ///
157d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  /// Given the following function template:
158d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  ///
159d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  /// \code
160d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  /// template<typename F, typename ...Types>
161d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  /// void forward(const F &f, Types &&...args) {
162d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  ///   f(static_cast<Types&&>(args)...);
163d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  /// }
164d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  /// \endcode
165d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  ///
166d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  /// The expressions \c args and \c static_cast<Types&&>(args) both
167d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  /// contain parameter packs.
168ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  bool containsUnexpandedParameterPack() const {
169ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    return ExprBits.ContainsUnexpandedParameterPack;
170d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  }
171d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor
172bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor  /// \brief Set the bit that describes whether this expression
173bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor  /// contains an unexpanded parameter pack.
174bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor  void setContainsUnexpandedParameterPack(bool PP = true) {
175bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor    ExprBits.ContainsUnexpandedParameterPack = PP;
176bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor  }
177bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor
1785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// getExprLoc - Return the preferred location for the arrow when diagnosing
1795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// a problem with a generic expression.
1804f311183be3d923da9fbe8702c453688b4c426a9Daniel Dunbar  SourceLocation getExprLoc() const LLVM_READONLY;
1811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
182026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner  /// isUnusedResultAWarning - Return true if this immediate expression should
183a6115068cde719142eb394db88612c185cabd05bEli Friedman  /// be warned about if the result is unused.  If so, fill in expr, location,
184a6115068cde719142eb394db88612c185cabd05bEli Friedman  /// and ranges with expr to warn on and source locations/ranges appropriate
185a6115068cde719142eb394db88612c185cabd05bEli Friedman  /// for a warning.
186a6115068cde719142eb394db88612c185cabd05bEli Friedman  bool isUnusedResultAWarning(const Expr *&WarnExpr, SourceLocation &Loc,
187a6115068cde719142eb394db88612c185cabd05bEli Friedman                              SourceRange &R1, SourceRange &R2,
188a6115068cde719142eb394db88612c185cabd05bEli Friedman                              ASTContext &Ctx) const;
1891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1907eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall  /// isLValue - True if this expression is an "l-value" according to
1917eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall  /// the rules of the current language.  C and C++ give somewhat
1927eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall  /// different rules for this concept, but in general, the result of
1937eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall  /// an l-value expression identifies a specific object whereas the
1947eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall  /// result of an r-value expression is a value detached from any
1957eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall  /// specific storage.
1965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ///
1977eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall  /// C++0x divides the concept of "r-value" into pure r-values
1987eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall  /// ("pr-values") and so-called expiring values ("x-values"), which
1997eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall  /// identify specific objects that can be safely cannibalized for
2007eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall  /// their resources.  This is an unfortunate abuse of terminology on
2017eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall  /// the part of the C++ committee.  In Clang, when we say "r-value",
2027eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall  /// we generally mean a pr-value.
2037eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall  bool isLValue() const { return getValueKind() == VK_LValue; }
2047eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall  bool isRValue() const { return getValueKind() == VK_RValue; }
2057eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall  bool isXValue() const { return getValueKind() == VK_XValue; }
2067eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall  bool isGLValue() const { return getValueKind() != VK_RValue; }
2077eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall
2087eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall  enum LValueClassification {
2095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    LV_Valid,
2105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    LV_NotObjectType,
2115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    LV_IncompleteVoidType,
212fec0b49c3fa621fbf63e420f3d54a5bb3a0265d2Steve Naroff    LV_DuplicateVectorComponents,
21386f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor    LV_InvalidExpression,
214077f490d0a514dcc448475f33f799934252b85a7Fariborz Jahanian    LV_InvalidMessageExpression,
2152514a309204341798f96912ce7a90841bea59727Fariborz Jahanian    LV_MemberFunction,
216e9ff443040cb571ae2c5c2626c4dc9a9a812d84aFariborz Jahanian    LV_SubObjCPropertySetting,
21736d02af300a207242f0486b4255420d8be796b21Richard Smith    LV_ClassTemporary,
21836d02af300a207242f0486b4255420d8be796b21Richard Smith    LV_ArrayTemporary
2195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  };
2207eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall  /// Reasons why an expression might not be an l-value.
2217eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall  LValueClassification ClassifyLValue(ASTContext &Ctx) const;
22253202857c60214d80950a975e6e52aebf30bd16aEli Friedman
2235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  enum isModifiableLvalueResult {
2245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    MLV_Valid,
2255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    MLV_NotObjectType,
2265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    MLV_IncompleteVoidType,
227fec0b49c3fa621fbf63e420f3d54a5bb3a0265d2Steve Naroff    MLV_DuplicateVectorComponents,
2285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    MLV_InvalidExpression,
229ca354faa7e9b99af17070c82b9662a5fca76422cChris Lattner    MLV_LValueCast,           // Specialized form of MLV_InvalidExpression.
2305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    MLV_IncompleteType,
2315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    MLV_ConstQualified,
2324f6a7d7ead09b439216c32f2de806a998aeb222aSteve Naroff    MLV_ArrayType,
233ba8d2d684e74a20bef03828c21c991d222c7e9e5Fariborz Jahanian    MLV_ReadonlyProperty,
23486f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor    MLV_NoSetterProperty,
2352514a309204341798f96912ce7a90841bea59727Fariborz Jahanian    MLV_MemberFunction,
236e9ff443040cb571ae2c5c2626c4dc9a9a812d84aFariborz Jahanian    MLV_SubObjCPropertySetting,
237077f490d0a514dcc448475f33f799934252b85a7Fariborz Jahanian    MLV_InvalidMessageExpression,
23836d02af300a207242f0486b4255420d8be796b21Richard Smith    MLV_ClassTemporary,
23936d02af300a207242f0486b4255420d8be796b21Richard Smith    MLV_ArrayTemporary
2405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  };
241ad0fe03b897f9486191e75c8d90c3ffa9b4fd6a5Ted Kremenek  /// isModifiableLvalue - C99 6.3.2.1: an lvalue that does not have array type,
242ad0fe03b897f9486191e75c8d90c3ffa9b4fd6a5Ted Kremenek  /// does not have an incomplete type, does not have a const-qualified type,
243ad0fe03b897f9486191e75c8d90c3ffa9b4fd6a5Ted Kremenek  /// and if it is a structure or union, does not have any member (including,
244ad0fe03b897f9486191e75c8d90c3ffa9b4fd6a5Ted Kremenek  /// recursively, any member or element of all contained aggregates or unions)
245ad0fe03b897f9486191e75c8d90c3ffa9b4fd6a5Ted Kremenek  /// with a const-qualified type.
246ad0fe03b897f9486191e75c8d90c3ffa9b4fd6a5Ted Kremenek  ///
247ad0fe03b897f9486191e75c8d90c3ffa9b4fd6a5Ted Kremenek  /// \param Loc [in,out] - A source location which *may* be filled
248ad0fe03b897f9486191e75c8d90c3ffa9b4fd6a5Ted Kremenek  /// in with the location of the expression making this a
249ad0fe03b897f9486191e75c8d90c3ffa9b4fd6a5Ted Kremenek  /// non-modifiable lvalue, if specified.
25044e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar  isModifiableLvalueResult isModifiableLvalue(ASTContext &Ctx,
25144e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar                                              SourceLocation *Loc = 0) const;
2521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2532111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  /// \brief The return type of classify(). Represents the C++0x expression
2542111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  ///        taxonomy.
2552111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  class Classification {
2562111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  public:
2572111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl    /// \brief The various classification results. Most of these mean prvalue.
2582111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl    enum Kinds {
2592111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl      CL_LValue,
2602111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl      CL_XValue,
2612111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl      CL_Function, // Functions cannot be lvalues in C.
2622111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl      CL_Void, // Void cannot be an lvalue in C.
2631c860d5640e8eebb11a5d515a761242b66761b0bPeter Collingbourne      CL_AddressableVoid, // Void expression whose address can be taken in C.
2642111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl      CL_DuplicateVectorComponents, // A vector shuffle with dupes.
2652111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl      CL_MemberFunction, // An expression referring to a member function
2662111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl      CL_SubObjCPropertySetting,
26736d02af300a207242f0486b4255420d8be796b21Richard Smith      CL_ClassTemporary, // A temporary of class type, or subobject thereof.
26836d02af300a207242f0486b4255420d8be796b21Richard Smith      CL_ArrayTemporary, // A temporary of array type.
269077f490d0a514dcc448475f33f799934252b85a7Fariborz Jahanian      CL_ObjCMessageRValue, // ObjC message is an rvalue
2702111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl      CL_PRValue // A prvalue for any other reason, of any other type
2712111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl    };
2722111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl    /// \brief The results of modification testing.
2732111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl    enum ModifiableType {
2742111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl      CM_Untested, // testModifiable was false.
2752111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl      CM_Modifiable,
2762111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl      CM_RValue, // Not modifiable because it's an rvalue
2772111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl      CM_Function, // Not modifiable because it's a function; C++ only
2782111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl      CM_LValueCast, // Same as CM_RValue, but indicates GCC cast-as-lvalue ext
2792111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl      CM_NoSetterProperty,// Implicit assignment to ObjC property without setter
2802111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl      CM_ConstQualified,
2812111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl      CM_ArrayType,
2822111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl      CM_IncompleteType
2832111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl    };
2842111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl
2852111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  private:
2862111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl    friend class Expr;
2872111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl
2882111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl    unsigned short Kind;
2892111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl    unsigned short Modifiable;
2902111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl
2912111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl    explicit Classification(Kinds k, ModifiableType m)
2922111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl      : Kind(k), Modifiable(m)
2932111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl    {}
2942111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl
2952111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  public:
2962111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl    Classification() {}
2972111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl
2982111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl    Kinds getKind() const { return static_cast<Kinds>(Kind); }
2992111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl    ModifiableType getModifiable() const {
3002111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl      assert(Modifiable != CM_Untested && "Did not test for modifiability.");
3012111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl      return static_cast<ModifiableType>(Modifiable);
3022111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl    }
3032111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl    bool isLValue() const { return Kind == CL_LValue; }
3042111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl    bool isXValue() const { return Kind == CL_XValue; }
3052111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl    bool isGLValue() const { return Kind <= CL_XValue; }
3062111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl    bool isPRValue() const { return Kind >= CL_Function; }
3072111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl    bool isRValue() const { return Kind >= CL_XValue; }
3082111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl    bool isModifiable() const { return getModifiable() == CM_Modifiable; }
309ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3102c9a03f3b249e4d9d76eadf758a33142adc4d0a4Douglas Gregor    /// \brief Create a simple, modifiably lvalue
3112c9a03f3b249e4d9d76eadf758a33142adc4d0a4Douglas Gregor    static Classification makeSimpleLValue() {
3122c9a03f3b249e4d9d76eadf758a33142adc4d0a4Douglas Gregor      return Classification(CL_LValue, CM_Modifiable);
3132c9a03f3b249e4d9d76eadf758a33142adc4d0a4Douglas Gregor    }
314ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3152111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  };
316369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl  /// \brief Classify - Classify this expression according to the C++0x
3172111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  ///        expression taxonomy.
3182111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  ///
3192111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  /// C++0x defines ([basic.lval]) a new taxonomy of expressions to replace the
3202111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  /// old lvalue vs rvalue. This function determines the type of expression this
3212111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  /// is. There are three expression types:
3222111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  /// - lvalues are classical lvalues as in C++03.
3232111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  /// - prvalues are equivalent to rvalues in C++03.
3242111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  /// - xvalues are expressions yielding unnamed rvalue references, e.g. a
3252111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  ///   function returning an rvalue reference.
3262111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  /// lvalues and xvalues are collectively referred to as glvalues, while
3272111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  /// prvalues and xvalues together form rvalues.
3282111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  Classification Classify(ASTContext &Ctx) const {
3292111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl    return ClassifyImpl(Ctx, 0);
3302111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  }
3312111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl
332369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl  /// \brief ClassifyModifiable - Classify this expression according to the
3332111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  ///        C++0x expression taxonomy, and see if it is valid on the left side
3342111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  ///        of an assignment.
3352111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  ///
3362111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  /// This function extends classify in that it also tests whether the
3372111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  /// expression is modifiable (C99 6.3.2.1p1).
3382111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  /// \param Loc A source location that might be filled with a relevant location
3392111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  ///            if the expression is not modifiable.
3402111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  Classification ClassifyModifiable(ASTContext &Ctx, SourceLocation &Loc) const{
3412111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl    return ClassifyImpl(Ctx, &Loc);
3422111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  }
3432111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl
344f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall  /// getValueKindForType - Given a formal return or parameter type,
345f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall  /// give its value kind.
346f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall  static ExprValueKind getValueKindForType(QualType T) {
347f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    if (const ReferenceType *RT = T->getAs<ReferenceType>())
3480943168ac126b8047f30f6bd215fbe7db14d61baJohn McCall      return (isa<LValueReferenceType>(RT)
3490943168ac126b8047f30f6bd215fbe7db14d61baJohn McCall                ? VK_LValue
3500943168ac126b8047f30f6bd215fbe7db14d61baJohn McCall                : (RT->getPointeeType()->isFunctionType()
3510943168ac126b8047f30f6bd215fbe7db14d61baJohn McCall                     ? VK_LValue : VK_XValue));
352f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    return VK_RValue;
353f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall  }
354f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall
355f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall  /// getValueKind - The value kind that this expression produces.
356f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall  ExprValueKind getValueKind() const {
357f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    return static_cast<ExprValueKind>(ExprBits.ValueKind);
358f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall  }
359f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall
360f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall  /// getObjectKind - The object kind that this expression produces.
361f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall  /// Object kinds are meaningful only for expressions that yield an
362f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall  /// l-value or x-value.
363f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall  ExprObjectKind getObjectKind() const {
364f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    return static_cast<ExprObjectKind>(ExprBits.ObjectKind);
365f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall  }
366f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall
36756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  bool isOrdinaryOrBitFieldObject() const {
36856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall    ExprObjectKind OK = getObjectKind();
36956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall    return (OK == OK_Ordinary || OK == OK_BitField);
37056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  }
37156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall
372f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall  /// setValueKind - Set the value kind produced by this expression.
373f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall  void setValueKind(ExprValueKind Cat) { ExprBits.ValueKind = Cat; }
374f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall
375f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall  /// setObjectKind - Set the object kind produced by this expression.
376f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall  void setObjectKind(ExprObjectKind Cat) { ExprBits.ObjectKind = Cat; }
377f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall
3782111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redlprivate:
3792111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  Classification ClassifyImpl(ASTContext &Ctx, SourceLocation *Loc) const;
3802111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl
3812111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redlpublic:
3822111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl
38333bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor  /// \brief If this expression refers to a bit-field, retrieve the
38433bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor  /// declaration of that bit-field.
38533bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor  FieldDecl *getBitField();
3865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
38738d068e8f13a119b89a3b8b0f79f35cab1ffd09aAnders Carlsson  const FieldDecl *getBitField() const {
38838d068e8f13a119b89a3b8b0f79f35cab1ffd09aAnders Carlsson    return const_cast<Expr*>(this)->getBitField();
38938d068e8f13a119b89a3b8b0f79f35cab1ffd09aAnders Carlsson  }
3901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
391f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall  /// \brief If this expression is an l-value for an Objective C
392f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall  /// property, find the underlying property reference expression.
393f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall  const ObjCPropertyRefExpr *getObjCProperty() const;
394f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall
395093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson  /// \brief Returns whether this expression refers to a vector element.
396093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson  bool refersToVectorElement() const;
3974919dfd54e2296ca997e3d1c9dab85976bba8e95John McCall
3984919dfd54e2296ca997e3d1c9dab85976bba8e95John McCall  /// \brief Returns whether this expression has a placeholder type.
3994919dfd54e2296ca997e3d1c9dab85976bba8e95John McCall  bool hasPlaceholderType() const {
4004919dfd54e2296ca997e3d1c9dab85976bba8e95John McCall    return getType()->isPlaceholderType();
4014919dfd54e2296ca997e3d1c9dab85976bba8e95John McCall  }
4024919dfd54e2296ca997e3d1c9dab85976bba8e95John McCall
4034919dfd54e2296ca997e3d1c9dab85976bba8e95John McCall  /// \brief Returns whether this expression has a specific placeholder type.
4044919dfd54e2296ca997e3d1c9dab85976bba8e95John McCall  bool hasPlaceholderType(BuiltinType::Kind K) const {
40585def357129b6cdfd69a66ad0e6994506418a2a9John McCall    assert(BuiltinType::isPlaceholderTypeKind(K));
4064919dfd54e2296ca997e3d1c9dab85976bba8e95John McCall    if (const BuiltinType *BT = dyn_cast<BuiltinType>(getType()))
4074919dfd54e2296ca997e3d1c9dab85976bba8e95John McCall      return BT->getKind() == K;
4084919dfd54e2296ca997e3d1c9dab85976bba8e95John McCall    return false;
4094919dfd54e2296ca997e3d1c9dab85976bba8e95John McCall  }
410ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
4112b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner  /// isKnownToHaveBooleanValue - Return true if this is an integer expression
4122b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner  /// that is known to return 0 or 1.  This happens for _Bool/bool expressions
4132b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner  /// but also int expressions which are produced by things like comparisons in
4142b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner  /// C.
4152b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner  bool isKnownToHaveBooleanValue() const;
416ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
4175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// isIntegerConstantExpr - Return true if this expression is a valid integer
4185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// constant expression, and, if so, return its value in Result.  If not a
4195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// valid i-c-e, return false and fill in Loc (if specified) with the location
4205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// of the invalid expression.
421282e7e66748cc6dd14d6f7f2cb52e5373c531e61Richard Smith  ///
422282e7e66748cc6dd14d6f7f2cb52e5373c531e61Richard Smith  /// Note: This does not perform the implicit conversions required by C++11
423282e7e66748cc6dd14d6f7f2cb52e5373c531e61Richard Smith  /// [expr.const]p5.
424590b6646ef747d2f7b42e5f40487ff07642d7b6fChris Lattner  bool isIntegerConstantExpr(llvm::APSInt &Result, ASTContext &Ctx,
425590b6646ef747d2f7b42e5f40487ff07642d7b6fChris Lattner                             SourceLocation *Loc = 0,
4265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer                             bool isEvaluated = true) const;
427f48fdb0937e67f691393f9ffdf75653e5128ea13Richard Smith  bool isIntegerConstantExpr(ASTContext &Ctx, SourceLocation *Loc = 0) const;
4280e35b4ecee380c2b4c33d75da6bc2fb6f6bc7df3Richard Smith
42970488e201ccd94d4bb1ef0868cc13cca2b7d4ff6Richard Smith  /// isCXX98IntegralConstantExpr - Return true if this expression is an
43070488e201ccd94d4bb1ef0868cc13cca2b7d4ff6Richard Smith  /// integral constant expression in C++98. Can only be used in C++.
43170488e201ccd94d4bb1ef0868cc13cca2b7d4ff6Richard Smith  bool isCXX98IntegralConstantExpr(ASTContext &Ctx) const;
43270488e201ccd94d4bb1ef0868cc13cca2b7d4ff6Richard Smith
4334c3fc9b38d3723f73e4ded594cebf38c76f91d93Richard Smith  /// isCXX11ConstantExpr - Return true if this expression is a constant
4344c3fc9b38d3723f73e4ded594cebf38c76f91d93Richard Smith  /// expression in C++11. Can only be used in C++.
435282e7e66748cc6dd14d6f7f2cb52e5373c531e61Richard Smith  ///
436282e7e66748cc6dd14d6f7f2cb52e5373c531e61Richard Smith  /// Note: This does not perform the implicit conversions required by C++11
437282e7e66748cc6dd14d6f7f2cb52e5373c531e61Richard Smith  /// [expr.const]p5.
4384c3fc9b38d3723f73e4ded594cebf38c76f91d93Richard Smith  bool isCXX11ConstantExpr(ASTContext &Ctx, APValue *Result = 0,
4394c3fc9b38d3723f73e4ded594cebf38c76f91d93Richard Smith                           SourceLocation *Loc = 0) const;
4404c3fc9b38d3723f73e4ded594cebf38c76f91d93Richard Smith
441745f5147e065900267c85a5568785a1991d4838fRichard Smith  /// isPotentialConstantExpr - Return true if this function's definition
442745f5147e065900267c85a5568785a1991d4838fRichard Smith  /// might be usable in a constant expression in C++11, if it were marked
443745f5147e065900267c85a5568785a1991d4838fRichard Smith  /// constexpr. Return false if the function can never produce a constant
444745f5147e065900267c85a5568785a1991d4838fRichard Smith  /// expression, along with diagnostics describing why not.
445745f5147e065900267c85a5568785a1991d4838fRichard Smith  static bool isPotentialConstantExpr(const FunctionDecl *FD,
446745f5147e065900267c85a5568785a1991d4838fRichard Smith                                      llvm::SmallVectorImpl<
447745f5147e065900267c85a5568785a1991d4838fRichard Smith                                        PartialDiagnosticAt> &Diags);
448745f5147e065900267c85a5568785a1991d4838fRichard Smith
4490e35b4ecee380c2b4c33d75da6bc2fb6f6bc7df3Richard Smith  /// isConstantInitializer - Returns true if this expression can be emitted to
4500e35b4ecee380c2b4c33d75da6bc2fb6f6bc7df3Richard Smith  /// IR as a constant, and thus can be used as a constant initializer in C.
4514204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall  bool isConstantInitializer(ASTContext &Ctx, bool ForRef) const;
4521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4531e12c59e8f9bb76c23628c4e0d0a1dfced0b1fa0Richard Smith  /// EvalStatus is a struct with detailed info about an evaluation in progress.
4541e12c59e8f9bb76c23628c4e0d0a1dfced0b1fa0Richard Smith  struct EvalStatus {
45594deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson    /// HasSideEffects - Whether the evaluated expression has side effects.
45694deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson    /// For example, (f() && 0) can be folded, but it still has side effects.
45794deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson    bool HasSideEffects;
4581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
459dd1f29b6d686899bfd033f26e16cb1621e5549e8Richard Smith    /// Diag - If this is non-null, it will be filled in with a stack of notes
460dd1f29b6d686899bfd033f26e16cb1621e5549e8Richard Smith    /// indicating why evaluation failed (or why it failed to produce a constant
461dd1f29b6d686899bfd033f26e16cb1621e5549e8Richard Smith    /// expression).
462dd1f29b6d686899bfd033f26e16cb1621e5549e8Richard Smith    /// If the expression is unfoldable, the notes will indicate why it's not
463dd1f29b6d686899bfd033f26e16cb1621e5549e8Richard Smith    /// foldable. If the expression is foldable, but not a constant expression,
464dd1f29b6d686899bfd033f26e16cb1621e5549e8Richard Smith    /// the notes will describes why it isn't a constant expression. If the
465dd1f29b6d686899bfd033f26e16cb1621e5549e8Richard Smith    /// expression *is* a constant expression, no notes will be produced.
466dd1f29b6d686899bfd033f26e16cb1621e5549e8Richard Smith    llvm::SmallVectorImpl<PartialDiagnosticAt> *Diag;
467dd1f29b6d686899bfd033f26e16cb1621e5549e8Richard Smith
468dd1f29b6d686899bfd033f26e16cb1621e5549e8Richard Smith    EvalStatus() : HasSideEffects(false), Diag(0) {}
469e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara
470e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara    // hasSideEffects - Return true if the evaluated expression has
471e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara    // side effects.
472e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara    bool hasSideEffects() const {
473e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara      return HasSideEffects;
474e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara    }
47594deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson  };
47694deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson
4771e12c59e8f9bb76c23628c4e0d0a1dfced0b1fa0Richard Smith  /// EvalResult is a struct with detailed info about an evaluated expression.
4781e12c59e8f9bb76c23628c4e0d0a1dfced0b1fa0Richard Smith  struct EvalResult : EvalStatus {
4791e12c59e8f9bb76c23628c4e0d0a1dfced0b1fa0Richard Smith    /// Val - This is the value the expression can be folded to.
4801e12c59e8f9bb76c23628c4e0d0a1dfced0b1fa0Richard Smith    APValue Val;
4811e12c59e8f9bb76c23628c4e0d0a1dfced0b1fa0Richard Smith
4821e12c59e8f9bb76c23628c4e0d0a1dfced0b1fa0Richard Smith    // isGlobalLValue - Return true if the evaluated lvalue expression
4831e12c59e8f9bb76c23628c4e0d0a1dfced0b1fa0Richard Smith    // is global.
4841e12c59e8f9bb76c23628c4e0d0a1dfced0b1fa0Richard Smith    bool isGlobalLValue() const;
4851e12c59e8f9bb76c23628c4e0d0a1dfced0b1fa0Richard Smith  };
4861e12c59e8f9bb76c23628c4e0d0a1dfced0b1fa0Richard Smith
48751f4708c00110940ca3f337961915f2ca1668375Richard Smith  /// EvaluateAsRValue - Return true if this is a constant which we can fold to
48851f4708c00110940ca3f337961915f2ca1668375Richard Smith  /// an rvalue using any crazy technique (that has nothing to do with language
48951f4708c00110940ca3f337961915f2ca1668375Richard Smith  /// standards) that we want to, even if the expression has side-effects. If
49051f4708c00110940ca3f337961915f2ca1668375Richard Smith  /// this function returns true, it returns the folded constant in Result. If
49151f4708c00110940ca3f337961915f2ca1668375Richard Smith  /// the expression is a glvalue, an lvalue-to-rvalue conversion will be
49251f4708c00110940ca3f337961915f2ca1668375Richard Smith  /// applied.
49351f4708c00110940ca3f337961915f2ca1668375Richard Smith  bool EvaluateAsRValue(EvalResult &Result, const ASTContext &Ctx) const;
4945b45d4ef1ea3f04ec863daf8aa29be6c6e021750Anders Carlsson
495cd7a445c6b46c5585580dfb652300c8483c0cb6bJohn McCall  /// EvaluateAsBooleanCondition - Return true if this is a constant
496cd7a445c6b46c5585580dfb652300c8483c0cb6bJohn McCall  /// which we we can fold and convert to a boolean condition using
497a6b8b2c09610b8bc4330e948ece8b940c2386406Richard Smith  /// any crazy technique that we want to, even if the expression has
498a6b8b2c09610b8bc4330e948ece8b940c2386406Richard Smith  /// side-effects.
4994ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad  bool EvaluateAsBooleanCondition(bool &Result, const ASTContext &Ctx) const;
500cd7a445c6b46c5585580dfb652300c8483c0cb6bJohn McCall
50180d4b55db94db2172a04617d1a80feca6bbcea5cRichard Smith  enum SideEffectsKind { SE_NoSideEffects, SE_AllowSideEffects };
50280d4b55db94db2172a04617d1a80feca6bbcea5cRichard Smith
503a6b8b2c09610b8bc4330e948ece8b940c2386406Richard Smith  /// EvaluateAsInt - Return true if this is a constant which we can fold and
50480d4b55db94db2172a04617d1a80feca6bbcea5cRichard Smith  /// convert to an integer, using any crazy technique that we want to.
50580d4b55db94db2172a04617d1a80feca6bbcea5cRichard Smith  bool EvaluateAsInt(llvm::APSInt &Result, const ASTContext &Ctx,
50680d4b55db94db2172a04617d1a80feca6bbcea5cRichard Smith                     SideEffectsKind AllowSideEffects = SE_NoSideEffects) const;
507a6b8b2c09610b8bc4330e948ece8b940c2386406Richard Smith
50851f4708c00110940ca3f337961915f2ca1668375Richard Smith  /// isEvaluatable - Call EvaluateAsRValue to see if this expression can be
50951f4708c00110940ca3f337961915f2ca1668375Richard Smith  /// constant folded without side-effects, but discard the result.
5104ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad  bool isEvaluatable(const ASTContext &Ctx) const;
511c44eec6dd29ee9415cbd38a35deff4c8b67abb6aAnders Carlsson
5126ddf4784a22b994b954ed74c6061d4603d474639Fariborz Jahanian  /// HasSideEffects - This routine returns true for all those expressions
51360b70388e43d146d968a1cc0705b30cb2d7263feRichard Smith  /// which have any effect other than producing a value. Example is a function
51460b70388e43d146d968a1cc0705b30cb2d7263feRichard Smith  /// call, volatile variable read, or throwing an exception.
5154ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad  bool HasSideEffects(const ASTContext &Ctx) const;
51651f4708c00110940ca3f337961915f2ca1668375Richard Smith
51725d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor  /// \brief Determine whether this expression involves a call to any function
51825d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor  /// that is not trivial.
51925d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor  bool hasNonTrivialCall(ASTContext &Ctx);
52025d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor
52151f4708c00110940ca3f337961915f2ca1668375Richard Smith  /// EvaluateKnownConstInt - Call EvaluateAsRValue and return the folded
52251f4708c00110940ca3f337961915f2ca1668375Richard Smith  /// integer. This must be called on an expression that constant folds to an
52351f4708c00110940ca3f337961915f2ca1668375Richard Smith  /// integer.
524a6b8b2c09610b8bc4330e948ece8b940c2386406Richard Smith  llvm::APSInt EvaluateKnownConstInt(const ASTContext &Ctx) const;
52551fe996231b1d7199f76e4005ff4c943d5deeecdAnders Carlsson
52651f4708c00110940ca3f337961915f2ca1668375Richard Smith  /// EvaluateAsLValue - Evaluate an expression to see if we can fold it to an
52751f4708c00110940ca3f337961915f2ca1668375Richard Smith  /// lvalue with link time known address, with no side-effects.
5284ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad  bool EvaluateAsLValue(EvalResult &Result, const ASTContext &Ctx) const;
5291b78276a75a5a0f496a82429c1ff9604d622a76dAnders Carlsson
530099e7f647ccda915513f2b2ec53352dc756082d3Richard Smith  /// EvaluateAsInitializer - Evaluate an expression as if it were the
531099e7f647ccda915513f2b2ec53352dc756082d3Richard Smith  /// initializer of the given declaration. Returns true if the initializer
532099e7f647ccda915513f2b2ec53352dc756082d3Richard Smith  /// can be folded to a constant, and produces any relevant notes. In C++11,
533099e7f647ccda915513f2b2ec53352dc756082d3Richard Smith  /// notes will be produced if the expression is not a constant expression.
534099e7f647ccda915513f2b2ec53352dc756082d3Richard Smith  bool EvaluateAsInitializer(APValue &Result, const ASTContext &Ctx,
535099e7f647ccda915513f2b2ec53352dc756082d3Richard Smith                             const VarDecl *VD,
536099e7f647ccda915513f2b2ec53352dc756082d3Richard Smith                       llvm::SmallVectorImpl<PartialDiagnosticAt> &Notes) const;
537099e7f647ccda915513f2b2ec53352dc756082d3Richard Smith
53882214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth  /// \brief Enumeration used to describe the kind of Null pointer constant
53982214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth  /// returned from \c isNullPointerConstant().
54082214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth  enum NullPointerConstantKind {
54182214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth    /// \brief Expression is not a Null pointer constant.
54282214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth    NPCK_NotNull = 0,
54382214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth
54450800fc551ac6b8a95cca662223e7f061bbd169aDavid Blaikie    /// \brief Expression is a Null pointer constant built from a zero integer
54550800fc551ac6b8a95cca662223e7f061bbd169aDavid Blaikie    /// expression that is not a simple, possibly parenthesized, zero literal.
54650800fc551ac6b8a95cca662223e7f061bbd169aDavid Blaikie    /// C++ Core Issue 903 will classify these expressions as "not pointers"
54750800fc551ac6b8a95cca662223e7f061bbd169aDavid Blaikie    /// once it is adopted.
54850800fc551ac6b8a95cca662223e7f061bbd169aDavid Blaikie    /// http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#903
54950800fc551ac6b8a95cca662223e7f061bbd169aDavid Blaikie    NPCK_ZeroExpression,
55050800fc551ac6b8a95cca662223e7f061bbd169aDavid Blaikie
55150800fc551ac6b8a95cca662223e7f061bbd169aDavid Blaikie    /// \brief Expression is a Null pointer constant built from a literal zero.
55250800fc551ac6b8a95cca662223e7f061bbd169aDavid Blaikie    NPCK_ZeroLiteral,
55382214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth
55482214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth    /// \brief Expression is a C++0X nullptr.
55582214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth    NPCK_CXX0X_nullptr,
55682214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth
55782214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth    /// \brief Expression is a GNU-style __null constant.
55882214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth    NPCK_GNUNull
55982214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth  };
56082214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth
561ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor  /// \brief Enumeration used to describe how \c isNullPointerConstant()
562ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor  /// should cope with value-dependent expressions.
563ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor  enum NullPointerConstantValueDependence {
564ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor    /// \brief Specifies that the expression should never be value-dependent.
565ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor    NPC_NeverValueDependent = 0,
566ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
567ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor    /// \brief Specifies that a value-dependent expression of integral or
568ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor    /// dependent type should be considered a null pointer constant.
569ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor    NPC_ValueDependentIsNull,
570ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
571ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor    /// \brief Specifies that a value-dependent expression should be considered
572ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor    /// to never be a null pointer constant.
573ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor    NPC_ValueDependentIsNotNull
574ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor  };
575ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
57682214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth  /// isNullPointerConstant - C99 6.3.2.3p3 - Test if this reduces down to
57782214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth  /// a Null pointer constant. The return value can further distinguish the
57882214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth  /// kind of NULL pointer constant that was detected.
57982214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth  NullPointerConstantKind isNullPointerConstant(
58082214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth      ASTContext &Ctx,
58182214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth      NullPointerConstantValueDependence NPC) const;
582efa9b3877ef298bcb792600ac33521827e1f7fafAnders Carlsson
58344baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian  /// isOBJCGCCandidate - Return true if this expression may be used in a read/
5841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// write barrier.
585102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanian  bool isOBJCGCCandidate(ASTContext &Ctx) const;
5861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
58711ab79030938209f50691acae0ddb65e72a58ca9Argyrios Kyrtzidis  /// \brief Returns true if this expression is a bound member function.
58811ab79030938209f50691acae0ddb65e72a58ca9Argyrios Kyrtzidis  bool isBoundMemberFunction(ASTContext &Ctx) const;
58911ab79030938209f50691acae0ddb65e72a58ca9Argyrios Kyrtzidis
590864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall  /// \brief Given an expression of bound-member type, find the type
591864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall  /// of the member.  Returns null if this is an *overloaded* bound
592864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall  /// member expression.
593864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall  static QualType findBoundMemberType(const Expr *expr);
594864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall
59591a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall  /// IgnoreImpCasts - Skip past any implicit casts which might
59691a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall  /// surround this expression.  Only skips ImplicitCastExprs.
597f9ff5876289d5228c299b57416a62c8c3b848287Daniel Dunbar  Expr *IgnoreImpCasts() LLVM_READONLY;
59891a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall
5997e5e5f4cc36fe50f46ad76dca7a266434c94f475John McCall  /// IgnoreImplicit - Skip past any implicit AST nodes which might
6007e5e5f4cc36fe50f46ad76dca7a266434c94f475John McCall  /// surround this expression.
601f9ff5876289d5228c299b57416a62c8c3b848287Daniel Dunbar  Expr *IgnoreImplicit() LLVM_READONLY {
602f9ff5876289d5228c299b57416a62c8c3b848287Daniel Dunbar    return cast<Expr>(Stmt::IgnoreImplicit());
603f9ff5876289d5228c299b57416a62c8c3b848287Daniel Dunbar  }
6047e5e5f4cc36fe50f46ad76dca7a266434c94f475John McCall
605132283beb1b032e0acd09bdfb45dceadeea0026eJordan Rose  const Expr *IgnoreImplicit() const LLVM_READONLY {
606132283beb1b032e0acd09bdfb45dceadeea0026eJordan Rose    return const_cast<Expr*>(this)->IgnoreImplicit();
607132283beb1b032e0acd09bdfb45dceadeea0026eJordan Rose  }
608132283beb1b032e0acd09bdfb45dceadeea0026eJordan Rose
6094e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek  /// IgnoreParens - Ignore parentheses.  If this Expr is a ParenExpr, return
6101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///  its subexpression.  If that subexpression is also a ParenExpr,
6114e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek  ///  then this method recursively returns its subexpression, and so forth.
6124e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek  ///  Otherwise, the method returns the current Expr.
613f9ff5876289d5228c299b57416a62c8c3b848287Daniel Dunbar  Expr *IgnoreParens() LLVM_READONLY;
61456f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner
61556f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner  /// IgnoreParenCasts - Ignore parentheses and casts.  Strip off any ParenExpr
61627c8dc06f65d7abcf6a7e7f64a7960c9a150ca01Douglas Gregor  /// or CastExprs, returning their operand.
617f9ff5876289d5228c299b57416a62c8c3b848287Daniel Dunbar  Expr *IgnoreParenCasts() LLVM_READONLY;
6181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
619ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  /// IgnoreParenImpCasts - Ignore parentheses and implicit casts.  Strip off
620ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  /// any ParenExpr or ImplicitCastExprs, returning their operand.
621f9ff5876289d5228c299b57416a62c8c3b848287Daniel Dunbar  Expr *IgnoreParenImpCasts() LLVM_READONLY;
6222fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCall
6232f072b442879b8bba8c5dea11d7c61bedb1924aeHans Wennborg  /// IgnoreConversionOperator - Ignore conversion operator. If this Expr is a
6242f072b442879b8bba8c5dea11d7c61bedb1924aeHans Wennborg  /// call to a conversion operator, return the argument.
625f9ff5876289d5228c299b57416a62c8c3b848287Daniel Dunbar  Expr *IgnoreConversionOperator() LLVM_READONLY;
6262f072b442879b8bba8c5dea11d7c61bedb1924aeHans Wennborg
627f9ff5876289d5228c299b57416a62c8c3b848287Daniel Dunbar  const Expr *IgnoreConversionOperator() const LLVM_READONLY {
6282f072b442879b8bba8c5dea11d7c61bedb1924aeHans Wennborg    return const_cast<Expr*>(this)->IgnoreConversionOperator();
6292f072b442879b8bba8c5dea11d7c61bedb1924aeHans Wennborg  }
6302f072b442879b8bba8c5dea11d7c61bedb1924aeHans Wennborg
631f9ff5876289d5228c299b57416a62c8c3b848287Daniel Dunbar  const Expr *IgnoreParenImpCasts() const LLVM_READONLY {
6324d3175c1e5a44251ea97b0c81e80f060629d9c08Ted Kremenek    return const_cast<Expr*>(this)->IgnoreParenImpCasts();
6334d3175c1e5a44251ea97b0c81e80f060629d9c08Ted Kremenek  }
634ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
635f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall  /// Ignore parentheses and lvalue casts.  Strip off any ParenExpr and
636f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall  /// CastExprs that represent lvalue casts, returning their operand.
637f9ff5876289d5228c299b57416a62c8c3b848287Daniel Dunbar  Expr *IgnoreParenLValueCasts() LLVM_READONLY;
638ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
639f9ff5876289d5228c299b57416a62c8c3b848287Daniel Dunbar  const Expr *IgnoreParenLValueCasts() const LLVM_READONLY {
640f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall    return const_cast<Expr*>(this)->IgnoreParenLValueCasts();
641f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall  }
6424d3175c1e5a44251ea97b0c81e80f060629d9c08Ted Kremenek
643ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner  /// IgnoreParenNoopCasts - Ignore parentheses and casts that do not change the
644ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner  /// value (including ptr->int casts of the same size).  Strip off any
645ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner  /// ParenExpr or CastExprs, returning their operand.
646f9ff5876289d5228c299b57416a62c8c3b848287Daniel Dunbar  Expr *IgnoreParenNoopCasts(ASTContext &Ctx) LLVM_READONLY;
6471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
648632fbaa22fbed7c090eb83775731bfff786c2198Rafael Espindola  /// Ignore parentheses and derived-to-base casts.
649632fbaa22fbed7c090eb83775731bfff786c2198Rafael Espindola  Expr *ignoreParenBaseCasts() LLVM_READONLY;
650632fbaa22fbed7c090eb83775731bfff786c2198Rafael Espindola
651632fbaa22fbed7c090eb83775731bfff786c2198Rafael Espindola  const Expr *ignoreParenBaseCasts() const LLVM_READONLY {
652632fbaa22fbed7c090eb83775731bfff786c2198Rafael Espindola    return const_cast<Expr*>(this)->ignoreParenBaseCasts();
653632fbaa22fbed7c090eb83775731bfff786c2198Rafael Espindola  }
654632fbaa22fbed7c090eb83775731bfff786c2198Rafael Espindola
6556eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor  /// \brief Determine whether this expression is a default function argument.
6566eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor  ///
6576eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor  /// Default arguments are implicitly generated in the abstract syntax tree
658ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  /// by semantic analysis for function calls, object constructions, etc. in
6596eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor  /// C++. Default arguments are represented by \c CXXDefaultArgExpr nodes;
6606eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor  /// this routine also looks through any implicit casts to determine whether
6616eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor  /// the expression is a default argument.
6626eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor  bool isDefaultArgument() const;
663ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
664558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall  /// \brief Determine whether the result of this expression is a
665558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall  /// temporary object of the given class type.
666558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall  bool isTemporaryObject(ASTContext &Ctx, const CXXRecordDecl *TempTy) const;
6672f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor
66875e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor  /// \brief Whether this expression is an implicit reference to 'this' in C++.
66975e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor  bool isImplicitCXXThis() const;
67091a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall
671f9ff5876289d5228c299b57416a62c8c3b848287Daniel Dunbar  const Expr *IgnoreImpCasts() const LLVM_READONLY {
67291a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall    return const_cast<Expr*>(this)->IgnoreImpCasts();
67391a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall  }
674f9ff5876289d5228c299b57416a62c8c3b848287Daniel Dunbar  const Expr *IgnoreParens() const LLVM_READONLY {
6754e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek    return const_cast<Expr*>(this)->IgnoreParens();
6764e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek  }
677f9ff5876289d5228c299b57416a62c8c3b848287Daniel Dunbar  const Expr *IgnoreParenCasts() const LLVM_READONLY {
67856f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner    return const_cast<Expr*>(this)->IgnoreParenCasts();
67956f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner  }
680f9ff5876289d5228c299b57416a62c8c3b848287Daniel Dunbar  const Expr *IgnoreParenNoopCasts(ASTContext &Ctx) const LLVM_READONLY {
681ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner    return const_cast<Expr*>(this)->IgnoreParenNoopCasts(Ctx);
682ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner  }
6831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
68413a140caba448a66ffcc5ff0d32a87d6e4f4ad3fAhmed Charles  static bool hasAnyTypeDependentArguments(llvm::ArrayRef<Expr *> Exprs);
685898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor
6868d852e35adb46e0799538dfc9c80d44f27cd3597Rafael Espindola  /// \brief For an expression of class type or pointer to class type,
6878d852e35adb46e0799538dfc9c80d44f27cd3597Rafael Espindola  /// return the most derived class decl the expression is known to refer to.
6880b4fe503ef00d9f8ea330850d3e3b303e9c7c876Rafael Espindola  ///
6890b4fe503ef00d9f8ea330850d3e3b303e9c7c876Rafael Espindola  /// If this expression is a cast, this method looks through it to find the
6908d852e35adb46e0799538dfc9c80d44f27cd3597Rafael Espindola  /// most derived decl that can be inferred from the expression.
6918d852e35adb46e0799538dfc9c80d44f27cd3597Rafael Espindola  /// This is valid because derived-to-base conversions have undefined
6928d852e35adb46e0799538dfc9c80d44f27cd3597Rafael Espindola  /// behavior if the object isn't dynamically of the derived type.
6938d852e35adb46e0799538dfc9c80d44f27cd3597Rafael Espindola  const CXXRecordDecl *getBestDynamicClassType() const;
6940b4fe503ef00d9f8ea330850d3e3b303e9c7c876Rafael Espindola
6951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
6965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return T->getStmtClass() >= firstExprConstant &&
6971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump           T->getStmtClass() <= lastExprConstant;
6985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
6995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Expr *) { return true; }
7005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
7015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
7021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7035549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek//===----------------------------------------------------------------------===//
7045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// Primary Expressions.
7055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===//
7065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
70756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall/// OpaqueValueExpr - An expression referring to an opaque object of a
70856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall/// fixed type and value class.  These don't correspond to concrete
70956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall/// syntax; instead they're used to express operations (usually copy
71056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall/// operations) on values whose source is generally obvious from
71156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall/// context.
71256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCallclass OpaqueValueExpr : public Expr {
71356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  friend class ASTStmtReader;
71456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  Expr *SourceExpr;
71556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  SourceLocation Loc;
716ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
71756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCallpublic:
718ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  OpaqueValueExpr(SourceLocation Loc, QualType T, ExprValueKind VK,
71997df54e0c075bc8d6a869597e771dad0c11a2180Douglas Gregor                  ExprObjectKind OK = OK_Ordinary,
72097df54e0c075bc8d6a869597e771dad0c11a2180Douglas Gregor                  Expr *SourceExpr = 0)
72156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall    : Expr(OpaqueValueExprClass, T, VK, OK,
72297df54e0c075bc8d6a869597e771dad0c11a2180Douglas Gregor           T->isDependentType(),
72397df54e0c075bc8d6a869597e771dad0c11a2180Douglas Gregor           T->isDependentType() ||
72497df54e0c075bc8d6a869597e771dad0c11a2180Douglas Gregor           (SourceExpr && SourceExpr->isValueDependent()),
725561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor           T->isInstantiationDependentType(),
726ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie           false),
72797df54e0c075bc8d6a869597e771dad0c11a2180Douglas Gregor      SourceExpr(SourceExpr), Loc(Loc) {
72856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  }
72956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall
73056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  /// Given an expression which invokes a copy constructor --- i.e.  a
73156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  /// CXXConstructExpr, possibly wrapped in an ExprWithCleanups ---
73256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  /// find the OpaqueValueExpr that's the source of the construction.
73356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  static const OpaqueValueExpr *findInCopyConstruct(const Expr *expr);
73456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall
73556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  explicit OpaqueValueExpr(EmptyShell Empty)
73656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall    : Expr(OpaqueValueExprClass, Empty) { }
73756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall
73856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  /// \brief Retrieve the location of this expression.
73956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  SourceLocation getLocation() const { return Loc; }
740ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
741aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY {
74256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall    if (SourceExpr) return SourceExpr->getSourceRange();
74356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall    return Loc;
74456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  }
7454f311183be3d923da9fbe8702c453688b4c426a9Daniel Dunbar  SourceLocation getExprLoc() const LLVM_READONLY {
74656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall    if (SourceExpr) return SourceExpr->getExprLoc();
74756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall    return Loc;
74856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  }
74956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall
75056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  child_range children() { return child_range(); }
75156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall
75256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  /// The source expression of an opaque value expression is the
75356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  /// expression which originally generated the value.  This is
75456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  /// provided as a convenience for analyses that don't wish to
75556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  /// precisely model the execution behavior of the program.
75656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  ///
75756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  /// The source expression is typically set when building the
75856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  /// expression which binds the opaque value expression in the first
75956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  /// place.
76056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  Expr *getSourceExpr() const { return SourceExpr; }
76156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall
76256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  static bool classof(const Stmt *T) {
76356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall    return T->getStmtClass() == OpaqueValueExprClass;
76456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  }
76556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  static bool classof(const OpaqueValueExpr *) { return true; }
76656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall};
76756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall
768cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth/// \brief A reference to a declared variable, function, enum, etc.
769cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth/// [C99 6.5.1p2]
770cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth///
771cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth/// This encodes all the information about how a declaration is referenced
772cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth/// within an expression.
773cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth///
774cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth/// There are several optional constructs attached to DeclRefExprs only when
775cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth/// they apply in order to conserve memory. These are laid out past the end of
776cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth/// the object, and flags in the DeclRefExprBitfield track whether they exist:
777cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth///
778cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth///   DeclRefExprBits.HasQualifier:
779cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth///       Specifies when this declaration reference expression has a C++
780cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth///       nested-name-specifier.
7813aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth///   DeclRefExprBits.HasFoundDecl:
7823aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth///       Specifies when this declaration reference expression has a record of
7833aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth///       a NamedDecl (different from the referenced ValueDecl) which was found
7843aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth///       during name lookup and/or overload resolution.
785e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara///   DeclRefExprBits.HasTemplateKWAndArgsInfo:
786cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth///       Specifies when this declaration reference expression has an explicit
787e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara///       C++ template keyword and/or template argument list.
788f4b88a45902af1802a1cb42ba48b1c474474f228John McCall///   DeclRefExprBits.RefersToEnclosingLocal
789f4b88a45902af1802a1cb42ba48b1c474474f228John McCall///       Specifies when this declaration reference expression (validly)
790f4b88a45902af1802a1cb42ba48b1c474474f228John McCall///       refers to a local variable from a different function.
7915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass DeclRefExpr : public Expr {
792cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth  /// \brief The declaration that we are referencing.
793cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth  ValueDecl *D;
7942577743c5650c646fb705df01403707e94f2df04Abramo Bagnara
795cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth  /// \brief The location of the declaration name itself.
7965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation Loc;
7979e922b1663ecb95dc7eee03002fd66ed18fb3192Argyrios Kyrtzidis
798cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth  /// \brief Provides source/type location info for the declaration name
799cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth  /// embedded in D.
8002577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  DeclarationNameLoc DNLoc;
8012577743c5650c646fb705df01403707e94f2df04Abramo Bagnara
8026857c3e12c86fd0271eb46baab5b18756a94f4cbChandler Carruth  /// \brief Helper to retrieve the optional NestedNameSpecifierLoc.
8036857c3e12c86fd0271eb46baab5b18756a94f4cbChandler Carruth  NestedNameSpecifierLoc &getInternalQualifierLoc() {
8047e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth    assert(hasQualifier());
8056857c3e12c86fd0271eb46baab5b18756a94f4cbChandler Carruth    return *reinterpret_cast<NestedNameSpecifierLoc *>(this + 1);
806a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  }
807cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth
8086857c3e12c86fd0271eb46baab5b18756a94f4cbChandler Carruth  /// \brief Helper to retrieve the optional NestedNameSpecifierLoc.
8096857c3e12c86fd0271eb46baab5b18756a94f4cbChandler Carruth  const NestedNameSpecifierLoc &getInternalQualifierLoc() const {
8106857c3e12c86fd0271eb46baab5b18756a94f4cbChandler Carruth    return const_cast<DeclRefExpr *>(this)->getInternalQualifierLoc();
811a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  }
812096832c5ed5b9106fa177ebc148489760c3bc496John McCall
8133aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth  /// \brief Test whether there is a distinct FoundDecl attached to the end of
8143aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth  /// this DRE.
8153aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth  bool hasFoundDecl() const { return DeclRefExprBits.HasFoundDecl; }
8163aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth
8173aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth  /// \brief Helper to retrieve the optional NamedDecl through which this
8183aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth  /// reference occured.
8193aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth  NamedDecl *&getInternalFoundDecl() {
8203aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth    assert(hasFoundDecl());
8213aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth    if (hasQualifier())
8223aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth      return *reinterpret_cast<NamedDecl **>(&getInternalQualifierLoc() + 1);
8233aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth    return *reinterpret_cast<NamedDecl **>(this + 1);
8243aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth  }
8253aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth
8263aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth  /// \brief Helper to retrieve the optional NamedDecl through which this
8273aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth  /// reference occured.
8283aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth  NamedDecl *getInternalFoundDecl() const {
8293aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth    return const_cast<DeclRefExpr *>(this)->getInternalFoundDecl();
8303aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth  }
8313aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth
8323d13c5a1e72ed8f8be9c083791d30643d1b1ec43Daniel Dunbar  DeclRefExpr(ASTContext &Ctx,
8333d13c5a1e72ed8f8be9c083791d30643d1b1ec43Daniel Dunbar              NestedNameSpecifierLoc QualifierLoc,
834e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara              SourceLocation TemplateKWLoc,
835f4b88a45902af1802a1cb42ba48b1c474474f228John McCall              ValueDecl *D, bool refersToEnclosingLocal,
836f4b88a45902af1802a1cb42ba48b1c474474f228John McCall              const DeclarationNameInfo &NameInfo,
8373aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth              NamedDecl *FoundD,
8382577743c5650c646fb705df01403707e94f2df04Abramo Bagnara              const TemplateArgumentListInfo *TemplateArgs,
839f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall              QualType T, ExprValueKind VK);
8402577743c5650c646fb705df01403707e94f2df04Abramo Bagnara
841663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis  /// \brief Construct an empty declaration reference expression.
842663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis  explicit DeclRefExpr(EmptyShell Empty)
843663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis    : Expr(DeclRefExprClass, Empty) { }
8447e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth
8450da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor  /// \brief Computes the type- and value-dependence flags for this
8460da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor  /// declaration reference expression.
8473d13c5a1e72ed8f8be9c083791d30643d1b1ec43Daniel Dunbar  void computeDependence(ASTContext &C);
8489e922b1663ecb95dc7eee03002fd66ed18fb3192Argyrios Kyrtzidis
8495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
850f4b88a45902af1802a1cb42ba48b1c474474f228John McCall  DeclRefExpr(ValueDecl *D, bool refersToEnclosingLocal, QualType T,
851f4b88a45902af1802a1cb42ba48b1c474474f228John McCall              ExprValueKind VK, SourceLocation L,
8525b8968cc599eb6100bb73ae87be9d6cd2577ac9eDouglas Gregor              const DeclarationNameLoc &LocInfo = DeclarationNameLoc())
853561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor    : Expr(DeclRefExprClass, T, VK, OK_Ordinary, false, false, false, false),
8545b8968cc599eb6100bb73ae87be9d6cd2577ac9eDouglas Gregor      D(D), Loc(L), DNLoc(LocInfo) {
855cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth    DeclRefExprBits.HasQualifier = 0;
856e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    DeclRefExprBits.HasTemplateKWAndArgsInfo = 0;
8573aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth    DeclRefExprBits.HasFoundDecl = 0;
8587cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara    DeclRefExprBits.HadMultipleCandidates = 0;
859f4b88a45902af1802a1cb42ba48b1c474474f228John McCall    DeclRefExprBits.RefersToEnclosingLocal = refersToEnclosingLocal;
8603d13c5a1e72ed8f8be9c083791d30643d1b1ec43Daniel Dunbar    computeDependence(D->getASTContext());
8610da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor  }
8621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
863a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  static DeclRefExpr *Create(ASTContext &Context,
86440d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor                             NestedNameSpecifierLoc QualifierLoc,
865e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara                             SourceLocation TemplateKWLoc,
866dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall                             ValueDecl *D,
867f4b88a45902af1802a1cb42ba48b1c474474f228John McCall                             bool isEnclosingLocal,
868a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor                             SourceLocation NameLoc,
869f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                             QualType T, ExprValueKind VK,
8703aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth                             NamedDecl *FoundD = 0,
8710da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor                             const TemplateArgumentListInfo *TemplateArgs = 0);
872663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis
8732577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  static DeclRefExpr *Create(ASTContext &Context,
87440d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor                             NestedNameSpecifierLoc QualifierLoc,
875e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara                             SourceLocation TemplateKWLoc,
8762577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                             ValueDecl *D,
877f4b88a45902af1802a1cb42ba48b1c474474f228John McCall                             bool isEnclosingLocal,
8782577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                             const DeclarationNameInfo &NameInfo,
879f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                             QualType T, ExprValueKind VK,
8803aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth                             NamedDecl *FoundD = 0,
8812577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                             const TemplateArgumentListInfo *TemplateArgs = 0);
8822577743c5650c646fb705df01403707e94f2df04Abramo Bagnara
883663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis  /// \brief Construct an empty declaration reference expression.
884663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis  static DeclRefExpr *CreateEmpty(ASTContext &Context,
8853aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth                                  bool HasQualifier,
8863aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth                                  bool HasFoundDecl,
887e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara                                  bool HasTemplateKWAndArgsInfo,
888def0354384d9c4431f7b58b664b59896d4623028Douglas Gregor                                  unsigned NumTemplateArgs);
8897e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth
890cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth  ValueDecl *getDecl() { return D; }
891cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth  const ValueDecl *getDecl() const { return D; }
892cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth  void setDecl(ValueDecl *NewD) { D = NewD; }
893904eed3f6148758d39a2d3c88f3133274460d645Douglas Gregor
8942577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  DeclarationNameInfo getNameInfo() const {
8952577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    return DeclarationNameInfo(getDecl()->getDeclName(), Loc, DNLoc);
8962577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  }
8972577743c5650c646fb705df01403707e94f2df04Abramo Bagnara
8989e922b1663ecb95dc7eee03002fd66ed18fb3192Argyrios Kyrtzidis  SourceLocation getLocation() const { return Loc; }
8990b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor  void setLocation(SourceLocation L) { Loc = L; }
900aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY;
901aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceLocation getLocStart() const LLVM_READONLY;
902aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceLocation getLocEnd() const LLVM_READONLY;
9031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
904a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// \brief Determine whether this declaration reference was preceded by a
905a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// C++ nested-name-specifier, e.g., \c N::foo.
906cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth  bool hasQualifier() const { return DeclRefExprBits.HasQualifier; }
9077e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth
9087e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth  /// \brief If the name was qualified, retrieves the nested-name-specifier
909a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// that precedes the name. Otherwise, returns NULL.
910a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  NestedNameSpecifier *getQualifier() const {
911a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor    if (!hasQualifier())
912a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor      return 0;
9137e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth
9146857c3e12c86fd0271eb46baab5b18756a94f4cbChandler Carruth    return getInternalQualifierLoc().getNestedNameSpecifier();
915a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  }
91640d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor
9177e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth  /// \brief If the name was qualified, retrieves the nested-name-specifier
91840d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor  /// that precedes the name, with source-location information.
91940d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor  NestedNameSpecifierLoc getQualifierLoc() const {
92040d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor    if (!hasQualifier())
92140d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor      return NestedNameSpecifierLoc();
9227e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth
9236857c3e12c86fd0271eb46baab5b18756a94f4cbChandler Carruth    return getInternalQualifierLoc();
92440d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor  }
92540d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor
9263aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth  /// \brief Get the NamedDecl through which this reference occured.
9273aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth  ///
9283aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth  /// This Decl may be different from the ValueDecl actually referred to in the
9293aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth  /// presence of using declarations, etc. It always returns non-NULL, and may
9303aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth  /// simple return the ValueDecl when appropriate.
9313aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth  NamedDecl *getFoundDecl() {
9323aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth    return hasFoundDecl() ? getInternalFoundDecl() : D;
9333aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth  }
9343aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth
9353aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth  /// \brief Get the NamedDecl through which this reference occurred.
9363aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth  /// See non-const variant.
9373aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth  const NamedDecl *getFoundDecl() const {
9383aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth    return hasFoundDecl() ? getInternalFoundDecl() : D;
9393aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth  }
9403aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth
941e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  bool hasTemplateKWAndArgsInfo() const {
942e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    return DeclRefExprBits.HasTemplateKWAndArgsInfo;
943096832c5ed5b9106fa177ebc148489760c3bc496John McCall  }
9447e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth
945e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// \brief Return the optional template keyword and arguments info.
946e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo() {
947e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    if (!hasTemplateKWAndArgsInfo())
948e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara      return 0;
949e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara
9503aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth    if (hasFoundDecl())
951e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara      return reinterpret_cast<ASTTemplateKWAndArgsInfo *>(
9523aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth        &getInternalFoundDecl() + 1);
9533aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth
9543aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth    if (hasQualifier())
955e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara      return reinterpret_cast<ASTTemplateKWAndArgsInfo *>(
9563aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth        &getInternalQualifierLoc() + 1);
9577e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth
958e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    return reinterpret_cast<ASTTemplateKWAndArgsInfo *>(this + 1);
959e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  }
960e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara
961e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// \brief Return the optional template keyword and arguments info.
962e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  const ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo() const {
963e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    return const_cast<DeclRefExpr*>(this)->getTemplateKWAndArgsInfo();
964e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  }
965e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara
966e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// \brief Retrieve the location of the template keyword preceding
967e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// this name, if any.
968e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  SourceLocation getTemplateKeywordLoc() const {
969e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    if (!hasTemplateKWAndArgsInfo()) return SourceLocation();
970e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    return getTemplateKWAndArgsInfo()->getTemplateKeywordLoc();
971e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  }
972e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara
973e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// \brief Retrieve the location of the left angle bracket starting the
974e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// explicit template argument list following the name, if any.
975e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  SourceLocation getLAngleLoc() const {
976e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    if (!hasTemplateKWAndArgsInfo()) return SourceLocation();
977e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    return getTemplateKWAndArgsInfo()->LAngleLoc;
978e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  }
979e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara
980e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// \brief Retrieve the location of the right angle bracket ending the
981e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// explicit template argument list following the name, if any.
982e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  SourceLocation getRAngleLoc() const {
983e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    if (!hasTemplateKWAndArgsInfo()) return SourceLocation();
984e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    return getTemplateKWAndArgsInfo()->RAngleLoc;
985e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  }
986e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara
987e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// \brief Determines whether the name in this declaration reference
988e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// was preceded by the template keyword.
989e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  bool hasTemplateKeyword() const { return getTemplateKeywordLoc().isValid(); }
990e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara
991e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// \brief Determines whether this declaration reference was followed by an
992e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// explicit template argument list.
993e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  bool hasExplicitTemplateArgs() const { return getLAngleLoc().isValid(); }
994e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara
995e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// \brief Retrieve the explicit template argument list that followed the
996e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// member template name.
997e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  ASTTemplateArgumentListInfo &getExplicitTemplateArgs() {
998e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    assert(hasExplicitTemplateArgs());
999e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    return *getTemplateKWAndArgsInfo();
1000096832c5ed5b9106fa177ebc148489760c3bc496John McCall  }
10017e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth
1002096832c5ed5b9106fa177ebc148489760c3bc496John McCall  /// \brief Retrieve the explicit template argument list that followed the
1003096832c5ed5b9106fa177ebc148489760c3bc496John McCall  /// member template name.
1004b0c3e0909bb04af0bfb82ad01ab6909649d68ccaArgyrios Kyrtzidis  const ASTTemplateArgumentListInfo &getExplicitTemplateArgs() const {
1005096832c5ed5b9106fa177ebc148489760c3bc496John McCall    return const_cast<DeclRefExpr *>(this)->getExplicitTemplateArgs();
1006a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  }
1007d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall
1008096832c5ed5b9106fa177ebc148489760c3bc496John McCall  /// \brief Retrieves the optional explicit template arguments.
1009096832c5ed5b9106fa177ebc148489760c3bc496John McCall  /// This points to the same data as getExplicitTemplateArgs(), but
1010096832c5ed5b9106fa177ebc148489760c3bc496John McCall  /// returns null if there are no explicit template arguments.
1011e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  const ASTTemplateArgumentListInfo *getOptionalExplicitTemplateArgs() const {
1012096832c5ed5b9106fa177ebc148489760c3bc496John McCall    if (!hasExplicitTemplateArgs()) return 0;
1013096832c5ed5b9106fa177ebc148489760c3bc496John McCall    return &getExplicitTemplateArgs();
1014096832c5ed5b9106fa177ebc148489760c3bc496John McCall  }
10157e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth
1016d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  /// \brief Copies the template arguments (if present) into the given
1017d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  /// structure.
1018d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
1019096832c5ed5b9106fa177ebc148489760c3bc496John McCall    if (hasExplicitTemplateArgs())
1020096832c5ed5b9106fa177ebc148489760c3bc496John McCall      getExplicitTemplateArgs().copyInto(List);
1021d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  }
10227e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth
1023a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// \brief Retrieve the template arguments provided as part of this
1024a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// template-id.
1025833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  const TemplateArgumentLoc *getTemplateArgs() const {
1026096832c5ed5b9106fa177ebc148489760c3bc496John McCall    if (!hasExplicitTemplateArgs())
1027a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor      return 0;
10287e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth
1029096832c5ed5b9106fa177ebc148489760c3bc496John McCall    return getExplicitTemplateArgs().getTemplateArgs();
1030a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  }
10317e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth
1032a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// \brief Retrieve the number of template arguments provided as part of this
1033a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// template-id.
1034a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  unsigned getNumTemplateArgs() const {
1035096832c5ed5b9106fa177ebc148489760c3bc496John McCall    if (!hasExplicitTemplateArgs())
1036a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor      return 0;
10377e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth
1038096832c5ed5b9106fa177ebc148489760c3bc496John McCall    return getExplicitTemplateArgs().NumTemplateArgs;
1039a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  }
10407e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth
10417cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara  /// \brief Returns true if this expression refers to a function that
10427cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara  /// was resolved from an overloaded set having size greater than 1.
10437cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara  bool hadMultipleCandidates() const {
10447cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara    return DeclRefExprBits.HadMultipleCandidates;
10457cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara  }
10467cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara  /// \brief Sets the flag telling whether this expression refers to
10477cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara  /// a function that was resolved from an overloaded set having size
10487cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara  /// greater than 1.
10497cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara  void setHadMultipleCandidates(bool V = true) {
10507cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara    DeclRefExprBits.HadMultipleCandidates = V;
10517cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara  }
10527cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara
1053f4b88a45902af1802a1cb42ba48b1c474474f228John McCall  /// Does this DeclRefExpr refer to a local declaration from an
1054f4b88a45902af1802a1cb42ba48b1c474474f228John McCall  /// enclosing function scope?
1055f4b88a45902af1802a1cb42ba48b1c474474f228John McCall  bool refersToEnclosingLocal() const {
1056f4b88a45902af1802a1cb42ba48b1c474474f228John McCall    return DeclRefExprBits.RefersToEnclosingLocal;
1057f4b88a45902af1802a1cb42ba48b1c474474f228John McCall  }
1058f4b88a45902af1802a1cb42ba48b1c474474f228John McCall
10591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
106099e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor    return T->getStmtClass() == DeclRefExprClass;
10615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
10625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const DeclRefExpr *) { return true; }
10631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
106477ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  // Iterators
106563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(); }
10667e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth
106760adf4acf40b72227740bf966fb87eebddff3f37Sebastian Redl  friend class ASTStmtReader;
10683397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl  friend class ASTStmtWriter;
10695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
10705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1071d9f6910f4ef37c0e8eeee2a01287d9572c3176efChris Lattner/// PredefinedExpr - [C99 6.4.2.2] - A predefined identifier such as __func__.
1072d9f6910f4ef37c0e8eeee2a01287d9572c3176efChris Lattnerclass PredefinedExpr : public Expr {
1073227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlssonpublic:
1074227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson  enum IdentType {
1075227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson    Func,
1076227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson    Function,
107728ad063b279378b19cb0704f977429df366a151eNico Weber    LFunction,  // Same as Function, but as wide string.
1078848fa64143fbe5ae62a601ad61277f741e54dfabAnders Carlsson    PrettyFunction,
1079848fa64143fbe5ae62a601ad61277f741e54dfabAnders Carlsson    /// PrettyFunctionNoVirtual - The same as PrettyFunction, except that the
1080848fa64143fbe5ae62a601ad61277f741e54dfabAnders Carlsson    /// 'virtual' keyword is omitted for virtual member functions.
1081848fa64143fbe5ae62a601ad61277f741e54dfabAnders Carlsson    PrettyFunctionNoVirtual
1082227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson  };
10831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1084227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlssonprivate:
1085227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson  SourceLocation Loc;
1086227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson  IdentType Type;
1087227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlssonpublic:
10881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  PredefinedExpr(SourceLocation l, QualType type, IdentType IT)
1089f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    : Expr(PredefinedExprClass, type, VK_LValue, OK_Ordinary,
1090ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie           type->isDependentType(), type->isDependentType(),
1091561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor           type->isInstantiationDependentType(),
1092bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           /*ContainsUnexpandedParameterPack=*/false),
1093f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall      Loc(l), Type(IT) {}
10941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
109517fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor  /// \brief Construct an empty predefined expression.
10961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  explicit PredefinedExpr(EmptyShell Empty)
109717fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor    : Expr(PredefinedExprClass, Empty) { }
109817fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor
1099227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson  IdentType getIdentType() const { return Type; }
110017fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor  void setIdentType(IdentType IT) { Type = IT; }
110117fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor
110217fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor  SourceLocation getLocation() const { return Loc; }
110317fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor  void setLocation(SourceLocation L) { Loc = L; }
110417fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor
1105848fa64143fbe5ae62a601ad61277f741e54dfabAnders Carlsson  static std::string ComputeName(IdentType IT, const Decl *CurrentDecl);
11063a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson
1107aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY { return SourceRange(Loc); }
1108227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson
11091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
11101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == PredefinedExprClass;
1111227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson  }
1112d9f6910f4ef37c0e8eeee2a01287d9572c3176efChris Lattner  static bool classof(const PredefinedExpr *) { return true; }
11131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
111477ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  // Iterators
111563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(); }
1116227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson};
1117227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson
11189996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis/// \brief Used by IntegerLiteral/FloatingLiteral to store the numeric without
11199996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis/// leaking memory.
11209996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis///
11219996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis/// For large floats/integers, APFloat/APInt will allocate memory from the heap
11229996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis/// to represent these numbers.  Unfortunately, when we use a BumpPtrAllocator
11239996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis/// to allocate IntegerLiteral/FloatingLiteral nodes the memory associated with
11249996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis/// the APFloat/APInt values will never get freed. APNumericStorage uses
11259996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis/// ASTContext's allocator for memory allocation.
11269996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidisclass APNumericStorage {
11279996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis  union {
11289996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis    uint64_t VAL;    ///< Used to store the <= 64 bits integer value.
11299996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis    uint64_t *pVal;  ///< Used to store the >64 bits integer value.
11309996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis  };
113191219326471798c7d3b02dc48691581580338969Benjamin Kramer  unsigned BitWidth;
11329996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis
11339996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis  bool hasAllocation() const { return llvm::APInt::getNumWords(BitWidth) > 1; }
11349996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis
11359996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis  APNumericStorage(const APNumericStorage&); // do not implement
11369996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis  APNumericStorage& operator=(const APNumericStorage&); // do not implement
11379996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis
11389996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidisprotected:
113991219326471798c7d3b02dc48691581580338969Benjamin Kramer  APNumericStorage() : VAL(0), BitWidth(0) { }
11409996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis
11419996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis  llvm::APInt getIntValue() const {
11429996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis    unsigned NumWords = llvm::APInt::getNumWords(BitWidth);
11439996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis    if (NumWords > 1)
11449996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis      return llvm::APInt(BitWidth, NumWords, pVal);
11459996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis    else
11469996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis      return llvm::APInt(BitWidth, VAL);
11479996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis  }
11489996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis  void setIntValue(ASTContext &C, const llvm::APInt &Val);
11499996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis};
11509996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis
115191219326471798c7d3b02dc48691581580338969Benjamin Kramerclass APIntStorage : private APNumericStorage {
1152ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikiepublic:
1153ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  llvm::APInt getValue() const { return getIntValue(); }
11549996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis  void setValue(ASTContext &C, const llvm::APInt &Val) { setIntValue(C, Val); }
11559996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis};
11569996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis
1157bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramerclass APFloatStorage : private APNumericStorage {
1158ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikiepublic:
115931dfd642d5ac33c4ee0cfe1d7a1d4da455dcc7a4Akira Hatanaka  llvm::APFloat getValue(bool IsIEEE) const {
116031dfd642d5ac33c4ee0cfe1d7a1d4da455dcc7a4Akira Hatanaka    return llvm::APFloat(getIntValue(), IsIEEE);
116131dfd642d5ac33c4ee0cfe1d7a1d4da455dcc7a4Akira Hatanaka  }
11629996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis  void setValue(ASTContext &C, const llvm::APFloat &Val) {
11639996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis    setIntValue(C, Val.bitcastToAPInt());
11649996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis  }
11659996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis};
11669996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis
116791219326471798c7d3b02dc48691581580338969Benjamin Kramerclass IntegerLiteral : public Expr, public APIntStorage {
11685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation Loc;
11699996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis
11709996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis  /// \brief Construct an empty integer literal.
11719996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis  explicit IntegerLiteral(EmptyShell Empty)
11729996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis    : Expr(IntegerLiteralClass, Empty) { }
11739996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis
11745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
11751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  // type should be IntTy, LongTy, LongLongTy, UnsignedIntTy, UnsignedLongTy,
11765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // or UnsignedLongLongTy
1177478851c3ed6bd784e7377dffd8e57b200c1b9ba9Benjamin Kramer  IntegerLiteral(ASTContext &C, const llvm::APInt &V, QualType type,
1178478851c3ed6bd784e7377dffd8e57b200c1b9ba9Benjamin Kramer                 SourceLocation l);
1179a135fb43eb94524a6529768596a4533eed9aa70dAnders Carlsson
11801dd986dff9ddfbec687975700770bb377988e9edRichard Trieu  /// \brief Returns a new integer literal with value 'V' and type 'type'.
11811dd986dff9ddfbec687975700770bb377988e9edRichard Trieu  /// \param type - either IntTy, LongTy, LongLongTy, UnsignedIntTy,
11821dd986dff9ddfbec687975700770bb377988e9edRichard Trieu  /// UnsignedLongTy, or UnsignedLongLongTy which should match the size of V
11831dd986dff9ddfbec687975700770bb377988e9edRichard Trieu  /// \param V - the value that the returned integer literal contains.
11849996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis  static IntegerLiteral *Create(ASTContext &C, const llvm::APInt &V,
11859996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis                                QualType type, SourceLocation l);
11861dd986dff9ddfbec687975700770bb377988e9edRichard Trieu  /// \brief Returns a new empty integer literal.
11879996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis  static IntegerLiteral *Create(ASTContext &C, EmptyShell Empty);
11880b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor
1189aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY { return SourceRange(Loc); }
11905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1191313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor  /// \brief Retrieve the location of the literal.
1192313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor  SourceLocation getLocation() const { return Loc; }
1193313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor
11940b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor  void setLocation(SourceLocation Location) { Loc = Location; }
11950b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor
11961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
11971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == IntegerLiteralClass;
11985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
11995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const IntegerLiteral *) { return true; }
12001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
120177ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  // Iterators
120263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(); }
12035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
12045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
12055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass CharacterLiteral : public Expr {
12065cee1195584fa8672253139c86e922daeda69b9eDouglas Gregorpublic:
12075cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor  enum CharacterKind {
12085cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor    Ascii,
12095cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor    Wide,
12105cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor    UTF16,
12115cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor    UTF32
12125cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor  };
12135cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor
12145cee1195584fa8672253139c86e922daeda69b9eDouglas Gregorprivate:
12155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  unsigned Value;
12165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation Loc;
12175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
12185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // type should be IntTy
12195cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor  CharacterLiteral(unsigned value, CharacterKind kind, QualType type,
12205cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor                   SourceLocation l)
1221bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor    : Expr(CharacterLiteralClass, type, VK_RValue, OK_Ordinary, false, false,
1222561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor           false, false),
1223bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer      Value(value), Loc(l) {
1224bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer    CharacterLiteralBits.Kind = kind;
12255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
12260b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor
12270b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor  /// \brief Construct an empty character literal.
12280b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor  CharacterLiteral(EmptyShell Empty) : Expr(CharacterLiteralClass, Empty) { }
12290b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor
1230018d8e0596dd57401eeddcf11ac84ff0a065fbbeChris Lattner  SourceLocation getLocation() const { return Loc; }
1231bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer  CharacterKind getKind() const {
1232bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer    return static_cast<CharacterKind>(CharacterLiteralBits.Kind);
1233bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer  }
12341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1235aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY { return SourceRange(Loc); }
12361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
12375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  unsigned getValue() const { return Value; }
12385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
12390b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor  void setLocation(SourceLocation Location) { Loc = Location; }
1240bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer  void setKind(CharacterKind kind) { CharacterLiteralBits.Kind = kind; }
12410b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor  void setValue(unsigned Val) { Value = Val; }
12420b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor
12431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
12441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == CharacterLiteralClass;
12455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
12465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const CharacterLiteral *) { return true; }
124777ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek
124877ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  // Iterators
124963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(); }
12505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
12515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1252bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramerclass FloatingLiteral : public Expr, private APFloatStorage {
12535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation Loc;
12549996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis
12559996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis  FloatingLiteral(ASTContext &C, const llvm::APFloat &V, bool isexact,
1256478851c3ed6bd784e7377dffd8e57b200c1b9ba9Benjamin Kramer                  QualType Type, SourceLocation L);
12575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
125817fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor  /// \brief Construct an empty floating-point literal.
1259478851c3ed6bd784e7377dffd8e57b200c1b9ba9Benjamin Kramer  explicit FloatingLiteral(ASTContext &C, EmptyShell Empty);
126017fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor
12619996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidispublic:
12629996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis  static FloatingLiteral *Create(ASTContext &C, const llvm::APFloat &V,
12639996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis                                 bool isexact, QualType Type, SourceLocation L);
12649996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis  static FloatingLiteral *Create(ASTContext &C, EmptyShell Empty);
12659996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis
1266bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer  llvm::APFloat getValue() const {
1267bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer    return APFloatStorage::getValue(FloatingLiteralBits.IsIEEE);
1268bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer  }
12699996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis  void setValue(ASTContext &C, const llvm::APFloat &Val) {
1270bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer    APFloatStorage::setValue(C, Val);
12719996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis  }
127217fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor
1273bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer  bool isExact() const { return FloatingLiteralBits.IsExact; }
1274bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer  void setExact(bool E) { FloatingLiteralBits.IsExact = E; }
1275c9bec4bfea9090a08dd83a7b213f0c8adf8d78ecChris Lattner
1276da8249e57f3badecf925571881fe57243935c6c1Chris Lattner  /// getValueAsApproximateDouble - This returns the value as an inaccurate
1277da8249e57f3badecf925571881fe57243935c6c1Chris Lattner  /// double.  Note that this may cause loss of precision, but is useful for
1278da8249e57f3badecf925571881fe57243935c6c1Chris Lattner  /// debugging dumps, etc.
1279da8249e57f3badecf925571881fe57243935c6c1Chris Lattner  double getValueAsApproximateDouble() const;
12801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
128117fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor  SourceLocation getLocation() const { return Loc; }
128217fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor  void setLocation(SourceLocation L) { Loc = L; }
128317fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor
1284aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY { return SourceRange(Loc); }
12855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
12861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
12871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == FloatingLiteralClass;
12885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
12895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const FloatingLiteral *) { return true; }
12901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
129177ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  // Iterators
129263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(); }
12935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
12945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
12955d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner/// ImaginaryLiteral - We support imaginary integer and floating point literals,
12965d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner/// like "1.0i".  We represent these as a wrapper around FloatingLiteral and
12975d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner/// IntegerLiteral classes.  Instances of this class always have a Complex type
12985d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner/// whose element type matches the subexpression.
12995d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner///
13005d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattnerclass ImaginaryLiteral : public Expr {
13015549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Stmt *Val;
13025d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattnerpublic:
13035d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner  ImaginaryLiteral(Expr *val, QualType Ty)
1304bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor    : Expr(ImaginaryLiteralClass, Ty, VK_RValue, OK_Ordinary, false, false,
1305561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor           false, false),
1306f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall      Val(val) {}
13071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1308cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor  /// \brief Build an empty imaginary literal.
13091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  explicit ImaginaryLiteral(EmptyShell Empty)
1310cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor    : Expr(ImaginaryLiteralClass, Empty) { }
1311cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor
13125549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  const Expr *getSubExpr() const { return cast<Expr>(Val); }
13135549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getSubExpr() { return cast<Expr>(Val); }
1314cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor  void setSubExpr(Expr *E) { Val = E; }
1315cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor
1316aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY { return Val->getSourceRange(); }
13171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
13181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == ImaginaryLiteralClass;
13195d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner  }
13205d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner  static bool classof(const ImaginaryLiteral *) { return true; }
13211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
13225d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner  // Iterators
132363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(&Val, &Val+1); }
13245d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner};
13255d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner
1326e6a82b2c29ad05534841e5f8fd033fb17b6f61e2Ted Kremenek/// StringLiteral - This represents a string literal expression, e.g. "foo"
1327e6a82b2c29ad05534841e5f8fd033fb17b6f61e2Ted Kremenek/// or L"bar" (wide strings).  The actual string is returned by getStrData()
1328e6a82b2c29ad05534841e5f8fd033fb17b6f61e2Ted Kremenek/// is NOT null-terminated, and the length of the string is determined by
1329a7ad98ff0919d6a24ea7c46634ea29bea551c1a0Chris Lattner/// calling getByteLength().  The C type for a string is always a
1330c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// ConstantArrayType.  In C++, the char type is const qualified, in C it is
1331c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// not.
1332690398188ea5b428f06aa13c7d4ce6eb741ad4f9Chris Lattner///
1333690398188ea5b428f06aa13c7d4ce6eb741ad4f9Chris Lattner/// Note that strings in C can be formed by concatenation of multiple string
13348bea7c0ee44c71c817de7dc2be932b73bec90c9fChris Lattner/// literal pptokens in translation phase #6.  This keeps track of the locations
1335690398188ea5b428f06aa13c7d4ce6eb741ad4f9Chris Lattner/// of each of these pieces.
1336c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner///
1337c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// Strings in C can also be truncated and extended by assigning into arrays,
1338c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// e.g. with constructs like:
1339c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner///   char X[2] = "foobar";
1340c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// In this case, getByteLength() will return 6, but the string literal will
1341c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// have type "char[2]".
13425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass StringLiteral : public Expr {
13435cee1195584fa8672253139c86e922daeda69b9eDouglas Gregorpublic:
13445cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor  enum StringKind {
13455cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor    Ascii,
13465cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor    Wide,
13475cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor    UTF8,
13485cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor    UTF16,
13495cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor    UTF32
13505cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor  };
13515cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor
13525cee1195584fa8672253139c86e922daeda69b9eDouglas Gregorprivate:
13533e2193ce5feb2feb092e5ae615e85148e06e9fd2Anders Carlsson  friend class ASTStmtReader;
13543e2193ce5feb2feb092e5ae615e85148e06e9fd2Anders Carlsson
135564f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman  union {
135664f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman    const char *asChar;
135764f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman    const uint16_t *asUInt16;
135864f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman    const uint32_t *asUInt32;
135964f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman  } StrData;
136064f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman  unsigned Length;
13610840f2378e9b5764755c5dffd27d7878c7606a0cBenjamin Kramer  unsigned CharByteWidth : 4;
13625cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor  unsigned Kind : 3;
13630840f2378e9b5764755c5dffd27d7878c7606a0cBenjamin Kramer  unsigned IsPascal : 1;
13640840f2378e9b5764755c5dffd27d7878c7606a0cBenjamin Kramer  unsigned NumConcatenated;
1365726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner  SourceLocation TokLocs[1];
13662085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner
1367f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall  StringLiteral(QualType Ty) :
1368561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor    Expr(StringLiteralClass, Ty, VK_LValue, OK_Ordinary, false, false, false,
1369561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor         false) {}
13701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
137164f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman  static int mapCharByteWidth(TargetInfo const &target,StringKind k);
137264f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman
13735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
13742085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner  /// This is the "fully general" constructor that allows representation of
13752085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner  /// strings formed from multiple concatenated tokens.
13765cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor  static StringLiteral *Create(ASTContext &C, StringRef Str, StringKind Kind,
137765aa6885818d4b4eea2e5a9d12085b2398148662Jay Foad                               bool Pascal, QualType Ty,
1378a135fb43eb94524a6529768596a4533eed9aa70dAnders Carlsson                               const SourceLocation *Loc, unsigned NumStrs);
13792085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner
13802085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner  /// Simple constructor for string literals made from one token.
13815cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor  static StringLiteral *Create(ASTContext &C, StringRef Str, StringKind Kind,
13825cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor                               bool Pascal, QualType Ty,
13835cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor                               SourceLocation Loc) {
13845cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor    return Create(C, Str, Kind, Pascal, Ty, &Loc, 1);
13852085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner  }
1386a135fb43eb94524a6529768596a4533eed9aa70dAnders Carlsson
1387673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor  /// \brief Construct an empty string literal.
1388673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor  static StringLiteral *CreateEmpty(ASTContext &C, unsigned NumStrs);
1389673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor
1390686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  StringRef getString() const {
139164f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman    assert(CharByteWidth==1
139264f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman           && "This function is used in places that assume strings use char");
139364f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman    return StringRef(StrData.asChar, getByteLength());
139464f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman  }
139564f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman
13960982205bade2fb4fc984c27b2ab401e683963b10James Dennett  /// Allow access to clients that need the byte representation, such as
13970982205bade2fb4fc984c27b2ab401e683963b10James Dennett  /// ASTWriterStmt::VisitStringLiteral().
139864f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman  StringRef getBytes() const {
1399e91e0ae772004912285ccc3848b27208da8c045bChris Lattner    // FIXME: StringRef may not be the right type to use as a result for this.
1400e91e0ae772004912285ccc3848b27208da8c045bChris Lattner    if (CharByteWidth == 1)
1401e91e0ae772004912285ccc3848b27208da8c045bChris Lattner      return StringRef(StrData.asChar, getByteLength());
1402e91e0ae772004912285ccc3848b27208da8c045bChris Lattner    if (CharByteWidth == 4)
140364f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman      return StringRef(reinterpret_cast<const char*>(StrData.asUInt32),
140464f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman                       getByteLength());
1405e91e0ae772004912285ccc3848b27208da8c045bChris Lattner    assert(CharByteWidth == 2 && "unsupported CharByteWidth");
1406e91e0ae772004912285ccc3848b27208da8c045bChris Lattner    return StringRef(reinterpret_cast<const char*>(StrData.asUInt16),
1407e91e0ae772004912285ccc3848b27208da8c045bChris Lattner                     getByteLength());
1408b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar  }
14092f4eaef37476ae6891ede8ba215d0f6fd093629bBenjamin Kramer
14108ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu  void outputString(raw_ostream &OS);
14118ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu
141264f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman  uint32_t getCodeUnit(size_t i) const {
1413e91e0ae772004912285ccc3848b27208da8c045bChris Lattner    assert(i < Length && "out of bounds access");
1414e91e0ae772004912285ccc3848b27208da8c045bChris Lattner    if (CharByteWidth == 1)
141564f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman      return static_cast<unsigned char>(StrData.asChar[i]);
1416e91e0ae772004912285ccc3848b27208da8c045bChris Lattner    if (CharByteWidth == 4)
1417e91e0ae772004912285ccc3848b27208da8c045bChris Lattner      return StrData.asUInt32[i];
1418e91e0ae772004912285ccc3848b27208da8c045bChris Lattner    assert(CharByteWidth == 2 && "unsupported CharByteWidth");
1419e91e0ae772004912285ccc3848b27208da8c045bChris Lattner    return StrData.asUInt16[i];
142064f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman  }
142164f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman
142264f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman  unsigned getByteLength() const { return CharByteWidth*Length; }
142364f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman  unsigned getLength() const { return Length; }
142464f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman  unsigned getCharByteWidth() const { return CharByteWidth; }
1425673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor
1426673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor  /// \brief Sets the string data to the given string data.
142764f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman  void setString(ASTContext &C, StringRef Str,
142864f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman                 StringKind Kind, bool IsPascal);
1429673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor
14305cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor  StringKind getKind() const { return static_cast<StringKind>(Kind); }
1431ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1432ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
14335cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor  bool isAscii() const { return Kind == Ascii; }
14345cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor  bool isWide() const { return Kind == Wide; }
14355cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor  bool isUTF8() const { return Kind == UTF8; }
14365cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor  bool isUTF16() const { return Kind == UTF16; }
14375cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor  bool isUTF32() const { return Kind == UTF32; }
14383e2193ce5feb2feb092e5ae615e85148e06e9fd2Anders Carlsson  bool isPascal() const { return IsPascal; }
14395cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor
14408d4141f83d9de379547cf05bd75d4c6cf894b189Steve Naroff  bool containsNonAsciiOrNull() const {
1441686775deca8b8685eb90801495880e3abdd844c2Chris Lattner    StringRef Str = getString();
1442b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar    for (unsigned i = 0, e = Str.size(); i != e; ++i)
1443b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar      if (!isascii(Str[i]) || !Str[i])
144433fdb738a6c125f4c788733897021b7c1a062b0cSteve Naroff        return true;
144533fdb738a6c125f4c788733897021b7c1a062b0cSteve Naroff    return false;
144633fdb738a6c125f4c788733897021b7c1a062b0cSteve Naroff  }
1447ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1448726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner  /// getNumConcatenated - Get the number of string literal tokens that were
1449726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner  /// concatenated in translation phase #6 to form this string literal.
1450726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner  unsigned getNumConcatenated() const { return NumConcatenated; }
14511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1452726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner  SourceLocation getStrTokenLoc(unsigned TokNum) const {
1453726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner    assert(TokNum < NumConcatenated && "Invalid tok number");
1454726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner    return TokLocs[TokNum];
1455726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner  }
14561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  void setStrTokenLoc(unsigned TokNum, SourceLocation L) {
1457673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor    assert(TokNum < NumConcatenated && "Invalid tok number");
1458673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor    TokLocs[TokNum] = L;
1459673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor  }
1460ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
146108f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner  /// getLocationOfByte - Return a source location that points to the specified
146208f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner  /// byte of this string literal.
146308f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner  ///
146408f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner  /// Strings are amazingly complex.  They can be formed from multiple tokens
146508f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner  /// and can have escape sequences in them in addition to the usual trigraph
146608f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner  /// and escaped newline business.  This routine handles this complexity.
146708f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner  ///
146808f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner  SourceLocation getLocationOfByte(unsigned ByteNo, const SourceManager &SM,
146908f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner                                   const LangOptions &Features,
147008f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner                                   const TargetInfo &Target) const;
1471673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor
1472b137299ce5bb6c36fbba651858600857fda4dd50Chris Lattner  typedef const SourceLocation *tokloc_iterator;
1473b137299ce5bb6c36fbba651858600857fda4dd50Chris Lattner  tokloc_iterator tokloc_begin() const { return TokLocs; }
1474b137299ce5bb6c36fbba651858600857fda4dd50Chris Lattner  tokloc_iterator tokloc_end() const { return TokLocs+NumConcatenated; }
14755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1476aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY {
14771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return SourceRange(TokLocs[0], TokLocs[NumConcatenated-1]);
14785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
14791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
14801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == StringLiteralClass;
14815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
14825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const StringLiteral *) { return true; }
14831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
148477ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  // Iterators
148563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(); }
14865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
14875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
14885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ParenExpr - This represents a parethesized expression, e.g. "(1)".  This
14895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// AST node is only formed if full location information is requested.
14905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass ParenExpr : public Expr {
14915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation L, R;
14925549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Stmt *Val;
14935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
14945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ParenExpr(SourceLocation l, SourceLocation r, Expr *val)
1495898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor    : Expr(ParenExprClass, val->getType(),
1496f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall           val->getValueKind(), val->getObjectKind(),
1497bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           val->isTypeDependent(), val->isValueDependent(),
1498561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor           val->isInstantiationDependent(),
1499bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           val->containsUnexpandedParameterPack()),
1500898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor      L(l), R(r), Val(val) {}
15011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1502c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor  /// \brief Construct an empty parenthesized expression.
15031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  explicit ParenExpr(EmptyShell Empty)
1504c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor    : Expr(ParenExprClass, Empty) { }
1505c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor
15065549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  const Expr *getSubExpr() const { return cast<Expr>(Val); }
15075549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getSubExpr() { return cast<Expr>(Val); }
1508c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor  void setSubExpr(Expr *E) { Val = E; }
1509c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor
1510aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY { return SourceRange(L, R); }
15115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1512313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor  /// \brief Get the location of the left parentheses '('.
1513313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor  SourceLocation getLParen() const { return L; }
1514c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor  void setLParen(SourceLocation Loc) { L = Loc; }
1515313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor
1516313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor  /// \brief Get the location of the right parentheses ')'.
1517313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor  SourceLocation getRParen() const { return R; }
1518c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor  void setRParen(SourceLocation Loc) { R = Loc; }
1519313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor
15201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
15211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == ParenExprClass;
15225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
15235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const ParenExpr *) { return true; }
15241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
152577ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  // Iterators
152663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(&Val, &Val+1); }
15275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
15285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
15295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
15300518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl/// UnaryOperator - This represents the unary-expression's (except sizeof and
15310518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl/// alignof), the postinc/postdec operators from postfix-expression, and various
15325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// extensions.
1533dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner///
1534dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner/// Notes on various nodes:
1535dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner///
1536dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner/// Real/Imag - These return the real/imag part of a complex operand.  If
1537dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner///   applied to a non-complex value, the former returns its operand and the
1538dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner///   later returns zero in the type of the operand.
1539dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner///
15405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass UnaryOperator : public Expr {
15415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
15425baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall  typedef UnaryOperatorKind Opcode;
15435baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall
15445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprivate:
15450799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall  unsigned Opc : 5;
15465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation Loc;
15470799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall  Stmt *Val;
15481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumppublic:
15495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1550f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall  UnaryOperator(Expr *input, Opcode opc, QualType type,
1551f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                ExprValueKind VK, ExprObjectKind OK, SourceLocation l)
1552f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    : Expr(UnaryOperatorClass, type, VK, OK,
1553de7e66256b1bdfcf6526994825a8c8fced52a31cEli Friedman           input->isTypeDependent() || type->isDependentType(),
1554bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           input->isValueDependent(),
1555ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie           (input->isInstantiationDependent() ||
1556561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor            type->isInstantiationDependentType()),
1557bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           input->containsUnexpandedParameterPack()),
15580799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall      Opc(opc), Loc(l), Val(input) {}
15595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
15600b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor  /// \brief Build an empty unary operator.
15611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  explicit UnaryOperator(EmptyShell Empty)
15622de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall    : Expr(UnaryOperatorClass, Empty), Opc(UO_AddrOf) { }
15630b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor
15640799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall  Opcode getOpcode() const { return static_cast<Opcode>(Opc); }
15650b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor  void setOpcode(Opcode O) { Opc = O; }
15660b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor
15675549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getSubExpr() const { return cast<Expr>(Val); }
15680b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor  void setSubExpr(Expr *E) { Val = E; }
15690b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor
15705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// getOperatorLoc - Return the location of the operator.
15715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation getOperatorLoc() const { return Loc; }
15720b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor  void setOperatorLoc(SourceLocation L) { Loc = L; }
15730b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor
15745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// isPostfix - Return true if this is a postfix operation, like x++.
15752085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner  static bool isPostfix(Opcode Op) {
15762de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall    return Op == UO_PostInc || Op == UO_PostDec;
15772085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner  }
15785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1579cc7bd10c0de9449b795bda3c5dcc6d83cc48436bZhanyong Wan  /// isPrefix - Return true if this is a prefix operation, like --x.
15802085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner  static bool isPrefix(Opcode Op) {
15812de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall    return Op == UO_PreInc || Op == UO_PreDec;
15822085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner  }
15835a56ac30d04e8f0431a08980885662a47a6308aaTed Kremenek
15840799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall  bool isPrefix() const { return isPrefix(getOpcode()); }
15850799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall  bool isPostfix() const { return isPostfix(getOpcode()); }
15863c3b7f90a863af43fa63043d396553ecf205351cJohn McCall
15873c3b7f90a863af43fa63043d396553ecf205351cJohn McCall  static bool isIncrementOp(Opcode Op) {
15883c3b7f90a863af43fa63043d396553ecf205351cJohn McCall    return Op == UO_PreInc || Op == UO_PostInc;
15893c3b7f90a863af43fa63043d396553ecf205351cJohn McCall  }
15902de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  bool isIncrementOp() const {
15913c3b7f90a863af43fa63043d396553ecf205351cJohn McCall    return isIncrementOp(getOpcode());
15923c3b7f90a863af43fa63043d396553ecf205351cJohn McCall  }
15933c3b7f90a863af43fa63043d396553ecf205351cJohn McCall
15943c3b7f90a863af43fa63043d396553ecf205351cJohn McCall  static bool isDecrementOp(Opcode Op) {
15953c3b7f90a863af43fa63043d396553ecf205351cJohn McCall    return Op == UO_PreDec || Op == UO_PostDec;
15962de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  }
15973c3b7f90a863af43fa63043d396553ecf205351cJohn McCall  bool isDecrementOp() const {
15983c3b7f90a863af43fa63043d396553ecf205351cJohn McCall    return isDecrementOp(getOpcode());
15993c3b7f90a863af43fa63043d396553ecf205351cJohn McCall  }
16003c3b7f90a863af43fa63043d396553ecf205351cJohn McCall
16013c3b7f90a863af43fa63043d396553ecf205351cJohn McCall  static bool isIncrementDecrementOp(Opcode Op) { return Op <= UO_PreDec; }
16022de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  bool isIncrementDecrementOp() const {
16033c3b7f90a863af43fa63043d396553ecf205351cJohn McCall    return isIncrementDecrementOp(getOpcode());
16042de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  }
16053c3b7f90a863af43fa63043d396553ecf205351cJohn McCall
16062de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  static bool isArithmeticOp(Opcode Op) {
16072de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall    return Op >= UO_Plus && Op <= UO_LNot;
16082de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  }
16090799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall  bool isArithmeticOp() const { return isArithmeticOp(getOpcode()); }
16101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
16115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// getOpcodeStr - Turn an Opcode enum value into the punctuation char it
16125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// corresponds to, e.g. "sizeof" or "[pre]++"
16135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static const char *getOpcodeStr(Opcode Op);
16145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1615bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor  /// \brief Retrieve the unary opcode that corresponds to the given
1616bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor  /// overloaded operator.
1617bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor  static Opcode getOverloadedOpcode(OverloadedOperatorKind OO, bool Postfix);
1618bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor
1619bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor  /// \brief Retrieve the overloaded operator kind that corresponds to
1620bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor  /// the given unary opcode.
1621bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor  static OverloadedOperatorKind getOverloadedOperator(Opcode Opc);
1622bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor
1623aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY {
16245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    if (isPostfix())
16255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      return SourceRange(Val->getLocStart(), Loc);
16265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    else
16275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      return SourceRange(Loc, Val->getLocEnd());
16285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
16294f311183be3d923da9fbe8702c453688b4c426a9Daniel Dunbar  SourceLocation getExprLoc() const LLVM_READONLY { return Loc; }
16301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
16311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
16321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == UnaryOperatorClass;
16335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
16345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const UnaryOperator *) { return true; }
16351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
163677ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  // Iterators
163763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(&Val, &Val+1); }
16385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
16395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
16408ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// OffsetOfExpr - [C99 7.17] - This represents an expression of the form
16418ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// offsetof(record-type, member-designator). For example, given:
16428ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// @code
16438ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// struct S {
16448ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor///   float f;
1645ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie///   double d;
16468ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// };
16478ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// struct T {
16488ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor///   int i;
16498ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor///   struct S s[10];
16508ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// };
16518ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// @endcode
1652ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie/// we can represent and evaluate the expression @c offsetof(struct T, s[2].d).
16538ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor
16548ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregorclass OffsetOfExpr : public Expr {
16558ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregorpublic:
16568ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  // __builtin_offsetof(type, identifier(.identifier|[expr])*)
16578ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  class OffsetOfNode {
16588ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  public:
16598ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    /// \brief The kind of offsetof node we have.
16608ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    enum Kind {
1661cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor      /// \brief An index into an array.
16628ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor      Array = 0x00,
1663cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor      /// \brief A field.
16648ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor      Field = 0x01,
1665cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor      /// \brief A field in a dependent type, known only by its name.
1666cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor      Identifier = 0x02,
1667cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor      /// \brief An implicit indirection through a C++ base class, when the
1668cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor      /// field found is in a base class.
1669cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor      Base = 0x03
16708ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    };
16718ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor
16728ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  private:
16738ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    enum { MaskBits = 2, Mask = 0x03 };
1674ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
16758ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    /// \brief The source range that covers this part of the designator.
16768ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    SourceRange Range;
1677ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
16788ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    /// \brief The data describing the designator, which comes in three
16798ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    /// different forms, depending on the lower two bits.
1680ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    ///   - An unsigned index into the array of Expr*'s stored after this node
16818ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    ///     in memory, for [constant-expression] designators.
16828ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    ///   - A FieldDecl*, for references to a known field.
16838ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    ///   - An IdentifierInfo*, for references to a field with a given name
16848ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    ///     when the class type is dependent.
1685ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    ///   - A CXXBaseSpecifier*, for references that look at a field in a
1686cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor    ///     base class.
16878ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    uintptr_t Data;
1688ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
16898ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  public:
16908ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    /// \brief Create an offsetof node that refers to an array element.
1691ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    OffsetOfNode(SourceLocation LBracketLoc, unsigned Index,
16928ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor                 SourceLocation RBracketLoc)
16938ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor      : Range(LBracketLoc, RBracketLoc), Data((Index << 2) | Array) { }
1694ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
16958ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    /// \brief Create an offsetof node that refers to a field.
1696ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    OffsetOfNode(SourceLocation DotLoc, FieldDecl *Field,
16978ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor                 SourceLocation NameLoc)
1698ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie      : Range(DotLoc.isValid()? DotLoc : NameLoc, NameLoc),
16998ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor        Data(reinterpret_cast<uintptr_t>(Field) | OffsetOfNode::Field) { }
1700ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
17018ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    /// \brief Create an offsetof node that refers to an identifier.
17028ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    OffsetOfNode(SourceLocation DotLoc, IdentifierInfo *Name,
17038ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor                 SourceLocation NameLoc)
1704ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie      : Range(DotLoc.isValid()? DotLoc : NameLoc, NameLoc),
17058ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor        Data(reinterpret_cast<uintptr_t>(Name) | Identifier) { }
1706cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor
1707cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor    /// \brief Create an offsetof node that refers into a C++ base class.
1708cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor    explicit OffsetOfNode(const CXXBaseSpecifier *Base)
1709cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor      : Range(), Data(reinterpret_cast<uintptr_t>(Base) | OffsetOfNode::Base) {}
1710ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
17118ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    /// \brief Determine what kind of offsetof node this is.
1712ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    Kind getKind() const {
17138ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor      return static_cast<Kind>(Data & Mask);
17148ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    }
1715ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
17168ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    /// \brief For an array element node, returns the index into the array
17178ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    /// of expressions.
17188ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    unsigned getArrayExprIndex() const {
17198ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor      assert(getKind() == Array);
17208ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor      return Data >> 2;
17218ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    }
17228ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor
17238ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    /// \brief For a field offsetof node, returns the field.
17248ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    FieldDecl *getField() const {
17258ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor      assert(getKind() == Field);
1726cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor      return reinterpret_cast<FieldDecl *>(Data & ~(uintptr_t)Mask);
17278ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    }
1728ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
17298ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    /// \brief For a field or identifier offsetof node, returns the name of
17308ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    /// the field.
17318ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    IdentifierInfo *getFieldName() const;
1732ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1733cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor    /// \brief For a base class node, returns the base specifier.
1734cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor    CXXBaseSpecifier *getBase() const {
1735cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor      assert(getKind() == Base);
1736ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie      return reinterpret_cast<CXXBaseSpecifier *>(Data & ~(uintptr_t)Mask);
1737cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor    }
1738ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
17398ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    /// \brief Retrieve the source range that covers this offsetof node.
17408ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    ///
17418ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    /// For an array element node, the source range contains the locations of
17428ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    /// the square brackets. For a field or identifier node, the source range
1743ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    /// contains the location of the period (if there is one) and the
17448ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    /// identifier.
1745aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar    SourceRange getSourceRange() const LLVM_READONLY { return Range; }
17468ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  };
17478ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor
17488ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregorprivate:
1749ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
17508ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  SourceLocation OperatorLoc, RParenLoc;
17518ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  // Base type;
17528ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  TypeSourceInfo *TSInfo;
17538ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  // Number of sub-components (i.e. instances of OffsetOfNode).
17548ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  unsigned NumComps;
17558ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  // Number of sub-expressions (i.e. array subscript expressions).
17568ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  unsigned NumExprs;
1757ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1758ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  OffsetOfExpr(ASTContext &C, QualType type,
17598ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor               SourceLocation OperatorLoc, TypeSourceInfo *tsi,
1760ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie               OffsetOfNode* compsPtr, unsigned numComps,
17618ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor               Expr** exprsPtr, unsigned numExprs,
17628ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor               SourceLocation RParenLoc);
17638ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor
17648ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  explicit OffsetOfExpr(unsigned numComps, unsigned numExprs)
17658ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    : Expr(OffsetOfExprClass, EmptyShell()),
1766ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie      TSInfo(0), NumComps(numComps), NumExprs(numExprs) {}
17678ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor
17688ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregorpublic:
1769ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1770ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  static OffsetOfExpr *Create(ASTContext &C, QualType type,
1771ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie                              SourceLocation OperatorLoc, TypeSourceInfo *tsi,
1772ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie                              OffsetOfNode* compsPtr, unsigned numComps,
17738ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor                              Expr** exprsPtr, unsigned numExprs,
17748ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor                              SourceLocation RParenLoc);
17758ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor
1776ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  static OffsetOfExpr *CreateEmpty(ASTContext &C,
17778ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor                                   unsigned NumComps, unsigned NumExprs);
17788ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor
17798ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  /// getOperatorLoc - Return the location of the operator.
17808ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  SourceLocation getOperatorLoc() const { return OperatorLoc; }
17818ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  void setOperatorLoc(SourceLocation L) { OperatorLoc = L; }
17828ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor
17838ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  /// \brief Return the location of the right parentheses.
17848ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  SourceLocation getRParenLoc() const { return RParenLoc; }
17858ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  void setRParenLoc(SourceLocation R) { RParenLoc = R; }
1786ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
17878ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  TypeSourceInfo *getTypeSourceInfo() const {
17888ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    return TSInfo;
17898ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  }
17908ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  void setTypeSourceInfo(TypeSourceInfo *tsi) {
17918ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    TSInfo = tsi;
17928ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  }
1793ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
17948cad3046be06ea73ff8892d947697a21d7a440d3Peter Collingbourne  const OffsetOfNode &getComponent(unsigned Idx) const {
17958ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    assert(Idx < NumComps && "Subscript out of range");
17968cad3046be06ea73ff8892d947697a21d7a440d3Peter Collingbourne    return reinterpret_cast<const OffsetOfNode *> (this + 1)[Idx];
17978ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  }
17988ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor
17998ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  void setComponent(unsigned Idx, OffsetOfNode ON) {
18008ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    assert(Idx < NumComps && "Subscript out of range");
18018ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    reinterpret_cast<OffsetOfNode *> (this + 1)[Idx] = ON;
18028ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  }
1803ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
18048ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  unsigned getNumComponents() const {
18058ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    return NumComps;
18068ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  }
18078ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor
18088ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  Expr* getIndexExpr(unsigned Idx) {
18098ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    assert(Idx < NumExprs && "Subscript out of range");
18108ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    return reinterpret_cast<Expr **>(
18118ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor                    reinterpret_cast<OffsetOfNode *>(this+1) + NumComps)[Idx];
18128ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  }
18138cad3046be06ea73ff8892d947697a21d7a440d3Peter Collingbourne  const Expr *getIndexExpr(unsigned Idx) const {
18148cad3046be06ea73ff8892d947697a21d7a440d3Peter Collingbourne    return const_cast<OffsetOfExpr*>(this)->getIndexExpr(Idx);
18158cad3046be06ea73ff8892d947697a21d7a440d3Peter Collingbourne  }
18168ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor
18178ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  void setIndexExpr(unsigned Idx, Expr* E) {
18188ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    assert(Idx < NumComps && "Subscript out of range");
18198ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    reinterpret_cast<Expr **>(
18208ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor                reinterpret_cast<OffsetOfNode *>(this+1) + NumComps)[Idx] = E;
18218ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  }
1822ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
18238ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  unsigned getNumExpressions() const {
18248ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    return NumExprs;
18258ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  }
18268ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor
1827aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY {
18288ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    return SourceRange(OperatorLoc, RParenLoc);
18298ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  }
18308ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor
18318ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  static bool classof(const Stmt *T) {
18328ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    return T->getStmtClass() == OffsetOfExprClass;
18338ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  }
18348ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor
18358ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  static bool classof(const OffsetOfExpr *) { return true; }
18368ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor
18378ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  // Iterators
183863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() {
183963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    Stmt **begin =
184063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall      reinterpret_cast<Stmt**>(reinterpret_cast<OffsetOfNode*>(this + 1)
184163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall                               + NumComps);
184263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return child_range(begin, begin + NumExprs);
184363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
18448ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor};
18458ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor
1846f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne/// UnaryExprOrTypeTraitExpr - expression with either a type or (unevaluated)
1847f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne/// expression operand.  Used for sizeof/alignof (C99 6.5.3.4) and
1848f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne/// vec_step (OpenCL 1.1 6.11.12).
1849f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourneclass UnaryExprOrTypeTraitExpr : public Expr {
1850d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl  union {
1851a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall    TypeSourceInfo *Ty;
1852d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl    Stmt *Ex;
1853d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl  } Argument;
18545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation OpLoc, RParenLoc;
185542602bb40aefcc2751d4078ba88aacf4d965c9bdDouglas Gregor
18565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
1857f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne  UnaryExprOrTypeTraitExpr(UnaryExprOrTypeTrait ExprKind, TypeSourceInfo *TInfo,
1858f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne                           QualType resultType, SourceLocation op,
1859f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne                           SourceLocation rp) :
1860f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne      Expr(UnaryExprOrTypeTraitExprClass, resultType, VK_RValue, OK_Ordinary,
1861ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor           false, // Never type-dependent (C++ [temp.dep.expr]p3).
18622850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl           // Value-dependent if the argument is type-dependent.
1863bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           TInfo->getType()->isDependentType(),
1864561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor           TInfo->getType()->isInstantiationDependentType(),
1865bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           TInfo->getType()->containsUnexpandedParameterPack()),
1866bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer      OpLoc(op), RParenLoc(rp) {
1867bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer    UnaryExprOrTypeTraitExprBits.Kind = ExprKind;
1868bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer    UnaryExprOrTypeTraitExprBits.IsType = true;
1869a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall    Argument.Ty = TInfo;
1870ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor  }
1871ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor
1872f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne  UnaryExprOrTypeTraitExpr(UnaryExprOrTypeTrait ExprKind, Expr *E,
1873f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne                           QualType resultType, SourceLocation op,
1874f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne                           SourceLocation rp) :
1875f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne      Expr(UnaryExprOrTypeTraitExprClass, resultType, VK_RValue, OK_Ordinary,
1876ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor           false, // Never type-dependent (C++ [temp.dep.expr]p3).
1877ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor           // Value-dependent if the argument is type-dependent.
1878bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           E->isTypeDependent(),
1879561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor           E->isInstantiationDependent(),
1880bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           E->containsUnexpandedParameterPack()),
1881bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer      OpLoc(op), RParenLoc(rp) {
1882bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer    UnaryExprOrTypeTraitExprBits.Kind = ExprKind;
1883bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer    UnaryExprOrTypeTraitExprBits.IsType = false;
1884ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor    Argument.Ex = E;
1885d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl  }
18860518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl
18870b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor  /// \brief Construct an empty sizeof/alignof expression.
1888f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne  explicit UnaryExprOrTypeTraitExpr(EmptyShell Empty)
1889f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne    : Expr(UnaryExprOrTypeTraitExprClass, Empty) { }
18900b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor
1891f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne  UnaryExprOrTypeTrait getKind() const {
1892bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer    return static_cast<UnaryExprOrTypeTrait>(UnaryExprOrTypeTraitExprBits.Kind);
1893f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne  }
1894bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer  void setKind(UnaryExprOrTypeTrait K) { UnaryExprOrTypeTraitExprBits.Kind = K;}
18950b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor
1896bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer  bool isArgumentType() const { return UnaryExprOrTypeTraitExprBits.IsType; }
18970518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl  QualType getArgumentType() const {
18985ab75172051a6d2ea71a80a79e81c65519fd3462John McCall    return getArgumentTypeInfo()->getType();
18995ab75172051a6d2ea71a80a79e81c65519fd3462John McCall  }
1900a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall  TypeSourceInfo *getArgumentTypeInfo() const {
19010518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl    assert(isArgumentType() && "calling getArgumentType() when arg is expr");
19025ab75172051a6d2ea71a80a79e81c65519fd3462John McCall    return Argument.Ty;
19030518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl  }
1904caae7b099a0324b7c15dc89a9b70969d5d7ce996Chris Lattner  Expr *getArgumentExpr() {
19050518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl    assert(!isArgumentType() && "calling getArgumentExpr() when arg is type");
1906d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl    return static_cast<Expr*>(Argument.Ex);
19070518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl  }
1908caae7b099a0324b7c15dc89a9b70969d5d7ce996Chris Lattner  const Expr *getArgumentExpr() const {
1909f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne    return const_cast<UnaryExprOrTypeTraitExpr*>(this)->getArgumentExpr();
1910caae7b099a0324b7c15dc89a9b70969d5d7ce996Chris Lattner  }
19110b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor
1912bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer  void setArgument(Expr *E) {
1913bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer    Argument.Ex = E;
1914bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer    UnaryExprOrTypeTraitExprBits.IsType = false;
1915bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer  }
1916a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall  void setArgument(TypeSourceInfo *TInfo) {
1917a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall    Argument.Ty = TInfo;
1918bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer    UnaryExprOrTypeTraitExprBits.IsType = true;
19190b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor  }
19200b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor
19210518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl  /// Gets the argument type, or the type of the argument expression, whichever
19220518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl  /// is appropriate.
19230518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl  QualType getTypeOfArgument() const {
19240518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl    return isArgumentType() ? getArgumentType() : getArgumentExpr()->getType();
19250518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl  }
19260518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl
192776e773a443be9f006610f46529e07d4c8d857680Chris Lattner  SourceLocation getOperatorLoc() const { return OpLoc; }
19280b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor  void setOperatorLoc(SourceLocation L) { OpLoc = L; }
19290b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor
19300b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor  SourceLocation getRParenLoc() const { return RParenLoc; }
19310b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
1932866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek
1933aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY {
1934866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek    return SourceRange(OpLoc, RParenLoc);
1935866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek  }
19365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
19371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
1938f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne    return T->getStmtClass() == UnaryExprOrTypeTraitExprClass;
19395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
1940f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne  static bool classof(const UnaryExprOrTypeTraitExpr *) { return true; }
19411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
194277ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  // Iterators
194363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children();
19445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
19455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
19465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===//
19475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// Postfix Operators.
19485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===//
19495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
19505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ArraySubscriptExpr - [C99 6.5.2.1] Array Subscripting.
19515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass ArraySubscriptExpr : public Expr {
195277ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  enum { LHS, RHS, END_EXPR=2 };
19531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  Stmt* SubExprs[END_EXPR];
19545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation RBracketLoc;
19555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
19562324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek  ArraySubscriptExpr(Expr *lhs, Expr *rhs, QualType t,
1957f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                     ExprValueKind VK, ExprObjectKind OK,
195873d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner                     SourceLocation rbracketloc)
1959f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall  : Expr(ArraySubscriptExprClass, t, VK, OK,
19602850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl         lhs->isTypeDependent() || rhs->isTypeDependent(),
1961bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor         lhs->isValueDependent() || rhs->isValueDependent(),
1962561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor         (lhs->isInstantiationDependent() ||
1963561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor          rhs->isInstantiationDependent()),
1964bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor         (lhs->containsUnexpandedParameterPack() ||
1965bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor          rhs->containsUnexpandedParameterPack())),
19662850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl    RBracketLoc(rbracketloc) {
196773d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner    SubExprs[LHS] = lhs;
196873d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner    SubExprs[RHS] = rhs;
196973d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner  }
19701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1971cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor  /// \brief Create an empty array subscript expression.
1972cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor  explicit ArraySubscriptExpr(EmptyShell Shell)
1973cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor    : Expr(ArraySubscriptExprClass, Shell) { }
1974cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor
19752324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek  /// An array access can be written A[4] or 4[A] (both are equivalent).
19762324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek  /// - getBase() and getIdx() always present the normalized view: A[4].
19772324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek  ///    In this case getBase() returns "A" and getIdx() returns "4".
19782324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek  /// - getLHS() and getRHS() present the syntactic view. e.g. for
19792324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek  ///    4[A] getLHS() returns "4".
198033fd5c124aac15bab7cad95e4e0e7761356d2c06Christopher Lamb  /// Note: Because vector element access is also written A[4] we must
198133fd5c124aac15bab7cad95e4e0e7761356d2c06Christopher Lamb  /// predicate the format conversion in getBase and getIdx only on the
198233fd5c124aac15bab7cad95e4e0e7761356d2c06Christopher Lamb  /// the type of the RHS, as it is possible for the LHS to be a vector of
198333fd5c124aac15bab7cad95e4e0e7761356d2c06Christopher Lamb  /// integer type
19845549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getLHS() { return cast<Expr>(SubExprs[LHS]); }
19855549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  const Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); }
1986cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor  void setLHS(Expr *E) { SubExprs[LHS] = E; }
1987cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor
19885549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getRHS() { return cast<Expr>(SubExprs[RHS]); }
19895549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  const Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); }
1990cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor  void setRHS(Expr *E) { SubExprs[RHS] = E; }
19911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
19921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  Expr *getBase() {
19935549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek    return cast<Expr>(getRHS()->getType()->isIntegerType() ? getLHS():getRHS());
199477ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  }
19951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
19961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  const Expr *getBase() const {
19975549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek    return cast<Expr>(getRHS()->getType()->isIntegerType() ? getLHS():getRHS());
19982324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek  }
19991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
20001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  Expr *getIdx() {
20015549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek    return cast<Expr>(getRHS()->getType()->isIntegerType() ? getRHS():getLHS());
20022324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek  }
20031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
200477ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  const Expr *getIdx() const {
20055549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek    return cast<Expr>(getRHS()->getType()->isIntegerType() ? getRHS():getLHS());
20061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  }
20071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2008aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY {
200977ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek    return SourceRange(getLHS()->getLocStart(), RBracketLoc);
20105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
20111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2012026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner  SourceLocation getRBracketLoc() const { return RBracketLoc; }
2013cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor  void setRBracketLoc(SourceLocation L) { RBracketLoc = L; }
2014cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor
20154f311183be3d923da9fbe8702c453688b4c426a9Daniel Dunbar  SourceLocation getExprLoc() const LLVM_READONLY { return getBase()->getExprLoc(); }
20165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
20171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
20181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == ArraySubscriptExprClass;
20195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
20205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const ArraySubscriptExpr *) { return true; }
20211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
202277ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  // Iterators
202363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() {
202463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR);
202563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
20265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
20275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
20285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
2029b4609806e9232593ece09ce08b630836e825865cDouglas Gregor/// CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
20301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// CallExpr itself represents a normal function call, e.g., "f(x, 2)",
2031b4609806e9232593ece09ce08b630836e825865cDouglas Gregor/// while its subclasses may represent alternative syntax that (semantically)
20321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// results in a function call. For example, CXXOperatorCallExpr is
2033b4609806e9232593ece09ce08b630836e825865cDouglas Gregor/// a subclass for overloaded operator calls that use operator syntax, e.g.,
2034b4609806e9232593ece09ce08b630836e825865cDouglas Gregor/// "str1 + str2" to resolve to a function call.
20355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass CallExpr : public Expr {
2036cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne  enum { FN=0, PREARGS_START=1 };
20375549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Stmt **SubExprs;
20385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  unsigned NumArgs;
20395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation RParenLoc;
20401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2041b4609806e9232593ece09ce08b630836e825865cDouglas Gregorprotected:
2042cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne  // These versions of the constructor are for derived classes.
2043cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne  CallExpr(ASTContext& C, StmtClass SC, Expr *fn, unsigned NumPreArgs,
2044cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne           Expr **args, unsigned numargs, QualType t, ExprValueKind VK,
2045cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne           SourceLocation rparenloc);
2046cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne  CallExpr(ASTContext &C, StmtClass SC, unsigned NumPreArgs, EmptyShell Empty);
2047cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne
2048cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne  Stmt *getPreArg(unsigned i) {
2049cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne    assert(i < getNumPreArgs() && "Prearg access out of range!");
2050cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne    return SubExprs[PREARGS_START+i];
2051cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne  }
2052cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne  const Stmt *getPreArg(unsigned i) const {
2053cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne    assert(i < getNumPreArgs() && "Prearg access out of range!");
2054cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne    return SubExprs[PREARGS_START+i];
2055cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne  }
2056cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne  void setPreArg(unsigned i, Stmt *PreArg) {
2057cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne    assert(i < getNumPreArgs() && "Prearg access out of range!");
2058cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne    SubExprs[PREARGS_START+i] = PreArg;
2059cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne  }
2060cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne
2061cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne  unsigned getNumPreArgs() const { return CallExprBits.NumPreArgs; }
206242602bb40aefcc2751d4078ba88aacf4d965c9bdDouglas Gregor
20635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
20641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  CallExpr(ASTContext& C, Expr *fn, Expr **args, unsigned numargs, QualType t,
2065f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall           ExprValueKind VK, SourceLocation rparenloc);
20661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
20671f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor  /// \brief Build an empty call expression.
2068ba0a9006dbc4814e1e35f82812cb5a1dad65e8b8Argyrios Kyrtzidis  CallExpr(ASTContext &C, StmtClass SC, EmptyShell Empty);
20691f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor
20705549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  const Expr *getCallee() const { return cast<Expr>(SubExprs[FN]); }
20715549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getCallee() { return cast<Expr>(SubExprs[FN]); }
207218b2515e1bf8c86a4900792692e42fe1296be28dChris Lattner  void setCallee(Expr *F) { SubExprs[FN] = F; }
2073a00425414e8c209cabc25d1826b200aeb94259afZhongxing Xu
2074d20254f2875d0004c57ee766f258dbcee29f4841Nuno Lopes  Decl *getCalleeDecl();
2075d20254f2875d0004c57ee766f258dbcee29f4841Nuno Lopes  const Decl *getCalleeDecl() const {
2076d20254f2875d0004c57ee766f258dbcee29f4841Nuno Lopes    return const_cast<CallExpr*>(this)->getCalleeDecl();
2077d20254f2875d0004c57ee766f258dbcee29f4841Nuno Lopes  }
2078d20254f2875d0004c57ee766f258dbcee29f4841Nuno Lopes
2079a00425414e8c209cabc25d1826b200aeb94259afZhongxing Xu  /// \brief If the callee is a FunctionDecl, return it. Otherwise return 0.
2080a00425414e8c209cabc25d1826b200aeb94259afZhongxing Xu  FunctionDecl *getDirectCallee();
2081bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner  const FunctionDecl *getDirectCallee() const {
2082bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner    return const_cast<CallExpr*>(this)->getDirectCallee();
2083bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner  }
2084a00425414e8c209cabc25d1826b200aeb94259afZhongxing Xu
20855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// getNumArgs - Return the number of actual arguments to this call.
20865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ///
20875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  unsigned getNumArgs() const { return NumArgs; }
20881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2089aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  /// \brief Retrieve the call arguments.
2090cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne  Expr **getArgs() {
2091cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne    return reinterpret_cast<Expr **>(SubExprs+getNumPreArgs()+PREARGS_START);
2092cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne  }
2093d0dcceae2a8ca0e37b5dd471a704de8583d49c95Richard Smith  const Expr *const *getArgs() const {
2094d0dcceae2a8ca0e37b5dd471a704de8583d49c95Richard Smith    return const_cast<CallExpr*>(this)->getArgs();
2095d0dcceae2a8ca0e37b5dd471a704de8583d49c95Richard Smith  }
2096ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
20975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// getArg - Return the specified argument.
20985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  Expr *getArg(unsigned Arg) {
20995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    assert(Arg < NumArgs && "Arg access out of range!");
2100cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne    return cast<Expr>(SubExprs[Arg+getNumPreArgs()+PREARGS_START]);
21015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
21025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  const Expr *getArg(unsigned Arg) const {
21035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    assert(Arg < NumArgs && "Arg access out of range!");
2104cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne    return cast<Expr>(SubExprs[Arg+getNumPreArgs()+PREARGS_START]);
21055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
21061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2107934f276cc5b45e19cd12ebb2d04fd7972a23865cSteve Naroff  /// setArg - Set the specified argument.
2108934f276cc5b45e19cd12ebb2d04fd7972a23865cSteve Naroff  void setArg(unsigned Arg, Expr *ArgExpr) {
2109934f276cc5b45e19cd12ebb2d04fd7972a23865cSteve Naroff    assert(Arg < NumArgs && "Arg access out of range!");
2110cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne    SubExprs[Arg+getNumPreArgs()+PREARGS_START] = ArgExpr;
2111934f276cc5b45e19cd12ebb2d04fd7972a23865cSteve Naroff  }
21121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2113d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner  /// setNumArgs - This changes the number of arguments present in this call.
2114d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner  /// Any orphaned expressions are deleted by this, and any new operands are set
2115d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner  /// to null.
21168189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  void setNumArgs(ASTContext& C, unsigned NumArgs);
21171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
21185549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  typedef ExprIterator arg_iterator;
21195549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  typedef ConstExprIterator const_arg_iterator;
21201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2121cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne  arg_iterator arg_begin() { return SubExprs+PREARGS_START+getNumPreArgs(); }
2122cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne  arg_iterator arg_end() {
2123cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne    return SubExprs+PREARGS_START+getNumPreArgs()+getNumArgs();
2124cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne  }
2125cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne  const_arg_iterator arg_begin() const {
2126cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne    return SubExprs+PREARGS_START+getNumPreArgs();
2127cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne  }
2128cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne  const_arg_iterator arg_end() const {
2129cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne    return SubExprs+PREARGS_START+getNumPreArgs()+getNumArgs();
2130cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne  }
21311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
21325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// getNumCommas - Return the number of commas that must have been present in
21335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// this function call.
21345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  unsigned getNumCommas() const { return NumArgs ? NumArgs - 1 : 0; }
21355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
2136cb888967400a03504c88acedd5248d6778a82f46Chris Lattner  /// isBuiltinCall - If this is a call to a builtin, return the builtin ID.  If
2137cb888967400a03504c88acedd5248d6778a82f46Chris Lattner  /// not, return 0.
2138180f47959a066795cc0f409433023af448bb0328Richard Smith  unsigned isBuiltinCall() const;
21391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
21401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// getCallReturnType - Get the return type of the call expr. This is not
21411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// always the type of the expr itself, if the return type is a reference
21426dde78f744382a5627a04f984a97049e0c4b5e73Anders Carlsson  /// type.
21436dde78f744382a5627a04f984a97049e0c4b5e73Anders Carlsson  QualType getCallReturnType() const;
21441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2145d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner  SourceLocation getRParenLoc() const { return RParenLoc; }
21461f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
2147866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek
2148aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY;
2149aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceLocation getLocStart() const LLVM_READONLY;
2150aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceLocation getLocEnd() const LLVM_READONLY;
21511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
21521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
21534bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt    return T->getStmtClass() >= firstCallExprConstant &&
21544bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt           T->getStmtClass() <= lastCallExprConstant;
21555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
21565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const CallExpr *) { return true; }
215788a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor
215877ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  // Iterators
215963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() {
216063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return child_range(&SubExprs[0],
216163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall                       &SubExprs[0]+NumArgs+getNumPreArgs()+PREARGS_START);
216263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
21635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
21645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
2165ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner/// MemberExpr - [C99 6.5.2.3] Structure and Union Members.  X->F and X.F.
21665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
21675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass MemberExpr : public Expr {
21686bb8017bb9e828d118e15e59d71c66bba323c364John McCall  /// Extra data stored in some member expressions.
21696857c3e12c86fd0271eb46baab5b18756a94f4cbChandler Carruth  struct MemberNameQualifier {
21706857c3e12c86fd0271eb46baab5b18756a94f4cbChandler Carruth    /// \brief The nested-name-specifier that qualifies the name, including
21716857c3e12c86fd0271eb46baab5b18756a94f4cbChandler Carruth    /// source-location information.
21726857c3e12c86fd0271eb46baab5b18756a94f4cbChandler Carruth    NestedNameSpecifierLoc QualifierLoc;
21736857c3e12c86fd0271eb46baab5b18756a94f4cbChandler Carruth
21746857c3e12c86fd0271eb46baab5b18756a94f4cbChandler Carruth    /// \brief The DeclAccessPair through which the MemberDecl was found due to
21756857c3e12c86fd0271eb46baab5b18756a94f4cbChandler Carruth    /// name qualifiers.
2176161755a09898c95d21bfff33707da9ca41cd53c5John McCall    DeclAccessPair FoundDecl;
21776bb8017bb9e828d118e15e59d71c66bba323c364John McCall  };
21786bb8017bb9e828d118e15e59d71c66bba323c364John McCall
2179ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner  /// Base - the expression for the base pointer or structure references.  In
2180ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner  /// X.F, this is "X".
21815549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Stmt *Base;
21821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2183ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner  /// MemberDecl - This is the decl being referenced by the field/member name.
2184ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner  /// In X.F, this is the decl referenced by F.
2185f595cc41c4d95fe323f8a2b209523de9956f874dEli Friedman  ValueDecl *MemberDecl;
21861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
21872577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  /// MemberDNLoc - Provides source/type location info for the
21882577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  /// declaration name embedded in MemberDecl.
21892577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  DeclarationNameLoc MemberDNLoc;
21902577743c5650c646fb705df01403707e94f2df04Abramo Bagnara
2191bbf4b22b3166e5065f4475006d83678e3e1d00a3Benjamin Kramer  /// MemberLoc - This is the location of the member name.
2192bbf4b22b3166e5065f4475006d83678e3e1d00a3Benjamin Kramer  SourceLocation MemberLoc;
2193bbf4b22b3166e5065f4475006d83678e3e1d00a3Benjamin Kramer
2194ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner  /// IsArrow - True if this is "X->F", false if this is "X.F".
219583f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor  bool IsArrow : 1;
21961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
219783f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor  /// \brief True if this member expression used a nested-name-specifier to
21986bb8017bb9e828d118e15e59d71c66bba323c364John McCall  /// refer to the member, e.g., "x->Base::f", or found its member via a using
21996bb8017bb9e828d118e15e59d71c66bba323c364John McCall  /// declaration.  When true, a MemberNameQualifier
2200c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  /// structure is allocated immediately after the MemberExpr.
22016bb8017bb9e828d118e15e59d71c66bba323c364John McCall  bool HasQualifierOrFoundDecl : 1;
22021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2203e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// \brief True if this member expression specified a template keyword
2204e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// and/or a template argument list explicitly, e.g., x->f<int>,
2205e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// x->template f, x->template f<int>.
2206e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// When true, an ASTTemplateKWAndArgsInfo structure and its
2207e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// TemplateArguments (if any) are allocated immediately after
2208e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// the MemberExpr or, if the member expression also has a qualifier,
2209e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// after the MemberNameQualifier structure.
2210e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  bool HasTemplateKWAndArgsInfo : 1;
22111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
22127cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara  /// \brief True if this member expression refers to a method that
22137cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara  /// was resolved from an overloaded set having size greater than 1.
22147cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara  bool HadMultipleCandidates : 1;
22157cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara
221683f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor  /// \brief Retrieve the qualifier that preceded the member name, if any.
22176bb8017bb9e828d118e15e59d71c66bba323c364John McCall  MemberNameQualifier *getMemberQualifier() {
22186bb8017bb9e828d118e15e59d71c66bba323c364John McCall    assert(HasQualifierOrFoundDecl);
22196bb8017bb9e828d118e15e59d71c66bba323c364John McCall    return reinterpret_cast<MemberNameQualifier *> (this + 1);
222083f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor  }
222183f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor
222283f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor  /// \brief Retrieve the qualifier that preceded the member name, if any.
22236bb8017bb9e828d118e15e59d71c66bba323c364John McCall  const MemberNameQualifier *getMemberQualifier() const {
2224c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor    return const_cast<MemberExpr *>(this)->getMemberQualifier();
2225c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  }
22261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
22275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
2228f595cc41c4d95fe323f8a2b209523de9956f874dEli Friedman  MemberExpr(Expr *base, bool isarrow, ValueDecl *memberdecl,
2229f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall             const DeclarationNameInfo &NameInfo, QualType ty,
2230f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall             ExprValueKind VK, ExprObjectKind OK)
2231f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    : Expr(MemberExprClass, ty, VK, OK,
2232ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie           base->isTypeDependent(),
2233561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor           base->isValueDependent(),
2234561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor           base->isInstantiationDependent(),
2235bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           base->containsUnexpandedParameterPack()),
2236bbf4b22b3166e5065f4475006d83678e3e1d00a3Benjamin Kramer      Base(base), MemberDecl(memberdecl), MemberDNLoc(NameInfo.getInfo()),
2237bbf4b22b3166e5065f4475006d83678e3e1d00a3Benjamin Kramer      MemberLoc(NameInfo.getLoc()), IsArrow(isarrow),
2238e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara      HasQualifierOrFoundDecl(false), HasTemplateKWAndArgsInfo(false),
22397cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara      HadMultipleCandidates(false) {
22402577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    assert(memberdecl->getDeclName() == NameInfo.getName());
22412577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  }
22422577743c5650c646fb705df01403707e94f2df04Abramo Bagnara
22432577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  // NOTE: this constructor should be used only when it is known that
22442577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  // the member name can not provide additional syntactic info
22452577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  // (i.e., source locations for C++ operator names or type source info
2246e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  // for constructors, destructors and conversion operators).
22472577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  MemberExpr(Expr *base, bool isarrow, ValueDecl *memberdecl,
2248f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall             SourceLocation l, QualType ty,
2249f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall             ExprValueKind VK, ExprObjectKind OK)
2250f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    : Expr(MemberExprClass, ty, VK, OK,
2251bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           base->isTypeDependent(), base->isValueDependent(),
2252561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor           base->isInstantiationDependent(),
2253bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           base->containsUnexpandedParameterPack()),
2254bbf4b22b3166e5065f4475006d83678e3e1d00a3Benjamin Kramer      Base(base), MemberDecl(memberdecl), MemberDNLoc(), MemberLoc(l),
22552577743c5650c646fb705df01403707e94f2df04Abramo Bagnara      IsArrow(isarrow),
2256e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara      HasQualifierOrFoundDecl(false), HasTemplateKWAndArgsInfo(false),
22577cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara      HadMultipleCandidates(false) {}
2258510190777c4bd53e960eea4665b204778fec1b64Eli Friedman
22591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static MemberExpr *Create(ASTContext &C, Expr *base, bool isarrow,
226040d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor                            NestedNameSpecifierLoc QualifierLoc,
2261e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara                            SourceLocation TemplateKWLoc,
2262161755a09898c95d21bfff33707da9ca41cd53c5John McCall                            ValueDecl *memberdecl, DeclAccessPair founddecl,
22632577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                            DeclarationNameInfo MemberNameInfo,
2264d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall                            const TemplateArgumentListInfo *targs,
2265f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                            QualType ty, ExprValueKind VK, ExprObjectKind OK);
22661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
226788a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor  void setBase(Expr *E) { Base = E; }
22685549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getBase() const { return cast<Expr>(Base); }
226957e8b05fe9ba03d410db9c161e032cb79c9ab5baDouglas Gregor
227057e8b05fe9ba03d410db9c161e032cb79c9ab5baDouglas Gregor  /// \brief Retrieve the member declaration to which this expression refers.
227157e8b05fe9ba03d410db9c161e032cb79c9ab5baDouglas Gregor  ///
227257e8b05fe9ba03d410db9c161e032cb79c9ab5baDouglas Gregor  /// The returned declaration will either be a FieldDecl or (in C++)
227357e8b05fe9ba03d410db9c161e032cb79c9ab5baDouglas Gregor  /// a CXXMethodDecl.
2274f595cc41c4d95fe323f8a2b209523de9956f874dEli Friedman  ValueDecl *getMemberDecl() const { return MemberDecl; }
2275f595cc41c4d95fe323f8a2b209523de9956f874dEli Friedman  void setMemberDecl(ValueDecl *D) { MemberDecl = D; }
22761f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor
22776bb8017bb9e828d118e15e59d71c66bba323c364John McCall  /// \brief Retrieves the declaration found by lookup.
2278161755a09898c95d21bfff33707da9ca41cd53c5John McCall  DeclAccessPair getFoundDecl() const {
22796bb8017bb9e828d118e15e59d71c66bba323c364John McCall    if (!HasQualifierOrFoundDecl)
2280161755a09898c95d21bfff33707da9ca41cd53c5John McCall      return DeclAccessPair::make(getMemberDecl(),
2281161755a09898c95d21bfff33707da9ca41cd53c5John McCall                                  getMemberDecl()->getAccess());
22826bb8017bb9e828d118e15e59d71c66bba323c364John McCall    return getMemberQualifier()->FoundDecl;
22836bb8017bb9e828d118e15e59d71c66bba323c364John McCall  }
22846bb8017bb9e828d118e15e59d71c66bba323c364John McCall
22851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// \brief Determines whether this member expression actually had
22860979c805475d1ba49b5d6ef93c4d2ce6d2eab6edDouglas Gregor  /// a C++ nested-name-specifier prior to the name of the member, e.g.,
22870979c805475d1ba49b5d6ef93c4d2ce6d2eab6edDouglas Gregor  /// x->Base::foo.
22886bb8017bb9e828d118e15e59d71c66bba323c364John McCall  bool hasQualifier() const { return getQualifier() != 0; }
22891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
22901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// \brief If the member name was qualified, retrieves the
229183f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor  /// nested-name-specifier that precedes the member name. Otherwise, returns
229283f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor  /// NULL.
22931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  NestedNameSpecifier *getQualifier() const {
22946bb8017bb9e828d118e15e59d71c66bba323c364John McCall    if (!HasQualifierOrFoundDecl)
229583f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor      return 0;
22961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
229740d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor    return getMemberQualifier()->QualifierLoc.getNestedNameSpecifier();
229840d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor  }
229940d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor
2300ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  /// \brief If the member name was qualified, retrieves the
230140d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor  /// nested-name-specifier that precedes the member name, with source-location
230240d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor  /// information.
230340d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor  NestedNameSpecifierLoc getQualifierLoc() const {
230440d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor    if (!hasQualifier())
230540d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor      return NestedNameSpecifierLoc();
2306ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
230740d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor    return getMemberQualifier()->QualifierLoc;
230883f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor  }
2309c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor
2310e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// \brief Return the optional template keyword and arguments info.
2311e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo() {
2312e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    if (!HasTemplateKWAndArgsInfo)
2313e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara      return 0;
2314e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara
2315e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    if (!HasQualifierOrFoundDecl)
2316e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara      return reinterpret_cast<ASTTemplateKWAndArgsInfo *>(this + 1);
2317e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara
2318e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    return reinterpret_cast<ASTTemplateKWAndArgsInfo *>(
2319e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara                                                      getMemberQualifier() + 1);
2320e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  }
2321e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara
2322e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// \brief Return the optional template keyword and arguments info.
2323e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  const ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo() const {
2324e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    return const_cast<MemberExpr*>(this)->getTemplateKWAndArgsInfo();
2325e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  }
2326e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara
2327e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// \brief Retrieve the location of the template keyword preceding
2328e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// the member name, if any.
2329e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  SourceLocation getTemplateKeywordLoc() const {
2330e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    if (!HasTemplateKWAndArgsInfo) return SourceLocation();
2331e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    return getTemplateKWAndArgsInfo()->getTemplateKeywordLoc();
2332e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  }
2333e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara
2334e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// \brief Retrieve the location of the left angle bracket starting the
2335e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// explicit template argument list following the member name, if any.
2336e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  SourceLocation getLAngleLoc() const {
2337e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    if (!HasTemplateKWAndArgsInfo) return SourceLocation();
2338e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    return getTemplateKWAndArgsInfo()->LAngleLoc;
2339e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  }
2340e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara
2341e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// \brief Retrieve the location of the right angle bracket ending the
2342e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// explicit template argument list following the member name, if any.
2343e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  SourceLocation getRAngleLoc() const {
2344e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    if (!HasTemplateKWAndArgsInfo) return SourceLocation();
2345e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    return getTemplateKWAndArgsInfo()->RAngleLoc;
2346c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  }
23471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2348e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// Determines whether the member name was preceded by the template keyword.
2349e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  bool hasTemplateKeyword() const { return getTemplateKeywordLoc().isValid(); }
2350e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara
2351e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// \brief Determines whether the member name was followed by an
2352e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  /// explicit template argument list.
2353e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara  bool hasExplicitTemplateArgs() const { return getLAngleLoc().isValid(); }
2354e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara
2355d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  /// \brief Copies the template arguments (if present) into the given
2356d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  /// structure.
2357d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
2358096832c5ed5b9106fa177ebc148489760c3bc496John McCall    if (hasExplicitTemplateArgs())
2359096832c5ed5b9106fa177ebc148489760c3bc496John McCall      getExplicitTemplateArgs().copyInto(List);
2360096832c5ed5b9106fa177ebc148489760c3bc496John McCall  }
2361096832c5ed5b9106fa177ebc148489760c3bc496John McCall
2362096832c5ed5b9106fa177ebc148489760c3bc496John McCall  /// \brief Retrieve the explicit template argument list that
2363096832c5ed5b9106fa177ebc148489760c3bc496John McCall  /// follow the member template name.  This must only be called on an
2364096832c5ed5b9106fa177ebc148489760c3bc496John McCall  /// expression with explicit template arguments.
2365b0c3e0909bb04af0bfb82ad01ab6909649d68ccaArgyrios Kyrtzidis  ASTTemplateArgumentListInfo &getExplicitTemplateArgs() {
2366e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    assert(hasExplicitTemplateArgs());
2367e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    return *getTemplateKWAndArgsInfo();
2368096832c5ed5b9106fa177ebc148489760c3bc496John McCall  }
2369096832c5ed5b9106fa177ebc148489760c3bc496John McCall
2370096832c5ed5b9106fa177ebc148489760c3bc496John McCall  /// \brief Retrieve the explicit template argument list that
2371096832c5ed5b9106fa177ebc148489760c3bc496John McCall  /// followed the member template name.  This must only be called on
2372096832c5ed5b9106fa177ebc148489760c3bc496John McCall  /// an expression with explicit template arguments.
2373b0c3e0909bb04af0bfb82ad01ab6909649d68ccaArgyrios Kyrtzidis  const ASTTemplateArgumentListInfo &getExplicitTemplateArgs() const {
2374096832c5ed5b9106fa177ebc148489760c3bc496John McCall    return const_cast<MemberExpr *>(this)->getExplicitTemplateArgs();
2375096832c5ed5b9106fa177ebc148489760c3bc496John McCall  }
2376096832c5ed5b9106fa177ebc148489760c3bc496John McCall
2377096832c5ed5b9106fa177ebc148489760c3bc496John McCall  /// \brief Retrieves the optional explicit template arguments.
2378096832c5ed5b9106fa177ebc148489760c3bc496John McCall  /// This points to the same data as getExplicitTemplateArgs(), but
2379096832c5ed5b9106fa177ebc148489760c3bc496John McCall  /// returns null if there are no explicit template arguments.
2380b0c3e0909bb04af0bfb82ad01ab6909649d68ccaArgyrios Kyrtzidis  const ASTTemplateArgumentListInfo *getOptionalExplicitTemplateArgs() const {
2381096832c5ed5b9106fa177ebc148489760c3bc496John McCall    if (!hasExplicitTemplateArgs()) return 0;
2382096832c5ed5b9106fa177ebc148489760c3bc496John McCall    return &getExplicitTemplateArgs();
2383d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  }
2384ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
2385c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  /// \brief Retrieve the template arguments provided as part of this
2386c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  /// template-id.
2387833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  const TemplateArgumentLoc *getTemplateArgs() const {
2388e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    if (!hasExplicitTemplateArgs())
23891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump      return 0;
23901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2391096832c5ed5b9106fa177ebc148489760c3bc496John McCall    return getExplicitTemplateArgs().getTemplateArgs();
2392c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  }
23931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2394c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  /// \brief Retrieve the number of template arguments provided as part of this
2395c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  /// template-id.
23961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  unsigned getNumTemplateArgs() const {
2397e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara    if (!hasExplicitTemplateArgs())
23981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump      return 0;
23991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2400096832c5ed5b9106fa177ebc148489760c3bc496John McCall    return getExplicitTemplateArgs().NumTemplateArgs;
2401c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  }
24021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
24032577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  /// \brief Retrieve the member declaration name info.
24042577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  DeclarationNameInfo getMemberNameInfo() const {
24052577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    return DeclarationNameInfo(MemberDecl->getDeclName(),
24062577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                               MemberLoc, MemberDNLoc);
24072577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  }
24082577743c5650c646fb705df01403707e94f2df04Abramo Bagnara
24095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isArrow() const { return IsArrow; }
24101f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor  void setArrow(bool A) { IsArrow = A; }
24111f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor
2412ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner  /// getMemberLoc - Return the location of the "member", in X->F, it is the
2413ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner  /// location of 'F'.
2414026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner  SourceLocation getMemberLoc() const { return MemberLoc; }
24151f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor  void setMemberLoc(SourceLocation L) { MemberLoc = L; }
24165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
2417aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY;
2418aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceLocation getLocStart() const LLVM_READONLY;
2419aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceLocation getLocEnd() const LLVM_READONLY;
2420ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
24214f311183be3d923da9fbe8702c453688b4c426a9Daniel Dunbar  SourceLocation getExprLoc() const LLVM_READONLY { return MemberLoc; }
24225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
242375e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor  /// \brief Determine whether the base of this explicit is implicit.
242475e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor  bool isImplicitAccess() const {
242575e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor    return getBase() && getBase()->isImplicitCXXThis();
242675e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor  }
24277cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara
24287cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara  /// \brief Returns true if this member expression refers to a method that
24297cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara  /// was resolved from an overloaded set having size greater than 1.
24307cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara  bool hadMultipleCandidates() const {
24317cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara    return HadMultipleCandidates;
24327cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara  }
24337cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara  /// \brief Sets the flag telling whether this expression refers to
24347cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara  /// a method that was resolved from an overloaded set having size
24357cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara  /// greater than 1.
24367cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara  void setHadMultipleCandidates(bool V = true) {
24377cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara    HadMultipleCandidates = V;
24387cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara  }
24397cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara
24401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
244183f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor    return T->getStmtClass() == MemberExprClass;
24425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
24435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const MemberExpr *) { return true; }
24441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
24451237c673c07f9d827129ba02720108816abde562Ted Kremenek  // Iterators
244663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(&Base, &Base+1); }
24474045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis
24484045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis  friend class ASTReader;
24494045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis  friend class ASTStmtWriter;
24505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
24515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
24521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// CompoundLiteralExpr - [C99 6.5.2.5]
2453aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff///
2454aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroffclass CompoundLiteralExpr : public Expr {
24550fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner  /// LParenLoc - If non-null, this is the location of the left paren in a
24560fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner  /// compound literal like "(int){4}".  This can be null if this is a
24570fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner  /// synthesized compound expression.
24580fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner  SourceLocation LParenLoc;
24591d7d8d66eff7ed0f3e957d330930cc9ab8047addJohn McCall
24601d7d8d66eff7ed0f3e957d330930cc9ab8047addJohn McCall  /// The type as written.  This can be an incomplete array type, in
24611d7d8d66eff7ed0f3e957d330930cc9ab8047addJohn McCall  /// which case the actual expression type will be different.
24623654c6993697a30af0c5a472963fe8c03e622b98Benjamin Kramer  /// The int part of the pair stores whether this expr is file scope.
24633654c6993697a30af0c5a472963fe8c03e622b98Benjamin Kramer  llvm::PointerIntPair<TypeSourceInfo *, 1, bool> TInfoAndScope;
24645549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Stmt *Init;
2465aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroffpublic:
246642f56b50062cd3b3c6b23fdb9053578ae9145664John McCall  CompoundLiteralExpr(SourceLocation lparenloc, TypeSourceInfo *tinfo,
2467f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                      QualType T, ExprValueKind VK, Expr *init, bool fileScope)
2468f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    : Expr(CompoundLiteralExprClass, T, VK, OK_Ordinary,
2469ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie           tinfo->getType()->isDependentType(),
2470bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           init->isValueDependent(),
2471561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor           (init->isInstantiationDependent() ||
2472561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor            tinfo->getType()->isInstantiationDependentType()),
2473bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           init->containsUnexpandedParameterPack()),
24743654c6993697a30af0c5a472963fe8c03e622b98Benjamin Kramer      LParenLoc(lparenloc), TInfoAndScope(tinfo, fileScope), Init(init) {}
24751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2476ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor  /// \brief Construct an empty compound literal.
2477ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor  explicit CompoundLiteralExpr(EmptyShell Empty)
2478ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor    : Expr(CompoundLiteralExprClass, Empty) { }
2479ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor
24805549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  const Expr *getInitializer() const { return cast<Expr>(Init); }
24815549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getInitializer() { return cast<Expr>(Init); }
2482ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor  void setInitializer(Expr *E) { Init = E; }
2483e9b12198c4cc7f5687960100351b4af006c14469Steve Naroff
24843654c6993697a30af0c5a472963fe8c03e622b98Benjamin Kramer  bool isFileScope() const { return TInfoAndScope.getInt(); }
24853654c6993697a30af0c5a472963fe8c03e622b98Benjamin Kramer  void setFileScope(bool FS) { TInfoAndScope.setInt(FS); }
2486ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor
24870fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner  SourceLocation getLParenLoc() const { return LParenLoc; }
2488ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor  void setLParenLoc(SourceLocation L) { LParenLoc = L; }
2489ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor
24903654c6993697a30af0c5a472963fe8c03e622b98Benjamin Kramer  TypeSourceInfo *getTypeSourceInfo() const {
24913654c6993697a30af0c5a472963fe8c03e622b98Benjamin Kramer    return TInfoAndScope.getPointer();
24923654c6993697a30af0c5a472963fe8c03e622b98Benjamin Kramer  }
24933654c6993697a30af0c5a472963fe8c03e622b98Benjamin Kramer  void setTypeSourceInfo(TypeSourceInfo *tinfo) {
24943654c6993697a30af0c5a472963fe8c03e622b98Benjamin Kramer    TInfoAndScope.setPointer(tinfo);
24953654c6993697a30af0c5a472963fe8c03e622b98Benjamin Kramer  }
249642f56b50062cd3b3c6b23fdb9053578ae9145664John McCall
2497aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY {
24980fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner    // FIXME: Init should never be null.
24990fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner    if (!Init)
25000fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner      return SourceRange();
25010fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner    if (LParenLoc.isInvalid())
250273d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner      return Init->getSourceRange();
25030fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner    return SourceRange(LParenLoc, Init->getLocEnd());
250473d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner  }
2505aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff
25061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
25071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == CompoundLiteralExprClass;
2508aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff  }
2509aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff  static bool classof(const CompoundLiteralExpr *) { return true; }
25101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
25111237c673c07f9d827129ba02720108816abde562Ted Kremenek  // Iterators
251263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(&Init, &Init+1); }
2513aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff};
2514aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff
251549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// CastExpr - Base class for type casts, including both implicit
251649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// casts (ImplicitCastExpr) and explicit casts that have some
251749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// representation in the source code (ExplicitCastExpr's derived
251849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// classes).
25190835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidisclass CastExpr : public Expr {
2520cdef2b75aa60cde1ca00e0aa3f89139ac89c6ae4Anders Carlssonpublic:
25215baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall  typedef clang::CastKind CastKind;
25221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2523cdef2b75aa60cde1ca00e0aa3f89139ac89c6ae4Anders Carlssonprivate:
25240835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis  Stmt *Op;
2525409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson
25261d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall  void CheckCastConsistency() const;
2527409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson
2528f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  const CXXBaseSpecifier * const *path_buffer() const {
2529f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall    return const_cast<CastExpr*>(this)->path_buffer();
2530f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  }
2531f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  CXXBaseSpecifier **path_buffer();
2532f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall
2533654f6b2b53af2c950c62ef0161fa021648accbcbArgyrios Kyrtzidis  void setBasePathSize(unsigned basePathSize) {
2534654f6b2b53af2c950c62ef0161fa021648accbcbArgyrios Kyrtzidis    CastExprBits.BasePathSize = basePathSize;
2535654f6b2b53af2c950c62ef0161fa021648accbcbArgyrios Kyrtzidis    assert(CastExprBits.BasePathSize == basePathSize &&
2536654f6b2b53af2c950c62ef0161fa021648accbcbArgyrios Kyrtzidis           "basePathSize doesn't fit in bits of CastExprBits.BasePathSize!");
2537654f6b2b53af2c950c62ef0161fa021648accbcbArgyrios Kyrtzidis  }
2538654f6b2b53af2c950c62ef0161fa021648accbcbArgyrios Kyrtzidis
25390835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidisprotected:
2540f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall  CastExpr(StmtClass SC, QualType ty, ExprValueKind VK,
2541f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall           const CastKind kind, Expr *op, unsigned BasePathSize) :
2542f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    Expr(SC, ty, VK, OK_Ordinary,
2543898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor         // Cast expressions are type-dependent if the type is
2544898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor         // dependent (C++ [temp.dep.expr]p3).
2545898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor         ty->isDependentType(),
2546898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor         // Cast expressions are value-dependent if the type is
2547898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor         // dependent or if the subexpression is value-dependent.
2548bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor         ty->isDependentType() || (op && op->isValueDependent()),
2549ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie         (ty->isInstantiationDependentType() ||
2550561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor          (op && op->isInstantiationDependent())),
2551bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor         (ty->containsUnexpandedParameterPack() ||
2552bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor          op->containsUnexpandedParameterPack())),
25538e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    Op(op) {
2554daa8e4e888758d55a7a759dd4a91b83921cef222John McCall    assert(kind != CK_Invalid && "creating cast with invalid cast kind");
25558e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    CastExprBits.Kind = kind;
2556654f6b2b53af2c950c62ef0161fa021648accbcbArgyrios Kyrtzidis    setBasePathSize(BasePathSize);
25571d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall#ifndef NDEBUG
2558daa8e4e888758d55a7a759dd4a91b83921cef222John McCall    CheckCastConsistency();
25591d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall#endif
2560f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  }
25611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2562087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor  /// \brief Construct an empty cast.
2563f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  CastExpr(StmtClass SC, EmptyShell Empty, unsigned BasePathSize)
25648e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    : Expr(SC, Empty) {
2565654f6b2b53af2c950c62ef0161fa021648accbcbArgyrios Kyrtzidis    setBasePathSize(BasePathSize);
25668e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  }
25671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
25680835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidispublic:
25698e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  CastKind getCastKind() const { return (CastKind) CastExprBits.Kind; }
25708e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  void setCastKind(CastKind K) { CastExprBits.Kind = K; }
2571f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson  const char *getCastKindName() const;
2572f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson
25730835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis  Expr *getSubExpr() { return cast<Expr>(Op); }
25740835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis  const Expr *getSubExpr() const { return cast<Expr>(Op); }
2575087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor  void setSubExpr(Expr *E) { Op = E; }
2576087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor
25776eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor  /// \brief Retrieve the cast subexpression as it was written in the source
25786eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor  /// code, looking through any implicit casts or other intermediate nodes
25796eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor  /// introduced by semantic analysis.
25806eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor  Expr *getSubExprAsWritten();
25816eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor  const Expr *getSubExprAsWritten() const {
25826eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor    return const_cast<CastExpr *>(this)->getSubExprAsWritten();
25836eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor  }
258441b2dcd465f1e438502c420effc9d0c747f9db8fAnders Carlsson
2585f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  typedef CXXBaseSpecifier **path_iterator;
2586f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  typedef const CXXBaseSpecifier * const *path_const_iterator;
25878e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  bool path_empty() const { return CastExprBits.BasePathSize == 0; }
25888e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  unsigned path_size() const { return CastExprBits.BasePathSize; }
2589f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  path_iterator path_begin() { return path_buffer(); }
2590f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  path_iterator path_end() { return path_buffer() + path_size(); }
2591f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  path_const_iterator path_begin() const { return path_buffer(); }
2592f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  path_const_iterator path_end() const { return path_buffer() + path_size(); }
2593f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall
2594f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  void setCastPath(const CXXCastPath &Path);
259541b2dcd465f1e438502c420effc9d0c747f9db8fAnders Carlsson
25961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
25974bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt    return T->getStmtClass() >= firstCastExprConstant &&
25984bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt           T->getStmtClass() <= lastCastExprConstant;
25990835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis  }
26000835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis  static bool classof(const CastExpr *) { return true; }
26011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
26020835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis  // Iterators
260363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(&Op, &Op+1); }
26040835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis};
26050835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis
260649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// ImplicitCastExpr - Allows us to explicitly represent implicit type
260749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// conversions, which have no direct representation in the original
260849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// source code. For example: converting T[]->T*, void f()->void
260949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// (*f)(), float->double, short->int, etc.
261049b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff///
2611bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// In C, implicit casts always produce rvalues. However, in C++, an
2612bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// implicit cast whose result is being bound to a reference will be
2613906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redl/// an lvalue or xvalue. For example:
2614bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor///
2615bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// @code
2616bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// class Base { };
2617bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// class Derived : public Base { };
2618906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redl/// Derived &&ref();
26191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// void f(Derived d) {
2620906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redl///   Base& b = d; // initializer is an ImplicitCastExpr
2621906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redl///                // to an lvalue of type Base
2622906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redl///   Base&& r = ref(); // initializer is an ImplicitCastExpr
2623906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redl///                     // to an xvalue of type Base
2624bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// }
2625bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// @endcode
26260835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidisclass ImplicitCastExpr : public CastExpr {
2627906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redlprivate:
2628f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  ImplicitCastExpr(QualType ty, CastKind kind, Expr *op,
26295baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall                   unsigned BasePathLength, ExprValueKind VK)
2630f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    : CastExpr(ImplicitCastExprClass, ty, VK, kind, op, BasePathLength) {
26315baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall  }
263290045e8ebabf50d6f1b3a67081a621b20b5e5341Steve Naroff
2633087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor  /// \brief Construct an empty implicit cast.
2634f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  explicit ImplicitCastExpr(EmptyShell Shell, unsigned PathSize)
2635f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall    : CastExpr(ImplicitCastExprClass, Shell, PathSize) { }
2636f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall
2637f871d0cc377a1367b519a6cce26be74607566ebaJohn McCallpublic:
2638f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  enum OnStack_t { OnStack };
2639f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  ImplicitCastExpr(OnStack_t _, QualType ty, CastKind kind, Expr *op,
26405baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall                   ExprValueKind VK)
2641f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    : CastExpr(ImplicitCastExprClass, ty, VK, kind, op, 0) {
26425baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall  }
2643f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall
2644f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  static ImplicitCastExpr *Create(ASTContext &Context, QualType T,
2645f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall                                  CastKind Kind, Expr *Operand,
2646f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall                                  const CXXCastPath *BasePath,
26475baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall                                  ExprValueKind Cat);
2648f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall
2649f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  static ImplicitCastExpr *CreateEmpty(ASTContext &Context, unsigned PathSize);
2650087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor
2651aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY {
26520835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis    return getSubExpr()->getSourceRange();
26530835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis  }
2654aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceLocation getLocStart() const LLVM_READONLY {
2655396ec676b7a39665fa3a3f86f8e0520f8d7e93a8Daniel Dunbar    return getSubExpr()->getLocStart();
2656396ec676b7a39665fa3a3f86f8e0520f8d7e93a8Daniel Dunbar  }
2657aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceLocation getLocEnd() const LLVM_READONLY {
2658396ec676b7a39665fa3a3f86f8e0520f8d7e93a8Daniel Dunbar    return getSubExpr()->getLocEnd();
2659396ec676b7a39665fa3a3f86f8e0520f8d7e93a8Daniel Dunbar  }
266090045e8ebabf50d6f1b3a67081a621b20b5e5341Steve Naroff
26611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
26621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == ImplicitCastExprClass;
266349b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff  }
266449b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff  static bool classof(const ImplicitCastExpr *) { return true; }
266549b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff};
266649b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff
266791a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCallinline Expr *Expr::IgnoreImpCasts() {
266891a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall  Expr *e = this;
266991a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall  while (ImplicitCastExpr *ice = dyn_cast<ImplicitCastExpr>(e))
267091a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall    e = ice->getSubExpr();
267191a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall  return e;
267291a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall}
267391a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall
267449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// ExplicitCastExpr - An explicit cast written in the source
26751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// code.
267649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor///
267749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// This class is effectively an abstract class, because it provides
267849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// the basic representation of an explicitly-written cast without
267949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// specifying which kind of cast (C cast, functional cast, static
268049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// cast, etc.) was written; specific derived classes represent the
268149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// particular style of cast and its location information.
26825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
268349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// Unlike implicit casts, explicit cast nodes have two different
268449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// types: the type that was written into the source code, and the
268549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// actual type of the expression as determined by semantic
268649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// analysis. These types may differ slightly. For example, in C++ one
268749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// can cast to a reference type, which indicates that the resulting
2688906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redl/// expression will be an lvalue or xvalue. The reference type, however,
2689906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redl/// will not be used as the type of the expression.
26900835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidisclass ExplicitCastExpr : public CastExpr {
26919d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall  /// TInfo - Source type info for the (written) type
26929d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall  /// this expression is casting to.
26939d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall  TypeSourceInfo *TInfo;
269449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor
269549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregorprotected:
2696f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall  ExplicitCastExpr(StmtClass SC, QualType exprTy, ExprValueKind VK,
2697f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                   CastKind kind, Expr *op, unsigned PathSize,
2698f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                   TypeSourceInfo *writtenTy)
2699f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    : CastExpr(SC, exprTy, VK, kind, op, PathSize), TInfo(writtenTy) {}
270049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor
2701db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor  /// \brief Construct an empty explicit cast.
2702f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  ExplicitCastExpr(StmtClass SC, EmptyShell Shell, unsigned PathSize)
2703f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall    : CastExpr(SC, Shell, PathSize) { }
2704db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor
270549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregorpublic:
27069d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall  /// getTypeInfoAsWritten - Returns the type source info for the type
27079d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall  /// that this expression is casting to.
27089d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall  TypeSourceInfo *getTypeInfoAsWritten() const { return TInfo; }
27099d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall  void setTypeInfoAsWritten(TypeSourceInfo *writtenTy) { TInfo = writtenTy; }
27109d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall
271149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  /// getTypeAsWritten - Returns the type that this expression is
271249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  /// casting to, as written in the source code.
27139d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall  QualType getTypeAsWritten() const { return TInfo->getType(); }
271449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor
27151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
27164bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt     return T->getStmtClass() >= firstExplicitCastExprConstant &&
27174bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt            T->getStmtClass() <= lastExplicitCastExprConstant;
271849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  }
271949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  static bool classof(const ExplicitCastExpr *) { return true; }
272049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor};
272149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor
27226eec8e883de118b431e3ead5b1e604a6ac68ff6bDouglas Gregor/// CStyleCastExpr - An explicit cast in C (C99 6.5.4) or a C-style
272349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// cast in C++ (C++ [expr.cast]), which uses the syntax
272449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// (Type)expr. For example: @c (int)f.
27256eec8e883de118b431e3ead5b1e604a6ac68ff6bDouglas Gregorclass CStyleCastExpr : public ExplicitCastExpr {
2726b2f9e516327310d95840d442416084508f80c183Steve Naroff  SourceLocation LPLoc; // the location of the left paren
2727b2f9e516327310d95840d442416084508f80c183Steve Naroff  SourceLocation RPLoc; // the location of the right paren
2728f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall
2729f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall  CStyleCastExpr(QualType exprTy, ExprValueKind vk, CastKind kind, Expr *op,
2730f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall                 unsigned PathSize, TypeSourceInfo *writtenTy,
273141b2dcd465f1e438502c420effc9d0c747f9db8fAnders Carlsson                 SourceLocation l, SourceLocation r)
2732f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    : ExplicitCastExpr(CStyleCastExprClass, exprTy, vk, kind, op, PathSize,
273341b2dcd465f1e438502c420effc9d0c747f9db8fAnders Carlsson                       writtenTy), LPLoc(l), RPLoc(r) {}
273449b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff
2735db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor  /// \brief Construct an empty C-style explicit cast.
2736f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  explicit CStyleCastExpr(EmptyShell Shell, unsigned PathSize)
2737f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall    : ExplicitCastExpr(CStyleCastExprClass, Shell, PathSize) { }
2738f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall
2739f871d0cc377a1367b519a6cce26be74607566ebaJohn McCallpublic:
2740f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall  static CStyleCastExpr *Create(ASTContext &Context, QualType T,
2741f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                                ExprValueKind VK, CastKind K,
2742f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall                                Expr *Op, const CXXCastPath *BasePath,
2743f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall                                TypeSourceInfo *WrittenTy, SourceLocation L,
2744f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall                                SourceLocation R);
2745f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall
2746f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  static CStyleCastExpr *CreateEmpty(ASTContext &Context, unsigned PathSize);
2747db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor
2748b2f9e516327310d95840d442416084508f80c183Steve Naroff  SourceLocation getLParenLoc() const { return LPLoc; }
2749db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor  void setLParenLoc(SourceLocation L) { LPLoc = L; }
2750db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor
2751b2f9e516327310d95840d442416084508f80c183Steve Naroff  SourceLocation getRParenLoc() const { return RPLoc; }
2752db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor  void setRParenLoc(SourceLocation L) { RPLoc = L; }
2753db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor
2754aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY {
2755b2f9e516327310d95840d442416084508f80c183Steve Naroff    return SourceRange(LPLoc, getSubExpr()->getSourceRange().getEnd());
27565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
27571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
27581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == CStyleCastExprClass;
27595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
27606eec8e883de118b431e3ead5b1e604a6ac68ff6bDouglas Gregor  static bool classof(const CStyleCastExpr *) { return true; }
27615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
27625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
27633fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// \brief A builtin binary operation expression such as "x + y" or "x <= y".
27643fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor///
27653fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// This expression node kind describes a builtin binary operation,
27663fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// such as "x + y" for integer values "x" and "y". The operands will
27673fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// already have been converted to appropriate types (e.g., by
27683fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// performing promotions or conversions).
27693fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor///
27703fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// In C++, where operators may be overloaded, a different kind of
27713fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// expression node (CXXOperatorCallExpr) is used to express the
27723fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// invocation of an overloaded operator with operator syntax. Within
27733fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// a C++ template, whether BinaryOperator or CXXOperatorCallExpr is
27743fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// used to store an expression "x + y" depends on the subexpressions
27753fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// for x and y. If neither x or y is type-dependent, and the "+"
27763fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// operator resolves to a built-in operation, BinaryOperator will be
27773fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// used to express the computation (x and y may still be
27783fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// value-dependent). If either x or y is type-dependent, or if the
27793fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// "+" resolves to an overloaded operator, CXXOperatorCallExpr will
27803fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// be used to express the computation.
27815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass BinaryOperator : public Expr {
27825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
27835baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall  typedef BinaryOperatorKind Opcode;
27845baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall
278517d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattnerprivate:
27860799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall  unsigned Opc : 6;
27870799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall  SourceLocation OpLoc;
27880799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall
278917d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner  enum { LHS, RHS, END_EXPR };
27905549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Stmt* SubExprs[END_EXPR];
27911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumppublic:
27921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
279317d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner  BinaryOperator(Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy,
2794f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                 ExprValueKind VK, ExprObjectKind OK,
279517d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner                 SourceLocation opLoc)
2796f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    : Expr(BinaryOperatorClass, ResTy, VK, OK,
2797898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor           lhs->isTypeDependent() || rhs->isTypeDependent(),
2798bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           lhs->isValueDependent() || rhs->isValueDependent(),
2799561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor           (lhs->isInstantiationDependent() ||
2800561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor            rhs->isInstantiationDependent()),
2801bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           (lhs->containsUnexpandedParameterPack() ||
2802bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor            rhs->containsUnexpandedParameterPack())),
2803898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor      Opc(opc), OpLoc(opLoc) {
28041237c673c07f9d827129ba02720108816abde562Ted Kremenek    SubExprs[LHS] = lhs;
28051237c673c07f9d827129ba02720108816abde562Ted Kremenek    SubExprs[RHS] = rhs;
28061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    assert(!isCompoundAssignmentOp() &&
28075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer           "Use ArithAssignBinaryOperator for compound assignments");
28085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
28095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
2810db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor  /// \brief Construct an empty binary operator.
28111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  explicit BinaryOperator(EmptyShell Empty)
28122de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall    : Expr(BinaryOperatorClass, Empty), Opc(BO_Comma) { }
2813db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor
28144f311183be3d923da9fbe8702c453688b4c426a9Daniel Dunbar  SourceLocation getExprLoc() const LLVM_READONLY { return OpLoc; }
281517d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner  SourceLocation getOperatorLoc() const { return OpLoc; }
2816db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor  void setOperatorLoc(SourceLocation L) { OpLoc = L; }
2817db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor
28180799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall  Opcode getOpcode() const { return static_cast<Opcode>(Opc); }
2819db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor  void setOpcode(Opcode O) { Opc = O; }
2820db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor
28215549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); }
2822db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor  void setLHS(Expr *E) { SubExprs[LHS] = E; }
28235549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); }
2824db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor  void setRHS(Expr *E) { SubExprs[RHS] = E; }
2825db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor
2826aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY {
28275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return SourceRange(getLHS()->getLocStart(), getRHS()->getLocEnd());
28285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
28291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
28305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// getOpcodeStr - Turn an Opcode enum value into the punctuation char it
28315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// corresponds to, e.g. "<<=".
28325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static const char *getOpcodeStr(Opcode Op);
28335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
28340799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall  const char *getOpcodeStr() const { return getOpcodeStr(getOpcode()); }
2835a84c02d0f4d63975a1c52b9bb8308d88e9d79352Ted Kremenek
2836063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor  /// \brief Retrieve the binary opcode that corresponds to the given
2837063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor  /// overloaded operator.
2838063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor  static Opcode getOverloadedOpcode(OverloadedOperatorKind OO);
2839063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor
2840063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor  /// \brief Retrieve the overloaded operator kind that corresponds to
2841063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor  /// the given binary opcode.
2842063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor  static OverloadedOperatorKind getOverloadedOperator(Opcode Opc);
2843063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor
28445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// predicates to categorize the respective opcodes.
2845200121569dc6cff10a1fb6ed7500098770b9dd25Sebastian Redl  bool isPtrMemOp() const { return Opc == BO_PtrMemD || Opc == BO_PtrMemI; }
28462de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  bool isMultiplicativeOp() const { return Opc >= BO_Mul && Opc <= BO_Rem; }
28472de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  static bool isAdditiveOp(Opcode Opc) { return Opc == BO_Add || Opc==BO_Sub; }
28480799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall  bool isAdditiveOp() const { return isAdditiveOp(getOpcode()); }
28492de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  static bool isShiftOp(Opcode Opc) { return Opc == BO_Shl || Opc == BO_Shr; }
28500799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall  bool isShiftOp() const { return isShiftOp(getOpcode()); }
2851aee3c9375f97a49edef2a36f15df6abd9748e2a1Sebastian Redl
28522de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  static bool isBitwiseOp(Opcode Opc) { return Opc >= BO_And && Opc <= BO_Or; }
28530799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall  bool isBitwiseOp() const { return isBitwiseOp(getOpcode()); }
2854f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek
28552de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  static bool isRelationalOp(Opcode Opc) { return Opc >= BO_LT && Opc<=BO_GE; }
28560799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall  bool isRelationalOp() const { return isRelationalOp(getOpcode()); }
2857f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek
28582de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  static bool isEqualityOp(Opcode Opc) { return Opc == BO_EQ || Opc == BO_NE; }
28590799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall  bool isEqualityOp() const { return isEqualityOp(getOpcode()); }
28601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
28612de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  static bool isComparisonOp(Opcode Opc) { return Opc >= BO_LT && Opc<=BO_NE; }
28620799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall  bool isComparisonOp() const { return isComparisonOp(getOpcode()); }
2863aee3c9375f97a49edef2a36f15df6abd9748e2a1Sebastian Redl
28642de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  static bool isLogicalOp(Opcode Opc) { return Opc == BO_LAnd || Opc==BO_LOr; }
28650799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall  bool isLogicalOp() const { return isLogicalOp(getOpcode()); }
2866f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek
28670e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall  static bool isAssignmentOp(Opcode Opc) {
28680e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall    return Opc >= BO_Assign && Opc <= BO_OrAssign;
28690e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall  }
28700e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall  bool isAssignmentOp() const { return isAssignmentOp(getOpcode()); }
28710e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall
28720e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall  static bool isCompoundAssignmentOp(Opcode Opc) {
28732de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall    return Opc > BO_Assign && Opc <= BO_OrAssign;
28742de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  }
28750e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall  bool isCompoundAssignmentOp() const {
28760e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall    return isCompoundAssignmentOp(getOpcode());
28770e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall  }
28784b9c2d235fb9449e249d74f48ecfec601650de93John McCall  static Opcode getOpForCompoundAssignment(Opcode Opc) {
28794b9c2d235fb9449e249d74f48ecfec601650de93John McCall    assert(isCompoundAssignmentOp(Opc));
2880b92e5d0acbb21e57498fcc4157e108a50c82b857John McCall    if (Opc >= BO_AndAssign)
2881b92e5d0acbb21e57498fcc4157e108a50c82b857John McCall      return Opcode(unsigned(Opc) - BO_AndAssign + BO_And);
28824b9c2d235fb9449e249d74f48ecfec601650de93John McCall    else
28834b9c2d235fb9449e249d74f48ecfec601650de93John McCall      return Opcode(unsigned(Opc) - BO_MulAssign + BO_Mul);
28844b9c2d235fb9449e249d74f48ecfec601650de93John McCall  }
28850e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall
28860e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall  static bool isShiftAssignOp(Opcode Opc) {
28872de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall    return Opc == BO_ShlAssign || Opc == BO_ShrAssign;
28882de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  }
28890e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall  bool isShiftAssignOp() const {
28900e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall    return isShiftAssignOp(getOpcode());
28910e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall  }
28921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
28931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *S) {
28944bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt    return S->getStmtClass() >= firstBinaryOperatorConstant &&
28954bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt           S->getStmtClass() <= lastBinaryOperatorConstant;
28965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
28975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const BinaryOperator *) { return true; }
28981237c673c07f9d827129ba02720108816abde562Ted Kremenek
28991237c673c07f9d827129ba02720108816abde562Ted Kremenek  // Iterators
290063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() {
290163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR);
290263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
29031237c673c07f9d827129ba02720108816abde562Ted Kremenek
29045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprotected:
290517d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner  BinaryOperator(Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy,
2906f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                 ExprValueKind VK, ExprObjectKind OK,
29072333f7727f97018d6742e1e0938133bcfad967abEli Friedman                 SourceLocation opLoc, bool dead)
2908f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    : Expr(CompoundAssignOperatorClass, ResTy, VK, OK,
29092333f7727f97018d6742e1e0938133bcfad967abEli Friedman           lhs->isTypeDependent() || rhs->isTypeDependent(),
2910bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           lhs->isValueDependent() || rhs->isValueDependent(),
2911561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor           (lhs->isInstantiationDependent() ||
2912561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor            rhs->isInstantiationDependent()),
2913bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           (lhs->containsUnexpandedParameterPack() ||
2914bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor            rhs->containsUnexpandedParameterPack())),
29152333f7727f97018d6742e1e0938133bcfad967abEli Friedman      Opc(opc), OpLoc(opLoc) {
29161237c673c07f9d827129ba02720108816abde562Ted Kremenek    SubExprs[LHS] = lhs;
29171237c673c07f9d827129ba02720108816abde562Ted Kremenek    SubExprs[RHS] = rhs;
29185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
2919ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor
29201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  BinaryOperator(StmtClass SC, EmptyShell Empty)
29212de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall    : Expr(SC, Empty), Opc(BO_MulAssign) { }
29225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
29235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
29245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// CompoundAssignOperator - For compound assignments (e.g. +=), we keep
29255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// track of the type the operation is performed in.  Due to the semantics of
2926ec5bc81fd55bfcc26fc4bde6d5e33113d94c2209Zhongxing Xu/// these operators, the operands are promoted, the arithmetic performed, an
29275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// implicit conversion back to the result type done, then the assignment takes
29285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// place.  This captures the intermediate type which the computation is done
29295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// in.
29305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass CompoundAssignOperator : public BinaryOperator {
2931ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman  QualType ComputationLHSType;
2932ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman  QualType ComputationResultType;
29335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
2934f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall  CompoundAssignOperator(Expr *lhs, Expr *rhs, Opcode opc, QualType ResType,
2935f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                         ExprValueKind VK, ExprObjectKind OK,
2936f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                         QualType CompLHSType, QualType CompResultType,
293717d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner                         SourceLocation OpLoc)
2938f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    : BinaryOperator(lhs, rhs, opc, ResType, VK, OK, OpLoc, true),
2939ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman      ComputationLHSType(CompLHSType),
2940ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman      ComputationResultType(CompResultType) {
29411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    assert(isCompoundAssignmentOp() &&
29425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer           "Only should be used for compound assignments");
29435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
29445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
2945ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor  /// \brief Build an empty compound assignment operator expression.
2946ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor  explicit CompoundAssignOperator(EmptyShell Empty)
2947ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor    : BinaryOperator(CompoundAssignOperatorClass, Empty) { }
2948ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor
2949ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman  // The two computation types are the type the LHS is converted
2950ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman  // to for the computation and the type of the result; the two are
2951ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman  // distinct in a few cases (specifically, int+=ptr and ptr-=ptr).
2952ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman  QualType getComputationLHSType() const { return ComputationLHSType; }
2953ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor  void setComputationLHSType(QualType T) { ComputationLHSType = T; }
2954ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor
2955ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman  QualType getComputationResultType() const { return ComputationResultType; }
2956ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor  void setComputationResultType(QualType T) { ComputationResultType = T; }
2957ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor
29585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const CompoundAssignOperator *) { return true; }
29591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *S) {
29601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return S->getStmtClass() == CompoundAssignOperatorClass;
29615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
29625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
29635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
296456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall/// AbstractConditionalOperator - An abstract base class for
296556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall/// ConditionalOperator and BinaryConditionalOperator.
296656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCallclass AbstractConditionalOperator : public Expr {
296756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  SourceLocation QuestionLoc, ColonLoc;
296856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  friend class ASTStmtReader;
296956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall
297056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCallprotected:
297156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  AbstractConditionalOperator(StmtClass SC, QualType T,
297256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall                              ExprValueKind VK, ExprObjectKind OK,
2973561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor                              bool TD, bool VD, bool ID,
297456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall                              bool ContainsUnexpandedParameterPack,
297556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall                              SourceLocation qloc,
297656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall                              SourceLocation cloc)
2977561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor    : Expr(SC, T, VK, OK, TD, VD, ID, ContainsUnexpandedParameterPack),
297856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall      QuestionLoc(qloc), ColonLoc(cloc) {}
297956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall
298056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  AbstractConditionalOperator(StmtClass SC, EmptyShell Empty)
298156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall    : Expr(SC, Empty) { }
298256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall
298356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCallpublic:
298456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  // getCond - Return the expression representing the condition for
298556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  //   the ?: operator.
298656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  Expr *getCond() const;
298756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall
298856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  // getTrueExpr - Return the subexpression representing the value of
298956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  //   the expression if the condition evaluates to true.
299056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  Expr *getTrueExpr() const;
299156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall
299256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  // getFalseExpr - Return the subexpression representing the value of
299356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  //   the expression if the condition evaluates to false.  This is
299456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  //   the same as getRHS.
299556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  Expr *getFalseExpr() const;
299656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall
299756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  SourceLocation getQuestionLoc() const { return QuestionLoc; }
299856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  SourceLocation getColonLoc() const { return ColonLoc; }
299956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall
300056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  static bool classof(const Stmt *T) {
300156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall    return T->getStmtClass() == ConditionalOperatorClass ||
300256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall           T->getStmtClass() == BinaryConditionalOperatorClass;
300356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  }
300456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  static bool classof(const AbstractConditionalOperator *) { return true; }
300556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall};
300656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall
300756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall/// ConditionalOperator - The ?: ternary operator.  The GNU "missing
300856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall/// middle" extension is a BinaryConditionalOperator.
300956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCallclass ConditionalOperator : public AbstractConditionalOperator {
30101237c673c07f9d827129ba02720108816abde562Ted Kremenek  enum { COND, LHS, RHS, END_EXPR };
30115549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Stmt* SubExprs[END_EXPR]; // Left/Middle/Right hand sides.
301256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall
301356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  friend class ASTStmtReader;
30145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
301547e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor  ConditionalOperator(Expr *cond, SourceLocation QLoc, Expr *lhs,
301656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall                      SourceLocation CLoc, Expr *rhs,
30170943168ac126b8047f30f6bd215fbe7db14d61baJohn McCall                      QualType t, ExprValueKind VK, ExprObjectKind OK)
301856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall    : AbstractConditionalOperator(ConditionalOperatorClass, t, VK, OK,
3019898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor           // FIXME: the type of the conditional operator doesn't
3020898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor           // depend on the type of the conditional, but the standard
3021898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor           // seems to imply that it could. File a bug!
302256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall           (lhs->isTypeDependent() || rhs->isTypeDependent()),
302356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall           (cond->isValueDependent() || lhs->isValueDependent() ||
302456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall            rhs->isValueDependent()),
3025561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor           (cond->isInstantiationDependent() ||
3026561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor            lhs->isInstantiationDependent() ||
3027561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor            rhs->isInstantiationDependent()),
3028bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           (cond->containsUnexpandedParameterPack() ||
302956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall            lhs->containsUnexpandedParameterPack() ||
303056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall            rhs->containsUnexpandedParameterPack()),
303156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall                                  QLoc, CLoc) {
30321237c673c07f9d827129ba02720108816abde562Ted Kremenek    SubExprs[COND] = cond;
30331237c673c07f9d827129ba02720108816abde562Ted Kremenek    SubExprs[LHS] = lhs;
30341237c673c07f9d827129ba02720108816abde562Ted Kremenek    SubExprs[RHS] = rhs;
30351237c673c07f9d827129ba02720108816abde562Ted Kremenek  }
30365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
3037ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor  /// \brief Build an empty conditional operator.
3038ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor  explicit ConditionalOperator(EmptyShell Empty)
303956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall    : AbstractConditionalOperator(ConditionalOperatorClass, Empty) { }
3040ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor
3041395a2abf0028968d85958610e393e067885dc14fTed Kremenek  // getCond - Return the expression representing the condition for
304256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  //   the ?: operator.
30435549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getCond() const { return cast<Expr>(SubExprs[COND]); }
3044395a2abf0028968d85958610e393e067885dc14fTed Kremenek
304556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  // getTrueExpr - Return the subexpression representing the value of
304656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  //   the expression if the condition evaluates to true.
304756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  Expr *getTrueExpr() const { return cast<Expr>(SubExprs[LHS]); }
30481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
304956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  // getFalseExpr - Return the subexpression representing the value of
305056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  //   the expression if the condition evaluates to false.  This is
305156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  //   the same as getRHS.
30525549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getFalseExpr() const { return cast<Expr>(SubExprs[RHS]); }
3053ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
305456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); }
30555549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); }
305647e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor
3057aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY {
30585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return SourceRange(getCond()->getLocStart(), getRHS()->getLocEnd());
30595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
30601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
30611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == ConditionalOperatorClass;
30625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
30635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const ConditionalOperator *) { return true; }
30641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
30651237c673c07f9d827129ba02720108816abde562Ted Kremenek  // Iterators
306663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() {
306763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR);
306863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
30695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
30705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
307156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall/// BinaryConditionalOperator - The GNU extension to the conditional
307256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall/// operator which allows the middle operand to be omitted.
307356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall///
307456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall/// This is a different expression kind on the assumption that almost
307556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall/// every client ends up needing to know that these are different.
307656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCallclass BinaryConditionalOperator : public AbstractConditionalOperator {
307756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  enum { COMMON, COND, LHS, RHS, NUM_SUBEXPRS };
307856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall
307956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  /// - the common condition/left-hand-side expression, which will be
308056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  ///   evaluated as the opaque value
308156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  /// - the condition, expressed in terms of the opaque value
308256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  /// - the left-hand-side, expressed in terms of the opaque value
308356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  /// - the right-hand-side
308456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  Stmt *SubExprs[NUM_SUBEXPRS];
308556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  OpaqueValueExpr *OpaqueValue;
308656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall
308756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  friend class ASTStmtReader;
308856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCallpublic:
308956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  BinaryConditionalOperator(Expr *common, OpaqueValueExpr *opaqueValue,
309056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall                            Expr *cond, Expr *lhs, Expr *rhs,
309156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall                            SourceLocation qloc, SourceLocation cloc,
309256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall                            QualType t, ExprValueKind VK, ExprObjectKind OK)
309356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall    : AbstractConditionalOperator(BinaryConditionalOperatorClass, t, VK, OK,
309456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall           (common->isTypeDependent() || rhs->isTypeDependent()),
309556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall           (common->isValueDependent() || rhs->isValueDependent()),
3096561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor           (common->isInstantiationDependent() ||
3097561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor            rhs->isInstantiationDependent()),
309856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall           (common->containsUnexpandedParameterPack() ||
309956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall            rhs->containsUnexpandedParameterPack()),
310056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall                                  qloc, cloc),
310156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall      OpaqueValue(opaqueValue) {
310256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall    SubExprs[COMMON] = common;
310356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall    SubExprs[COND] = cond;
310456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall    SubExprs[LHS] = lhs;
310556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall    SubExprs[RHS] = rhs;
310697df54e0c075bc8d6a869597e771dad0c11a2180Douglas Gregor    assert(OpaqueValue->getSourceExpr() == common && "Wrong opaque value");
310756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  }
310856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall
310956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  /// \brief Build an empty conditional operator.
311056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  explicit BinaryConditionalOperator(EmptyShell Empty)
311156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall    : AbstractConditionalOperator(BinaryConditionalOperatorClass, Empty) { }
311256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall
311356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  /// \brief getCommon - Return the common expression, written to the
311456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  ///   left of the condition.  The opaque value will be bound to the
311556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  ///   result of this expression.
311656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  Expr *getCommon() const { return cast<Expr>(SubExprs[COMMON]); }
311756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall
311856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  /// \brief getOpaqueValue - Return the opaque value placeholder.
311956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  OpaqueValueExpr *getOpaqueValue() const { return OpaqueValue; }
312056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall
312156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  /// \brief getCond - Return the condition expression; this is defined
312256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  ///   in terms of the opaque value.
312356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  Expr *getCond() const { return cast<Expr>(SubExprs[COND]); }
312456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall
312556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  /// \brief getTrueExpr - Return the subexpression which will be
312656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  ///   evaluated if the condition evaluates to true;  this is defined
312756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  ///   in terms of the opaque value.
312856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  Expr *getTrueExpr() const {
312956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall    return cast<Expr>(SubExprs[LHS]);
313056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  }
313156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall
313256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  /// \brief getFalseExpr - Return the subexpression which will be
313356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  ///   evaluated if the condnition evaluates to false; this is
313456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  ///   defined in terms of the opaque value.
313556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  Expr *getFalseExpr() const {
313656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall    return cast<Expr>(SubExprs[RHS]);
313756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  }
3138ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3139aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY {
314056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall    return SourceRange(getCommon()->getLocStart(), getFalseExpr()->getLocEnd());
314156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  }
314256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  static bool classof(const Stmt *T) {
314356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall    return T->getStmtClass() == BinaryConditionalOperatorClass;
314456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  }
314556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  static bool classof(const BinaryConditionalOperator *) { return true; }
314656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall
314756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  // Iterators
314856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  child_range children() {
314956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall    return child_range(SubExprs, SubExprs + NUM_SUBEXPRS);
315056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  }
315156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall};
315256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall
315356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCallinline Expr *AbstractConditionalOperator::getCond() const {
315456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  if (const ConditionalOperator *co = dyn_cast<ConditionalOperator>(this))
315556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall    return co->getCond();
315656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  return cast<BinaryConditionalOperator>(this)->getCond();
315756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall}
315856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall
315956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCallinline Expr *AbstractConditionalOperator::getTrueExpr() const {
316056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  if (const ConditionalOperator *co = dyn_cast<ConditionalOperator>(this))
316156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall    return co->getTrueExpr();
316256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  return cast<BinaryConditionalOperator>(this)->getTrueExpr();
316356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall}
316456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall
316556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCallinline Expr *AbstractConditionalOperator::getFalseExpr() const {
316656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  if (const ConditionalOperator *co = dyn_cast<ConditionalOperator>(this))
316756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall    return co->getFalseExpr();
316856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  return cast<BinaryConditionalOperator>(this)->getFalseExpr();
316956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall}
317056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall
31716481a57fefbf1a313ff439028470fe4c27a3b7a3Chris Lattner/// AddrLabelExpr - The GNU address of label extension, representing &&label.
31726481a57fefbf1a313ff439028470fe4c27a3b7a3Chris Lattnerclass AddrLabelExpr : public Expr {
31735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation AmpAmpLoc, LabelLoc;
3174ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner  LabelDecl *Label;
31755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
3176ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner  AddrLabelExpr(SourceLocation AALoc, SourceLocation LLoc, LabelDecl *L,
31776481a57fefbf1a313ff439028470fe4c27a3b7a3Chris Lattner                QualType t)
3178561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor    : Expr(AddrLabelExprClass, t, VK_RValue, OK_Ordinary, false, false, false,
3179561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor           false),
31802333f7727f97018d6742e1e0938133bcfad967abEli Friedman      AmpAmpLoc(AALoc), LabelLoc(LLoc), Label(L) {}
31811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
31827d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor  /// \brief Build an empty address of a label expression.
31831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  explicit AddrLabelExpr(EmptyShell Empty)
31847d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor    : Expr(AddrLabelExprClass, Empty) { }
31857d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor
31867d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor  SourceLocation getAmpAmpLoc() const { return AmpAmpLoc; }
31877d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor  void setAmpAmpLoc(SourceLocation L) { AmpAmpLoc = L; }
31887d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor  SourceLocation getLabelLoc() const { return LabelLoc; }
31897d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor  void setLabelLoc(SourceLocation L) { LabelLoc = L; }
31907d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor
3191aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY {
31925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return SourceRange(AmpAmpLoc, LabelLoc);
31935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
31941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3195ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner  LabelDecl *getLabel() const { return Label; }
3196ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner  void setLabel(LabelDecl *L) { Label = L; }
31977d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor
31985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Stmt *T) {
31991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == AddrLabelExprClass;
32005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
32016481a57fefbf1a313ff439028470fe4c27a3b7a3Chris Lattner  static bool classof(const AddrLabelExpr *) { return true; }
32021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
32031237c673c07f9d827129ba02720108816abde562Ted Kremenek  // Iterators
320463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(); }
32055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
3206ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner
3207ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner/// StmtExpr - This is the GNU Statement Expression extension: ({int X=4; X;}).
3208ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner/// The StmtExpr contains a single CompoundStmt node, which it evaluates and
3209ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner/// takes the value of the last subexpression.
3210f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall///
3211f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall/// A StmtExpr is always an r-value; values "returned" out of a
3212f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall/// StmtExpr will be copied.
3213ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattnerclass StmtExpr : public Expr {
32145549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Stmt *SubStmt;
3215ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner  SourceLocation LParenLoc, RParenLoc;
3216ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattnerpublic:
32172333f7727f97018d6742e1e0938133bcfad967abEli Friedman  // FIXME: Does type-dependence need to be computed differently?
3218561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor  // FIXME: Do we need to compute instantiation instantiation-dependence for
3219561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor  // statements? (ugh!)
3220d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff  StmtExpr(CompoundStmt *substmt, QualType T,
3221d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff           SourceLocation lp, SourceLocation rp) :
3222f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    Expr(StmtExprClass, T, VK_RValue, OK_Ordinary,
3223561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor         T->isDependentType(), false, false, false),
32242333f7727f97018d6742e1e0938133bcfad967abEli Friedman    SubStmt(substmt), LParenLoc(lp), RParenLoc(rp) { }
32251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
32266a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor  /// \brief Build an empty statement expression.
32276a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor  explicit StmtExpr(EmptyShell Empty) : Expr(StmtExprClass, Empty) { }
32286a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor
32295549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  CompoundStmt *getSubStmt() { return cast<CompoundStmt>(SubStmt); }
32305549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  const CompoundStmt *getSubStmt() const { return cast<CompoundStmt>(SubStmt); }
32316a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor  void setSubStmt(CompoundStmt *S) { SubStmt = S; }
32326a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor
3233aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY {
3234ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner    return SourceRange(LParenLoc, RParenLoc);
3235ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner  }
32361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3237026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner  SourceLocation getLParenLoc() const { return LParenLoc; }
32386a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor  void setLParenLoc(SourceLocation L) { LParenLoc = L; }
3239026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner  SourceLocation getRParenLoc() const { return RParenLoc; }
32406a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
32411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3242ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner  static bool classof(const Stmt *T) {
32431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == StmtExprClass;
3244ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner  }
3245ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner  static bool classof(const StmtExpr *) { return true; }
32461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
32471237c673c07f9d827129ba02720108816abde562Ted Kremenek  // Iterators
324863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(&SubStmt, &SubStmt+1); }
3249ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner};
3250ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner
3251d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff
3252d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// ShuffleVectorExpr - clang-specific builtin-in function
3253d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// __builtin_shufflevector.
3254d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// This AST node represents a operator that does a constant
3255d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// shuffle, similar to LLVM's shufflevector instruction. It takes
3256d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// two vectors and a variable number of constant indices,
3257d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// and returns the appropriately shuffled vector.
3258d38617c8a50f9729c254ab76cd359af797c6739bEli Friedmanclass ShuffleVectorExpr : public Expr {
3259d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  SourceLocation BuiltinLoc, RParenLoc;
3260d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman
3261d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  // SubExprs - the list of values passed to the __builtin_shufflevector
3262d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  // function. The first two are vectors, and the rest are constant
3263d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  // indices.  The number of values in this list is always
3264d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  // 2+the number of indices in the vector type.
32655549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Stmt **SubExprs;
3266d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  unsigned NumExprs;
3267d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman
3268d38617c8a50f9729c254ab76cd359af797c6739bEli Friedmanpublic:
3269a88dc3079bedf70a5cfc39791727e43a10383006Nate Begeman  ShuffleVectorExpr(ASTContext &C, Expr **args, unsigned nexpr,
32701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                    QualType Type, SourceLocation BLoc,
3271bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor                    SourceLocation RP);
327294cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor
327394cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor  /// \brief Build an empty vector-shuffle expression.
32741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  explicit ShuffleVectorExpr(EmptyShell Empty)
327594cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor    : Expr(ShuffleVectorExprClass, Empty), SubExprs(0) { }
327694cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor
327794cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor  SourceLocation getBuiltinLoc() const { return BuiltinLoc; }
327894cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor  void setBuiltinLoc(SourceLocation L) { BuiltinLoc = L; }
32791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
328094cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor  SourceLocation getRParenLoc() const { return RParenLoc; }
328194cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
328294cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor
3283aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY {
3284d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman    return SourceRange(BuiltinLoc, RParenLoc);
3285d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  }
3286d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  static bool classof(const Stmt *T) {
32871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == ShuffleVectorExprClass;
3288d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  }
3289d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  static bool classof(const ShuffleVectorExpr *) { return true; }
32901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3291d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  /// getNumSubExprs - Return the size of the SubExprs array.  This includes the
3292d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  /// constant expression, the actual arguments passed in, and the function
3293d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  /// pointers.
3294d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  unsigned getNumSubExprs() const { return NumExprs; }
32951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3296aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  /// \brief Retrieve the array of expressions.
3297aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  Expr **getSubExprs() { return reinterpret_cast<Expr **>(SubExprs); }
3298ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3299d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  /// getExpr - Return the Expr at the specified index.
3300d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  Expr *getExpr(unsigned Index) {
3301d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman    assert((Index < NumExprs) && "Arg access out of range!");
33025549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek    return cast<Expr>(SubExprs[Index]);
3303d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  }
3304d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  const Expr *getExpr(unsigned Index) const {
3305d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman    assert((Index < NumExprs) && "Arg access out of range!");
33065549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek    return cast<Expr>(SubExprs[Index]);
3307d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  }
33081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3309888376a2bbcfc2f047902249f8455918e2489ae1Nate Begeman  void setExprs(ASTContext &C, Expr ** Exprs, unsigned NumExprs);
331094cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor
3311dde8c94873976632e3ada4d8d067e1e244184d51Eli Friedman  unsigned getShuffleMaskIdx(ASTContext &Ctx, unsigned N) {
3312dde8c94873976632e3ada4d8d067e1e244184d51Eli Friedman    assert((N < NumExprs - 2) && "Shuffle idx out of range!");
3313a6b8b2c09610b8bc4330e948ece8b940c2386406Richard Smith    return getExpr(N+2)->EvaluateKnownConstInt(Ctx).getZExtValue();
3314d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  }
33151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3316d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  // Iterators
331763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() {
331863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return child_range(&SubExprs[0], &SubExprs[0]+NumExprs);
331963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
3320d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman};
3321d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman
3322d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff/// ChooseExpr - GNU builtin-in function __builtin_choose_expr.
33231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// This AST node is similar to the conditional operator (?:) in C, with
3324d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff/// the following exceptions:
33257976932a1c256d447316ffac58e9821417725e34Eli Friedman/// - the test expression must be a integer constant expression.
33267976932a1c256d447316ffac58e9821417725e34Eli Friedman/// - the expression returned acts like the chosen subexpression in every
33277976932a1c256d447316ffac58e9821417725e34Eli Friedman///   visible way: the type is the same as that of the chosen subexpression,
33287976932a1c256d447316ffac58e9821417725e34Eli Friedman///   and all predicates (whether it's an l-value, whether it's an integer
33297976932a1c256d447316ffac58e9821417725e34Eli Friedman///   constant expression, etc.) return the same result as for the chosen
33307976932a1c256d447316ffac58e9821417725e34Eli Friedman///   sub-expression.
3331d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroffclass ChooseExpr : public Expr {
33321237c673c07f9d827129ba02720108816abde562Ted Kremenek  enum { COND, LHS, RHS, END_EXPR };
33335549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Stmt* SubExprs[END_EXPR]; // Left/Middle/Right hand sides.
3334d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff  SourceLocation BuiltinLoc, RParenLoc;
3335d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroffpublic:
3336f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall  ChooseExpr(SourceLocation BLoc, Expr *cond, Expr *lhs, Expr *rhs,
3337f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall             QualType t, ExprValueKind VK, ExprObjectKind OK,
3338ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor             SourceLocation RP, bool TypeDependent, bool ValueDependent)
3339bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor    : Expr(ChooseExprClass, t, VK, OK, TypeDependent, ValueDependent,
3340561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor           (cond->isInstantiationDependent() ||
3341561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor            lhs->isInstantiationDependent() ||
3342561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor            rhs->isInstantiationDependent()),
3343bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           (cond->containsUnexpandedParameterPack() ||
3344bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor            lhs->containsUnexpandedParameterPack() ||
3345bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor            rhs->containsUnexpandedParameterPack())),
33461237c673c07f9d827129ba02720108816abde562Ted Kremenek      BuiltinLoc(BLoc), RParenLoc(RP) {
33471237c673c07f9d827129ba02720108816abde562Ted Kremenek      SubExprs[COND] = cond;
33481237c673c07f9d827129ba02720108816abde562Ted Kremenek      SubExprs[LHS] = lhs;
33491237c673c07f9d827129ba02720108816abde562Ted Kremenek      SubExprs[RHS] = rhs;
33501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    }
33517976932a1c256d447316ffac58e9821417725e34Eli Friedman
335244cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  /// \brief Build an empty __builtin_choose_expr.
335344cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  explicit ChooseExpr(EmptyShell Empty) : Expr(ChooseExprClass, Empty) { }
335444cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor
33557976932a1c256d447316ffac58e9821417725e34Eli Friedman  /// isConditionTrue - Return whether the condition is true (i.e. not
33567976932a1c256d447316ffac58e9821417725e34Eli Friedman  /// equal to zero).
33574ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad  bool isConditionTrue(const ASTContext &C) const;
33587976932a1c256d447316ffac58e9821417725e34Eli Friedman
33597976932a1c256d447316ffac58e9821417725e34Eli Friedman  /// getChosenSubExpr - Return the subexpression chosen according to the
33607976932a1c256d447316ffac58e9821417725e34Eli Friedman  /// condition.
33614ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad  Expr *getChosenSubExpr(const ASTContext &C) const {
33627976932a1c256d447316ffac58e9821417725e34Eli Friedman    return isConditionTrue(C) ? getLHS() : getRHS();
33637976932a1c256d447316ffac58e9821417725e34Eli Friedman  }
33647976932a1c256d447316ffac58e9821417725e34Eli Friedman
33655549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getCond() const { return cast<Expr>(SubExprs[COND]); }
336644cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  void setCond(Expr *E) { SubExprs[COND] = E; }
33675549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); }
336844cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  void setLHS(Expr *E) { SubExprs[LHS] = E; }
33695549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); }
337044cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  void setRHS(Expr *E) { SubExprs[RHS] = E; }
337144cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor
337244cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  SourceLocation getBuiltinLoc() const { return BuiltinLoc; }
337344cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  void setBuiltinLoc(SourceLocation L) { BuiltinLoc = L; }
33741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
337544cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  SourceLocation getRParenLoc() const { return RParenLoc; }
337644cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
33771237c673c07f9d827129ba02720108816abde562Ted Kremenek
3378aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY {
3379d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff    return SourceRange(BuiltinLoc, RParenLoc);
3380d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff  }
3381d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff  static bool classof(const Stmt *T) {
33821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == ChooseExprClass;
3383d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff  }
3384d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff  static bool classof(const ChooseExpr *) { return true; }
33851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
33861237c673c07f9d827129ba02720108816abde562Ted Kremenek  // Iterators
338763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() {
338863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR);
338963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
3390d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff};
3391d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff
33922d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// GNUNullExpr - Implements the GNU __null extension, which is a name
33932d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// for a null pointer constant that has integral type (e.g., int or
33942d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// long) and is the same size and alignment as a pointer. The __null
33952d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// extension is typically only used by system headers, which define
33962d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// NULL as __null in C++ rather than using 0 (which is an integer
33972d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// that may not match the size of a pointer).
33982d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregorclass GNUNullExpr : public Expr {
33992d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor  /// TokenLoc - The location of the __null keyword.
34002d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor  SourceLocation TokenLoc;
34012d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor
34022d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregorpublic:
34031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  GNUNullExpr(QualType Ty, SourceLocation Loc)
3404561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor    : Expr(GNUNullExprClass, Ty, VK_RValue, OK_Ordinary, false, false, false,
3405561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor           false),
3406f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall      TokenLoc(Loc) { }
34072d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor
340844cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  /// \brief Build an empty GNU __null expression.
340944cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  explicit GNUNullExpr(EmptyShell Empty) : Expr(GNUNullExprClass, Empty) { }
341044cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor
34112d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor  /// getTokenLocation - The location of the __null token.
34122d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor  SourceLocation getTokenLocation() const { return TokenLoc; }
341344cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  void setTokenLocation(SourceLocation L) { TokenLoc = L; }
34142d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor
3415aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY {
34162d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor    return SourceRange(TokenLoc);
34172d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor  }
34182d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor  static bool classof(const Stmt *T) {
34191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == GNUNullExprClass;
34202d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor  }
34212d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor  static bool classof(const GNUNullExpr *) { return true; }
34221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
34232d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor  // Iterators
342463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(); }
34252d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor};
34262d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor
342774626d6ef2e194fcc911e071556660ff331eb4a8Zhongxing Xu/// VAArgExpr, used for the builtin function __builtin_va_arg.
34287c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlssonclass VAArgExpr : public Expr {
34295549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Stmt *Val;
34302cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara  TypeSourceInfo *TInfo;
34317c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson  SourceLocation BuiltinLoc, RParenLoc;
34327c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlssonpublic:
34332cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara  VAArgExpr(SourceLocation BLoc, Expr* e, TypeSourceInfo *TInfo,
34342cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara            SourceLocation RPLoc, QualType t)
3435f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    : Expr(VAArgExprClass, t, VK_RValue, OK_Ordinary,
3436bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           t->isDependentType(), false,
3437561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor           (TInfo->getType()->isInstantiationDependentType() ||
3438561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor            e->isInstantiationDependent()),
3439bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           (TInfo->getType()->containsUnexpandedParameterPack() ||
3440bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor            e->containsUnexpandedParameterPack())),
34412cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara      Val(e), TInfo(TInfo),
34427c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson      BuiltinLoc(BLoc),
34437c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson      RParenLoc(RPLoc) { }
34441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
344574626d6ef2e194fcc911e071556660ff331eb4a8Zhongxing Xu  /// \brief Create an empty __builtin_va_arg expression.
3446d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor  explicit VAArgExpr(EmptyShell Empty) : Expr(VAArgExprClass, Empty) { }
3447d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor
34485549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  const Expr *getSubExpr() const { return cast<Expr>(Val); }
34495549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getSubExpr() { return cast<Expr>(Val); }
3450d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor  void setSubExpr(Expr *E) { Val = E; }
3451d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor
34522cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara  TypeSourceInfo *getWrittenTypeInfo() const { return TInfo; }
34532cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara  void setWrittenTypeInfo(TypeSourceInfo *TI) { TInfo = TI; }
34542cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara
3455d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor  SourceLocation getBuiltinLoc() const { return BuiltinLoc; }
3456d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor  void setBuiltinLoc(SourceLocation L) { BuiltinLoc = L; }
34571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3458d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor  SourceLocation getRParenLoc() const { return RParenLoc; }
3459d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
3460d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor
3461aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY {
34627c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson    return SourceRange(BuiltinLoc, RParenLoc);
34631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  }
34647c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson  static bool classof(const Stmt *T) {
34657c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson    return T->getStmtClass() == VAArgExprClass;
34667c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson  }
34677c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson  static bool classof(const VAArgExpr *) { return true; }
34681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
34697c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson  // Iterators
347063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(&Val, &Val+1); }
34717c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson};
34721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
34734c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// @brief Describes an C or C++ initializer list.
34744c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor///
34754c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// InitListExpr describes an initializer list, which can be used to
34764c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// initialize objects of different types, including
34774c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// struct/class/union types, arrays, and vectors. For example:
34784c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor///
34794c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// @code
34804c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// struct foo x = { 1, { 2, 3 } };
34814c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// @endcode
3482196ef51bc4d008ec1c69851fb3b0f8d036065931Chris Lattner///
34834c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// Prior to semantic analysis, an initializer list will represent the
34844c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// initializer list as written by the user, but will have the
34854c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// placeholder type "void". This initializer list is called the
34864c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// syntactic form of the initializer, and may contain C99 designated
34874c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// initializers (represented as DesignatedInitExprs), initializations
34884c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// of subobject members without explicit braces, and so on. Clients
34894c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// interested in the original syntax of the initializer list should
34904c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// use the syntactic form of the initializer list.
3491196ef51bc4d008ec1c69851fb3b0f8d036065931Chris Lattner///
34924c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// After semantic analysis, the initializer list will represent the
34934c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// semantic form of the initializer, where the initializations of all
34944c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// subobjects are made explicit with nested InitListExpr nodes and
34954c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// C99 designators have been eliminated by placing the designated
34964c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// initializations into the subobject they initialize. Additionally,
34974c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// any "holes" in the initialization, where no initializer has been
34984c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// specified for a particular subobject, will be replaced with
34993498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor/// implicitly-generated ImplicitValueInitExpr expressions that
35004c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// value-initialize the subobjects. Note, however, that the
35014c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// initializer lists may still have fewer initializers than there are
35024c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// elements to initialize within the object.
3503196ef51bc4d008ec1c69851fb3b0f8d036065931Chris Lattner///
35044c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// Given the semantic form of the initializer list, one can retrieve
35054c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// the original syntactic form of that initializer list (if it
35064c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// exists) using getSyntacticForm(). Since many initializer lists
35074c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// have the same syntactic and semantic forms, getSyntacticForm() may
35084c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// return NULL, indicating that the current initializer list also
35094c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// serves as its syntactic form.
351066b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlssonclass InitListExpr : public Expr {
3511ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek  // FIXME: Eliminate this vector in favor of ASTContext allocation
3512709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek  typedef ASTVector<Stmt *> InitExprsTy;
3513709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek  InitExprsTy InitExprs;
351466b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson  SourceLocation LBraceLoc, RBraceLoc;
35151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
35164c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  /// Contains the initializer list that describes the syntactic form
35174c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  /// written in the source code.
35184c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  InitListExpr *SyntacticForm;
35194c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor
35204423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis  /// \brief Either:
35214423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis  ///  If this initializer list initializes an array with more elements than
35224423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis  ///  there are initializers in the list, specifies an expression to be used
35234423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis  ///  for value initialization of the rest of the elements.
35244423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis  /// Or
35254423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis  ///  If this initializer list initializes a union, specifies which
35264423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis  ///  field within the union will be initialized.
35274423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis  llvm::PointerUnion<Expr *, FieldDecl *> ArrayFillerOrUnionFieldInit;
35280bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor
352966b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlssonpublic:
3530709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek  InitListExpr(ASTContext &C, SourceLocation lbraceloc,
3531709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek               Expr **initexprs, unsigned numinits,
3532ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek               SourceLocation rbraceloc);
3533d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor
3534d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  /// \brief Build an empty initializer list.
3535709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek  explicit InitListExpr(ASTContext &C, EmptyShell Empty)
3536709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek    : Expr(InitListExprClass, Empty), InitExprs(C) { }
35371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3538ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek  unsigned getNumInits() const { return InitExprs.size(); }
35391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3540aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  /// \brief Retrieve the set of initializers.
3541aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  Expr **getInits() { return reinterpret_cast<Expr **>(InitExprs.data()); }
3542ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
354316c5dea6c2d3e4cf529de9d9b37f6a40441acb2cChris Lattner  const Expr *getInit(unsigned Init) const {
3544c5ae899b4bbf65488445316c63168079177db0edSteve Naroff    assert(Init < getNumInits() && "Initializer access out of range!");
35454c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor    return cast_or_null<Expr>(InitExprs[Init]);
354666b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson  }
35471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
354816c5dea6c2d3e4cf529de9d9b37f6a40441acb2cChris Lattner  Expr *getInit(unsigned Init) {
3549c5ae899b4bbf65488445316c63168079177db0edSteve Naroff    assert(Init < getNumInits() && "Initializer access out of range!");
35504c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor    return cast_or_null<Expr>(InitExprs[Init]);
355166b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson  }
35521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
35531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  void setInit(unsigned Init, Expr *expr) {
3554c5ae899b4bbf65488445316c63168079177db0edSteve Naroff    assert(Init < getNumInits() && "Initializer access out of range!");
35559e8925e72f53a9e2c4633b6b48e965ed01702fe4Steve Naroff    InitExprs[Init] = expr;
35569e8925e72f53a9e2c4633b6b48e965ed01702fe4Steve Naroff  }
3557c5ae899b4bbf65488445316c63168079177db0edSteve Naroff
3558fa2192042f223b5122a9e17719930f77634fd31fDouglas Gregor  /// \brief Reserve space for some number of initializers.
3559709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek  void reserveInits(ASTContext &C, unsigned NumInits);
35601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
35614c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  /// @brief Specify the number of initializers
35624c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  ///
35634c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  /// If there are more than @p NumInits initializers, the remaining
35644c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  /// initializers will be destroyed. If there are fewer than @p
35654c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  /// NumInits initializers, NULL expressions will be added for the
35664c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  /// unknown initializers.
35674c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  void resizeInits(ASTContext &Context, unsigned NumInits);
35684c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor
35694c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  /// @brief Updates the initializer at index @p Init with the new
35704c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  /// expression @p expr, and returns the old expression at that
35714c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  /// location.
35724c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  ///
35734c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  /// When @p Init is out of range for this initializer list, the
35744c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  /// initializer list will be extended with NULL expressions to
3575fc8f0e14ad142ed811e90fbd9a30e419e301c717Chris Lattner  /// accommodate the new entry.
3576709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek  Expr *updateInit(ASTContext &C, unsigned Init, Expr *expr);
3577c5ae899b4bbf65488445316c63168079177db0edSteve Naroff
35784423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis  /// \brief If this initializer list initializes an array with more elements
35794423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis  /// than there are initializers in the list, specifies an expression to be
35804423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis  /// used for value initialization of the rest of the elements.
35814423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis  Expr *getArrayFiller() {
35824423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis    return ArrayFillerOrUnionFieldInit.dyn_cast<Expr *>();
35834423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis  }
35848cad3046be06ea73ff8892d947697a21d7a440d3Peter Collingbourne  const Expr *getArrayFiller() const {
35858cad3046be06ea73ff8892d947697a21d7a440d3Peter Collingbourne    return const_cast<InitListExpr *>(this)->getArrayFiller();
35868cad3046be06ea73ff8892d947697a21d7a440d3Peter Collingbourne  }
35873e8dc2ac8926dfbebd8f2f6b74ceba4befccd4d2Argyrios Kyrtzidis  void setArrayFiller(Expr *filler);
35884423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis
358921f77cd0c3da8a1dbaf6245cae43baf4c0b80ea4Argyrios Kyrtzidis  /// \brief Return true if this is an array initializer and its array "filler"
359021f77cd0c3da8a1dbaf6245cae43baf4c0b80ea4Argyrios Kyrtzidis  /// has been set.
359121f77cd0c3da8a1dbaf6245cae43baf4c0b80ea4Argyrios Kyrtzidis  bool hasArrayFiller() const { return getArrayFiller(); }
359221f77cd0c3da8a1dbaf6245cae43baf4c0b80ea4Argyrios Kyrtzidis
35930bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor  /// \brief If this initializes a union, specifies which field in the
35940bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor  /// union to initialize.
35950bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor  ///
35960bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor  /// Typically, this field is the first named field within the
35970bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor  /// union. However, a designated initializer can specify the
35980bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor  /// initialization of a different field within the union.
35994423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis  FieldDecl *getInitializedFieldInUnion() {
36004423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis    return ArrayFillerOrUnionFieldInit.dyn_cast<FieldDecl *>();
36014423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis  }
36028cad3046be06ea73ff8892d947697a21d7a440d3Peter Collingbourne  const FieldDecl *getInitializedFieldInUnion() const {
36038cad3046be06ea73ff8892d947697a21d7a440d3Peter Collingbourne    return const_cast<InitListExpr *>(this)->getInitializedFieldInUnion();
36048cad3046be06ea73ff8892d947697a21d7a440d3Peter Collingbourne  }
36054423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis  void setInitializedFieldInUnion(FieldDecl *FD) {
36064423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis    ArrayFillerOrUnionFieldInit = FD;
36074423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis  }
36080bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor
3609c5ae899b4bbf65488445316c63168079177db0edSteve Naroff  // Explicit InitListExpr's originate from source code (and have valid source
3610c5ae899b4bbf65488445316c63168079177db0edSteve Naroff  // locations). Implicit InitListExpr's are created by the semantic analyzer.
3611b3eef68111ffc220e449be96da1747998c057790Douglas Gregor  bool isExplicit() {
3612b3eef68111ffc220e449be96da1747998c057790Douglas Gregor    return LBraceLoc.isValid() && RBraceLoc.isValid();
3613b3eef68111ffc220e449be96da1747998c057790Douglas Gregor  }
36141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3615fe587201feaebc69e6d18858bea85c77926b6ecfRichard Smith  // Is this an initializer for an array of characters, initialized by a string
3616fe587201feaebc69e6d18858bea85c77926b6ecfRichard Smith  // literal or an @encode?
3617fe587201feaebc69e6d18858bea85c77926b6ecfRichard Smith  bool isStringLiteralInit() const;
3618fe587201feaebc69e6d18858bea85c77926b6ecfRichard Smith
3619d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  SourceLocation getLBraceLoc() const { return LBraceLoc; }
3620d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  void setLBraceLoc(SourceLocation Loc) { LBraceLoc = Loc; }
3621d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  SourceLocation getRBraceLoc() const { return RBraceLoc; }
362287fd703e097c27d63479cb83b687d4000a22bbb1Douglas Gregor  void setRBraceLoc(SourceLocation Loc) { RBraceLoc = Loc; }
362387fd703e097c27d63479cb83b687d4000a22bbb1Douglas Gregor
36244c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  /// @brief Retrieve the initializer list that describes the
36254c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  /// syntactic form of the initializer.
36264c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  ///
36271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
36284c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  InitListExpr *getSyntacticForm() const { return SyntacticForm; }
36294c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  void setSyntacticForm(InitListExpr *Init) { SyntacticForm = Init; }
36304c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor
363132cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl  bool hadArrayRangeDesignator() const {
363232cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl    return InitListExprBits.HadArrayRangeDesignator != 0;
363332cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl  }
36341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  void sawArrayRangeDesignator(bool ARD = true) {
363532cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl    InitListExprBits.HadArrayRangeDesignator = ARD;
363632cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl  }
363732cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl
363832cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl  bool initializesStdInitializerList() const {
363932cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl    return InitListExprBits.InitializesStdInitializerList != 0;
364032cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl  }
364132cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl  void setInitializesStdInitializerList(bool ISIL = true) {
364232cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl    InitListExprBits.InitializesStdInitializerList = ISIL;
3643a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor  }
3644a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor
3645aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY;
3646c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek
364766b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson  static bool classof(const Stmt *T) {
36481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == InitListExprClass;
364966b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson  }
365066b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson  static bool classof(const InitListExpr *) { return true; }
36511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
365266b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson  // Iterators
365363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() {
365463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    if (InitExprs.empty()) return child_range();
365563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return child_range(&InitExprs[0], &InitExprs[0] + InitExprs.size());
365663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
36571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3658709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek  typedef InitExprsTy::iterator iterator;
36598111a6150cb68a238d55a31f9f4f90869a43f988Zhongxing Xu  typedef InitExprsTy::const_iterator const_iterator;
3660709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek  typedef InitExprsTy::reverse_iterator reverse_iterator;
36618111a6150cb68a238d55a31f9f4f90869a43f988Zhongxing Xu  typedef InitExprsTy::const_reverse_iterator const_reverse_iterator;
36621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3663ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek  iterator begin() { return InitExprs.begin(); }
36648111a6150cb68a238d55a31f9f4f90869a43f988Zhongxing Xu  const_iterator begin() const { return InitExprs.begin(); }
3665ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek  iterator end() { return InitExprs.end(); }
36668111a6150cb68a238d55a31f9f4f90869a43f988Zhongxing Xu  const_iterator end() const { return InitExprs.end(); }
3667ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek  reverse_iterator rbegin() { return InitExprs.rbegin(); }
36688111a6150cb68a238d55a31f9f4f90869a43f988Zhongxing Xu  const_reverse_iterator rbegin() const { return InitExprs.rbegin(); }
3669ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek  reverse_iterator rend() { return InitExprs.rend(); }
36708111a6150cb68a238d55a31f9f4f90869a43f988Zhongxing Xu  const_reverse_iterator rend() const { return InitExprs.rend(); }
36714423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis
36724423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis  friend class ASTStmtReader;
36734423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis  friend class ASTStmtWriter;
367466b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson};
367566b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson
367605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// @brief Represents a C99 designated initializer expression.
367705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor///
367805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// A designated initializer expression (C99 6.7.8) contains one or
367905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// more designators (which can be field designators, array
368005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// designators, or GNU array-range designators) followed by an
368105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// expression that initializes the field or element(s) that the
368205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// designators refer to. For example, given:
36831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump///
368405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// @code
368505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// struct point {
368605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor///   double x;
368705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor///   double y;
368805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// };
368905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// struct point ptarray[10] = { [2].y = 1.0, [2].x = 2.0, [0].x = 1.0 };
369005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// @endcode
369105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor///
369205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// The InitListExpr contains three DesignatedInitExprs, the first of
369305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// which covers @c [2].y=1.0. This DesignatedInitExpr will have two
369405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// designators, one array designator for @c [2] followed by one field
369505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// designator for @c .y. The initalization expression will be 1.0.
369605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregorclass DesignatedInitExpr : public Expr {
3697ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregorpublic:
3698ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor  /// \brief Forward declaration of the Designator class.
3699ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor  class Designator;
3700ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor
3701ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregorprivate:
370205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// The location of the '=' or ':' prior to the actual initializer
370305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// expression.
370405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  SourceLocation EqualOrColonLoc;
370505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
3706eeae8f072748affce25ab4064982626361293390Douglas Gregor  /// Whether this designated initializer used the GNU deprecated
370705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// syntax rather than the C99 '=' syntax.
3708eeae8f072748affce25ab4064982626361293390Douglas Gregor  bool GNUSyntax : 1;
370905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
371005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// The number of designators in this initializer expression.
371105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  unsigned NumDesignators : 15;
371205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
371305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// The number of subexpressions of this initializer expression,
371405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// which contains both the initializer and any additional
371505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// expressions used by array and array-range designators.
371605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  unsigned NumSubExprs : 16;
371705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
3718a72c352e4950cb487942427550777378b68dc078Benjamin Kramer  /// \brief The designators in this designated initialization
3719a72c352e4950cb487942427550777378b68dc078Benjamin Kramer  /// expression.
3720a72c352e4950cb487942427550777378b68dc078Benjamin Kramer  Designator *Designators;
3721a72c352e4950cb487942427550777378b68dc078Benjamin Kramer
3722ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor
3723319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregor  DesignatedInitExpr(ASTContext &C, QualType Ty, unsigned NumDesignators,
3724ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor                     const Designator *Designators,
3725eeae8f072748affce25ab4064982626361293390Douglas Gregor                     SourceLocation EqualOrColonLoc, bool GNUSyntax,
37269ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor                     Expr **IndexExprs, unsigned NumIndexExprs,
37279ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor                     Expr *Init);
372805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
3729d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  explicit DesignatedInitExpr(unsigned NumSubExprs)
3730d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor    : Expr(DesignatedInitExprClass, EmptyShell()),
3731a72c352e4950cb487942427550777378b68dc078Benjamin Kramer      NumDesignators(0), NumSubExprs(NumSubExprs), Designators(0) { }
3732d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor
373305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregorpublic:
373405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// A field designator, e.g., ".x".
373505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  struct FieldDesignator {
373605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// Refers to the field that is being initialized. The low bit
373705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// of this field determines whether this is actually a pointer
373805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// to an IdentifierInfo (if 1) or a FieldDecl (if 0). When
373905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// initially constructed, a field designator will store an
374005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// IdentifierInfo*. After semantic analysis has resolved that
374105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// name, the field designator will instead store a FieldDecl*.
374205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    uintptr_t NameOrField;
37431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
374405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// The location of the '.' in the designated initializer.
374505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    unsigned DotLoc;
37461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
374705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// The location of the field name in the designated initializer.
374805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    unsigned FieldLoc;
374905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  };
375005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
375105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// An array or GNU array-range designator, e.g., "[9]" or "[10..15]".
375205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  struct ArrayOrRangeDesignator {
375305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// Location of the first index expression within the designated
375405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// initializer expression's list of subexpressions.
375505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    unsigned Index;
375605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// The location of the '[' starting the array range designator.
375705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    unsigned LBracketLoc;
375805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// The location of the ellipsis separating the start and end
375905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// indices. Only valid for GNU array-range designators.
376005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    unsigned EllipsisLoc;
376105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// The location of the ']' terminating the array range designator.
37621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    unsigned RBracketLoc;
376305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  };
376405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
376505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// @brief Represents a single C99 designator.
376605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  ///
376705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// @todo This class is infuriatingly similar to clang::Designator,
376805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// but minor differences (storing indices vs. storing pointers)
376905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// keep us from reusing it. Try harder, later, to rectify these
377005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// differences.
377105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  class Designator {
377205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// @brief The kind of designator this describes.
377305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    enum {
377405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      FieldDesignator,
377505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      ArrayDesignator,
377605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      ArrayRangeDesignator
377705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    } Kind;
377805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
377905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    union {
378005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      /// A field designator, e.g., ".x".
378105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      struct FieldDesignator Field;
378205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      /// An array or GNU array-range designator, e.g., "[9]" or "[10..15]".
378305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      struct ArrayOrRangeDesignator ArrayOrRange;
378405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    };
378505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    friend class DesignatedInitExpr;
378605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
378705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  public:
3788ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor    Designator() {}
3789ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor
379005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// @brief Initializes a field designator.
37911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    Designator(const IdentifierInfo *FieldName, SourceLocation DotLoc,
37921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump               SourceLocation FieldLoc)
379305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      : Kind(FieldDesignator) {
379405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      Field.NameOrField = reinterpret_cast<uintptr_t>(FieldName) | 0x01;
379505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      Field.DotLoc = DotLoc.getRawEncoding();
379605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      Field.FieldLoc = FieldLoc.getRawEncoding();
379705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    }
379805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
379905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// @brief Initializes an array designator.
38001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    Designator(unsigned Index, SourceLocation LBracketLoc,
380105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor               SourceLocation RBracketLoc)
380205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      : Kind(ArrayDesignator) {
380305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      ArrayOrRange.Index = Index;
380405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      ArrayOrRange.LBracketLoc = LBracketLoc.getRawEncoding();
380505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      ArrayOrRange.EllipsisLoc = SourceLocation().getRawEncoding();
380605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      ArrayOrRange.RBracketLoc = RBracketLoc.getRawEncoding();
380705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    }
380805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
380905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    /// @brief Initializes a GNU array-range designator.
38101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    Designator(unsigned Index, SourceLocation LBracketLoc,
381105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor               SourceLocation EllipsisLoc, SourceLocation RBracketLoc)
381205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      : Kind(ArrayRangeDesignator) {
381305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      ArrayOrRange.Index = Index;
381405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      ArrayOrRange.LBracketLoc = LBracketLoc.getRawEncoding();
381505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      ArrayOrRange.EllipsisLoc = EllipsisLoc.getRawEncoding();
381605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      ArrayOrRange.RBracketLoc = RBracketLoc.getRawEncoding();
381705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    }
381805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
381905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    bool isFieldDesignator() const { return Kind == FieldDesignator; }
382005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    bool isArrayDesignator() const { return Kind == ArrayDesignator; }
382105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    bool isArrayRangeDesignator() const { return Kind == ArrayRangeDesignator; }
382205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
3823b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth    IdentifierInfo *getFieldName() const;
382405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
3825b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth    FieldDecl *getField() const {
382605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      assert(Kind == FieldDesignator && "Only valid on a field designator");
382705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      if (Field.NameOrField & 0x01)
382805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor        return 0;
382905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      else
383005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor        return reinterpret_cast<FieldDecl *>(Field.NameOrField);
383105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    }
383205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
383305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    void setField(FieldDecl *FD) {
383405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      assert(Kind == FieldDesignator && "Only valid on a field designator");
383505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      Field.NameOrField = reinterpret_cast<uintptr_t>(FD);
383605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    }
383705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
383887f55cf59e82f246d8605733e9300d0c5f6830a6Douglas Gregor    SourceLocation getDotLoc() const {
383987f55cf59e82f246d8605733e9300d0c5f6830a6Douglas Gregor      assert(Kind == FieldDesignator && "Only valid on a field designator");
384087f55cf59e82f246d8605733e9300d0c5f6830a6Douglas Gregor      return SourceLocation::getFromRawEncoding(Field.DotLoc);
384187f55cf59e82f246d8605733e9300d0c5f6830a6Douglas Gregor    }
384287f55cf59e82f246d8605733e9300d0c5f6830a6Douglas Gregor
384305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    SourceLocation getFieldLoc() const {
384405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      assert(Kind == FieldDesignator && "Only valid on a field designator");
384505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      return SourceLocation::getFromRawEncoding(Field.FieldLoc);
384605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    }
384705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
384805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    SourceLocation getLBracketLoc() const {
384905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      assert((Kind == ArrayDesignator || Kind == ArrayRangeDesignator) &&
385005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor             "Only valid on an array or array-range designator");
385105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      return SourceLocation::getFromRawEncoding(ArrayOrRange.LBracketLoc);
385205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    }
385305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
385405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    SourceLocation getRBracketLoc() const {
385505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      assert((Kind == ArrayDesignator || Kind == ArrayRangeDesignator) &&
385605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor             "Only valid on an array or array-range designator");
385705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      return SourceLocation::getFromRawEncoding(ArrayOrRange.RBracketLoc);
385805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    }
385905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
386005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    SourceLocation getEllipsisLoc() const {
386105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      assert(Kind == ArrayRangeDesignator &&
386205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor             "Only valid on an array-range designator");
386305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      return SourceLocation::getFromRawEncoding(ArrayOrRange.EllipsisLoc);
386405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    }
38654c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor
3866d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor    unsigned getFirstExprIndex() const {
3867d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor      assert((Kind == ArrayDesignator || Kind == ArrayRangeDesignator) &&
3868d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor             "Only valid on an array or array-range designator");
3869d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor      return ArrayOrRange.Index;
3870d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor    }
3871d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor
38724c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor    SourceLocation getStartLocation() const {
38734c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor      if (Kind == FieldDesignator)
38744c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor        return getDotLoc().isInvalid()? getFieldLoc() : getDotLoc();
38754c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor      else
38764c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor        return getLBracketLoc();
38774c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor    }
387824f4674e697fb53587f0e8485e9c6592f7021ef2Abramo Bagnara    SourceLocation getEndLocation() const {
387924f4674e697fb53587f0e8485e9c6592f7021ef2Abramo Bagnara      return Kind == FieldDesignator ? getFieldLoc() : getRBracketLoc();
388024f4674e697fb53587f0e8485e9c6592f7021ef2Abramo Bagnara    }
3881aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar    SourceRange getSourceRange() const LLVM_READONLY {
388224f4674e697fb53587f0e8485e9c6592f7021ef2Abramo Bagnara      return SourceRange(getStartLocation(), getEndLocation());
388324f4674e697fb53587f0e8485e9c6592f7021ef2Abramo Bagnara    }
388405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  };
388505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
38861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static DesignatedInitExpr *Create(ASTContext &C, Designator *Designators,
388705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor                                    unsigned NumDesignators,
388805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor                                    Expr **IndexExprs, unsigned NumIndexExprs,
388905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor                                    SourceLocation EqualOrColonLoc,
3890eeae8f072748affce25ab4064982626361293390Douglas Gregor                                    bool GNUSyntax, Expr *Init);
389105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
3892d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  static DesignatedInitExpr *CreateEmpty(ASTContext &C, unsigned NumIndexExprs);
3893d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor
389405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// @brief Returns the number of designators in this initializer.
389505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  unsigned size() const { return NumDesignators; }
389605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
389705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  // Iterator access to the designators.
3898b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth  typedef Designator *designators_iterator;
3899ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor  designators_iterator designators_begin() { return Designators; }
39001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  designators_iterator designators_end() {
39011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return Designators + NumDesignators;
3902ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor  }
390305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
3904b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth  typedef const Designator *const_designators_iterator;
3905b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth  const_designators_iterator designators_begin() const { return Designators; }
3906b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth  const_designators_iterator designators_end() const {
3907b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth    return Designators + NumDesignators;
3908b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth  }
3909b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth
3910cdba6595a61a7bd31f504260abf63c900a759d0fTed Kremenek  typedef std::reverse_iterator<designators_iterator>
3911cdba6595a61a7bd31f504260abf63c900a759d0fTed Kremenek          reverse_designators_iterator;
3912cdba6595a61a7bd31f504260abf63c900a759d0fTed Kremenek  reverse_designators_iterator designators_rbegin() {
3913cdba6595a61a7bd31f504260abf63c900a759d0fTed Kremenek    return reverse_designators_iterator(designators_end());
3914cdba6595a61a7bd31f504260abf63c900a759d0fTed Kremenek  }
3915cdba6595a61a7bd31f504260abf63c900a759d0fTed Kremenek  reverse_designators_iterator designators_rend() {
3916cdba6595a61a7bd31f504260abf63c900a759d0fTed Kremenek    return reverse_designators_iterator(designators_begin());
3917cdba6595a61a7bd31f504260abf63c900a759d0fTed Kremenek  }
3918cdba6595a61a7bd31f504260abf63c900a759d0fTed Kremenek
3919b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth  typedef std::reverse_iterator<const_designators_iterator>
3920b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth          const_reverse_designators_iterator;
3921b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth  const_reverse_designators_iterator designators_rbegin() const {
3922b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth    return const_reverse_designators_iterator(designators_end());
3923b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth  }
3924b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth  const_reverse_designators_iterator designators_rend() const {
3925b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth    return const_reverse_designators_iterator(designators_begin());
3926b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth  }
3927b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth
3928711997184366d584c9c437102cae1e9d9927b986Douglas Gregor  Designator *getDesignator(unsigned Idx) { return &designators_begin()[Idx]; }
3929711997184366d584c9c437102cae1e9d9927b986Douglas Gregor
3930ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  void setDesignators(ASTContext &C, const Designator *Desigs,
3931319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregor                      unsigned NumDesigs);
3932d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor
393305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  Expr *getArrayIndex(const Designator& D);
393405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  Expr *getArrayRangeStart(const Designator& D);
393505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  Expr *getArrayRangeEnd(const Designator& D);
393605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
393705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// @brief Retrieve the location of the '=' that precedes the
393805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// initializer value itself, if present.
393905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  SourceLocation getEqualOrColonLoc() const { return EqualOrColonLoc; }
3940d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  void setEqualOrColonLoc(SourceLocation L) { EqualOrColonLoc = L; }
394105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
394205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// @brief Determines whether this designated initializer used the
3943eeae8f072748affce25ab4064982626361293390Douglas Gregor  /// deprecated GNU syntax for designated initializers.
3944eeae8f072748affce25ab4064982626361293390Douglas Gregor  bool usesGNUSyntax() const { return GNUSyntax; }
3945d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  void setGNUSyntax(bool GNU) { GNUSyntax = GNU; }
394605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
394705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// @brief Retrieve the initializer value.
39481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  Expr *getInit() const {
394905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    return cast<Expr>(*const_cast<DesignatedInitExpr*>(this)->child_begin());
395005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  }
395105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
395205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  void setInit(Expr *init) {
395305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    *child_begin() = init;
395405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  }
395505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
3956d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  /// \brief Retrieve the total number of subexpressions in this
3957d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  /// designated initializer expression, including the actual
3958d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  /// initialized value and any expressions that occur within array
3959d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  /// and array-range designators.
3960d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  unsigned getNumSubExprs() const { return NumSubExprs; }
3961d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor
3962d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  Expr *getSubExpr(unsigned Idx) {
3963d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor    assert(Idx < NumSubExprs && "Subscript out of range");
3964d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor    char* Ptr = static_cast<char*>(static_cast<void *>(this));
3965d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor    Ptr += sizeof(DesignatedInitExpr);
3966d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor    return reinterpret_cast<Expr**>(reinterpret_cast<void**>(Ptr))[Idx];
3967d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  }
3968d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor
3969d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  void setSubExpr(unsigned Idx, Expr *E) {
3970d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor    assert(Idx < NumSubExprs && "Subscript out of range");
3971d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor    char* Ptr = static_cast<char*>(static_cast<void *>(this));
3972d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor    Ptr += sizeof(DesignatedInitExpr);
3973d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor    reinterpret_cast<Expr**>(reinterpret_cast<void**>(Ptr))[Idx] = E;
3974d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  }
3975d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor
3976ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor  /// \brief Replaces the designator at index @p Idx with the series
3977ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor  /// of designators in [First, Last).
3978319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregor  void ExpandDesignator(ASTContext &C, unsigned Idx, const Designator *First,
3979ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor                        const Designator *Last);
3980ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor
398124f4674e697fb53587f0e8485e9c6592f7021ef2Abramo Bagnara  SourceRange getDesignatorsSourceRange() const;
398224f4674e697fb53587f0e8485e9c6592f7021ef2Abramo Bagnara
3983aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY;
398405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
398505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  static bool classof(const Stmt *T) {
39861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == DesignatedInitExprClass;
398705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  }
398805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  static bool classof(const DesignatedInitExpr *) { return true; }
398905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
399005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  // Iterators
399163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() {
399263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    Stmt **begin = reinterpret_cast<Stmt**>(this + 1);
399363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return child_range(begin, begin + NumSubExprs);
399463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
39953498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor};
39963498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor
39973498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor/// \brief Represents an implicitly-generated value initialization of
39983498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor/// an object of a given type.
39993498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor///
40001a51b4a11b7db25cac2134249711ecaaf9d1c0a8Douglas Gregor/// Implicit value initializations occur within semantic initializer
40011a51b4a11b7db25cac2134249711ecaaf9d1c0a8Douglas Gregor/// list expressions (InitListExpr) as placeholders for subobject
40023498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor/// initializations not explicitly specified by the user.
40031a51b4a11b7db25cac2134249711ecaaf9d1c0a8Douglas Gregor///
40041a51b4a11b7db25cac2134249711ecaaf9d1c0a8Douglas Gregor/// \see InitListExpr
40051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpclass ImplicitValueInitExpr : public Expr {
40063498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregorpublic:
40071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  explicit ImplicitValueInitExpr(QualType ty)
4008f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    : Expr(ImplicitValueInitExprClass, ty, VK_RValue, OK_Ordinary,
4009561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor           false, false, ty->isInstantiationDependentType(), false) { }
40103498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor
4011d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  /// \brief Construct an empty implicit value initialization.
4012d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  explicit ImplicitValueInitExpr(EmptyShell Empty)
4013d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor    : Expr(ImplicitValueInitExprClass, Empty) { }
4014d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor
40151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
40163498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor    return T->getStmtClass() == ImplicitValueInitExprClass;
40173498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor  }
40183498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor  static bool classof(const ImplicitValueInitExpr *) { return true; }
40193498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor
4020aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY {
40213498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor    return SourceRange();
40223498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor  }
40233498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor
40243498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor  // Iterators
402563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(); }
402605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor};
402705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
40282ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman
40292ef13e5abef0570a9f567b4671367275c05d4d34Nate Begemanclass ParenListExpr : public Expr {
40302ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman  Stmt **Exprs;
40312ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman  unsigned NumExprs;
40322ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman  SourceLocation LParenLoc, RParenLoc;
40332ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman
40342ef13e5abef0570a9f567b4671367275c05d4d34Nate Begemanpublic:
40351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ParenListExpr(ASTContext& C, SourceLocation lparenloc, Expr **exprs,
40365b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl                unsigned numexprs, SourceLocation rparenloc);
40372ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman
40382ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman  /// \brief Build an empty paren list.
403937bdfe284ad365f753741d1d89c078c148b3f4afArgyrios Kyrtzidis  explicit ParenListExpr(EmptyShell Empty) : Expr(ParenListExprClass, Empty) { }
40401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
40412ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman  unsigned getNumExprs() const { return NumExprs; }
40421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
40431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  const Expr* getExpr(unsigned Init) const {
40442ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman    assert(Init < getNumExprs() && "Initializer access out of range!");
40452ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman    return cast_or_null<Expr>(Exprs[Init]);
40462ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman  }
40471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
40481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  Expr* getExpr(unsigned Init) {
40492ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman    assert(Init < getNumExprs() && "Initializer access out of range!");
40502ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman    return cast_or_null<Expr>(Exprs[Init]);
40512ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman  }
40522ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman
405383ddad3ab513f5d73698cf9fbeb4ed3f011bc3b9Douglas Gregor  Expr **getExprs() { return reinterpret_cast<Expr **>(Exprs); }
40541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
40552ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman  SourceLocation getLParenLoc() const { return LParenLoc; }
40562ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman  SourceLocation getRParenLoc() const { return RParenLoc; }
40572ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman
4058aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY {
40592ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman    return SourceRange(LParenLoc, RParenLoc);
40601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  }
40612ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman  static bool classof(const Stmt *T) {
40621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == ParenListExprClass;
40632ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman  }
40642ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman  static bool classof(const ParenListExpr *) { return true; }
40651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
40662ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman  // Iterators
406763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() {
406863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall    return child_range(&Exprs[0], &Exprs[0]+NumExprs);
406963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  }
407037bdfe284ad365f753741d1d89c078c148b3f4afArgyrios Kyrtzidis
407160adf4acf40b72227740bf966fb87eebddff3f37Sebastian Redl  friend class ASTStmtReader;
40723397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl  friend class ASTStmtWriter;
40732ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman};
40742ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman
40751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4076ffbe9b9c64ab2e94b9d48ec56e511f75826fc80aBenjamin Kramer/// \brief Represents a C11 generic selection.
4077f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne///
4078ffbe9b9c64ab2e94b9d48ec56e511f75826fc80aBenjamin Kramer/// A generic selection (C11 6.5.1.1) contains an unevaluated controlling
4079f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// expression, followed by one or more generic associations.  Each generic
4080f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// association specifies a type name and an expression, or "default" and an
4081f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// expression (in which case it is known as a default generic association).
4082f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// The type and value of the generic selection are identical to those of its
4083f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// result expression, which is defined as the expression in the generic
4084f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// association with a type name that is compatible with the type of the
4085f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// controlling expression, or the expression in the default generic association
4086f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// if no types are compatible.  For example:
4087f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne///
4088f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// @code
4089f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// _Generic(X, double: 1, float: 2, default: 3)
4090f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// @endcode
4091f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne///
4092f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// The above expression evaluates to 1 if 1.0 is substituted for X, 2 if 1.0f
4093f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// or 3 if "hello".
4094f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne///
4095f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// As an extension, generic selections are allowed in C++, where the following
4096f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// additional semantics apply:
4097f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne///
4098f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// Any generic selection whose controlling expression is type-dependent or
4099f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// which names a dependent type in its association list is result-dependent,
4100f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// which means that the choice of result expression is dependent.
4101f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// Result-dependent generic associations are both type- and value-dependent.
4102f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourneclass GenericSelectionExpr : public Expr {
4103f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne  enum { CONTROLLING, END_EXPR };
4104f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne  TypeSourceInfo **AssocTypes;
4105f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne  Stmt **SubExprs;
4106f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne  unsigned NumAssocs, ResultIndex;
4107f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne  SourceLocation GenericLoc, DefaultLoc, RParenLoc;
4108f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne
4109f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbournepublic:
4110f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne  GenericSelectionExpr(ASTContext &Context,
4111f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne                       SourceLocation GenericLoc, Expr *ControllingExpr,
4112f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne                       TypeSourceInfo **AssocTypes, Expr **AssocExprs,
4113f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne                       unsigned NumAssocs, SourceLocation DefaultLoc,
4114f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne                       SourceLocation RParenLoc,
4115f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne                       bool ContainsUnexpandedParameterPack,
4116f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne                       unsigned ResultIndex);
4117f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne
4118f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne  /// This constructor is used in the result-dependent case.
4119f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne  GenericSelectionExpr(ASTContext &Context,
4120f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne                       SourceLocation GenericLoc, Expr *ControllingExpr,
4121f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne                       TypeSourceInfo **AssocTypes, Expr **AssocExprs,
4122f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne                       unsigned NumAssocs, SourceLocation DefaultLoc,
4123f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne                       SourceLocation RParenLoc,
4124f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne                       bool ContainsUnexpandedParameterPack);
4125f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne
4126f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne  explicit GenericSelectionExpr(EmptyShell Empty)
4127f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne    : Expr(GenericSelectionExprClass, Empty) { }
4128f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne
4129f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne  unsigned getNumAssocs() const { return NumAssocs; }
4130f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne
4131f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne  SourceLocation getGenericLoc() const { return GenericLoc; }
4132f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne  SourceLocation getDefaultLoc() const { return DefaultLoc; }
4133f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne  SourceLocation getRParenLoc() const { return RParenLoc; }
4134f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne
4135f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne  const Expr *getAssocExpr(unsigned i) const {
4136f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne    return cast<Expr>(SubExprs[END_EXPR+i]);
4137f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne  }
4138f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne  Expr *getAssocExpr(unsigned i) { return cast<Expr>(SubExprs[END_EXPR+i]); }
4139f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne
4140f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne  const TypeSourceInfo *getAssocTypeSourceInfo(unsigned i) const {
4141f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne    return AssocTypes[i];
4142f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne  }
4143f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne  TypeSourceInfo *getAssocTypeSourceInfo(unsigned i) { return AssocTypes[i]; }
4144f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne
4145f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne  QualType getAssocType(unsigned i) const {
4146f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne    if (const TypeSourceInfo *TS = getAssocTypeSourceInfo(i))
4147f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne      return TS->getType();
4148f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne    else
4149f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne      return QualType();
4150f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne  }
4151f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne
4152f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne  const Expr *getControllingExpr() const {
4153f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne    return cast<Expr>(SubExprs[CONTROLLING]);
4154f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne  }
4155f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne  Expr *getControllingExpr() { return cast<Expr>(SubExprs[CONTROLLING]); }
4156f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne
4157f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne  /// Whether this generic selection is result-dependent.
4158f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne  bool isResultDependent() const { return ResultIndex == -1U; }
4159f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne
4160f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne  /// The zero-based index of the result expression's generic association in
4161f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne  /// the generic selection's association list.  Defined only if the
4162f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne  /// generic selection is not result-dependent.
4163f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne  unsigned getResultIndex() const {
4164f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne    assert(!isResultDependent() && "Generic selection is result-dependent");
4165f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne    return ResultIndex;
4166f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne  }
4167f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne
4168f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne  /// The generic selection's result expression.  Defined only if the
4169f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne  /// generic selection is not result-dependent.
4170f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne  const Expr *getResultExpr() const { return getAssocExpr(getResultIndex()); }
4171f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne  Expr *getResultExpr() { return getAssocExpr(getResultIndex()); }
4172f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne
4173aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY {
4174f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne    return SourceRange(GenericLoc, RParenLoc);
4175f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne  }
4176f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne  static bool classof(const Stmt *T) {
4177f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne    return T->getStmtClass() == GenericSelectionExprClass;
4178f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne  }
4179f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne  static bool classof(const GenericSelectionExpr *) { return true; }
4180f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne
4181f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne  child_range children() {
4182f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne    return child_range(SubExprs, SubExprs+END_EXPR+NumAssocs);
4183f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne  }
4184f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne
4185f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne  friend class ASTStmtReader;
4186f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne};
4187f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne
41884eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff//===----------------------------------------------------------------------===//
41894eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff// Clang Extensions
41904eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff//===----------------------------------------------------------------------===//
41914eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff
4192a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner
4193a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner/// ExtVectorElementExpr - This represents access to specific elements of a
4194a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner/// vector, and may occur on the left hand side or right hand side.  For example
4195a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner/// the following is legal:  "V.xy = V.zw" if V is a 4 element extended vector.
4196a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner///
419773525de7fd9bdd534382dc89a24f1f76db3e04b9Chris Lattner/// Note that the base may have either vector or pointer to vector type, just
419873525de7fd9bdd534382dc89a24f1f76db3e04b9Chris Lattner/// like a struct field reference.
419973525de7fd9bdd534382dc89a24f1f76db3e04b9Chris Lattner///
4200a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattnerclass ExtVectorElementExpr : public Expr {
4201a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  Stmt *Base;
4202d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor  IdentifierInfo *Accessor;
4203a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  SourceLocation AccessorLoc;
4204a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattnerpublic:
4205f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall  ExtVectorElementExpr(QualType ty, ExprValueKind VK, Expr *base,
4206f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                       IdentifierInfo &accessor, SourceLocation loc)
42070943168ac126b8047f30f6bd215fbe7db14d61baJohn McCall    : Expr(ExtVectorElementExprClass, ty, VK,
42080943168ac126b8047f30f6bd215fbe7db14d61baJohn McCall           (VK == VK_RValue ? OK_Ordinary : OK_VectorComponent),
4209bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           base->isTypeDependent(), base->isValueDependent(),
4210561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor           base->isInstantiationDependent(),
4211bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           base->containsUnexpandedParameterPack()),
4212d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor      Base(base), Accessor(&accessor), AccessorLoc(loc) {}
42131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4214d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor  /// \brief Build an empty vector element expression.
4215d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor  explicit ExtVectorElementExpr(EmptyShell Empty)
4216d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor    : Expr(ExtVectorElementExprClass, Empty) { }
4217d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor
4218a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  const Expr *getBase() const { return cast<Expr>(Base); }
4219a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  Expr *getBase() { return cast<Expr>(Base); }
4220d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor  void setBase(Expr *E) { Base = E; }
4221d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor
4222d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor  IdentifierInfo &getAccessor() const { return *Accessor; }
4223d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor  void setAccessor(IdentifierInfo *II) { Accessor = II; }
4224d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor
4225d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor  SourceLocation getAccessorLoc() const { return AccessorLoc; }
4226d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor  void setAccessorLoc(SourceLocation L) { AccessorLoc = L; }
4227d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor
4228a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  /// getNumElements - Get the number of components being selected.
4229a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  unsigned getNumElements() const;
42301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4231a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  /// containsDuplicateElements - Return true if any element access is
4232a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  /// repeated.
4233a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  bool containsDuplicateElements() const;
42341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4235a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  /// getEncodedElementAccess - Encode the elements accessed into an llvm
4236a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  /// aggregate Constant of ConstantInt(s).
4237686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  void getEncodedElementAccess(SmallVectorImpl<unsigned> &Elts) const;
42381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4239aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY {
4240a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner    return SourceRange(getBase()->getLocStart(), AccessorLoc);
4241a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  }
42421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
42432140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner  /// isArrow - Return true if the base expression is a pointer to vector,
42442140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner  /// return false if the base expression is a vector.
42452140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner  bool isArrow() const;
42461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
42471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
42481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == ExtVectorElementExprClass;
4249a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  }
4250a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  static bool classof(const ExtVectorElementExpr *) { return true; }
42511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4252a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  // Iterators
425363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(&Base, &Base+1); }
4254a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner};
4255a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner
4256a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner
425756ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff/// BlockExpr - Adaptor class for mixing a BlockDecl with expressions.
42589c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff/// ^{ statement-body }   or   ^(int arg1, float arg2){ statement-body }
42594eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroffclass BlockExpr : public Expr {
426056ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroffprotected:
426156ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff  BlockDecl *TheBlock;
42624eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroffpublic:
4263469a1eb996e1cb0be54f9b210f836afbddcbb2ccJohn McCall  BlockExpr(BlockDecl *BD, QualType ty)
4264f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    : Expr(BlockExprClass, ty, VK_RValue, OK_Ordinary,
4265ec79d877c1998366480d97a7a6c94e15c053edd8Douglas Gregor           ty->isDependentType(), ty->isDependentType(),
4266ec79d877c1998366480d97a7a6c94e15c053edd8Douglas Gregor           ty->isInstantiationDependentType() || BD->isDependentContext(),
4267561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor           false),
4268469a1eb996e1cb0be54f9b210f836afbddcbb2ccJohn McCall      TheBlock(BD) {}
42699c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff
427084af7c27cdc615ff917a501d61256b4049383c97Douglas Gregor  /// \brief Build an empty block expression.
427184af7c27cdc615ff917a501d61256b4049383c97Douglas Gregor  explicit BlockExpr(EmptyShell Empty) : Expr(BlockExprClass, Empty) { }
427284af7c27cdc615ff917a501d61256b4049383c97Douglas Gregor
4273d5cab5435371b8cc74a9e05ebd40b5995ebad149Anders Carlsson  const BlockDecl *getBlockDecl() const { return TheBlock; }
427456ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff  BlockDecl *getBlockDecl() { return TheBlock; }
427584af7c27cdc615ff917a501d61256b4049383c97Douglas Gregor  void setBlockDecl(BlockDecl *BD) { TheBlock = BD; }
427684af7c27cdc615ff917a501d61256b4049383c97Douglas Gregor
427756ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff  // Convenience functions for probing the underlying BlockDecl.
427856ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff  SourceLocation getCaretLocation() const;
427956ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff  const Stmt *getBody() const;
428056ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff  Stmt *getBody();
42819c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff
4282aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY {
428356ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff    return SourceRange(getCaretLocation(), getBody()->getLocEnd());
42849c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff  }
42859c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff
428656ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff  /// getFunctionType - Return the underlying function type for this block.
4287a345edb668380691fc92d4e4aa0a5ffec366ca6aJohn McCall  const FunctionProtoType *getFunctionType() const;
428856ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff
42891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
42909c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff    return T->getStmtClass() == BlockExprClass;
42914eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  }
42924eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  static bool classof(const BlockExpr *) { return true; }
42931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
42944eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  // Iterators
429563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall  child_range children() { return child_range(); }
42964eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff};
42971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
429861eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner/// AsTypeExpr - Clang builtin function __builtin_astype [OpenCL 6.2.4.2]
429961eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner/// This AST node provides support for reinterpreting a type to another
430061eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner/// type of the same size.
4301379010addb0e84fd0fbc37c829baf658958521bdJohn McCallclass AsTypeExpr : public Expr { // Should this be an ExplicitCastExpr?
430261eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattnerprivate:
4303379010addb0e84fd0fbc37c829baf658958521bdJohn McCall  Stmt *SrcExpr;
430461eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner  SourceLocation BuiltinLoc, RParenLoc;
4305379010addb0e84fd0fbc37c829baf658958521bdJohn McCall
4306379010addb0e84fd0fbc37c829baf658958521bdJohn McCall  friend class ASTReader;
4307379010addb0e84fd0fbc37c829baf658958521bdJohn McCall  friend class ASTStmtReader;
4308379010addb0e84fd0fbc37c829baf658958521bdJohn McCall  explicit AsTypeExpr(EmptyShell Empty) : Expr(AsTypeExprClass, Empty) {}
4309ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
431061eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattnerpublic:
431161eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner  AsTypeExpr(Expr* SrcExpr, QualType DstType,
431261eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner             ExprValueKind VK, ExprObjectKind OK,
431361eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner             SourceLocation BuiltinLoc, SourceLocation RParenLoc)
4314ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    : Expr(AsTypeExprClass, DstType, VK, OK,
4315561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor           DstType->isDependentType(),
4316561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor           DstType->isDependentType() || SrcExpr->isValueDependent(),
4317561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor           (DstType->isInstantiationDependentType() ||
4318561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor            SrcExpr->isInstantiationDependent()),
4319561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor           (DstType->containsUnexpandedParameterPack() ||
4320561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor            SrcExpr->containsUnexpandedParameterPack())),
4321379010addb0e84fd0fbc37c829baf658958521bdJohn McCall  SrcExpr(SrcExpr), BuiltinLoc(BuiltinLoc), RParenLoc(RParenLoc) {}
4322ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
432361eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner  /// getSrcExpr - Return the Expr to be converted.
4324379010addb0e84fd0fbc37c829baf658958521bdJohn McCall  Expr *getSrcExpr() const { return cast<Expr>(SrcExpr); }
4325379010addb0e84fd0fbc37c829baf658958521bdJohn McCall
4326379010addb0e84fd0fbc37c829baf658958521bdJohn McCall  /// getBuiltinLoc - Return the location of the __builtin_astype token.
4327379010addb0e84fd0fbc37c829baf658958521bdJohn McCall  SourceLocation getBuiltinLoc() const { return BuiltinLoc; }
4328379010addb0e84fd0fbc37c829baf658958521bdJohn McCall
4329379010addb0e84fd0fbc37c829baf658958521bdJohn McCall  /// getRParenLoc - Return the location of final right parenthesis.
4330379010addb0e84fd0fbc37c829baf658958521bdJohn McCall  SourceLocation getRParenLoc() const { return RParenLoc; }
4331ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
4332aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY {
433361eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner    return SourceRange(BuiltinLoc, RParenLoc);
433461eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner  }
4335ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
433661eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner  static bool classof(const Stmt *T) {
4337ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    return T->getStmtClass() == AsTypeExprClass;
433861eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner  }
433961eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner  static bool classof(const AsTypeExpr *) { return true; }
4340ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
434161eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner  // Iterators
4342379010addb0e84fd0fbc37c829baf658958521bdJohn McCall  child_range children() { return child_range(&SrcExpr, &SrcExpr+1); }
434361eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner};
4344276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman
43454b9c2d235fb9449e249d74f48ecfec601650de93John McCall/// PseudoObjectExpr - An expression which accesses a pseudo-object
43464b9c2d235fb9449e249d74f48ecfec601650de93John McCall/// l-value.  A pseudo-object is an abstract object, accesses to which
43474b9c2d235fb9449e249d74f48ecfec601650de93John McCall/// are translated to calls.  The pseudo-object expression has a
43484b9c2d235fb9449e249d74f48ecfec601650de93John McCall/// syntactic form, which shows how the expression was actually
43494b9c2d235fb9449e249d74f48ecfec601650de93John McCall/// written in the source code, and a semantic form, which is a series
43504b9c2d235fb9449e249d74f48ecfec601650de93John McCall/// of expressions to be executed in order which detail how the
43514b9c2d235fb9449e249d74f48ecfec601650de93John McCall/// operation is actually evaluated.  Optionally, one of the semantic
43524b9c2d235fb9449e249d74f48ecfec601650de93John McCall/// forms may also provide a result value for the expression.
43534b9c2d235fb9449e249d74f48ecfec601650de93John McCall///
43544b9c2d235fb9449e249d74f48ecfec601650de93John McCall/// If any of the semantic-form expressions is an OpaqueValueExpr,
43554b9c2d235fb9449e249d74f48ecfec601650de93John McCall/// that OVE is required to have a source expression, and it is bound
43564b9c2d235fb9449e249d74f48ecfec601650de93John McCall/// to the result of that source expression.  Such OVEs may appear
43574b9c2d235fb9449e249d74f48ecfec601650de93John McCall/// only in subsequent semantic-form expressions and as
43584b9c2d235fb9449e249d74f48ecfec601650de93John McCall/// sub-expressions of the syntactic form.
43594b9c2d235fb9449e249d74f48ecfec601650de93John McCall///
43604b9c2d235fb9449e249d74f48ecfec601650de93John McCall/// PseudoObjectExpr should be used only when an operation can be
43614b9c2d235fb9449e249d74f48ecfec601650de93John McCall/// usefully described in terms of fairly simple rewrite rules on
43624b9c2d235fb9449e249d74f48ecfec601650de93John McCall/// objects and functions that are meant to be used by end-developers.
43634b9c2d235fb9449e249d74f48ecfec601650de93John McCall/// For example, under the Itanium ABI, dynamic casts are implemented
43644b9c2d235fb9449e249d74f48ecfec601650de93John McCall/// as a call to a runtime function called __dynamic_cast; using this
43654b9c2d235fb9449e249d74f48ecfec601650de93John McCall/// class to describe that would be inappropriate because that call is
43664b9c2d235fb9449e249d74f48ecfec601650de93John McCall/// not really part of the user-visible semantics, and instead the
43674b9c2d235fb9449e249d74f48ecfec601650de93John McCall/// cast is properly reflected in the AST and IR-generation has been
43684b9c2d235fb9449e249d74f48ecfec601650de93John McCall/// taught to generate the call as necessary.  In contrast, an
43694b9c2d235fb9449e249d74f48ecfec601650de93John McCall/// Objective-C property access is semantically defined to be
43704b9c2d235fb9449e249d74f48ecfec601650de93John McCall/// equivalent to a particular message send, and this is very much
43714b9c2d235fb9449e249d74f48ecfec601650de93John McCall/// part of the user model.  The name of this class encourages this
43724b9c2d235fb9449e249d74f48ecfec601650de93John McCall/// modelling design.
43734b9c2d235fb9449e249d74f48ecfec601650de93John McCallclass PseudoObjectExpr : public Expr {
43744b9c2d235fb9449e249d74f48ecfec601650de93John McCall  // PseudoObjectExprBits.NumSubExprs - The number of sub-expressions.
43754b9c2d235fb9449e249d74f48ecfec601650de93John McCall  // Always at least two, because the first sub-expression is the
43764b9c2d235fb9449e249d74f48ecfec601650de93John McCall  // syntactic form.
43774b9c2d235fb9449e249d74f48ecfec601650de93John McCall
43784b9c2d235fb9449e249d74f48ecfec601650de93John McCall  // PseudoObjectExprBits.ResultIndex - The index of the
43794b9c2d235fb9449e249d74f48ecfec601650de93John McCall  // sub-expression holding the result.  0 means the result is void,
43804b9c2d235fb9449e249d74f48ecfec601650de93John McCall  // which is unambiguous because it's the index of the syntactic
43814b9c2d235fb9449e249d74f48ecfec601650de93John McCall  // form.  Note that this is therefore 1 higher than the value passed
43824b9c2d235fb9449e249d74f48ecfec601650de93John McCall  // in to Create, which is an index within the semantic forms.
43834b9c2d235fb9449e249d74f48ecfec601650de93John McCall  // Note also that ASTStmtWriter assumes this encoding.
43844b9c2d235fb9449e249d74f48ecfec601650de93John McCall
43854b9c2d235fb9449e249d74f48ecfec601650de93John McCall  Expr **getSubExprsBuffer() { return reinterpret_cast<Expr**>(this + 1); }
43864b9c2d235fb9449e249d74f48ecfec601650de93John McCall  const Expr * const *getSubExprsBuffer() const {
43874b9c2d235fb9449e249d74f48ecfec601650de93John McCall    return reinterpret_cast<const Expr * const *>(this + 1);
43884b9c2d235fb9449e249d74f48ecfec601650de93John McCall  }
43894b9c2d235fb9449e249d74f48ecfec601650de93John McCall
43904b9c2d235fb9449e249d74f48ecfec601650de93John McCall  friend class ASTStmtReader;
43914b9c2d235fb9449e249d74f48ecfec601650de93John McCall
43924b9c2d235fb9449e249d74f48ecfec601650de93John McCall  PseudoObjectExpr(QualType type, ExprValueKind VK,
43934b9c2d235fb9449e249d74f48ecfec601650de93John McCall                   Expr *syntactic, ArrayRef<Expr*> semantic,
43944b9c2d235fb9449e249d74f48ecfec601650de93John McCall                   unsigned resultIndex);
43954b9c2d235fb9449e249d74f48ecfec601650de93John McCall
43964b9c2d235fb9449e249d74f48ecfec601650de93John McCall  PseudoObjectExpr(EmptyShell shell, unsigned numSemanticExprs);
43974b9c2d235fb9449e249d74f48ecfec601650de93John McCall
43984b9c2d235fb9449e249d74f48ecfec601650de93John McCall  unsigned getNumSubExprs() const {
43994b9c2d235fb9449e249d74f48ecfec601650de93John McCall    return PseudoObjectExprBits.NumSubExprs;
44004b9c2d235fb9449e249d74f48ecfec601650de93John McCall  }
44014b9c2d235fb9449e249d74f48ecfec601650de93John McCall
44024b9c2d235fb9449e249d74f48ecfec601650de93John McCallpublic:
44034b9c2d235fb9449e249d74f48ecfec601650de93John McCall  /// NoResult - A value for the result index indicating that there is
44044b9c2d235fb9449e249d74f48ecfec601650de93John McCall  /// no semantic result.
44054b9c2d235fb9449e249d74f48ecfec601650de93John McCall  enum { NoResult = ~0U };
44064b9c2d235fb9449e249d74f48ecfec601650de93John McCall
44074b9c2d235fb9449e249d74f48ecfec601650de93John McCall  static PseudoObjectExpr *Create(ASTContext &Context, Expr *syntactic,
44084b9c2d235fb9449e249d74f48ecfec601650de93John McCall                                  ArrayRef<Expr*> semantic,
44094b9c2d235fb9449e249d74f48ecfec601650de93John McCall                                  unsigned resultIndex);
44104b9c2d235fb9449e249d74f48ecfec601650de93John McCall
44114b9c2d235fb9449e249d74f48ecfec601650de93John McCall  static PseudoObjectExpr *Create(ASTContext &Context, EmptyShell shell,
44124b9c2d235fb9449e249d74f48ecfec601650de93John McCall                                  unsigned numSemanticExprs);
44134b9c2d235fb9449e249d74f48ecfec601650de93John McCall
44144b9c2d235fb9449e249d74f48ecfec601650de93John McCall  /// Return the syntactic form of this expression, i.e. the
44154b9c2d235fb9449e249d74f48ecfec601650de93John McCall  /// expression it actually looks like.  Likely to be expressed in
44164b9c2d235fb9449e249d74f48ecfec601650de93John McCall  /// terms of OpaqueValueExprs bound in the semantic form.
44174b9c2d235fb9449e249d74f48ecfec601650de93John McCall  Expr *getSyntacticForm() { return getSubExprsBuffer()[0]; }
44184b9c2d235fb9449e249d74f48ecfec601650de93John McCall  const Expr *getSyntacticForm() const { return getSubExprsBuffer()[0]; }
44194b9c2d235fb9449e249d74f48ecfec601650de93John McCall
44204b9c2d235fb9449e249d74f48ecfec601650de93John McCall  /// Return the index of the result-bearing expression into the semantics
44214b9c2d235fb9449e249d74f48ecfec601650de93John McCall  /// expressions, or PseudoObjectExpr::NoResult if there is none.
44224b9c2d235fb9449e249d74f48ecfec601650de93John McCall  unsigned getResultExprIndex() const {
44234b9c2d235fb9449e249d74f48ecfec601650de93John McCall    if (PseudoObjectExprBits.ResultIndex == 0) return NoResult;
44244b9c2d235fb9449e249d74f48ecfec601650de93John McCall    return PseudoObjectExprBits.ResultIndex - 1;
44254b9c2d235fb9449e249d74f48ecfec601650de93John McCall  }
44264b9c2d235fb9449e249d74f48ecfec601650de93John McCall
44274b9c2d235fb9449e249d74f48ecfec601650de93John McCall  /// Return the result-bearing expression, or null if there is none.
44284b9c2d235fb9449e249d74f48ecfec601650de93John McCall  Expr *getResultExpr() {
44294b9c2d235fb9449e249d74f48ecfec601650de93John McCall    if (PseudoObjectExprBits.ResultIndex == 0)
44304b9c2d235fb9449e249d74f48ecfec601650de93John McCall      return 0;
44314b9c2d235fb9449e249d74f48ecfec601650de93John McCall    return getSubExprsBuffer()[PseudoObjectExprBits.ResultIndex];
44324b9c2d235fb9449e249d74f48ecfec601650de93John McCall  }
44334b9c2d235fb9449e249d74f48ecfec601650de93John McCall  const Expr *getResultExpr() const {
44344b9c2d235fb9449e249d74f48ecfec601650de93John McCall    return const_cast<PseudoObjectExpr*>(this)->getResultExpr();
44354b9c2d235fb9449e249d74f48ecfec601650de93John McCall  }
44364b9c2d235fb9449e249d74f48ecfec601650de93John McCall
44374b9c2d235fb9449e249d74f48ecfec601650de93John McCall  unsigned getNumSemanticExprs() const { return getNumSubExprs() - 1; }
44384b9c2d235fb9449e249d74f48ecfec601650de93John McCall
44394b9c2d235fb9449e249d74f48ecfec601650de93John McCall  typedef Expr * const *semantics_iterator;
44404b9c2d235fb9449e249d74f48ecfec601650de93John McCall  typedef const Expr * const *const_semantics_iterator;
44414b9c2d235fb9449e249d74f48ecfec601650de93John McCall  semantics_iterator semantics_begin() {
44424b9c2d235fb9449e249d74f48ecfec601650de93John McCall    return getSubExprsBuffer() + 1;
44434b9c2d235fb9449e249d74f48ecfec601650de93John McCall  }
44444b9c2d235fb9449e249d74f48ecfec601650de93John McCall  const_semantics_iterator semantics_begin() const {
44454b9c2d235fb9449e249d74f48ecfec601650de93John McCall    return getSubExprsBuffer() + 1;
44464b9c2d235fb9449e249d74f48ecfec601650de93John McCall  }
44474b9c2d235fb9449e249d74f48ecfec601650de93John McCall  semantics_iterator semantics_end() {
44484b9c2d235fb9449e249d74f48ecfec601650de93John McCall    return getSubExprsBuffer() + getNumSubExprs();
44494b9c2d235fb9449e249d74f48ecfec601650de93John McCall  }
44504b9c2d235fb9449e249d74f48ecfec601650de93John McCall  const_semantics_iterator semantics_end() const {
44514b9c2d235fb9449e249d74f48ecfec601650de93John McCall    return getSubExprsBuffer() + getNumSubExprs();
44524b9c2d235fb9449e249d74f48ecfec601650de93John McCall  }
44534b9c2d235fb9449e249d74f48ecfec601650de93John McCall  Expr *getSemanticExpr(unsigned index) {
44544b9c2d235fb9449e249d74f48ecfec601650de93John McCall    assert(index + 1 < getNumSubExprs());
44554b9c2d235fb9449e249d74f48ecfec601650de93John McCall    return getSubExprsBuffer()[index + 1];
44564b9c2d235fb9449e249d74f48ecfec601650de93John McCall  }
44574b9c2d235fb9449e249d74f48ecfec601650de93John McCall  const Expr *getSemanticExpr(unsigned index) const {
44584b9c2d235fb9449e249d74f48ecfec601650de93John McCall    return const_cast<PseudoObjectExpr*>(this)->getSemanticExpr(index);
44594b9c2d235fb9449e249d74f48ecfec601650de93John McCall  }
44604b9c2d235fb9449e249d74f48ecfec601650de93John McCall
44614f311183be3d923da9fbe8702c453688b4c426a9Daniel Dunbar  SourceLocation getExprLoc() const LLVM_READONLY {
44624b9c2d235fb9449e249d74f48ecfec601650de93John McCall    return getSyntacticForm()->getExprLoc();
44634b9c2d235fb9449e249d74f48ecfec601650de93John McCall  }
4464aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY {
44654b9c2d235fb9449e249d74f48ecfec601650de93John McCall    return getSyntacticForm()->getSourceRange();
44664b9c2d235fb9449e249d74f48ecfec601650de93John McCall  }
44674b9c2d235fb9449e249d74f48ecfec601650de93John McCall
44684b9c2d235fb9449e249d74f48ecfec601650de93John McCall  child_range children() {
44694b9c2d235fb9449e249d74f48ecfec601650de93John McCall    Stmt **cs = reinterpret_cast<Stmt**>(getSubExprsBuffer());
44704b9c2d235fb9449e249d74f48ecfec601650de93John McCall    return child_range(cs, cs + getNumSubExprs());
44714b9c2d235fb9449e249d74f48ecfec601650de93John McCall  }
44724b9c2d235fb9449e249d74f48ecfec601650de93John McCall
44734b9c2d235fb9449e249d74f48ecfec601650de93John McCall  static bool classof(const Stmt *T) {
44744b9c2d235fb9449e249d74f48ecfec601650de93John McCall    return T->getStmtClass() == PseudoObjectExprClass;
44754b9c2d235fb9449e249d74f48ecfec601650de93John McCall  }
44764b9c2d235fb9449e249d74f48ecfec601650de93John McCall  static bool classof(const PseudoObjectExpr *) { return true; }
44774b9c2d235fb9449e249d74f48ecfec601650de93John McCall};
44784b9c2d235fb9449e249d74f48ecfec601650de93John McCall
4479276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman/// AtomicExpr - Variadic atomic builtins: __atomic_exchange, __atomic_fetch_*,
4480276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman/// __atomic_load, __atomic_store, and __atomic_compare_exchange_*, for the
4481ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith/// similarly-named C++11 instructions, and __c11 variants for <stdatomic.h>.
4482ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith/// All of these instructions take one primary pointer and at least one memory
4483ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith/// order.
4484276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedmanclass AtomicExpr : public Expr {
4485276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedmanpublic:
4486ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith  enum AtomicOp {
4487ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith#define BUILTIN(ID, TYPE, ATTRS)
4488ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith#define ATOMIC_BUILTIN(ID, TYPE, ATTRS) AO ## ID,
4489ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith#include "clang/Basic/Builtins.def"
4490ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith    // Avoid trailing comma
4491ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith    BI_First = 0
4492ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith  };
4493ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith
4494276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedmanprivate:
4495ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith  enum { PTR, ORDER, VAL1, ORDER_FAIL, VAL2, WEAK, END_EXPR };
4496276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman  Stmt* SubExprs[END_EXPR];
4497276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman  unsigned NumSubExprs;
4498276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman  SourceLocation BuiltinLoc, RParenLoc;
4499276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman  AtomicOp Op;
4500276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman
4501e1b2abc2ed3f2c98985b06b4ad01c977bd584020Richard Smith  friend class ASTStmtReader;
4502e1b2abc2ed3f2c98985b06b4ad01c977bd584020Richard Smith
4503276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedmanpublic:
4504dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman  AtomicExpr(SourceLocation BLoc, Expr **args, unsigned nexpr, QualType t,
4505dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman             AtomicOp op, SourceLocation RP);
4506276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman
4507e1b2abc2ed3f2c98985b06b4ad01c977bd584020Richard Smith  /// \brief Determine the number of arguments the specified atomic builtin
4508e1b2abc2ed3f2c98985b06b4ad01c977bd584020Richard Smith  /// should have.
4509e1b2abc2ed3f2c98985b06b4ad01c977bd584020Richard Smith  static unsigned getNumSubExprs(AtomicOp Op);
4510e1b2abc2ed3f2c98985b06b4ad01c977bd584020Richard Smith
4511276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman  /// \brief Build an empty AtomicExpr.
4512276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman  explicit AtomicExpr(EmptyShell Empty) : Expr(AtomicExprClass, Empty) { }
4513276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman
4514276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman  Expr *getPtr() const {
4515276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman    return cast<Expr>(SubExprs[PTR]);
4516276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman  }
4517276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman  Expr *getOrder() const {
4518276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman    return cast<Expr>(SubExprs[ORDER]);
4519276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman  }
4520276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman  Expr *getVal1() const {
4521ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith    if (Op == AO__c11_atomic_init)
45227a7ee3033e44b45630981355460ef89efa0bdcc4David Chisnall      return cast<Expr>(SubExprs[ORDER]);
4523ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith    assert(NumSubExprs > VAL1);
4524276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman    return cast<Expr>(SubExprs[VAL1]);
4525276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman  }
4526276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman  Expr *getOrderFail() const {
4527ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith    assert(NumSubExprs > ORDER_FAIL);
4528276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman    return cast<Expr>(SubExprs[ORDER_FAIL]);
4529276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman  }
4530276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman  Expr *getVal2() const {
4531ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith    if (Op == AO__atomic_exchange)
4532ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith      return cast<Expr>(SubExprs[ORDER_FAIL]);
4533ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith    assert(NumSubExprs > VAL2);
4534276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman    return cast<Expr>(SubExprs[VAL2]);
4535276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman  }
4536ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith  Expr *getWeak() const {
4537ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith    assert(NumSubExprs > WEAK);
4538ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith    return cast<Expr>(SubExprs[WEAK]);
4539ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith  }
4540276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman
4541276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman  AtomicOp getOp() const { return Op; }
4542276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman  unsigned getNumSubExprs() { return NumSubExprs; }
4543276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman
4544dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman  Expr **getSubExprs() { return reinterpret_cast<Expr **>(SubExprs); }
4545dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman
4546276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman  bool isVolatile() const {
4547276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman    return getPtr()->getType()->getPointeeType().isVolatileQualified();
4548276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman  }
4549276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman
4550276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman  bool isCmpXChg() const {
4551ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith    return getOp() == AO__c11_atomic_compare_exchange_strong ||
4552ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith           getOp() == AO__c11_atomic_compare_exchange_weak ||
4553ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith           getOp() == AO__atomic_compare_exchange ||
4554ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith           getOp() == AO__atomic_compare_exchange_n;
4555276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman  }
4556276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman
4557276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman  SourceLocation getBuiltinLoc() const { return BuiltinLoc; }
4558276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman  SourceLocation getRParenLoc() const { return RParenLoc; }
4559276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman
4560aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY {
4561276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman    return SourceRange(BuiltinLoc, RParenLoc);
4562276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman  }
4563276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman  static bool classof(const Stmt *T) {
4564276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman    return T->getStmtClass() == AtomicExprClass;
4565276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman  }
4566276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman  static bool classof(const AtomicExpr *) { return true; }
4567276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman
4568276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman  // Iterators
4569276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman  child_range children() {
4570276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman    return child_range(SubExprs, SubExprs+NumSubExprs);
4571276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman  }
4572276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman};
45735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}  // end namespace clang
45745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
45755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#endif
4576