Expr.h revision 60b70388e43d146d968a1cc0705b30cb2d7263fe
11e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)//===--- Expr.h - Classes for representing expressions ----------*- C++ -*-===//
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//                     The LLVM Compiler Infrastructure
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//
51e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// This file is distributed under the University of Illinois Open Source
65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// License. See LICENSE.TXT for details.
75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//
87d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)//===----------------------------------------------------------------------===//
95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//
10868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)//  This file defines the Expr interface and subclasses.
11868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)//
12868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)//===----------------------------------------------------------------------===//
13eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifndef LLVM_CLANG_AST_EXPR_H
15bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch#define LLVM_CLANG_AST_EXPR_H
165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
171e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "clang/AST/APValue.h"
181e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "clang/AST/Decl.h"
191e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "clang/AST/Stmt.h"
20f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "clang/AST/Type.h"
215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "clang/AST/DeclAccessPair.h"
225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "clang/AST/OperationKinds.h"
235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "clang/AST/ASTVector.h"
245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "clang/AST/TemplateBase.h"
255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "clang/Basic/TargetInfo.h"
265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "clang/Basic/TypeTraits.h"
275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "llvm/ADT/APSInt.h"
285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "llvm/ADT/APFloat.h"
295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "llvm/ADT/SmallVector.h"
305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "llvm/ADT/StringRef.h"
312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "llvm/Support/Compiler.h"
322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include <cctype>
335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace clang {
355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  class ASTContext;
365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  class APValue;
375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  class Decl;
385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  class IdentifierInfo;
395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  class ParmVarDecl;
405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  class NamedDecl;
412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  class ValueDecl;
425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  class BlockDecl;
435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  class CXXBaseSpecifier;
445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  class CXXOperatorCallExpr;
455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  class CXXMemberCallExpr;
465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  class ObjCPropertyRefExpr;
475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  class OpaqueValueExpr;
485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// \brief A simple array of base specifiers.
505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)typedef SmallVector<CXXBaseSpecifier*, 4> CXXCastPath;
515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// Expr - This represents one expression.  Note that Expr's are subclasses of
535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// Stmt.  This allows an expression to be transparently used any place a Stmt
545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// is required.
555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)///
565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class Expr : public Stmt {
575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  QualType TR;
585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)protected:
605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Expr(StmtClass SC, QualType T, ExprValueKind VK, ExprObjectKind OK,
615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)       bool TD, bool VD, bool ID, bool ContainsUnexpandedParameterPack)
625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    : Stmt(SC)
635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  {
645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    ExprBits.TypeDependent = TD;
655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    ExprBits.ValueDependent = VD;
665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    ExprBits.InstantiationDependent = ID;
675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    ExprBits.ValueKind = VK;
685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    ExprBits.ObjectKind = OK;
695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    ExprBits.ContainsUnexpandedParameterPack = ContainsUnexpandedParameterPack;
7090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    setType(T);
7190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  }
7290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// \brief Construct an empty expression.
745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  explicit Expr(StmtClass SC, EmptyShell) : Stmt(SC) { }
755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)public:
775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  QualType getType() const { return TR; }
785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void setType(QualType t) {
795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // In C++, the type of an expression is always adjusted so that it
805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // will not have reference type an expression will never have
815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // reference type (C++ [expr]p6). Use
825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // QualType::getNonReferenceType() to retrieve the non-reference
835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // type. Additionally, inspect Expr::isLvalue to determine whether
845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // an expression that is adjusted in this manner should be
855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // considered an lvalue.
865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    assert((t.isNull() || !t->isReferenceType()) &&
875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)           "Expressions can't have reference type");
885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    TR = t;
905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// isValueDependent - Determines whether this expression is
935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// value-dependent (C++ [temp.dep.constexpr]). For example, the
945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// array bound of "Chars" in the following example is
955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// value-dependent.
965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// @code
975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// template<int Size, char (&Chars)[Size]> struct meta_string;
985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// @endcode
995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool isValueDependent() const { return ExprBits.ValueDependent; }
10090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
1015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// \brief Set whether this expression is value-dependent or not.
1025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void setValueDependent(bool VD) {
1035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    ExprBits.ValueDependent = VD;
1045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    if (VD)
1055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      ExprBits.InstantiationDependent = true;
1065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
107bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch
108bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch  /// isTypeDependent - Determines whether this expression is
1095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// type-dependent (C++ [temp.dep.expr]), which means that its type
1105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// could change from one template instantiation to the next. For
1115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// example, the expressions "x" and "x + y" are type-dependent in
1125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// the following code, but "y" is not type-dependent:
113bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch  /// @code
114bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch  /// template<typename T>
115bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch  /// void add(T x, int y) {
1165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ///   x + y;
1175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// }
1185c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  /// @endcode
1195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool isTypeDependent() const { return ExprBits.TypeDependent; }
1205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// \brief Set whether this expression is type-dependent or not.
1225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void setTypeDependent(bool TD) {
1235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    ExprBits.TypeDependent = TD;
1245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    if (TD)
1255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      ExprBits.InstantiationDependent = true;
1265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
1275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// \brief Whether this expression is instantiation-dependent, meaning that
1295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// it depends in some way on a template parameter, even if neither its type
1305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// nor (constant) value can change due to the template instantiation.
1315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ///
1325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// In the following example, the expression \c sizeof(sizeof(T() + T())) is
1335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// instantiation-dependent (since it involves a template parameter \c T), but
1345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// is neither type- nor value-dependent, since the type of the inner
1355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// \c sizeof is known (\c std::size_t) and therefore the size of the outer
1365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// \c sizeof is known.
1375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ///
1385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// \code
1395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// template<typename T>
140a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  /// void f(T x, T y) {
1415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ///   sizeof(sizeof(T() + T());
1425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// }
1435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// \endcode
1445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ///
1455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool isInstantiationDependent() const {
1465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return ExprBits.InstantiationDependent;
1475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
1485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// \brief Set whether this expression is instantiation-dependent or not.
1505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void setInstantiationDependent(bool ID) {
1515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    ExprBits.InstantiationDependent = ID;
1525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
1535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// \brief Whether this expression contains an unexpanded parameter
1555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// pack (for C++0x variadic templates).
1565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ///
1575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// Given the following function template:
1585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ///
1595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// \code
1605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// template<typename F, typename ...Types>
1615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// void forward(const F &f, Types &&...args) {
1625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ///   f(static_cast<Types&&>(args)...);
1635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// }
1645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// \endcode
1655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ///
1665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// The expressions \c args and \c static_cast<Types&&>(args) both
167a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  /// contain parameter packs.
1685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool containsUnexpandedParameterPack() const {
1695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return ExprBits.ContainsUnexpandedParameterPack;
1705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
1715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// \brief Set the bit that describes whether this expression
1735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// contains an unexpanded parameter pack.
1745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void setContainsUnexpandedParameterPack(bool PP = true) {
1755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    ExprBits.ContainsUnexpandedParameterPack = PP;
1765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
1775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// getExprLoc - Return the preferred location for the arrow when diagnosing
1795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// a problem with a generic expression.
1805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  SourceLocation getExprLoc() const LLVM_READONLY;
1815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// isUnusedResultAWarning - Return true if this immediate expression should
1835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// be warned about if the result is unused.  If so, fill in expr, location,
1845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// and ranges with expr to warn on and source locations/ranges appropriate
1855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// for a warning.
1865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool isUnusedResultAWarning(const Expr *&WarnExpr, SourceLocation &Loc,
1875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                              SourceRange &R1, SourceRange &R2,
1885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                              ASTContext &Ctx) const;
1895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// isLValue - True if this expression is an "l-value" according to
1915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// the rules of the current language.  C and C++ give somewhat
1925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// different rules for this concept, but in general, the result of
1935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// an l-value expression identifies a specific object whereas the
1945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// result of an r-value expression is a value detached from any
1955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// specific storage.
1965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ///
1975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// C++0x divides the concept of "r-value" into pure r-values
1985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// ("pr-values") and so-called expiring values ("x-values"), which
1991e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  /// identify specific objects that can be safely cannibalized for
2005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// their resources.  This is an unfortunate abuse of terminology on
2015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// the part of the C++ committee.  In Clang, when we say "r-value",
2025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// we generally mean a pr-value.
2035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool isLValue() const { return getValueKind() == VK_LValue; }
2045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool isRValue() const { return getValueKind() == VK_RValue; }
2055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool isXValue() const { return getValueKind() == VK_XValue; }
2061e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  bool isGLValue() const { return getValueKind() != VK_RValue; }
2075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
208c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  enum LValueClassification {
2095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    LV_Valid,
2105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    LV_NotObjectType,
211a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    LV_IncompleteVoidType,
2125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    LV_DuplicateVectorComponents,
2132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    LV_InvalidExpression,
214f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    LV_InvalidMessageExpression,
2155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    LV_MemberFunction,
2165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    LV_SubObjCPropertySetting,
2175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    LV_ClassTemporary,
2185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    LV_ArrayTemporary
2195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  };
2205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// Reasons why an expression might not be an l-value.
2215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  LValueClassification ClassifyLValue(ASTContext &Ctx) const;
2225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2231e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  /// isModifiableLvalue - C99 6.3.2.1: an lvalue that does not have array type,
2245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// does not have an incomplete type, does not have a const-qualified type,
2255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// and if it is a structure or union, does not have any member (including,
2265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// recursively, any member or element of all contained aggregates or unions)
2275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// with a const-qualified type.
2285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ///
2295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// \param Loc [in,out] - A source location which *may* be filled
2305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// in with the location of the expression making this a
2315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// non-modifiable lvalue, if specified.
2325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  enum isModifiableLvalueResult {
2335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    MLV_Valid,
2345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    MLV_NotObjectType,
2355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    MLV_IncompleteVoidType,
2365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    MLV_DuplicateVectorComponents,
2375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    MLV_InvalidExpression,
2385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    MLV_LValueCast,           // Specialized form of MLV_InvalidExpression.
2395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    MLV_IncompleteType,
2405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    MLV_ConstQualified,
2415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    MLV_ArrayType,
2425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    MLV_ReadonlyProperty,
2435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    MLV_NoSetterProperty,
2445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    MLV_MemberFunction,
2455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    MLV_SubObjCPropertySetting,
2465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    MLV_InvalidMessageExpression,
2475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    MLV_ClassTemporary,
2485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    MLV_ArrayTemporary
2495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  };
2505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  isModifiableLvalueResult isModifiableLvalue(ASTContext &Ctx,
2515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                              SourceLocation *Loc = 0) const;
2525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// \brief The return type of classify(). Represents the C++0x expression
2545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ///        taxonomy.
2555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  class Classification {
2565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  public:
2575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    /// \brief The various classification results. Most of these mean prvalue.
2585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    enum Kinds {
2595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      CL_LValue,
2605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      CL_XValue,
2615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      CL_Function, // Functions cannot be lvalues in C.
2625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      CL_Void, // Void cannot be an lvalue in C.
2635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      CL_AddressableVoid, // Void expression whose address can be taken in C.
2645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      CL_DuplicateVectorComponents, // A vector shuffle with dupes.
2655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      CL_MemberFunction, // An expression referring to a member function
2665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      CL_SubObjCPropertySetting,
2675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      CL_ClassTemporary, // A temporary of class type, or subobject thereof.
2685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      CL_ArrayTemporary, // A temporary of array type.
2695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      CL_ObjCMessageRValue, // ObjC message is an rvalue
2705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      CL_PRValue // A prvalue for any other reason, of any other type
2714e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    };
2724e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    /// \brief The results of modification testing.
2734e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    enum ModifiableType {
2745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      CM_Untested, // testModifiable was false.
2754e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)      CM_Modifiable,
2765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      CM_RValue, // Not modifiable because it's an rvalue
2775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      CM_Function, // Not modifiable because it's a function; C++ only
2784e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)      CM_LValueCast, // Same as CM_RValue, but indicates GCC cast-as-lvalue ext
2795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      CM_NoSetterProperty,// Implicit assignment to ObjC property without setter
2805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      CM_ConstQualified,
2815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      CM_ArrayType,
282868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      CM_IncompleteType
283868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    };
284868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
285868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  private:
286868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    friend class Expr;
287868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
288868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    unsigned short Kind;
289868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    unsigned short Modifiable;
290868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
291868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    explicit Classification(Kinds k, ModifiableType m)
292868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      : Kind(k), Modifiable(m)
293868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    {}
294868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
295868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  public:
296868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    Classification() {}
297868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
298868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    Kinds getKind() const { return static_cast<Kinds>(Kind); }
299868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    ModifiableType getModifiable() const {
300868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      assert(Modifiable != CM_Untested && "Did not test for modifiability.");
3015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      return static_cast<ModifiableType>(Modifiable);
3025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    }
303868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    bool isLValue() const { return Kind == CL_LValue; }
3045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    bool isXValue() const { return Kind == CL_XValue; }
3055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    bool isGLValue() const { return Kind <= CL_XValue; }
3064e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    bool isPRValue() const { return Kind >= CL_Function; }
3074e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    bool isRValue() const { return Kind >= CL_XValue; }
3084e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    bool isModifiable() const { return getModifiable() == CM_Modifiable; }
3094e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
3104e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    /// \brief Create a simple, modifiably lvalue
3114e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    static Classification makeSimpleLValue() {
3124e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)      return Classification(CL_LValue, CM_Modifiable);
3135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    }
3144e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
3154e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  };
3165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// \brief Classify - Classify this expression according to the C++0x
317868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  ///        expression taxonomy.
3185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ///
3195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// C++0x defines ([basic.lval]) a new taxonomy of expressions to replace the
3205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// old lvalue vs rvalue. This function determines the type of expression this
3211e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  /// is. There are three expression types:
3225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// - lvalues are classical lvalues as in C++03.
3235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// - prvalues are equivalent to rvalues in C++03.
3241e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  /// - xvalues are expressions yielding unnamed rvalue references, e.g. a
3255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ///   function returning an rvalue reference.
326868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  /// lvalues and xvalues are collectively referred to as glvalues, while
327868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  /// prvalues and xvalues together form rvalues.
3285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Classification Classify(ASTContext &Ctx) const {
3295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return ClassifyImpl(Ctx, 0);
3305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
3315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// \brief ClassifyModifiable - Classify this expression according to the
3335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ///        C++0x expression taxonomy, and see if it is valid on the left side
3345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ///        of an assignment.
3355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ///
336868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  /// This function extends classify in that it also tests whether the
3375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  /// expression is modifiable (C99 6.3.2.1p1).
3385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  /// \param Loc A source location that might be filled with a relevant location
3395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  ///            if the expression is not modifiable.
3405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  Classification ClassifyModifiable(ASTContext &Ctx, SourceLocation &Loc) const{
3415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return ClassifyImpl(Ctx, &Loc);
3425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
3435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// getValueKindForType - Given a formal return or parameter type,
3455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// give its value kind.
3465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static ExprValueKind getValueKindForType(QualType T) {
3475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    if (const ReferenceType *RT = T->getAs<ReferenceType>())
3485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      return (isa<LValueReferenceType>(RT)
3495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                ? VK_LValue
3505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                : (RT->getPointeeType()->isFunctionType()
3515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                     ? VK_LValue : VK_XValue));
3525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return VK_RValue;
3532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
3545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// getValueKind - The value kind that this expression produces.
356868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  ExprValueKind getValueKind() const {
3575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return static_cast<ExprValueKind>(ExprBits.ValueKind);
3585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
3595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// getObjectKind - The object kind that this expression produces.
3615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// Object kinds are meaningful only for expressions that yield an
3625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// l-value or x-value.
363a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  ExprObjectKind getObjectKind() const {
3645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return static_cast<ExprObjectKind>(ExprBits.ObjectKind);
365868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  }
3665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool isOrdinaryOrBitFieldObject() const {
3685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    ExprObjectKind OK = getObjectKind();
3695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return (OK == OK_Ordinary || OK == OK_BitField);
3705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
3715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// setValueKind - Set the value kind produced by this expression.
3735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void setValueKind(ExprValueKind Cat) { ExprBits.ValueKind = Cat; }
3745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// setObjectKind - Set the object kind produced by this expression.
3765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void setObjectKind(ExprObjectKind Cat) { ExprBits.ObjectKind = Cat; }
3775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)private:
3795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Classification ClassifyImpl(ASTContext &Ctx, SourceLocation *Loc) const;
3805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)public:
3825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// \brief If this expression refers to a bit-field, retrieve the
3845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// declaration of that bit-field.
3855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  FieldDecl *getBitField();
3862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
3875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  const FieldDecl *getBitField() const {
3885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return const_cast<Expr*>(this)->getBitField();
3895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
3905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// \brief If this expression is an l-value for an Objective C
3925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// property, find the underlying property reference expression.
3935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  const ObjCPropertyRefExpr *getObjCProperty() const;
3945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// \brief Returns whether this expression refers to a vector element.
3965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool refersToVectorElement() const;
3975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// \brief Returns whether this expression has a placeholder type.
3995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool hasPlaceholderType() const {
400868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    return getType()->isPlaceholderType();
401868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  }
402868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
403868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  /// \brief Returns whether this expression has a specific placeholder type.
404868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  bool hasPlaceholderType(BuiltinType::Kind K) const {
4055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    assert(BuiltinType::isPlaceholderTypeKind(K));
4065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    if (const BuiltinType *BT = dyn_cast<BuiltinType>(getType()))
4075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      return BT->getKind() == K;
4085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return false;
4095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
4105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// isKnownToHaveBooleanValue - Return true if this is an integer expression
4125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// that is known to return 0 or 1.  This happens for _Bool/bool expressions
4135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// but also int expressions which are produced by things like comparisons in
4145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// C.
4155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool isKnownToHaveBooleanValue() const;
4165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// isIntegerConstantExpr - Return true if this expression is a valid integer
4185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// constant expression, and, if so, return its value in Result.  If not a
4195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// valid i-c-e, return false and fill in Loc (if specified) with the location
4205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// of the invalid expression.
4215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ///
4225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// Note: This does not perform the implicit conversions required by C++11
4235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// [expr.const]p5.
424868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  bool isIntegerConstantExpr(llvm::APSInt &Result, ASTContext &Ctx,
425868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)                             SourceLocation *Loc = 0,
426868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)                             bool isEvaluated = true) const;
427868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  bool isIntegerConstantExpr(ASTContext &Ctx, SourceLocation *Loc = 0) const;
428868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
429868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  /// isCXX98IntegralConstantExpr - Return true if this expression is an
430868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  /// integral constant expression in C++98. Can only be used in C++.
431868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  bool isCXX98IntegralConstantExpr(ASTContext &Ctx) const;
432868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
433868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  /// isCXX11ConstantExpr - Return true if this expression is a constant
434868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  /// expression in C++11. Can only be used in C++.
4355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ///
436868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  /// Note: This does not perform the implicit conversions required by C++11
4370529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch  /// [expr.const]p5.
438868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  bool isCXX11ConstantExpr(ASTContext &Ctx, APValue *Result = 0,
439868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)                           SourceLocation *Loc = 0) const;
440868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
441868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  /// isPotentialConstantExpr - Return true if this function's definition
442868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  /// might be usable in a constant expression in C++11, if it were marked
443868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  /// constexpr. Return false if the function can never produce a constant
444868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  /// expression, along with diagnostics describing why not.
445868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  static bool isPotentialConstantExpr(const FunctionDecl *FD,
4465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                      llvm::SmallVectorImpl<
447868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)                                        PartialDiagnosticAt> &Diags);
448868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
449868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  /// isConstantInitializer - Returns true if this expression can be emitted to
4505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// IR as a constant, and thus can be used as a constant initializer in C.
4515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool isConstantInitializer(ASTContext &Ctx, bool ForRef) const;
4525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// EvalStatus is a struct with detailed info about an evaluation in progress.
4545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  struct EvalStatus {
4555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    /// HasSideEffects - Whether the evaluated expression has side effects.
4565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    /// For example, (f() && 0) can be folded, but it still has side effects.
4575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    bool HasSideEffects;
4585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    /// Diag - If this is non-null, it will be filled in with a stack of notes
4605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    /// indicating why evaluation failed (or why it failed to produce a constant
4615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    /// expression).
4625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    /// If the expression is unfoldable, the notes will indicate why it's not
4635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    /// foldable. If the expression is foldable, but not a constant expression,
4645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    /// the notes will describes why it isn't a constant expression. If the
4655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    /// expression *is* a constant expression, no notes will be produced.
4665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    llvm::SmallVectorImpl<PartialDiagnosticAt> *Diag;
4675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    EvalStatus() : HasSideEffects(false), Diag(0) {}
4691e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
4702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    // hasSideEffects - Return true if the evaluated expression has
4712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    // side effects.
4724e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    bool hasSideEffects() const {
4734e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)      return HasSideEffects;
4741e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    }
4755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  };
4765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// EvalResult is a struct with detailed info about an evaluated expression.
4785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  struct EvalResult : EvalStatus {
4795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    /// Val - This is the value the expression can be folded to.
4805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    APValue Val;
4815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // isGlobalLValue - Return true if the evaluated lvalue expression
4835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // is global.
4845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    bool isGlobalLValue() const;
4855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  };
4865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// EvaluateAsRValue - Return true if this is a constant which we can fold to
4885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// an rvalue using any crazy technique (that has nothing to do with language
4895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// standards) that we want to, even if the expression has side-effects. If
4905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// this function returns true, it returns the folded constant in Result. If
4915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// the expression is a glvalue, an lvalue-to-rvalue conversion will be
4925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// applied.
4935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool EvaluateAsRValue(EvalResult &Result, const ASTContext &Ctx) const;
4945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// EvaluateAsBooleanCondition - Return true if this is a constant
4965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// which we we can fold and convert to a boolean condition using
4975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// any crazy technique that we want to, even if the expression has
4985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// side-effects.
4995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool EvaluateAsBooleanCondition(bool &Result, const ASTContext &Ctx) const;
5005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  enum SideEffectsKind { SE_NoSideEffects, SE_AllowSideEffects };
5022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
5032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  /// EvaluateAsInt - Return true if this is a constant which we can fold and
5042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  /// convert to an integer, using any crazy technique that we want to.
505c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  bool EvaluateAsInt(llvm::APSInt &Result, const ASTContext &Ctx,
5062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                     SideEffectsKind AllowSideEffects = SE_NoSideEffects) const;
5072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
508c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  /// isEvaluatable - Call EvaluateAsRValue to see if this expression can be
509f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  /// constant folded without side-effects, but discard the result.
510c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  bool isEvaluatable(const ASTContext &Ctx) const;
511f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
5125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// HasSideEffects - This routine returns true for all those expressions
5135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// which have any effect other than producing a value. Example is a function
5145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// call, volatile variable read, or throwing an exception.
5155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool HasSideEffects(const ASTContext &Ctx) const;
5165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// \brief Determine whether this expression involves a call to any function
5185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// that is not trivial.
5195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool hasNonTrivialCall(ASTContext &Ctx);
5205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// EvaluateKnownConstInt - Call EvaluateAsRValue and return the folded
5225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// integer. This must be called on an expression that constant folds to an
5235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// integer.
5245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  llvm::APSInt EvaluateKnownConstInt(const ASTContext &Ctx) const;
5255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// EvaluateAsLValue - Evaluate an expression to see if we can fold it to an
5275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// lvalue with link time known address, with no side-effects.
5285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool EvaluateAsLValue(EvalResult &Result, const ASTContext &Ctx) const;
5295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// EvaluateAsInitializer - Evaluate an expression as if it were the
5315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// initializer of the given declaration. Returns true if the initializer
5325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// can be folded to a constant, and produces any relevant notes. In C++11,
5335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// notes will be produced if the expression is not a constant expression.
5345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool EvaluateAsInitializer(APValue &Result, const ASTContext &Ctx,
5355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                             const VarDecl *VD,
5365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                       llvm::SmallVectorImpl<PartialDiagnosticAt> &Notes) const;
5375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// \brief Enumeration used to describe the kind of Null pointer constant
5395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// returned from \c isNullPointerConstant().
5405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  enum NullPointerConstantKind {
5415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    /// \brief Expression is not a Null pointer constant.
5425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    NPCK_NotNull = 0,
5435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    /// \brief Expression is a Null pointer constant built from a zero integer.
5455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    NPCK_ZeroInteger,
5465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    /// \brief Expression is a C++0X nullptr.
5485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    NPCK_CXX0X_nullptr,
5495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    /// \brief Expression is a GNU-style __null constant.
5515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    NPCK_GNUNull
5525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  };
5535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// \brief Enumeration used to describe how \c isNullPointerConstant()
5555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// should cope with value-dependent expressions.
5565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  enum NullPointerConstantValueDependence {
5575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    /// \brief Specifies that the expression should never be value-dependent.
5585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    NPC_NeverValueDependent = 0,
5595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    /// \brief Specifies that a value-dependent expression of integral or
5615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    /// dependent type should be considered a null pointer constant.
5625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    NPC_ValueDependentIsNull,
5635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    /// \brief Specifies that a value-dependent expression should be considered
5655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    /// to never be a null pointer constant.
5665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    NPC_ValueDependentIsNotNull
5675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  };
5685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// isNullPointerConstant - C99 6.3.2.3p3 - Test if this reduces down to
5705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// a Null pointer constant. The return value can further distinguish the
5715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// kind of NULL pointer constant that was detected.
5725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  NullPointerConstantKind isNullPointerConstant(
5735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      ASTContext &Ctx,
5745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      NullPointerConstantValueDependence NPC) const;
5755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// isOBJCGCCandidate - Return true if this expression may be used in a read/
5775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// write barrier.
5785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool isOBJCGCCandidate(ASTContext &Ctx) const;
5795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// \brief Returns true if this expression is a bound member function.
5815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool isBoundMemberFunction(ASTContext &Ctx) const;
5825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// \brief Given an expression of bound-member type, find the type
5845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// of the member.  Returns null if this is an *overloaded* bound
5855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// member expression.
5865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static QualType findBoundMemberType(const Expr *expr);
5875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// IgnoreImpCasts - Skip past any implicit casts which might
5895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// surround this expression.  Only skips ImplicitCastExprs.
5905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Expr *IgnoreImpCasts() LLVM_READONLY;
5915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// IgnoreImplicit - Skip past any implicit AST nodes which might
5935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// surround this expression.
5945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Expr *IgnoreImplicit() LLVM_READONLY {
5955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return cast<Expr>(Stmt::IgnoreImplicit());
5965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
5975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  const Expr *IgnoreImplicit() const LLVM_READONLY {
5995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return const_cast<Expr*>(this)->IgnoreImplicit();
6005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
6015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// IgnoreParens - Ignore parentheses.  If this Expr is a ParenExpr, return
6035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ///  its subexpression.  If that subexpression is also a ParenExpr,
6045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ///  then this method recursively returns its subexpression, and so forth.
6055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ///  Otherwise, the method returns the current Expr.
6065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Expr *IgnoreParens() LLVM_READONLY;
607a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch
608a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch  /// IgnoreParenCasts - Ignore parentheses and casts.  Strip off any ParenExpr
609a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch  /// or CastExprs, returning their operand.
610a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch  Expr *IgnoreParenCasts() LLVM_READONLY;
6115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// IgnoreParenImpCasts - Ignore parentheses and implicit casts.  Strip off
613a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch  /// any ParenExpr or ImplicitCastExprs, returning their operand.
6145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Expr *IgnoreParenImpCasts() LLVM_READONLY;
6155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// IgnoreConversionOperator - Ignore conversion operator. If this Expr is a
6175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// call to a conversion operator, return the argument.
6185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Expr *IgnoreConversionOperator() LLVM_READONLY;
6195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  const Expr *IgnoreConversionOperator() const LLVM_READONLY {
6215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return const_cast<Expr*>(this)->IgnoreConversionOperator();
6225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
6235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  const Expr *IgnoreParenImpCasts() const LLVM_READONLY {
6255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return const_cast<Expr*>(this)->IgnoreParenImpCasts();
6265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
6275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// Ignore parentheses and lvalue casts.  Strip off any ParenExpr and
6295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// CastExprs that represent lvalue casts, returning their operand.
6305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Expr *IgnoreParenLValueCasts() LLVM_READONLY;
6315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  const Expr *IgnoreParenLValueCasts() const LLVM_READONLY {
6335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return const_cast<Expr*>(this)->IgnoreParenLValueCasts();
6345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
6355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// IgnoreParenNoopCasts - Ignore parentheses and casts that do not change the
6375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// value (including ptr->int casts of the same size).  Strip off any
6387d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  /// ParenExpr or CastExprs, returning their operand.
6395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Expr *IgnoreParenNoopCasts(ASTContext &Ctx) LLVM_READONLY;
6405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// Ignore parentheses and derived-to-base casts.
6425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  Expr *ignoreParenBaseCasts() LLVM_READONLY;
6435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
6445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  const Expr *ignoreParenBaseCasts() const LLVM_READONLY {
6455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    return const_cast<Expr*>(this)->ignoreParenBaseCasts();
6465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  }
6475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
6485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  /// \brief Determine whether this expression is a default function argument.
6495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  ///
6505d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  /// Default arguments are implicitly generated in the abstract syntax tree
6515d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  /// by semantic analysis for function calls, object constructions, etc. in
6525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// C++. Default arguments are represented by \c CXXDefaultArgExpr nodes;
6535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// this routine also looks through any implicit casts to determine whether
6545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// the expression is a default argument.
6555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool isDefaultArgument() const;
6565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
657010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  /// \brief Determine whether the result of this expression is a
658010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  /// temporary object of the given class type.
6595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool isTemporaryObject(ASTContext &Ctx, const CXXRecordDecl *TempTy) const;
6605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// \brief Whether this expression is an implicit reference to 'this' in C++.
6625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool isImplicitCXXThis() const;
6635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  const Expr *IgnoreImpCasts() const LLVM_READONLY {
6655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return const_cast<Expr*>(this)->IgnoreImpCasts();
6665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
6675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  const Expr *IgnoreParens() const LLVM_READONLY {
6685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return const_cast<Expr*>(this)->IgnoreParens();
6695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
6705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  const Expr *IgnoreParenCasts() const LLVM_READONLY {
6715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return const_cast<Expr*>(this)->IgnoreParenCasts();
6725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
6735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  const Expr *IgnoreParenNoopCasts(ASTContext &Ctx) const LLVM_READONLY {
6745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return const_cast<Expr*>(this)->IgnoreParenNoopCasts(Ctx);
6755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
6765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static bool hasAnyTypeDependentArguments(llvm::ArrayRef<Expr *> Exprs);
6785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// \brief For an expression of class type or pointer to class type,
6805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// return the most derived class decl the expression is known to refer to.
6815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ///
6825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// If this expression is a cast, this method looks through it to find the
6835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// most derived decl that can be inferred from the expression.
6845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// This is valid because derived-to-base conversions have undefined
6855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// behavior if the object isn't dynamically of the derived type.
6865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  const CXXRecordDecl *getBestDynamicClassType() const;
6875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static bool classof(const Stmt *T) {
6895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return T->getStmtClass() >= firstExprConstant &&
6905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)           T->getStmtClass() <= lastExprConstant;
6915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
6925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static bool classof(const Expr *) { return true; }
6935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
6945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//===----------------------------------------------------------------------===//
6975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Primary Expressions.
6985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//===----------------------------------------------------------------------===//
6995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// OpaqueValueExpr - An expression referring to an opaque object of a
701f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)/// fixed type and value class.  These don't correspond to concrete
702f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)/// syntax; instead they're used to express operations (usually copy
7031e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)/// operations) on values whose source is generally obvious from
7040529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch/// context.
705ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdochclass OpaqueValueExpr : public Expr {
7062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  friend class ASTStmtReader;
707c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  Expr *SourceExpr;
7085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  SourceLocation Loc;
7095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)public:
7112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  OpaqueValueExpr(SourceLocation Loc, QualType T, ExprValueKind VK,
7125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                  ExprObjectKind OK = OK_Ordinary,
7135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                  Expr *SourceExpr = 0)
7145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    : Expr(OpaqueValueExprClass, T, VK, OK,
7155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)           T->isDependentType(),
7165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)           T->isDependentType() ||
7175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)           (SourceExpr && SourceExpr->isValueDependent()),
7185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)           T->isInstantiationDependentType(),
719868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)           false),
7205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      SourceExpr(SourceExpr), Loc(Loc) {
7215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
7225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// Given an expression which invokes a copy constructor --- i.e.  a
7245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// CXXConstructExpr, possibly wrapped in an ExprWithCleanups ---
7255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// find the OpaqueValueExpr that's the source of the construction.
7265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static const OpaqueValueExpr *findInCopyConstruct(const Expr *expr);
7275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  explicit OpaqueValueExpr(EmptyShell Empty)
7295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    : Expr(OpaqueValueExprClass, Empty) { }
7305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// \brief Retrieve the location of this expression.
7325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  SourceLocation getLocation() const { return Loc; }
7335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  SourceRange getSourceRange() const LLVM_READONLY {
735a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    if (SourceExpr) return SourceExpr->getSourceRange();
7365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    return Loc;
7375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
7382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  SourceLocation getExprLoc() const LLVM_READONLY {
7395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    if (SourceExpr) return SourceExpr->getExprLoc();
7405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return Loc;
7415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
7425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  child_range children() { return child_range(); }
7445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// The source expression of an opaque value expression is the
7465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// expression which originally generated the value.  This is
7475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// provided as a convenience for analyses that don't wish to
7485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// precisely model the execution behavior of the program.
7495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ///
7505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// The source expression is typically set when building the
7515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// expression which binds the opaque value expression in the first
7525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// place.
7535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Expr *getSourceExpr() const { return SourceExpr; }
7545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static bool classof(const Stmt *T) {
7565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return T->getStmtClass() == OpaqueValueExprClass;
7572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
7582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  static bool classof(const OpaqueValueExpr *) { return true; }
7595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
7602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
7615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// \brief A reference to a declared variable, function, enum, etc.
7625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// [C99 6.5.1p2]
763a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)///
7645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// This encodes all the information about how a declaration is referenced
765bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch/// within an expression.
766bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch///
767bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch/// There are several optional constructs attached to DeclRefExprs only when
768bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch/// they apply in order to conserve memory. These are laid out past the end of
7695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// the object, and flags in the DeclRefExprBitfield track whether they exist:
7705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)///
771a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)///   DeclRefExprBits.HasQualifier:
7725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)///       Specifies when this declaration reference expression has a C++
7735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)///       nested-name-specifier.
774a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)///   DeclRefExprBits.HasFoundDecl:
7755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)///       Specifies when this declaration reference expression has a record of
7765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)///       a NamedDecl (different from the referenced ValueDecl) which was found
777a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)///       during name lookup and/or overload resolution.
7785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)///   DeclRefExprBits.HasTemplateKWAndArgsInfo:
7795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)///       Specifies when this declaration reference expression has an explicit
780a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)///       C++ template keyword and/or template argument list.
7815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)///   DeclRefExprBits.RefersToEnclosingLocal
7825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)///       Specifies when this declaration reference expression (validly)
783a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)///       refers to a local variable from a different function.
7845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class DeclRefExpr : public Expr {
7855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// \brief The declaration that we are referencing.
786a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  ValueDecl *D;
7875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// \brief The location of the declaration name itself.
7895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  SourceLocation Loc;
7905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// \brief Provides source/type location info for the declaration name
7925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// embedded in D.
7935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  DeclarationNameLoc DNLoc;
7945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// \brief Helper to retrieve the optional NestedNameSpecifierLoc.
7961e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  NestedNameSpecifierLoc &getInternalQualifierLoc() {
7975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    assert(hasQualifier());
7985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return *reinterpret_cast<NestedNameSpecifierLoc *>(this + 1);
7995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
8005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// \brief Helper to retrieve the optional NestedNameSpecifierLoc.
8025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  const NestedNameSpecifierLoc &getInternalQualifierLoc() const {
8035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return const_cast<DeclRefExpr *>(this)->getInternalQualifierLoc();
8045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
8055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// \brief Test whether there is a distinct FoundDecl attached to the end of
8075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// this DRE.
8085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool hasFoundDecl() const { return DeclRefExprBits.HasFoundDecl; }
8095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// \brief Helper to retrieve the optional NamedDecl through which this
8115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// reference occured.
8125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  NamedDecl *&getInternalFoundDecl() {
8132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    assert(hasFoundDecl());
8142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    if (hasQualifier())
8152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      return *reinterpret_cast<NamedDecl **>(&getInternalQualifierLoc() + 1);
8162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    return *reinterpret_cast<NamedDecl **>(this + 1);
8175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
8185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
81990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  /// \brief Helper to retrieve the optional NamedDecl through which this
8205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// reference occured.
8212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  NamedDecl *getInternalFoundDecl() const {
8225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return const_cast<DeclRefExpr *>(this)->getInternalFoundDecl();
823424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  }
82490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
8250529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch  DeclRefExpr(ASTContext &Ctx,
8265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)              NestedNameSpecifierLoc QualifierLoc,
8271e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)              SourceLocation TemplateKWLoc,
8281e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)              ValueDecl *D, bool refersToEnclosingLocal,
8291e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)              const DeclarationNameInfo &NameInfo,
830c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)              NamedDecl *FoundD,
8315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)              const TemplateArgumentListInfo *TemplateArgs,
8325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)              QualType T, ExprValueKind VK);
8335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
8345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  /// \brief Construct an empty declaration reference expression.
835a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  explicit DeclRefExpr(EmptyShell Empty)
8362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    : Expr(DeclRefExprClass, Empty) { }
8372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
8382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  /// \brief Computes the type- and value-dependence flags for this
839a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  /// declaration reference expression.
840a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  void computeDependence(ASTContext &C);
8415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)public:
8435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  DeclRefExpr(ValueDecl *D, bool refersToEnclosingLocal, QualType T,
8445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)              ExprValueKind VK, SourceLocation L,
8455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)              const DeclarationNameLoc &LocInfo = DeclarationNameLoc())
8465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    : Expr(DeclRefExprClass, T, VK, OK_Ordinary, false, false, false, false),
8475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      D(D), Loc(L), DNLoc(LocInfo) {
8485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    DeclRefExprBits.HasQualifier = 0;
8495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    DeclRefExprBits.HasTemplateKWAndArgsInfo = 0;
8505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    DeclRefExprBits.HasFoundDecl = 0;
8515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    DeclRefExprBits.HadMultipleCandidates = 0;
8525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    DeclRefExprBits.RefersToEnclosingLocal = refersToEnclosingLocal;
8535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    computeDependence(D->getASTContext());
854a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  }
8555d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
8565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static DeclRefExpr *Create(ASTContext &Context,
8575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                             NestedNameSpecifierLoc QualifierLoc,
8585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                             SourceLocation TemplateKWLoc,
8595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                             ValueDecl *D,
8605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                             bool isEnclosingLocal,
8615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                             SourceLocation NameLoc,
8625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                             QualType T, ExprValueKind VK,
8635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                             NamedDecl *FoundD = 0,
8645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                             const TemplateArgumentListInfo *TemplateArgs = 0);
8655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static DeclRefExpr *Create(ASTContext &Context,
8675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                             NestedNameSpecifierLoc QualifierLoc,
8685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                             SourceLocation TemplateKWLoc,
8695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                             ValueDecl *D,
8705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                             bool isEnclosingLocal,
8715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                             const DeclarationNameInfo &NameInfo,
8725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                             QualType T, ExprValueKind VK,
8735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                             NamedDecl *FoundD = 0,
8745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                             const TemplateArgumentListInfo *TemplateArgs = 0);
8755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// \brief Construct an empty declaration reference expression.
8775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static DeclRefExpr *CreateEmpty(ASTContext &Context,
8785d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                                  bool HasQualifier,
879a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)                                  bool HasFoundDecl,
8805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                  bool HasTemplateKWAndArgsInfo,
8815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                  unsigned NumTemplateArgs);
8825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ValueDecl *getDecl() { return D; }
8845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  const ValueDecl *getDecl() const { return D; }
8855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void setDecl(ValueDecl *NewD) { D = NewD; }
8865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  DeclarationNameInfo getNameInfo() const {
8885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return DeclarationNameInfo(getDecl()->getDeclName(), Loc, DNLoc);
8895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
8905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  SourceLocation getLocation() const { return Loc; }
8925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void setLocation(SourceLocation L) { Loc = L; }
8935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  SourceRange getSourceRange() const LLVM_READONLY;
8945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  SourceLocation getLocStart() const LLVM_READONLY;
8955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  SourceLocation getLocEnd() const LLVM_READONLY;
8965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// \brief Determine whether this declaration reference was preceded by a
898c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  /// C++ nested-name-specifier, e.g., \c N::foo.
899c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  bool hasQualifier() const { return DeclRefExprBits.HasQualifier; }
900c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
9015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// \brief If the name was qualified, retrieves the nested-name-specifier
9025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// that precedes the name. Otherwise, returns NULL.
903a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  NestedNameSpecifier *getQualifier() const {
9045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    if (!hasQualifier())
9055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      return 0;
9065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
9075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return getInternalQualifierLoc().getNestedNameSpecifier();
9085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
9095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
9105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// \brief If the name was qualified, retrieves the nested-name-specifier
9115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// that precedes the name, with source-location information.
9125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  NestedNameSpecifierLoc getQualifierLoc() const {
9135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    if (!hasQualifier())
9145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      return NestedNameSpecifierLoc();
9155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
9165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return getInternalQualifierLoc();
9175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
9185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
9195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// \brief Get the NamedDecl through which this reference occured.
9205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ///
9215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// This Decl may be different from the ValueDecl actually referred to in the
9221e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  /// presence of using declarations, etc. It always returns non-NULL, and may
9235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// simple return the ValueDecl when appropriate.
924a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  NamedDecl *getFoundDecl() {
9255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return hasFoundDecl() ? getInternalFoundDecl() : D;
9265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
9275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
9285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// \brief Get the NamedDecl through which this reference occurred.
9295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// See non-const variant.
9305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  const NamedDecl *getFoundDecl() const {
9315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return hasFoundDecl() ? getInternalFoundDecl() : D;
9325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
9335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
9345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool hasTemplateKWAndArgsInfo() const {
9355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return DeclRefExprBits.HasTemplateKWAndArgsInfo;
9365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
937a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
9385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// \brief Return the optional template keyword and arguments info.
9395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo() {
9405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    if (!hasTemplateKWAndArgsInfo())
9415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      return 0;
942a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
9435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    if (hasFoundDecl())
9445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      return reinterpret_cast<ASTTemplateKWAndArgsInfo *>(
9455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        &getInternalFoundDecl() + 1);
9465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
9475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    if (hasQualifier())
9485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      return reinterpret_cast<ASTTemplateKWAndArgsInfo *>(
9495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        &getInternalQualifierLoc() + 1);
9505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
9515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return reinterpret_cast<ASTTemplateKWAndArgsInfo *>(this + 1);
9525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
9535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
9545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// \brief Return the optional template keyword and arguments info.
9555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  const ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo() const {
9565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return const_cast<DeclRefExpr*>(this)->getTemplateKWAndArgsInfo();
9575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
958868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
9595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// \brief Retrieve the location of the template keyword preceding
9605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// this name, if any.
9615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  SourceLocation getTemplateKeywordLoc() const {
9625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    if (!hasTemplateKWAndArgsInfo()) return SourceLocation();
9635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return getTemplateKWAndArgsInfo()->getTemplateKeywordLoc();
9645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
9655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
9665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// \brief Retrieve the location of the left angle bracket starting the
9675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// explicit template argument list following the name, if any.
9685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  SourceLocation getLAngleLoc() const {
9695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    if (!hasTemplateKWAndArgsInfo()) return SourceLocation();
9705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return getTemplateKWAndArgsInfo()->LAngleLoc;
9715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
9725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
9735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// \brief Retrieve the location of the right angle bracket ending the
9745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// explicit template argument list following the name, if any.
9755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  SourceLocation getRAngleLoc() const {
9765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    if (!hasTemplateKWAndArgsInfo()) return SourceLocation();
9775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return getTemplateKWAndArgsInfo()->RAngleLoc;
978bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch  }
979bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch
9805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// \brief Determines whether the name in this declaration reference
9815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// was preceded by the template keyword.
9825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool hasTemplateKeyword() const { return getTemplateKeywordLoc().isValid(); }
9835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
9845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// \brief Determines whether this declaration reference was followed by an
9855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// explicit template argument list.
9865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool hasExplicitTemplateArgs() const { return getLAngleLoc().isValid(); }
9875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
9885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// \brief Retrieve the explicit template argument list that followed the
989a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  /// member template name.
9905d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  ASTTemplateArgumentListInfo &getExplicitTemplateArgs() {
9915d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    assert(hasExplicitTemplateArgs());
9925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return *getTemplateKWAndArgsInfo();
9935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
9942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
9952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  /// \brief Retrieve the explicit template argument list that followed the
9962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  /// member template name.
9972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  const ASTTemplateArgumentListInfo &getExplicitTemplateArgs() const {
9982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    return const_cast<DeclRefExpr *>(this)->getExplicitTemplateArgs();
999a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  }
10005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
10015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// \brief Retrieves the optional explicit template arguments.
10025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// This points to the same data as getExplicitTemplateArgs(), but
10035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// returns null if there are no explicit template arguments.
10045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  const ASTTemplateArgumentListInfo *getOptionalExplicitTemplateArgs() const {
10055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    if (!hasExplicitTemplateArgs()) return 0;
10065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return &getExplicitTemplateArgs();
10075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
10085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
10095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// \brief Copies the template arguments (if present) into the given
10105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// structure.
10115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
10125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    if (hasExplicitTemplateArgs())
10135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      getExplicitTemplateArgs().copyInto(List);
10145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
10155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
10165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// \brief Retrieve the template arguments provided as part of this
10175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// template-id.
10185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  const TemplateArgumentLoc *getTemplateArgs() const {
10195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    if (!hasExplicitTemplateArgs())
10205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      return 0;
10215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
10225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return getExplicitTemplateArgs().getTemplateArgs();
10235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
10245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
10255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// \brief Retrieve the number of template arguments provided as part of this
10265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// template-id.
10275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  unsigned getNumTemplateArgs() const {
10285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    if (!hasExplicitTemplateArgs())
10295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      return 0;
10305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
10315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return getExplicitTemplateArgs().NumTemplateArgs;
10325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
1033a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
10345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// \brief Returns true if this expression refers to a function that
10355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// was resolved from an overloaded set having size greater than 1.
10365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool hadMultipleCandidates() const {
10375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return DeclRefExprBits.HadMultipleCandidates;
10385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
1039c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  /// \brief Sets the flag telling whether this expression refers to
1040c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  /// a function that was resolved from an overloaded set having size
1041c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  /// greater than 1.
1042c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  void setHadMultipleCandidates(bool V = true) {
1043c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    DeclRefExprBits.HadMultipleCandidates = V;
1044c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  }
1045c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1046c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  /// Does this DeclRefExpr refer to a local declaration from an
1047c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  /// enclosing function scope?
1048c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  bool refersToEnclosingLocal() const {
10495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return DeclRefExprBits.RefersToEnclosingLocal;
10505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
10515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
10525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static bool classof(const Stmt *T) {
1053a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    return T->getStmtClass() == DeclRefExprClass;
10545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  }
10555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static bool classof(const DeclRefExpr *) { return true; }
10565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
10575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Iterators
10585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  child_range children() { return child_range(); }
10595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
10605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  friend class ASTStmtReader;
1061a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  friend class ASTStmtWriter;
10625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
10635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
10645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// PredefinedExpr - [C99 6.4.2.2] - A predefined identifier such as __func__.
10655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class PredefinedExpr : public Expr {
10665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)public:
10675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  enum IdentType {
10685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    Func,
10695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    Function,
10705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    LFunction,  // Same as Function, but as wide string.
10715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    PrettyFunction,
10725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    /// PrettyFunctionNoVirtual - The same as PrettyFunction, except that the
10735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    /// 'virtual' keyword is omitted for virtual member functions.
10745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    PrettyFunctionNoVirtual
10755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  };
10765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
10775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)private:
10785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  SourceLocation Loc;
10795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  IdentType Type;
10805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)public:
1081a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  PredefinedExpr(SourceLocation l, QualType type, IdentType IT)
10825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    : Expr(PredefinedExprClass, type, VK_LValue, OK_Ordinary,
1083a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)           type->isDependentType(), type->isDependentType(),
10845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)           type->isInstantiationDependentType(),
10855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)           /*ContainsUnexpandedParameterPack=*/false),
10865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      Loc(l), Type(IT) {}
10875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
10885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// \brief Construct an empty predefined expression.
10895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  explicit PredefinedExpr(EmptyShell Empty)
10905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    : Expr(PredefinedExprClass, Empty) { }
10915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
10925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  IdentType getIdentType() const { return Type; }
10935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void setIdentType(IdentType IT) { Type = IT; }
10945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
10955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  SourceLocation getLocation() const { return Loc; }
10965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void setLocation(SourceLocation L) { Loc = L; }
10972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
10985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static std::string ComputeName(IdentType IT, const Decl *CurrentDecl);
10995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
11005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  SourceRange getSourceRange() const LLVM_READONLY { return SourceRange(Loc); }
11015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1102a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  static bool classof(const Stmt *T) {
11035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return T->getStmtClass() == PredefinedExprClass;
11045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
11055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static bool classof(const PredefinedExpr *) { return true; }
1106a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
11075d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Iterators
11085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  child_range children() { return child_range(); }
11095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
11105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
11115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// \brief Used by IntegerLiteral/FloatingLiteral to store the numeric without
1112a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)/// leaking memory.
11135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)///
11145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// For large floats/integers, APFloat/APInt will allocate memory from the heap
11155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// to represent these numbers.  Unfortunately, when we use a BumpPtrAllocator
11165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// to allocate IntegerLiteral/FloatingLiteral nodes the memory associated with
11175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// the APFloat/APInt values will never get freed. APNumericStorage uses
11185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// ASTContext's allocator for memory allocation.
11195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class APNumericStorage {
11205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  union {
11215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    uint64_t VAL;    ///< Used to store the <= 64 bits integer value.
11225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    uint64_t *pVal;  ///< Used to store the >64 bits integer value.
11235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  };
11245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  unsigned BitWidth;
11255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
11265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  bool hasAllocation() const { return llvm::APInt::getNumWords(BitWidth) > 1; }
11275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
11285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  APNumericStorage(const APNumericStorage&); // do not implement
11295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  APNumericStorage& operator=(const APNumericStorage&); // do not implement
11305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
11315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)protected:
11325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  APNumericStorage() : VAL(0), BitWidth(0) { }
1133a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
11345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  llvm::APInt getIntValue() const {
11355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    unsigned NumWords = llvm::APInt::getNumWords(BitWidth);
11365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    if (NumWords > 1)
11375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      return llvm::APInt(BitWidth, NumWords, pVal);
11385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    else
11395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      return llvm::APInt(BitWidth, VAL);
1140a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  }
11415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void setIntValue(ASTContext &C, const llvm::APInt &Val);
11425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
11435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
11445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class APIntStorage : private APNumericStorage {
11455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)public:
11465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  llvm::APInt getValue() const { return getIntValue(); }
11475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void setValue(ASTContext &C, const llvm::APInt &Val) { setIntValue(C, Val); }
11485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
11495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
11505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class APFloatStorage : private APNumericStorage {
11515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)public:
11525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  llvm::APFloat getValue(bool IsIEEE) const {
11532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    return llvm::APFloat(getIntValue(), IsIEEE);
11545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
11555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void setValue(ASTContext &C, const llvm::APFloat &Val) {
11565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    setIntValue(C, Val.bitcastToAPInt());
11575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
1158a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)};
11595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
11605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class IntegerLiteral : public Expr, public APIntStorage {
11615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  SourceLocation Loc;
1162a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
11635d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  /// \brief Construct an empty integer literal.
11647dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  explicit IntegerLiteral(EmptyShell Empty)
11657dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch    : Expr(IntegerLiteralClass, Empty) { }
11665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
11672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)public:
11685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // type should be IntTy, LongTy, LongLongTy, UnsignedIntTy, UnsignedLongTy,
11695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // or UnsignedLongLongTy
11705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  IntegerLiteral(ASTContext &C, const llvm::APInt &V, QualType type,
11715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                 SourceLocation l);
11725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
11735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// \brief Returns a new integer literal with value 'V' and type 'type'.
11745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// \param type - either IntTy, LongTy, LongLongTy, UnsignedIntTy,
11755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// UnsignedLongTy, or UnsignedLongLongTy which should match the size of V
11765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// \param V - the value that the returned integer literal contains.
11775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static IntegerLiteral *Create(ASTContext &C, const llvm::APInt &V,
11785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                QualType type, SourceLocation l);
11795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// \brief Returns a new empty integer literal.
11805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static IntegerLiteral *Create(ASTContext &C, EmptyShell Empty);
11815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
11825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  SourceRange getSourceRange() const LLVM_READONLY { return SourceRange(Loc); }
11835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1184a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  /// \brief Retrieve the location of the literal.
11855d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  SourceLocation getLocation() const { return Loc; }
11865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
11875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void setLocation(SourceLocation Location) { Loc = Location; }
11885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
11895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static bool classof(const Stmt *T) {
11905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return T->getStmtClass() == IntegerLiteralClass;
11915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
11925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static bool classof(const IntegerLiteral *) { return true; }
11935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1194a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // Iterators
11955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  child_range children() { return child_range(); }
11965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
11975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
11985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class CharacterLiteral : public Expr {
11995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)public:
12005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  enum CharacterKind {
12015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    Ascii,
12025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    Wide,
12035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    UTF16,
12045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    UTF32
12052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  };
12065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
12075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)private:
12082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  unsigned Value;
12092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  SourceLocation Loc;
12102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)public:
12115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // type should be IntTy
12125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  CharacterLiteral(unsigned value, CharacterKind kind, QualType type,
12135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                   SourceLocation l)
12145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    : Expr(CharacterLiteralClass, type, VK_RValue, OK_Ordinary, false, false,
12155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)           false, false),
12165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      Value(value), Loc(l) {
12175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    CharacterLiteralBits.Kind = kind;
12185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
12195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
12205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// \brief Construct an empty character literal.
12215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  CharacterLiteral(EmptyShell Empty) : Expr(CharacterLiteralClass, Empty) { }
12225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
12235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  SourceLocation getLocation() const { return Loc; }
1224bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch  CharacterKind getKind() const {
1225bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch    return static_cast<CharacterKind>(CharacterLiteralBits.Kind);
1226bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch  }
12275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
12285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  SourceRange getSourceRange() const LLVM_READONLY { return SourceRange(Loc); }
1229bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch
12305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  unsigned getValue() const { return Value; }
12315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
12325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void setLocation(SourceLocation Location) { Loc = Location; }
12335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void setKind(CharacterKind kind) { CharacterLiteralBits.Kind = kind; }
12345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void setValue(unsigned Val) { Value = Val; }
12355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
12365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static bool classof(const Stmt *T) {
12375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return T->getStmtClass() == CharacterLiteralClass;
12385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
12395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static bool classof(const CharacterLiteral *) { return true; }
12405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
12415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Iterators
12425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  child_range children() { return child_range(); }
12435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
12445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1245ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdochclass FloatingLiteral : public Expr, private APFloatStorage {
1246ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  SourceLocation Loc;
1247ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch
1248ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  FloatingLiteral(ASTContext &C, const llvm::APFloat &V, bool isexact,
1249ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch                  QualType Type, SourceLocation L);
1250ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch
1251ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  /// \brief Construct an empty floating-point literal.
1252ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  explicit FloatingLiteral(ASTContext &C, EmptyShell Empty);
12535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
12545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)public:
12555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static FloatingLiteral *Create(ASTContext &C, const llvm::APFloat &V,
12565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                 bool isexact, QualType Type, SourceLocation L);
12575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static FloatingLiteral *Create(ASTContext &C, EmptyShell Empty);
12585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
12591e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  llvm::APFloat getValue() const {
12605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return APFloatStorage::getValue(FloatingLiteralBits.IsIEEE);
12615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
12625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void setValue(ASTContext &C, const llvm::APFloat &Val) {
12635d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    APFloatStorage::setValue(C, Val);
12645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  }
1265868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
1266f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  bool isExact() const { return FloatingLiteralBits.IsExact; }
1267868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  void setExact(bool E) { FloatingLiteralBits.IsExact = E; }
12685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
12695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// getValueAsApproximateDouble - This returns the value as an inaccurate
12705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// double.  Note that this may cause loss of precision, but is useful for
12715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// debugging dumps, etc.
12725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  double getValueAsApproximateDouble() const;
12735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
12745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  SourceLocation getLocation() const { return Loc; }
12755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void setLocation(SourceLocation L) { Loc = L; }
12765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1277868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  SourceRange getSourceRange() const LLVM_READONLY { return SourceRange(Loc); }
1278868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
1279868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  static bool classof(const Stmt *T) {
12801e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    return T->getStmtClass() == FloatingLiteralClass;
12815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
12825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static bool classof(const FloatingLiteral *) { return true; }
1283f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
12845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Iterators
1285868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  child_range children() { return child_range(); }
1286868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)};
1287868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
12885d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)/// ImaginaryLiteral - We support imaginary integer and floating point literals,
12895d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)/// like "1.0i".  We represent these as a wrapper around FloatingLiteral and
12905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// IntegerLiteral classes.  Instances of this class always have a Complex type
12915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// whose element type matches the subexpression.
1292868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)///
1293868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)class ImaginaryLiteral : public Expr {
1294868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  Stmt *Val;
12955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)public:
12965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ImaginaryLiteral(Expr *val, QualType Ty)
12975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    : Expr(ImaginaryLiteralClass, Ty, VK_RValue, OK_Ordinary, false, false,
12985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)           false, false),
12995d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      Val(val) {}
13005d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
13015d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  /// \brief Build an empty imaginary literal.
13025d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  explicit ImaginaryLiteral(EmptyShell Empty)
13035d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    : Expr(ImaginaryLiteralClass, Empty) { }
13045d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
13055d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  const Expr *getSubExpr() const { return cast<Expr>(Val); }
13065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Expr *getSubExpr() { return cast<Expr>(Val); }
13075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void setSubExpr(Expr *E) { Val = E; }
13085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
13095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  SourceRange getSourceRange() const LLVM_READONLY { return Val->getSourceRange(); }
13105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static bool classof(const Stmt *T) {
13111e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    return T->getStmtClass() == ImaginaryLiteralClass;
13121e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  }
13131e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  static bool classof(const ImaginaryLiteral *) { return true; }
13145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
13155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Iterators
13165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  child_range children() { return child_range(&Val, &Val+1); }
13175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
13181e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
13195c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu/// StringLiteral - This represents a string literal expression, e.g. "foo"
13205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// or L"bar" (wide strings).  The actual string is returned by getStrData()
13215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// is NOT null-terminated, and the length of the string is determined by
13225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// calling getByteLength().  The C type for a string is always a
13235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// ConstantArrayType.  In C++, the char type is const qualified, in C it is
13241e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)/// not.
13251e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)///
13265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// Note that strings in C can be formed by concatenation of multiple string
13275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// literal pptokens in translation phase #6.  This keeps track of the locations
13285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// of each of these pieces.
1329f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)///
1330868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)/// Strings in C can also be truncated and extended by assigning into arrays,
1331868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)/// e.g. with constructs like:
1332868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)///   char X[2] = "foobar";
1333868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)/// In this case, getByteLength() will return 6, but the string literal will
1334868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)/// have type "char[2]".
13352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class StringLiteral : public Expr {
1336868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)public:
1337868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  enum StringKind {
1338868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    Ascii,
1339868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    Wide,
1340868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    UTF8,
1341868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    UTF16,
1342868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    UTF32
1343868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  };
1344868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
1345868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)private:
1346868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  friend class ASTStmtReader;
1347868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
1348868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  union {
1349868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    const char *asChar;
1350f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    const uint16_t *asUInt16;
1351f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    const uint32_t *asUInt32;
1352868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  } StrData;
1353868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  unsigned Length;
1354868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  unsigned CharByteWidth : 4;
13552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  unsigned Kind : 3;
13562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  unsigned IsPascal : 1;
13572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  unsigned NumConcatenated;
13582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  SourceLocation TokLocs[1];
13592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
13602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  StringLiteral(QualType Ty) :
13614e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    Expr(StringLiteralClass, Ty, VK_LValue, OK_Ordinary, false, false, false,
13624e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)         false) {}
13631e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
13642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  static int mapCharByteWidth(TargetInfo const &target,StringKind k);
13652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
13662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)public:
1367f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  /// This is the "fully general" constructor that allows representation of
1368868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  /// strings formed from multiple concatenated tokens.
1369f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  static StringLiteral *Create(ASTContext &C, StringRef Str, StringKind Kind,
13705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                               bool Pascal, QualType Ty,
1371868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)                               const SourceLocation *Loc, unsigned NumStrs);
1372868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
1373868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  /// Simple constructor for string literals made from one token.
1374868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  static StringLiteral *Create(ASTContext &C, StringRef Str, StringKind Kind,
1375868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)                               bool Pascal, QualType Ty,
1376868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)                               SourceLocation Loc) {
13775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return Create(C, Str, Kind, Pascal, Ty, &Loc, 1);
13785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
13792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1380c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  /// \brief Construct an empty string literal.
13812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  static StringLiteral *CreateEmpty(ASTContext &C, unsigned NumStrs);
13822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
13835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  StringRef getString() const {
1384ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch    assert(CharByteWidth==1
13855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)           && "This function is used in places that assume strings use char");
13865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return StringRef(StrData.asChar, getByteLength());
13875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
13885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
13895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// Allow access to clients that need the byte representation, such as
13905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// ASTWriterStmt::VisitStringLiteral().
13915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  StringRef getBytes() const {
1392ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch    // FIXME: StringRef may not be the right type to use as a result for this.
1393ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch    if (CharByteWidth == 1)
1394ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch      return StringRef(StrData.asChar, getByteLength());
1395ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch    if (CharByteWidth == 4)
1396ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch      return StringRef(reinterpret_cast<const char*>(StrData.asUInt32),
1397ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch                       getByteLength());
13985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    assert(CharByteWidth == 2 && "unsupported CharByteWidth");
13995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return StringRef(reinterpret_cast<const char*>(StrData.asUInt16),
14005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                     getByteLength());
14015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
14025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
14035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void outputString(raw_ostream &OS);
14045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
14055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  uint32_t getCodeUnit(size_t i) const {
14065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    assert(i < Length && "out of bounds access");
14075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    if (CharByteWidth == 1)
14080529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch      return static_cast<unsigned char>(StrData.asChar[i]);
14090529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    if (CharByteWidth == 4)
14105c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu      return StrData.asUInt32[i];
14115c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu    assert(CharByteWidth == 2 && "unsupported CharByteWidth");
14120529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    return StrData.asUInt16[i];
14130529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch  }
14145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1415ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  unsigned getByteLength() const { return CharByteWidth*Length; }
1416ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  unsigned getLength() const { return Length; }
1417ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  unsigned getCharByteWidth() const { return CharByteWidth; }
1418ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch
1419ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  /// \brief Sets the string data to the given string data.
1420ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  void setString(ASTContext &C, StringRef Str,
1421ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch                 StringKind Kind, bool IsPascal);
1422ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch
1423ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  StringKind getKind() const { return static_cast<StringKind>(Kind); }
1424ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch
1425ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch
1426ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  bool isAscii() const { return Kind == Ascii; }
1427ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  bool isWide() const { return Kind == Wide; }
1428ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  bool isUTF8() const { return Kind == UTF8; }
1429ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  bool isUTF16() const { return Kind == UTF16; }
1430ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  bool isUTF32() const { return Kind == UTF32; }
1431ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  bool isPascal() const { return IsPascal; }
1432ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch
1433ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  bool containsNonAsciiOrNull() const {
1434ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch    StringRef Str = getString();
1435ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch    for (unsigned i = 0, e = Str.size(); i != e; ++i)
1436ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch      if (!isascii(Str[i]) || !Str[i])
1437ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch        return true;
1438bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch    return false;
1439ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  }
1440ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch
1441ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  /// getNumConcatenated - Get the number of string literal tokens that were
1442ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  /// concatenated in translation phase #6 to form this string literal.
1443ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  unsigned getNumConcatenated() const { return NumConcatenated; }
1444ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch
1445ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  SourceLocation getStrTokenLoc(unsigned TokNum) const {
1446ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch    assert(TokNum < NumConcatenated && "Invalid tok number");
1447ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch    return TokLocs[TokNum];
1448ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  }
1449ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  void setStrTokenLoc(unsigned TokNum, SourceLocation L) {
1450ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch    assert(TokNum < NumConcatenated && "Invalid tok number");
1451ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch    TokLocs[TokNum] = L;
1452ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  }
1453ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch
14545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// getLocationOfByte - Return a source location that points to the specified
14555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// byte of this string literal.
14565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ///
14575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// Strings are amazingly complex.  They can be formed from multiple tokens
14585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// and can have escape sequences in them in addition to the usual trigraph
14595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// and escaped newline business.  This routine handles this complexity.
14604e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  ///
14614e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  SourceLocation getLocationOfByte(unsigned ByteNo, const SourceManager &SM,
14624e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)                                   const LangOptions &Features,
14634e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)                                   const TargetInfo &Target) const;
14645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
14655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  typedef const SourceLocation *tokloc_iterator;
14665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  tokloc_iterator tokloc_begin() const { return TokLocs; }
14675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  tokloc_iterator tokloc_end() const { return TokLocs+NumConcatenated; }
14685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
14695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  SourceRange getSourceRange() const LLVM_READONLY {
14705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return SourceRange(TokLocs[0], TokLocs[NumConcatenated-1]);
14715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
14725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static bool classof(const Stmt *T) {
14735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return T->getStmtClass() == StringLiteralClass;
14745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
14755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static bool classof(const StringLiteral *) { return true; }
14765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
14775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Iterators
14785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  child_range children() { return child_range(); }
14795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
14805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
14815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// ParenExpr - This represents a parethesized expression, e.g. "(1)".  This
14821e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)/// AST node is only formed if full location information is requested.
14835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class ParenExpr : public Expr {
14845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  SourceLocation L, R;
14855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Stmt *Val;
14865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)public:
14875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ParenExpr(SourceLocation l, SourceLocation r, Expr *val)
14885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    : Expr(ParenExprClass, val->getType(),
14895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)           val->getValueKind(), val->getObjectKind(),
14905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)           val->isTypeDependent(), val->isValueDependent(),
14915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)           val->isInstantiationDependent(),
14925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)           val->containsUnexpandedParameterPack()),
14935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      L(l), R(r), Val(val) {}
14945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
14955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// \brief Construct an empty parenthesized expression.
14965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  explicit ParenExpr(EmptyShell Empty)
14975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    : Expr(ParenExprClass, Empty) { }
14985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
14995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  const Expr *getSubExpr() const { return cast<Expr>(Val); }
15005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Expr *getSubExpr() { return cast<Expr>(Val); }
15015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void setSubExpr(Expr *E) { Val = E; }
15025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
15035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  SourceRange getSourceRange() const LLVM_READONLY { return SourceRange(L, R); }
15045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
15055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// \brief Get the location of the left parentheses '('.
15065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  SourceLocation getLParen() const { return L; }
15075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void setLParen(SourceLocation Loc) { L = Loc; }
15085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
15095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// \brief Get the location of the right parentheses ')'.
15105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  SourceLocation getRParen() const { return R; }
15115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void setRParen(SourceLocation Loc) { R = Loc; }
15125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
15135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static bool classof(const Stmt *T) {
15145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return T->getStmtClass() == ParenExprClass;
15155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
15165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static bool classof(const ParenExpr *) { return true; }
15175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
15185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Iterators
15195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  child_range children() { return child_range(&Val, &Val+1); }
15205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
15215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
15225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
15235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// UnaryOperator - This represents the unary-expression's (except sizeof and
15245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// alignof), the postinc/postdec operators from postfix-expression, and various
15255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// extensions.
15265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)///
15275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// Notes on various nodes:
15285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)///
15295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// Real/Imag - These return the real/imag part of a complex operand.  If
15305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)///   applied to a non-complex value, the former returns its operand and the
15315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)///   later returns zero in the type of the operand.
15325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)///
15335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class UnaryOperator : public Expr {
15345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)public:
15351e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  typedef UnaryOperatorKind Opcode;
15365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
15375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)private:
15385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  unsigned Opc : 5;
15395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  SourceLocation Loc;
15405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Stmt *Val;
1541a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)public:
15425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
15435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  UnaryOperator(Expr *input, Opcode opc, QualType type,
15445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                ExprValueKind VK, ExprObjectKind OK, SourceLocation l)
15455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    : Expr(UnaryOperatorClass, type, VK, OK,
15465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)           input->isTypeDependent() || type->isDependentType(),
15475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)           input->isValueDependent(),
15485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)           (input->isInstantiationDependent() ||
15495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)            type->isInstantiationDependentType()),
15505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)           input->containsUnexpandedParameterPack()),
15515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      Opc(opc), Loc(l), Val(input) {}
15525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
15535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// \brief Build an empty unary operator.
15545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  explicit UnaryOperator(EmptyShell Empty)
15555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    : Expr(UnaryOperatorClass, Empty), Opc(UO_AddrOf) { }
15565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
15575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Opcode getOpcode() const { return static_cast<Opcode>(Opc); }
15585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void setOpcode(Opcode O) { Opc = O; }
15595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
15605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Expr *getSubExpr() const { return cast<Expr>(Val); }
15615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void setSubExpr(Expr *E) { Val = E; }
15621e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
15635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// getOperatorLoc - Return the location of the operator.
15645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  SourceLocation getOperatorLoc() const { return Loc; }
15655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void setOperatorLoc(SourceLocation L) { Loc = L; }
15661e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
15671e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  /// isPostfix - Return true if this is a postfix operation, like x++.
15685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static bool isPostfix(Opcode Op) {
15695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return Op == UO_PostInc || Op == UO_PostDec;
15705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
15715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
15725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// isPrefix - Return true if this is a prefix operation, like --x.
15735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static bool isPrefix(Opcode Op) {
15745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return Op == UO_PreInc || Op == UO_PreDec;
15755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
15765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
15771e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  bool isPrefix() const { return isPrefix(getOpcode()); }
15781e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  bool isPostfix() const { return isPostfix(getOpcode()); }
15795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
15805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static bool isIncrementOp(Opcode Op) {
15815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return Op == UO_PreInc || Op == UO_PostInc;
15825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
15835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool isIncrementOp() const {
15845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return isIncrementOp(getOpcode());
15855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
15865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
15875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static bool isDecrementOp(Opcode Op) {
1588a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    return Op == UO_PreDec || Op == UO_PostDec;
1589a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  }
1590a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  bool isDecrementOp() const {
1591a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    return isDecrementOp(getOpcode());
1592a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  }
1593a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
1594a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  static bool isIncrementDecrementOp(Opcode Op) { return Op <= UO_PreDec; }
15955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool isIncrementDecrementOp() const {
15965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return isIncrementDecrementOp(getOpcode());
15975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
15985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
15995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static bool isArithmeticOp(Opcode Op) {
16005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return Op >= UO_Plus && Op <= UO_LNot;
16015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
16021e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  bool isArithmeticOp() const { return isArithmeticOp(getOpcode()); }
16035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
16045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// getOpcodeStr - Turn an Opcode enum value into the punctuation char it
16055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// corresponds to, e.g. "sizeof" or "[pre]++"
16065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static const char *getOpcodeStr(Opcode Op);
16075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
16085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// \brief Retrieve the unary opcode that corresponds to the given
16094e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  /// overloaded operator.
16105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static Opcode getOverloadedOpcode(OverloadedOperatorKind OO, bool Postfix);
16115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
16125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// \brief Retrieve the overloaded operator kind that corresponds to
16135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// the given unary opcode.
161458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  static OverloadedOperatorKind getOverloadedOperator(Opcode Opc);
16155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
16161e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  SourceRange getSourceRange() const LLVM_READONLY {
16171e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    if (isPostfix())
1618868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      return SourceRange(Val->getLocStart(), Loc);
161958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    else
162058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)      return SourceRange(Loc, Val->getLocEnd());
162158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  }
16225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  SourceLocation getExprLoc() const LLVM_READONLY { return Loc; }
16235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
16245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static bool classof(const Stmt *T) {
16255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return T->getStmtClass() == UnaryOperatorClass;
16265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
16275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static bool classof(const UnaryOperator *) { return true; }
16285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
16295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Iterators
16305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  child_range children() { return child_range(&Val, &Val+1); }
16315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
16325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
16335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// OffsetOfExpr - [C99 7.17] - This represents an expression of the form
16345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// offsetof(record-type, member-designator). For example, given:
16355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// @code
16365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// struct S {
16375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)///   float f;
16385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)///   double d;
16395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// };
16405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// struct T {
16415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)///   int i;
16425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)///   struct S s[10];
16435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// };
16445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// @endcode
16455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// we can represent and evaluate the expression @c offsetof(struct T, s[2].d).
16465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
16475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class OffsetOfExpr : public Expr {
16485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)public:
16495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // __builtin_offsetof(type, identifier(.identifier|[expr])*)
16505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  class OffsetOfNode {
16515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  public:
16525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    /// \brief The kind of offsetof node we have.
16535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    enum Kind {
16545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      /// \brief An index into an array.
16555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      Array = 0x00,
16565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      /// \brief A field.
16575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      Field = 0x01,
16585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      /// \brief A field in a dependent type, known only by its name.
16595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      Identifier = 0x02,
16605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      /// \brief An implicit indirection through a C++ base class, when the
16615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      /// field found is in a base class.
16625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      Base = 0x03
16635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    };
16645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
16655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  private:
16665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    enum { MaskBits = 2, Mask = 0x03 };
16675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
16685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    /// \brief The source range that covers this part of the designator.
16695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    SourceRange Range;
16705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
16715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    /// \brief The data describing the designator, which comes in three
16725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    /// different forms, depending on the lower two bits.
167358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    ///   - An unsigned index into the array of Expr*'s stored after this node
167458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    ///     in memory, for [constant-expression] designators.
167558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    ///   - A FieldDecl*, for references to a known field.
167658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    ///   - An IdentifierInfo*, for references to a field with a given name
167758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    ///     when the class type is dependent.
1678a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    ///   - A CXXBaseSpecifier*, for references that look at a field in a
1679a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch    ///     base class.
1680a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch    uintptr_t Data;
1681a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch
1682a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  public:
1683a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    /// \brief Create an offsetof node that refers to an array element.
16845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    OffsetOfNode(SourceLocation LBracketLoc, unsigned Index,
16855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                 SourceLocation RBracketLoc)
16865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      : Range(LBracketLoc, RBracketLoc), Data((Index << 2) | Array) { }
16875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
16885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    /// \brief Create an offsetof node that refers to a field.
16895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    OffsetOfNode(SourceLocation DotLoc, FieldDecl *Field,
16905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                 SourceLocation NameLoc)
16915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      : Range(DotLoc.isValid()? DotLoc : NameLoc, NameLoc),
16925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        Data(reinterpret_cast<uintptr_t>(Field) | OffsetOfNode::Field) { }
16935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
16945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    /// \brief Create an offsetof node that refers to an identifier.
16955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    OffsetOfNode(SourceLocation DotLoc, IdentifierInfo *Name,
16965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                 SourceLocation NameLoc)
16975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      : Range(DotLoc.isValid()? DotLoc : NameLoc, NameLoc),
16985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        Data(reinterpret_cast<uintptr_t>(Name) | Identifier) { }
16995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
17005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    /// \brief Create an offsetof node that refers into a C++ base class.
17015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    explicit OffsetOfNode(const CXXBaseSpecifier *Base)
17025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      : Range(), Data(reinterpret_cast<uintptr_t>(Base) | OffsetOfNode::Base) {}
17035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
17045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    /// \brief Determine what kind of offsetof node this is.
17055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    Kind getKind() const {
17065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      return static_cast<Kind>(Data & Mask);
17075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    }
17085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
17095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    /// \brief For an array element node, returns the index into the array
17105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    /// of expressions.
17115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    unsigned getArrayExprIndex() const {
17125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      assert(getKind() == Array);
17135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      return Data >> 2;
17145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    }
17152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
17162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    /// \brief For a field offsetof node, returns the field.
17172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    FieldDecl *getField() const {
17182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      assert(getKind() == Field);
17192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      return reinterpret_cast<FieldDecl *>(Data & ~(uintptr_t)Mask);
17202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    }
17212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
17222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    /// \brief For a field or identifier offsetof node, returns the name of
17232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    /// the field.
17242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    IdentifierInfo *getFieldName() const;
17251e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
17262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    /// \brief For a base class node, returns the base specifier.
17272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    CXXBaseSpecifier *getBase() const {
17285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      assert(getKind() == Base);
17295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      return reinterpret_cast<CXXBaseSpecifier *>(Data & ~(uintptr_t)Mask);
17305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    }
17315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
17325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    /// \brief Retrieve the source range that covers this offsetof node.
17335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    ///
17345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    /// For an array element node, the source range contains the locations of
17355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    /// the square brackets. For a field or identifier node, the source range
17365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    /// contains the location of the period (if there is one) and the
17375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    /// identifier.
17385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    SourceRange getSourceRange() const LLVM_READONLY { return Range; }
17395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  };
17405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
17415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)private:
17425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
17435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  SourceLocation OperatorLoc, RParenLoc;
17445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Base type;
17455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  TypeSourceInfo *TSInfo;
17465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Number of sub-components (i.e. instances of OffsetOfNode).
17475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  unsigned NumComps;
17485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Number of sub-expressions (i.e. array subscript expressions).
17495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  unsigned NumExprs;
1750
1751  OffsetOfExpr(ASTContext &C, QualType type,
1752               SourceLocation OperatorLoc, TypeSourceInfo *tsi,
1753               OffsetOfNode* compsPtr, unsigned numComps,
1754               Expr** exprsPtr, unsigned numExprs,
1755               SourceLocation RParenLoc);
1756
1757  explicit OffsetOfExpr(unsigned numComps, unsigned numExprs)
1758    : Expr(OffsetOfExprClass, EmptyShell()),
1759      TSInfo(0), NumComps(numComps), NumExprs(numExprs) {}
1760
1761public:
1762
1763  static OffsetOfExpr *Create(ASTContext &C, QualType type,
1764                              SourceLocation OperatorLoc, TypeSourceInfo *tsi,
1765                              OffsetOfNode* compsPtr, unsigned numComps,
1766                              Expr** exprsPtr, unsigned numExprs,
1767                              SourceLocation RParenLoc);
1768
1769  static OffsetOfExpr *CreateEmpty(ASTContext &C,
1770                                   unsigned NumComps, unsigned NumExprs);
1771
1772  /// getOperatorLoc - Return the location of the operator.
1773  SourceLocation getOperatorLoc() const { return OperatorLoc; }
1774  void setOperatorLoc(SourceLocation L) { OperatorLoc = L; }
1775
1776  /// \brief Return the location of the right parentheses.
1777  SourceLocation getRParenLoc() const { return RParenLoc; }
1778  void setRParenLoc(SourceLocation R) { RParenLoc = R; }
1779
1780  TypeSourceInfo *getTypeSourceInfo() const {
1781    return TSInfo;
1782  }
1783  void setTypeSourceInfo(TypeSourceInfo *tsi) {
1784    TSInfo = tsi;
1785  }
1786
1787  const OffsetOfNode &getComponent(unsigned Idx) const {
1788    assert(Idx < NumComps && "Subscript out of range");
1789    return reinterpret_cast<const OffsetOfNode *> (this + 1)[Idx];
1790  }
1791
1792  void setComponent(unsigned Idx, OffsetOfNode ON) {
1793    assert(Idx < NumComps && "Subscript out of range");
1794    reinterpret_cast<OffsetOfNode *> (this + 1)[Idx] = ON;
1795  }
1796
1797  unsigned getNumComponents() const {
1798    return NumComps;
1799  }
1800
1801  Expr* getIndexExpr(unsigned Idx) {
1802    assert(Idx < NumExprs && "Subscript out of range");
1803    return reinterpret_cast<Expr **>(
1804                    reinterpret_cast<OffsetOfNode *>(this+1) + NumComps)[Idx];
1805  }
1806  const Expr *getIndexExpr(unsigned Idx) const {
1807    return const_cast<OffsetOfExpr*>(this)->getIndexExpr(Idx);
1808  }
1809
1810  void setIndexExpr(unsigned Idx, Expr* E) {
1811    assert(Idx < NumComps && "Subscript out of range");
1812    reinterpret_cast<Expr **>(
1813                reinterpret_cast<OffsetOfNode *>(this+1) + NumComps)[Idx] = E;
1814  }
1815
1816  unsigned getNumExpressions() const {
1817    return NumExprs;
1818  }
1819
1820  SourceRange getSourceRange() const LLVM_READONLY {
1821    return SourceRange(OperatorLoc, RParenLoc);
1822  }
1823
1824  static bool classof(const Stmt *T) {
1825    return T->getStmtClass() == OffsetOfExprClass;
1826  }
1827
1828  static bool classof(const OffsetOfExpr *) { return true; }
1829
1830  // Iterators
1831  child_range children() {
1832    Stmt **begin =
1833      reinterpret_cast<Stmt**>(reinterpret_cast<OffsetOfNode*>(this + 1)
1834                               + NumComps);
1835    return child_range(begin, begin + NumExprs);
1836  }
1837};
1838
1839/// UnaryExprOrTypeTraitExpr - expression with either a type or (unevaluated)
1840/// expression operand.  Used for sizeof/alignof (C99 6.5.3.4) and
1841/// vec_step (OpenCL 1.1 6.11.12).
1842class UnaryExprOrTypeTraitExpr : public Expr {
1843  union {
1844    TypeSourceInfo *Ty;
1845    Stmt *Ex;
1846  } Argument;
1847  SourceLocation OpLoc, RParenLoc;
1848
1849public:
1850  UnaryExprOrTypeTraitExpr(UnaryExprOrTypeTrait ExprKind, TypeSourceInfo *TInfo,
1851                           QualType resultType, SourceLocation op,
1852                           SourceLocation rp) :
1853      Expr(UnaryExprOrTypeTraitExprClass, resultType, VK_RValue, OK_Ordinary,
1854           false, // Never type-dependent (C++ [temp.dep.expr]p3).
1855           // Value-dependent if the argument is type-dependent.
1856           TInfo->getType()->isDependentType(),
1857           TInfo->getType()->isInstantiationDependentType(),
1858           TInfo->getType()->containsUnexpandedParameterPack()),
1859      OpLoc(op), RParenLoc(rp) {
1860    UnaryExprOrTypeTraitExprBits.Kind = ExprKind;
1861    UnaryExprOrTypeTraitExprBits.IsType = true;
1862    Argument.Ty = TInfo;
1863  }
1864
1865  UnaryExprOrTypeTraitExpr(UnaryExprOrTypeTrait ExprKind, Expr *E,
1866                           QualType resultType, SourceLocation op,
1867                           SourceLocation rp) :
1868      Expr(UnaryExprOrTypeTraitExprClass, resultType, VK_RValue, OK_Ordinary,
1869           false, // Never type-dependent (C++ [temp.dep.expr]p3).
1870           // Value-dependent if the argument is type-dependent.
1871           E->isTypeDependent(),
1872           E->isInstantiationDependent(),
1873           E->containsUnexpandedParameterPack()),
1874      OpLoc(op), RParenLoc(rp) {
1875    UnaryExprOrTypeTraitExprBits.Kind = ExprKind;
1876    UnaryExprOrTypeTraitExprBits.IsType = false;
1877    Argument.Ex = E;
1878  }
1879
1880  /// \brief Construct an empty sizeof/alignof expression.
1881  explicit UnaryExprOrTypeTraitExpr(EmptyShell Empty)
1882    : Expr(UnaryExprOrTypeTraitExprClass, Empty) { }
1883
1884  UnaryExprOrTypeTrait getKind() const {
1885    return static_cast<UnaryExprOrTypeTrait>(UnaryExprOrTypeTraitExprBits.Kind);
1886  }
1887  void setKind(UnaryExprOrTypeTrait K) { UnaryExprOrTypeTraitExprBits.Kind = K;}
1888
1889  bool isArgumentType() const { return UnaryExprOrTypeTraitExprBits.IsType; }
1890  QualType getArgumentType() const {
1891    return getArgumentTypeInfo()->getType();
1892  }
1893  TypeSourceInfo *getArgumentTypeInfo() const {
1894    assert(isArgumentType() && "calling getArgumentType() when arg is expr");
1895    return Argument.Ty;
1896  }
1897  Expr *getArgumentExpr() {
1898    assert(!isArgumentType() && "calling getArgumentExpr() when arg is type");
1899    return static_cast<Expr*>(Argument.Ex);
1900  }
1901  const Expr *getArgumentExpr() const {
1902    return const_cast<UnaryExprOrTypeTraitExpr*>(this)->getArgumentExpr();
1903  }
1904
1905  void setArgument(Expr *E) {
1906    Argument.Ex = E;
1907    UnaryExprOrTypeTraitExprBits.IsType = false;
1908  }
1909  void setArgument(TypeSourceInfo *TInfo) {
1910    Argument.Ty = TInfo;
1911    UnaryExprOrTypeTraitExprBits.IsType = true;
1912  }
1913
1914  /// Gets the argument type, or the type of the argument expression, whichever
1915  /// is appropriate.
1916  QualType getTypeOfArgument() const {
1917    return isArgumentType() ? getArgumentType() : getArgumentExpr()->getType();
1918  }
1919
1920  SourceLocation getOperatorLoc() const { return OpLoc; }
1921  void setOperatorLoc(SourceLocation L) { OpLoc = L; }
1922
1923  SourceLocation getRParenLoc() const { return RParenLoc; }
1924  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
1925
1926  SourceRange getSourceRange() const LLVM_READONLY {
1927    return SourceRange(OpLoc, RParenLoc);
1928  }
1929
1930  static bool classof(const Stmt *T) {
1931    return T->getStmtClass() == UnaryExprOrTypeTraitExprClass;
1932  }
1933  static bool classof(const UnaryExprOrTypeTraitExpr *) { return true; }
1934
1935  // Iterators
1936  child_range children();
1937};
1938
1939//===----------------------------------------------------------------------===//
1940// Postfix Operators.
1941//===----------------------------------------------------------------------===//
1942
1943/// ArraySubscriptExpr - [C99 6.5.2.1] Array Subscripting.
1944class ArraySubscriptExpr : public Expr {
1945  enum { LHS, RHS, END_EXPR=2 };
1946  Stmt* SubExprs[END_EXPR];
1947  SourceLocation RBracketLoc;
1948public:
1949  ArraySubscriptExpr(Expr *lhs, Expr *rhs, QualType t,
1950                     ExprValueKind VK, ExprObjectKind OK,
1951                     SourceLocation rbracketloc)
1952  : Expr(ArraySubscriptExprClass, t, VK, OK,
1953         lhs->isTypeDependent() || rhs->isTypeDependent(),
1954         lhs->isValueDependent() || rhs->isValueDependent(),
1955         (lhs->isInstantiationDependent() ||
1956          rhs->isInstantiationDependent()),
1957         (lhs->containsUnexpandedParameterPack() ||
1958          rhs->containsUnexpandedParameterPack())),
1959    RBracketLoc(rbracketloc) {
1960    SubExprs[LHS] = lhs;
1961    SubExprs[RHS] = rhs;
1962  }
1963
1964  /// \brief Create an empty array subscript expression.
1965  explicit ArraySubscriptExpr(EmptyShell Shell)
1966    : Expr(ArraySubscriptExprClass, Shell) { }
1967
1968  /// An array access can be written A[4] or 4[A] (both are equivalent).
1969  /// - getBase() and getIdx() always present the normalized view: A[4].
1970  ///    In this case getBase() returns "A" and getIdx() returns "4".
1971  /// - getLHS() and getRHS() present the syntactic view. e.g. for
1972  ///    4[A] getLHS() returns "4".
1973  /// Note: Because vector element access is also written A[4] we must
1974  /// predicate the format conversion in getBase and getIdx only on the
1975  /// the type of the RHS, as it is possible for the LHS to be a vector of
1976  /// integer type
1977  Expr *getLHS() { return cast<Expr>(SubExprs[LHS]); }
1978  const Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); }
1979  void setLHS(Expr *E) { SubExprs[LHS] = E; }
1980
1981  Expr *getRHS() { return cast<Expr>(SubExprs[RHS]); }
1982  const Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); }
1983  void setRHS(Expr *E) { SubExprs[RHS] = E; }
1984
1985  Expr *getBase() {
1986    return cast<Expr>(getRHS()->getType()->isIntegerType() ? getLHS():getRHS());
1987  }
1988
1989  const Expr *getBase() const {
1990    return cast<Expr>(getRHS()->getType()->isIntegerType() ? getLHS():getRHS());
1991  }
1992
1993  Expr *getIdx() {
1994    return cast<Expr>(getRHS()->getType()->isIntegerType() ? getRHS():getLHS());
1995  }
1996
1997  const Expr *getIdx() const {
1998    return cast<Expr>(getRHS()->getType()->isIntegerType() ? getRHS():getLHS());
1999  }
2000
2001  SourceRange getSourceRange() const LLVM_READONLY {
2002    return SourceRange(getLHS()->getLocStart(), RBracketLoc);
2003  }
2004
2005  SourceLocation getRBracketLoc() const { return RBracketLoc; }
2006  void setRBracketLoc(SourceLocation L) { RBracketLoc = L; }
2007
2008  SourceLocation getExprLoc() const LLVM_READONLY { return getBase()->getExprLoc(); }
2009
2010  static bool classof(const Stmt *T) {
2011    return T->getStmtClass() == ArraySubscriptExprClass;
2012  }
2013  static bool classof(const ArraySubscriptExpr *) { return true; }
2014
2015  // Iterators
2016  child_range children() {
2017    return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR);
2018  }
2019};
2020
2021
2022/// CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
2023/// CallExpr itself represents a normal function call, e.g., "f(x, 2)",
2024/// while its subclasses may represent alternative syntax that (semantically)
2025/// results in a function call. For example, CXXOperatorCallExpr is
2026/// a subclass for overloaded operator calls that use operator syntax, e.g.,
2027/// "str1 + str2" to resolve to a function call.
2028class CallExpr : public Expr {
2029  enum { FN=0, PREARGS_START=1 };
2030  Stmt **SubExprs;
2031  unsigned NumArgs;
2032  SourceLocation RParenLoc;
2033
2034protected:
2035  // These versions of the constructor are for derived classes.
2036  CallExpr(ASTContext& C, StmtClass SC, Expr *fn, unsigned NumPreArgs,
2037           Expr **args, unsigned numargs, QualType t, ExprValueKind VK,
2038           SourceLocation rparenloc);
2039  CallExpr(ASTContext &C, StmtClass SC, unsigned NumPreArgs, EmptyShell Empty);
2040
2041  Stmt *getPreArg(unsigned i) {
2042    assert(i < getNumPreArgs() && "Prearg access out of range!");
2043    return SubExprs[PREARGS_START+i];
2044  }
2045  const Stmt *getPreArg(unsigned i) const {
2046    assert(i < getNumPreArgs() && "Prearg access out of range!");
2047    return SubExprs[PREARGS_START+i];
2048  }
2049  void setPreArg(unsigned i, Stmt *PreArg) {
2050    assert(i < getNumPreArgs() && "Prearg access out of range!");
2051    SubExprs[PREARGS_START+i] = PreArg;
2052  }
2053
2054  unsigned getNumPreArgs() const { return CallExprBits.NumPreArgs; }
2055
2056public:
2057  CallExpr(ASTContext& C, Expr *fn, Expr **args, unsigned numargs, QualType t,
2058           ExprValueKind VK, SourceLocation rparenloc);
2059
2060  /// \brief Build an empty call expression.
2061  CallExpr(ASTContext &C, StmtClass SC, EmptyShell Empty);
2062
2063  const Expr *getCallee() const { return cast<Expr>(SubExprs[FN]); }
2064  Expr *getCallee() { return cast<Expr>(SubExprs[FN]); }
2065  void setCallee(Expr *F) { SubExprs[FN] = F; }
2066
2067  Decl *getCalleeDecl();
2068  const Decl *getCalleeDecl() const {
2069    return const_cast<CallExpr*>(this)->getCalleeDecl();
2070  }
2071
2072  /// \brief If the callee is a FunctionDecl, return it. Otherwise return 0.
2073  FunctionDecl *getDirectCallee();
2074  const FunctionDecl *getDirectCallee() const {
2075    return const_cast<CallExpr*>(this)->getDirectCallee();
2076  }
2077
2078  /// getNumArgs - Return the number of actual arguments to this call.
2079  ///
2080  unsigned getNumArgs() const { return NumArgs; }
2081
2082  /// \brief Retrieve the call arguments.
2083  Expr **getArgs() {
2084    return reinterpret_cast<Expr **>(SubExprs+getNumPreArgs()+PREARGS_START);
2085  }
2086  const Expr *const *getArgs() const {
2087    return const_cast<CallExpr*>(this)->getArgs();
2088  }
2089
2090  /// getArg - Return the specified argument.
2091  Expr *getArg(unsigned Arg) {
2092    assert(Arg < NumArgs && "Arg access out of range!");
2093    return cast<Expr>(SubExprs[Arg+getNumPreArgs()+PREARGS_START]);
2094  }
2095  const Expr *getArg(unsigned Arg) const {
2096    assert(Arg < NumArgs && "Arg access out of range!");
2097    return cast<Expr>(SubExprs[Arg+getNumPreArgs()+PREARGS_START]);
2098  }
2099
2100  /// setArg - Set the specified argument.
2101  void setArg(unsigned Arg, Expr *ArgExpr) {
2102    assert(Arg < NumArgs && "Arg access out of range!");
2103    SubExprs[Arg+getNumPreArgs()+PREARGS_START] = ArgExpr;
2104  }
2105
2106  /// setNumArgs - This changes the number of arguments present in this call.
2107  /// Any orphaned expressions are deleted by this, and any new operands are set
2108  /// to null.
2109  void setNumArgs(ASTContext& C, unsigned NumArgs);
2110
2111  typedef ExprIterator arg_iterator;
2112  typedef ConstExprIterator const_arg_iterator;
2113
2114  arg_iterator arg_begin() { return SubExprs+PREARGS_START+getNumPreArgs(); }
2115  arg_iterator arg_end() {
2116    return SubExprs+PREARGS_START+getNumPreArgs()+getNumArgs();
2117  }
2118  const_arg_iterator arg_begin() const {
2119    return SubExprs+PREARGS_START+getNumPreArgs();
2120  }
2121  const_arg_iterator arg_end() const {
2122    return SubExprs+PREARGS_START+getNumPreArgs()+getNumArgs();
2123  }
2124
2125  /// getNumCommas - Return the number of commas that must have been present in
2126  /// this function call.
2127  unsigned getNumCommas() const { return NumArgs ? NumArgs - 1 : 0; }
2128
2129  /// isBuiltinCall - If this is a call to a builtin, return the builtin ID.  If
2130  /// not, return 0.
2131  unsigned isBuiltinCall() const;
2132
2133  /// getCallReturnType - Get the return type of the call expr. This is not
2134  /// always the type of the expr itself, if the return type is a reference
2135  /// type.
2136  QualType getCallReturnType() const;
2137
2138  SourceLocation getRParenLoc() const { return RParenLoc; }
2139  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
2140
2141  SourceRange getSourceRange() const LLVM_READONLY;
2142  SourceLocation getLocStart() const LLVM_READONLY;
2143  SourceLocation getLocEnd() const LLVM_READONLY;
2144
2145  static bool classof(const Stmt *T) {
2146    return T->getStmtClass() >= firstCallExprConstant &&
2147           T->getStmtClass() <= lastCallExprConstant;
2148  }
2149  static bool classof(const CallExpr *) { return true; }
2150
2151  // Iterators
2152  child_range children() {
2153    return child_range(&SubExprs[0],
2154                       &SubExprs[0]+NumArgs+getNumPreArgs()+PREARGS_START);
2155  }
2156};
2157
2158/// MemberExpr - [C99 6.5.2.3] Structure and Union Members.  X->F and X.F.
2159///
2160class MemberExpr : public Expr {
2161  /// Extra data stored in some member expressions.
2162  struct MemberNameQualifier {
2163    /// \brief The nested-name-specifier that qualifies the name, including
2164    /// source-location information.
2165    NestedNameSpecifierLoc QualifierLoc;
2166
2167    /// \brief The DeclAccessPair through which the MemberDecl was found due to
2168    /// name qualifiers.
2169    DeclAccessPair FoundDecl;
2170  };
2171
2172  /// Base - the expression for the base pointer or structure references.  In
2173  /// X.F, this is "X".
2174  Stmt *Base;
2175
2176  /// MemberDecl - This is the decl being referenced by the field/member name.
2177  /// In X.F, this is the decl referenced by F.
2178  ValueDecl *MemberDecl;
2179
2180  /// MemberDNLoc - Provides source/type location info for the
2181  /// declaration name embedded in MemberDecl.
2182  DeclarationNameLoc MemberDNLoc;
2183
2184  /// MemberLoc - This is the location of the member name.
2185  SourceLocation MemberLoc;
2186
2187  /// IsArrow - True if this is "X->F", false if this is "X.F".
2188  bool IsArrow : 1;
2189
2190  /// \brief True if this member expression used a nested-name-specifier to
2191  /// refer to the member, e.g., "x->Base::f", or found its member via a using
2192  /// declaration.  When true, a MemberNameQualifier
2193  /// structure is allocated immediately after the MemberExpr.
2194  bool HasQualifierOrFoundDecl : 1;
2195
2196  /// \brief True if this member expression specified a template keyword
2197  /// and/or a template argument list explicitly, e.g., x->f<int>,
2198  /// x->template f, x->template f<int>.
2199  /// When true, an ASTTemplateKWAndArgsInfo structure and its
2200  /// TemplateArguments (if any) are allocated immediately after
2201  /// the MemberExpr or, if the member expression also has a qualifier,
2202  /// after the MemberNameQualifier structure.
2203  bool HasTemplateKWAndArgsInfo : 1;
2204
2205  /// \brief True if this member expression refers to a method that
2206  /// was resolved from an overloaded set having size greater than 1.
2207  bool HadMultipleCandidates : 1;
2208
2209  /// \brief Retrieve the qualifier that preceded the member name, if any.
2210  MemberNameQualifier *getMemberQualifier() {
2211    assert(HasQualifierOrFoundDecl);
2212    return reinterpret_cast<MemberNameQualifier *> (this + 1);
2213  }
2214
2215  /// \brief Retrieve the qualifier that preceded the member name, if any.
2216  const MemberNameQualifier *getMemberQualifier() const {
2217    return const_cast<MemberExpr *>(this)->getMemberQualifier();
2218  }
2219
2220public:
2221  MemberExpr(Expr *base, bool isarrow, ValueDecl *memberdecl,
2222             const DeclarationNameInfo &NameInfo, QualType ty,
2223             ExprValueKind VK, ExprObjectKind OK)
2224    : Expr(MemberExprClass, ty, VK, OK,
2225           base->isTypeDependent(),
2226           base->isValueDependent(),
2227           base->isInstantiationDependent(),
2228           base->containsUnexpandedParameterPack()),
2229      Base(base), MemberDecl(memberdecl), MemberDNLoc(NameInfo.getInfo()),
2230      MemberLoc(NameInfo.getLoc()), IsArrow(isarrow),
2231      HasQualifierOrFoundDecl(false), HasTemplateKWAndArgsInfo(false),
2232      HadMultipleCandidates(false) {
2233    assert(memberdecl->getDeclName() == NameInfo.getName());
2234  }
2235
2236  // NOTE: this constructor should be used only when it is known that
2237  // the member name can not provide additional syntactic info
2238  // (i.e., source locations for C++ operator names or type source info
2239  // for constructors, destructors and conversion operators).
2240  MemberExpr(Expr *base, bool isarrow, ValueDecl *memberdecl,
2241             SourceLocation l, QualType ty,
2242             ExprValueKind VK, ExprObjectKind OK)
2243    : Expr(MemberExprClass, ty, VK, OK,
2244           base->isTypeDependent(), base->isValueDependent(),
2245           base->isInstantiationDependent(),
2246           base->containsUnexpandedParameterPack()),
2247      Base(base), MemberDecl(memberdecl), MemberDNLoc(), MemberLoc(l),
2248      IsArrow(isarrow),
2249      HasQualifierOrFoundDecl(false), HasTemplateKWAndArgsInfo(false),
2250      HadMultipleCandidates(false) {}
2251
2252  static MemberExpr *Create(ASTContext &C, Expr *base, bool isarrow,
2253                            NestedNameSpecifierLoc QualifierLoc,
2254                            SourceLocation TemplateKWLoc,
2255                            ValueDecl *memberdecl, DeclAccessPair founddecl,
2256                            DeclarationNameInfo MemberNameInfo,
2257                            const TemplateArgumentListInfo *targs,
2258                            QualType ty, ExprValueKind VK, ExprObjectKind OK);
2259
2260  void setBase(Expr *E) { Base = E; }
2261  Expr *getBase() const { return cast<Expr>(Base); }
2262
2263  /// \brief Retrieve the member declaration to which this expression refers.
2264  ///
2265  /// The returned declaration will either be a FieldDecl or (in C++)
2266  /// a CXXMethodDecl.
2267  ValueDecl *getMemberDecl() const { return MemberDecl; }
2268  void setMemberDecl(ValueDecl *D) { MemberDecl = D; }
2269
2270  /// \brief Retrieves the declaration found by lookup.
2271  DeclAccessPair getFoundDecl() const {
2272    if (!HasQualifierOrFoundDecl)
2273      return DeclAccessPair::make(getMemberDecl(),
2274                                  getMemberDecl()->getAccess());
2275    return getMemberQualifier()->FoundDecl;
2276  }
2277
2278  /// \brief Determines whether this member expression actually had
2279  /// a C++ nested-name-specifier prior to the name of the member, e.g.,
2280  /// x->Base::foo.
2281  bool hasQualifier() const { return getQualifier() != 0; }
2282
2283  /// \brief If the member name was qualified, retrieves the
2284  /// nested-name-specifier that precedes the member name. Otherwise, returns
2285  /// NULL.
2286  NestedNameSpecifier *getQualifier() const {
2287    if (!HasQualifierOrFoundDecl)
2288      return 0;
2289
2290    return getMemberQualifier()->QualifierLoc.getNestedNameSpecifier();
2291  }
2292
2293  /// \brief If the member name was qualified, retrieves the
2294  /// nested-name-specifier that precedes the member name, with source-location
2295  /// information.
2296  NestedNameSpecifierLoc getQualifierLoc() const {
2297    if (!hasQualifier())
2298      return NestedNameSpecifierLoc();
2299
2300    return getMemberQualifier()->QualifierLoc;
2301  }
2302
2303  /// \brief Return the optional template keyword and arguments info.
2304  ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo() {
2305    if (!HasTemplateKWAndArgsInfo)
2306      return 0;
2307
2308    if (!HasQualifierOrFoundDecl)
2309      return reinterpret_cast<ASTTemplateKWAndArgsInfo *>(this + 1);
2310
2311    return reinterpret_cast<ASTTemplateKWAndArgsInfo *>(
2312                                                      getMemberQualifier() + 1);
2313  }
2314
2315  /// \brief Return the optional template keyword and arguments info.
2316  const ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo() const {
2317    return const_cast<MemberExpr*>(this)->getTemplateKWAndArgsInfo();
2318  }
2319
2320  /// \brief Retrieve the location of the template keyword preceding
2321  /// the member name, if any.
2322  SourceLocation getTemplateKeywordLoc() const {
2323    if (!HasTemplateKWAndArgsInfo) return SourceLocation();
2324    return getTemplateKWAndArgsInfo()->getTemplateKeywordLoc();
2325  }
2326
2327  /// \brief Retrieve the location of the left angle bracket starting the
2328  /// explicit template argument list following the member name, if any.
2329  SourceLocation getLAngleLoc() const {
2330    if (!HasTemplateKWAndArgsInfo) return SourceLocation();
2331    return getTemplateKWAndArgsInfo()->LAngleLoc;
2332  }
2333
2334  /// \brief Retrieve the location of the right angle bracket ending the
2335  /// explicit template argument list following the member name, if any.
2336  SourceLocation getRAngleLoc() const {
2337    if (!HasTemplateKWAndArgsInfo) return SourceLocation();
2338    return getTemplateKWAndArgsInfo()->RAngleLoc;
2339  }
2340
2341  /// Determines whether the member name was preceded by the template keyword.
2342  bool hasTemplateKeyword() const { return getTemplateKeywordLoc().isValid(); }
2343
2344  /// \brief Determines whether the member name was followed by an
2345  /// explicit template argument list.
2346  bool hasExplicitTemplateArgs() const { return getLAngleLoc().isValid(); }
2347
2348  /// \brief Copies the template arguments (if present) into the given
2349  /// structure.
2350  void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
2351    if (hasExplicitTemplateArgs())
2352      getExplicitTemplateArgs().copyInto(List);
2353  }
2354
2355  /// \brief Retrieve the explicit template argument list that
2356  /// follow the member template name.  This must only be called on an
2357  /// expression with explicit template arguments.
2358  ASTTemplateArgumentListInfo &getExplicitTemplateArgs() {
2359    assert(hasExplicitTemplateArgs());
2360    return *getTemplateKWAndArgsInfo();
2361  }
2362
2363  /// \brief Retrieve the explicit template argument list that
2364  /// followed the member template name.  This must only be called on
2365  /// an expression with explicit template arguments.
2366  const ASTTemplateArgumentListInfo &getExplicitTemplateArgs() const {
2367    return const_cast<MemberExpr *>(this)->getExplicitTemplateArgs();
2368  }
2369
2370  /// \brief Retrieves the optional explicit template arguments.
2371  /// This points to the same data as getExplicitTemplateArgs(), but
2372  /// returns null if there are no explicit template arguments.
2373  const ASTTemplateArgumentListInfo *getOptionalExplicitTemplateArgs() const {
2374    if (!hasExplicitTemplateArgs()) return 0;
2375    return &getExplicitTemplateArgs();
2376  }
2377
2378  /// \brief Retrieve the template arguments provided as part of this
2379  /// template-id.
2380  const TemplateArgumentLoc *getTemplateArgs() const {
2381    if (!hasExplicitTemplateArgs())
2382      return 0;
2383
2384    return getExplicitTemplateArgs().getTemplateArgs();
2385  }
2386
2387  /// \brief Retrieve the number of template arguments provided as part of this
2388  /// template-id.
2389  unsigned getNumTemplateArgs() const {
2390    if (!hasExplicitTemplateArgs())
2391      return 0;
2392
2393    return getExplicitTemplateArgs().NumTemplateArgs;
2394  }
2395
2396  /// \brief Retrieve the member declaration name info.
2397  DeclarationNameInfo getMemberNameInfo() const {
2398    return DeclarationNameInfo(MemberDecl->getDeclName(),
2399                               MemberLoc, MemberDNLoc);
2400  }
2401
2402  bool isArrow() const { return IsArrow; }
2403  void setArrow(bool A) { IsArrow = A; }
2404
2405  /// getMemberLoc - Return the location of the "member", in X->F, it is the
2406  /// location of 'F'.
2407  SourceLocation getMemberLoc() const { return MemberLoc; }
2408  void setMemberLoc(SourceLocation L) { MemberLoc = L; }
2409
2410  SourceRange getSourceRange() const LLVM_READONLY;
2411  SourceLocation getLocStart() const LLVM_READONLY;
2412  SourceLocation getLocEnd() const LLVM_READONLY;
2413
2414  SourceLocation getExprLoc() const LLVM_READONLY { return MemberLoc; }
2415
2416  /// \brief Determine whether the base of this explicit is implicit.
2417  bool isImplicitAccess() const {
2418    return getBase() && getBase()->isImplicitCXXThis();
2419  }
2420
2421  /// \brief Returns true if this member expression refers to a method that
2422  /// was resolved from an overloaded set having size greater than 1.
2423  bool hadMultipleCandidates() const {
2424    return HadMultipleCandidates;
2425  }
2426  /// \brief Sets the flag telling whether this expression refers to
2427  /// a method that was resolved from an overloaded set having size
2428  /// greater than 1.
2429  void setHadMultipleCandidates(bool V = true) {
2430    HadMultipleCandidates = V;
2431  }
2432
2433  static bool classof(const Stmt *T) {
2434    return T->getStmtClass() == MemberExprClass;
2435  }
2436  static bool classof(const MemberExpr *) { return true; }
2437
2438  // Iterators
2439  child_range children() { return child_range(&Base, &Base+1); }
2440
2441  friend class ASTReader;
2442  friend class ASTStmtWriter;
2443};
2444
2445/// CompoundLiteralExpr - [C99 6.5.2.5]
2446///
2447class CompoundLiteralExpr : public Expr {
2448  /// LParenLoc - If non-null, this is the location of the left paren in a
2449  /// compound literal like "(int){4}".  This can be null if this is a
2450  /// synthesized compound expression.
2451  SourceLocation LParenLoc;
2452
2453  /// The type as written.  This can be an incomplete array type, in
2454  /// which case the actual expression type will be different.
2455  /// The int part of the pair stores whether this expr is file scope.
2456  llvm::PointerIntPair<TypeSourceInfo *, 1, bool> TInfoAndScope;
2457  Stmt *Init;
2458public:
2459  CompoundLiteralExpr(SourceLocation lparenloc, TypeSourceInfo *tinfo,
2460                      QualType T, ExprValueKind VK, Expr *init, bool fileScope)
2461    : Expr(CompoundLiteralExprClass, T, VK, OK_Ordinary,
2462           tinfo->getType()->isDependentType(),
2463           init->isValueDependent(),
2464           (init->isInstantiationDependent() ||
2465            tinfo->getType()->isInstantiationDependentType()),
2466           init->containsUnexpandedParameterPack()),
2467      LParenLoc(lparenloc), TInfoAndScope(tinfo, fileScope), Init(init) {}
2468
2469  /// \brief Construct an empty compound literal.
2470  explicit CompoundLiteralExpr(EmptyShell Empty)
2471    : Expr(CompoundLiteralExprClass, Empty) { }
2472
2473  const Expr *getInitializer() const { return cast<Expr>(Init); }
2474  Expr *getInitializer() { return cast<Expr>(Init); }
2475  void setInitializer(Expr *E) { Init = E; }
2476
2477  bool isFileScope() const { return TInfoAndScope.getInt(); }
2478  void setFileScope(bool FS) { TInfoAndScope.setInt(FS); }
2479
2480  SourceLocation getLParenLoc() const { return LParenLoc; }
2481  void setLParenLoc(SourceLocation L) { LParenLoc = L; }
2482
2483  TypeSourceInfo *getTypeSourceInfo() const {
2484    return TInfoAndScope.getPointer();
2485  }
2486  void setTypeSourceInfo(TypeSourceInfo *tinfo) {
2487    TInfoAndScope.setPointer(tinfo);
2488  }
2489
2490  SourceRange getSourceRange() const LLVM_READONLY {
2491    // FIXME: Init should never be null.
2492    if (!Init)
2493      return SourceRange();
2494    if (LParenLoc.isInvalid())
2495      return Init->getSourceRange();
2496    return SourceRange(LParenLoc, Init->getLocEnd());
2497  }
2498
2499  static bool classof(const Stmt *T) {
2500    return T->getStmtClass() == CompoundLiteralExprClass;
2501  }
2502  static bool classof(const CompoundLiteralExpr *) { return true; }
2503
2504  // Iterators
2505  child_range children() { return child_range(&Init, &Init+1); }
2506};
2507
2508/// CastExpr - Base class for type casts, including both implicit
2509/// casts (ImplicitCastExpr) and explicit casts that have some
2510/// representation in the source code (ExplicitCastExpr's derived
2511/// classes).
2512class CastExpr : public Expr {
2513public:
2514  typedef clang::CastKind CastKind;
2515
2516private:
2517  Stmt *Op;
2518
2519  void CheckCastConsistency() const;
2520
2521  const CXXBaseSpecifier * const *path_buffer() const {
2522    return const_cast<CastExpr*>(this)->path_buffer();
2523  }
2524  CXXBaseSpecifier **path_buffer();
2525
2526  void setBasePathSize(unsigned basePathSize) {
2527    CastExprBits.BasePathSize = basePathSize;
2528    assert(CastExprBits.BasePathSize == basePathSize &&
2529           "basePathSize doesn't fit in bits of CastExprBits.BasePathSize!");
2530  }
2531
2532protected:
2533  CastExpr(StmtClass SC, QualType ty, ExprValueKind VK,
2534           const CastKind kind, Expr *op, unsigned BasePathSize) :
2535    Expr(SC, ty, VK, OK_Ordinary,
2536         // Cast expressions are type-dependent if the type is
2537         // dependent (C++ [temp.dep.expr]p3).
2538         ty->isDependentType(),
2539         // Cast expressions are value-dependent if the type is
2540         // dependent or if the subexpression is value-dependent.
2541         ty->isDependentType() || (op && op->isValueDependent()),
2542         (ty->isInstantiationDependentType() ||
2543          (op && op->isInstantiationDependent())),
2544         (ty->containsUnexpandedParameterPack() ||
2545          op->containsUnexpandedParameterPack())),
2546    Op(op) {
2547    assert(kind != CK_Invalid && "creating cast with invalid cast kind");
2548    CastExprBits.Kind = kind;
2549    setBasePathSize(BasePathSize);
2550#ifndef NDEBUG
2551    CheckCastConsistency();
2552#endif
2553  }
2554
2555  /// \brief Construct an empty cast.
2556  CastExpr(StmtClass SC, EmptyShell Empty, unsigned BasePathSize)
2557    : Expr(SC, Empty) {
2558    setBasePathSize(BasePathSize);
2559  }
2560
2561public:
2562  CastKind getCastKind() const { return (CastKind) CastExprBits.Kind; }
2563  void setCastKind(CastKind K) { CastExprBits.Kind = K; }
2564  const char *getCastKindName() const;
2565
2566  Expr *getSubExpr() { return cast<Expr>(Op); }
2567  const Expr *getSubExpr() const { return cast<Expr>(Op); }
2568  void setSubExpr(Expr *E) { Op = E; }
2569
2570  /// \brief Retrieve the cast subexpression as it was written in the source
2571  /// code, looking through any implicit casts or other intermediate nodes
2572  /// introduced by semantic analysis.
2573  Expr *getSubExprAsWritten();
2574  const Expr *getSubExprAsWritten() const {
2575    return const_cast<CastExpr *>(this)->getSubExprAsWritten();
2576  }
2577
2578  typedef CXXBaseSpecifier **path_iterator;
2579  typedef const CXXBaseSpecifier * const *path_const_iterator;
2580  bool path_empty() const { return CastExprBits.BasePathSize == 0; }
2581  unsigned path_size() const { return CastExprBits.BasePathSize; }
2582  path_iterator path_begin() { return path_buffer(); }
2583  path_iterator path_end() { return path_buffer() + path_size(); }
2584  path_const_iterator path_begin() const { return path_buffer(); }
2585  path_const_iterator path_end() const { return path_buffer() + path_size(); }
2586
2587  void setCastPath(const CXXCastPath &Path);
2588
2589  static bool classof(const Stmt *T) {
2590    return T->getStmtClass() >= firstCastExprConstant &&
2591           T->getStmtClass() <= lastCastExprConstant;
2592  }
2593  static bool classof(const CastExpr *) { return true; }
2594
2595  // Iterators
2596  child_range children() { return child_range(&Op, &Op+1); }
2597};
2598
2599/// ImplicitCastExpr - Allows us to explicitly represent implicit type
2600/// conversions, which have no direct representation in the original
2601/// source code. For example: converting T[]->T*, void f()->void
2602/// (*f)(), float->double, short->int, etc.
2603///
2604/// In C, implicit casts always produce rvalues. However, in C++, an
2605/// implicit cast whose result is being bound to a reference will be
2606/// an lvalue or xvalue. For example:
2607///
2608/// @code
2609/// class Base { };
2610/// class Derived : public Base { };
2611/// Derived &&ref();
2612/// void f(Derived d) {
2613///   Base& b = d; // initializer is an ImplicitCastExpr
2614///                // to an lvalue of type Base
2615///   Base&& r = ref(); // initializer is an ImplicitCastExpr
2616///                     // to an xvalue of type Base
2617/// }
2618/// @endcode
2619class ImplicitCastExpr : public CastExpr {
2620private:
2621  ImplicitCastExpr(QualType ty, CastKind kind, Expr *op,
2622                   unsigned BasePathLength, ExprValueKind VK)
2623    : CastExpr(ImplicitCastExprClass, ty, VK, kind, op, BasePathLength) {
2624  }
2625
2626  /// \brief Construct an empty implicit cast.
2627  explicit ImplicitCastExpr(EmptyShell Shell, unsigned PathSize)
2628    : CastExpr(ImplicitCastExprClass, Shell, PathSize) { }
2629
2630public:
2631  enum OnStack_t { OnStack };
2632  ImplicitCastExpr(OnStack_t _, QualType ty, CastKind kind, Expr *op,
2633                   ExprValueKind VK)
2634    : CastExpr(ImplicitCastExprClass, ty, VK, kind, op, 0) {
2635  }
2636
2637  static ImplicitCastExpr *Create(ASTContext &Context, QualType T,
2638                                  CastKind Kind, Expr *Operand,
2639                                  const CXXCastPath *BasePath,
2640                                  ExprValueKind Cat);
2641
2642  static ImplicitCastExpr *CreateEmpty(ASTContext &Context, unsigned PathSize);
2643
2644  SourceRange getSourceRange() const LLVM_READONLY {
2645    return getSubExpr()->getSourceRange();
2646  }
2647  SourceLocation getLocStart() const LLVM_READONLY {
2648    return getSubExpr()->getLocStart();
2649  }
2650  SourceLocation getLocEnd() const LLVM_READONLY {
2651    return getSubExpr()->getLocEnd();
2652  }
2653
2654  static bool classof(const Stmt *T) {
2655    return T->getStmtClass() == ImplicitCastExprClass;
2656  }
2657  static bool classof(const ImplicitCastExpr *) { return true; }
2658};
2659
2660inline Expr *Expr::IgnoreImpCasts() {
2661  Expr *e = this;
2662  while (ImplicitCastExpr *ice = dyn_cast<ImplicitCastExpr>(e))
2663    e = ice->getSubExpr();
2664  return e;
2665}
2666
2667/// ExplicitCastExpr - An explicit cast written in the source
2668/// code.
2669///
2670/// This class is effectively an abstract class, because it provides
2671/// the basic representation of an explicitly-written cast without
2672/// specifying which kind of cast (C cast, functional cast, static
2673/// cast, etc.) was written; specific derived classes represent the
2674/// particular style of cast and its location information.
2675///
2676/// Unlike implicit casts, explicit cast nodes have two different
2677/// types: the type that was written into the source code, and the
2678/// actual type of the expression as determined by semantic
2679/// analysis. These types may differ slightly. For example, in C++ one
2680/// can cast to a reference type, which indicates that the resulting
2681/// expression will be an lvalue or xvalue. The reference type, however,
2682/// will not be used as the type of the expression.
2683class ExplicitCastExpr : public CastExpr {
2684  /// TInfo - Source type info for the (written) type
2685  /// this expression is casting to.
2686  TypeSourceInfo *TInfo;
2687
2688protected:
2689  ExplicitCastExpr(StmtClass SC, QualType exprTy, ExprValueKind VK,
2690                   CastKind kind, Expr *op, unsigned PathSize,
2691                   TypeSourceInfo *writtenTy)
2692    : CastExpr(SC, exprTy, VK, kind, op, PathSize), TInfo(writtenTy) {}
2693
2694  /// \brief Construct an empty explicit cast.
2695  ExplicitCastExpr(StmtClass SC, EmptyShell Shell, unsigned PathSize)
2696    : CastExpr(SC, Shell, PathSize) { }
2697
2698public:
2699  /// getTypeInfoAsWritten - Returns the type source info for the type
2700  /// that this expression is casting to.
2701  TypeSourceInfo *getTypeInfoAsWritten() const { return TInfo; }
2702  void setTypeInfoAsWritten(TypeSourceInfo *writtenTy) { TInfo = writtenTy; }
2703
2704  /// getTypeAsWritten - Returns the type that this expression is
2705  /// casting to, as written in the source code.
2706  QualType getTypeAsWritten() const { return TInfo->getType(); }
2707
2708  static bool classof(const Stmt *T) {
2709     return T->getStmtClass() >= firstExplicitCastExprConstant &&
2710            T->getStmtClass() <= lastExplicitCastExprConstant;
2711  }
2712  static bool classof(const ExplicitCastExpr *) { return true; }
2713};
2714
2715/// CStyleCastExpr - An explicit cast in C (C99 6.5.4) or a C-style
2716/// cast in C++ (C++ [expr.cast]), which uses the syntax
2717/// (Type)expr. For example: @c (int)f.
2718class CStyleCastExpr : public ExplicitCastExpr {
2719  SourceLocation LPLoc; // the location of the left paren
2720  SourceLocation RPLoc; // the location of the right paren
2721
2722  CStyleCastExpr(QualType exprTy, ExprValueKind vk, CastKind kind, Expr *op,
2723                 unsigned PathSize, TypeSourceInfo *writtenTy,
2724                 SourceLocation l, SourceLocation r)
2725    : ExplicitCastExpr(CStyleCastExprClass, exprTy, vk, kind, op, PathSize,
2726                       writtenTy), LPLoc(l), RPLoc(r) {}
2727
2728  /// \brief Construct an empty C-style explicit cast.
2729  explicit CStyleCastExpr(EmptyShell Shell, unsigned PathSize)
2730    : ExplicitCastExpr(CStyleCastExprClass, Shell, PathSize) { }
2731
2732public:
2733  static CStyleCastExpr *Create(ASTContext &Context, QualType T,
2734                                ExprValueKind VK, CastKind K,
2735                                Expr *Op, const CXXCastPath *BasePath,
2736                                TypeSourceInfo *WrittenTy, SourceLocation L,
2737                                SourceLocation R);
2738
2739  static CStyleCastExpr *CreateEmpty(ASTContext &Context, unsigned PathSize);
2740
2741  SourceLocation getLParenLoc() const { return LPLoc; }
2742  void setLParenLoc(SourceLocation L) { LPLoc = L; }
2743
2744  SourceLocation getRParenLoc() const { return RPLoc; }
2745  void setRParenLoc(SourceLocation L) { RPLoc = L; }
2746
2747  SourceRange getSourceRange() const LLVM_READONLY {
2748    return SourceRange(LPLoc, getSubExpr()->getSourceRange().getEnd());
2749  }
2750  static bool classof(const Stmt *T) {
2751    return T->getStmtClass() == CStyleCastExprClass;
2752  }
2753  static bool classof(const CStyleCastExpr *) { return true; }
2754};
2755
2756/// \brief A builtin binary operation expression such as "x + y" or "x <= y".
2757///
2758/// This expression node kind describes a builtin binary operation,
2759/// such as "x + y" for integer values "x" and "y". The operands will
2760/// already have been converted to appropriate types (e.g., by
2761/// performing promotions or conversions).
2762///
2763/// In C++, where operators may be overloaded, a different kind of
2764/// expression node (CXXOperatorCallExpr) is used to express the
2765/// invocation of an overloaded operator with operator syntax. Within
2766/// a C++ template, whether BinaryOperator or CXXOperatorCallExpr is
2767/// used to store an expression "x + y" depends on the subexpressions
2768/// for x and y. If neither x or y is type-dependent, and the "+"
2769/// operator resolves to a built-in operation, BinaryOperator will be
2770/// used to express the computation (x and y may still be
2771/// value-dependent). If either x or y is type-dependent, or if the
2772/// "+" resolves to an overloaded operator, CXXOperatorCallExpr will
2773/// be used to express the computation.
2774class BinaryOperator : public Expr {
2775public:
2776  typedef BinaryOperatorKind Opcode;
2777
2778private:
2779  unsigned Opc : 6;
2780  SourceLocation OpLoc;
2781
2782  enum { LHS, RHS, END_EXPR };
2783  Stmt* SubExprs[END_EXPR];
2784public:
2785
2786  BinaryOperator(Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy,
2787                 ExprValueKind VK, ExprObjectKind OK,
2788                 SourceLocation opLoc)
2789    : Expr(BinaryOperatorClass, ResTy, VK, OK,
2790           lhs->isTypeDependent() || rhs->isTypeDependent(),
2791           lhs->isValueDependent() || rhs->isValueDependent(),
2792           (lhs->isInstantiationDependent() ||
2793            rhs->isInstantiationDependent()),
2794           (lhs->containsUnexpandedParameterPack() ||
2795            rhs->containsUnexpandedParameterPack())),
2796      Opc(opc), OpLoc(opLoc) {
2797    SubExprs[LHS] = lhs;
2798    SubExprs[RHS] = rhs;
2799    assert(!isCompoundAssignmentOp() &&
2800           "Use ArithAssignBinaryOperator for compound assignments");
2801  }
2802
2803  /// \brief Construct an empty binary operator.
2804  explicit BinaryOperator(EmptyShell Empty)
2805    : Expr(BinaryOperatorClass, Empty), Opc(BO_Comma) { }
2806
2807  SourceLocation getExprLoc() const LLVM_READONLY { return OpLoc; }
2808  SourceLocation getOperatorLoc() const { return OpLoc; }
2809  void setOperatorLoc(SourceLocation L) { OpLoc = L; }
2810
2811  Opcode getOpcode() const { return static_cast<Opcode>(Opc); }
2812  void setOpcode(Opcode O) { Opc = O; }
2813
2814  Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); }
2815  void setLHS(Expr *E) { SubExprs[LHS] = E; }
2816  Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); }
2817  void setRHS(Expr *E) { SubExprs[RHS] = E; }
2818
2819  SourceRange getSourceRange() const LLVM_READONLY {
2820    return SourceRange(getLHS()->getLocStart(), getRHS()->getLocEnd());
2821  }
2822
2823  /// getOpcodeStr - Turn an Opcode enum value into the punctuation char it
2824  /// corresponds to, e.g. "<<=".
2825  static const char *getOpcodeStr(Opcode Op);
2826
2827  const char *getOpcodeStr() const { return getOpcodeStr(getOpcode()); }
2828
2829  /// \brief Retrieve the binary opcode that corresponds to the given
2830  /// overloaded operator.
2831  static Opcode getOverloadedOpcode(OverloadedOperatorKind OO);
2832
2833  /// \brief Retrieve the overloaded operator kind that corresponds to
2834  /// the given binary opcode.
2835  static OverloadedOperatorKind getOverloadedOperator(Opcode Opc);
2836
2837  /// predicates to categorize the respective opcodes.
2838  bool isPtrMemOp() const { return Opc == BO_PtrMemD || Opc == BO_PtrMemI; }
2839  bool isMultiplicativeOp() const { return Opc >= BO_Mul && Opc <= BO_Rem; }
2840  static bool isAdditiveOp(Opcode Opc) { return Opc == BO_Add || Opc==BO_Sub; }
2841  bool isAdditiveOp() const { return isAdditiveOp(getOpcode()); }
2842  static bool isShiftOp(Opcode Opc) { return Opc == BO_Shl || Opc == BO_Shr; }
2843  bool isShiftOp() const { return isShiftOp(getOpcode()); }
2844
2845  static bool isBitwiseOp(Opcode Opc) { return Opc >= BO_And && Opc <= BO_Or; }
2846  bool isBitwiseOp() const { return isBitwiseOp(getOpcode()); }
2847
2848  static bool isRelationalOp(Opcode Opc) { return Opc >= BO_LT && Opc<=BO_GE; }
2849  bool isRelationalOp() const { return isRelationalOp(getOpcode()); }
2850
2851  static bool isEqualityOp(Opcode Opc) { return Opc == BO_EQ || Opc == BO_NE; }
2852  bool isEqualityOp() const { return isEqualityOp(getOpcode()); }
2853
2854  static bool isComparisonOp(Opcode Opc) { return Opc >= BO_LT && Opc<=BO_NE; }
2855  bool isComparisonOp() const { return isComparisonOp(getOpcode()); }
2856
2857  static bool isLogicalOp(Opcode Opc) { return Opc == BO_LAnd || Opc==BO_LOr; }
2858  bool isLogicalOp() const { return isLogicalOp(getOpcode()); }
2859
2860  static bool isAssignmentOp(Opcode Opc) {
2861    return Opc >= BO_Assign && Opc <= BO_OrAssign;
2862  }
2863  bool isAssignmentOp() const { return isAssignmentOp(getOpcode()); }
2864
2865  static bool isCompoundAssignmentOp(Opcode Opc) {
2866    return Opc > BO_Assign && Opc <= BO_OrAssign;
2867  }
2868  bool isCompoundAssignmentOp() const {
2869    return isCompoundAssignmentOp(getOpcode());
2870  }
2871  static Opcode getOpForCompoundAssignment(Opcode Opc) {
2872    assert(isCompoundAssignmentOp(Opc));
2873    if (Opc >= BO_AndAssign)
2874      return Opcode(unsigned(Opc) - BO_AndAssign + BO_And);
2875    else
2876      return Opcode(unsigned(Opc) - BO_MulAssign + BO_Mul);
2877  }
2878
2879  static bool isShiftAssignOp(Opcode Opc) {
2880    return Opc == BO_ShlAssign || Opc == BO_ShrAssign;
2881  }
2882  bool isShiftAssignOp() const {
2883    return isShiftAssignOp(getOpcode());
2884  }
2885
2886  static bool classof(const Stmt *S) {
2887    return S->getStmtClass() >= firstBinaryOperatorConstant &&
2888           S->getStmtClass() <= lastBinaryOperatorConstant;
2889  }
2890  static bool classof(const BinaryOperator *) { return true; }
2891
2892  // Iterators
2893  child_range children() {
2894    return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR);
2895  }
2896
2897protected:
2898  BinaryOperator(Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy,
2899                 ExprValueKind VK, ExprObjectKind OK,
2900                 SourceLocation opLoc, bool dead)
2901    : Expr(CompoundAssignOperatorClass, ResTy, VK, OK,
2902           lhs->isTypeDependent() || rhs->isTypeDependent(),
2903           lhs->isValueDependent() || rhs->isValueDependent(),
2904           (lhs->isInstantiationDependent() ||
2905            rhs->isInstantiationDependent()),
2906           (lhs->containsUnexpandedParameterPack() ||
2907            rhs->containsUnexpandedParameterPack())),
2908      Opc(opc), OpLoc(opLoc) {
2909    SubExprs[LHS] = lhs;
2910    SubExprs[RHS] = rhs;
2911  }
2912
2913  BinaryOperator(StmtClass SC, EmptyShell Empty)
2914    : Expr(SC, Empty), Opc(BO_MulAssign) { }
2915};
2916
2917/// CompoundAssignOperator - For compound assignments (e.g. +=), we keep
2918/// track of the type the operation is performed in.  Due to the semantics of
2919/// these operators, the operands are promoted, the arithmetic performed, an
2920/// implicit conversion back to the result type done, then the assignment takes
2921/// place.  This captures the intermediate type which the computation is done
2922/// in.
2923class CompoundAssignOperator : public BinaryOperator {
2924  QualType ComputationLHSType;
2925  QualType ComputationResultType;
2926public:
2927  CompoundAssignOperator(Expr *lhs, Expr *rhs, Opcode opc, QualType ResType,
2928                         ExprValueKind VK, ExprObjectKind OK,
2929                         QualType CompLHSType, QualType CompResultType,
2930                         SourceLocation OpLoc)
2931    : BinaryOperator(lhs, rhs, opc, ResType, VK, OK, OpLoc, true),
2932      ComputationLHSType(CompLHSType),
2933      ComputationResultType(CompResultType) {
2934    assert(isCompoundAssignmentOp() &&
2935           "Only should be used for compound assignments");
2936  }
2937
2938  /// \brief Build an empty compound assignment operator expression.
2939  explicit CompoundAssignOperator(EmptyShell Empty)
2940    : BinaryOperator(CompoundAssignOperatorClass, Empty) { }
2941
2942  // The two computation types are the type the LHS is converted
2943  // to for the computation and the type of the result; the two are
2944  // distinct in a few cases (specifically, int+=ptr and ptr-=ptr).
2945  QualType getComputationLHSType() const { return ComputationLHSType; }
2946  void setComputationLHSType(QualType T) { ComputationLHSType = T; }
2947
2948  QualType getComputationResultType() const { return ComputationResultType; }
2949  void setComputationResultType(QualType T) { ComputationResultType = T; }
2950
2951  static bool classof(const CompoundAssignOperator *) { return true; }
2952  static bool classof(const Stmt *S) {
2953    return S->getStmtClass() == CompoundAssignOperatorClass;
2954  }
2955};
2956
2957/// AbstractConditionalOperator - An abstract base class for
2958/// ConditionalOperator and BinaryConditionalOperator.
2959class AbstractConditionalOperator : public Expr {
2960  SourceLocation QuestionLoc, ColonLoc;
2961  friend class ASTStmtReader;
2962
2963protected:
2964  AbstractConditionalOperator(StmtClass SC, QualType T,
2965                              ExprValueKind VK, ExprObjectKind OK,
2966                              bool TD, bool VD, bool ID,
2967                              bool ContainsUnexpandedParameterPack,
2968                              SourceLocation qloc,
2969                              SourceLocation cloc)
2970    : Expr(SC, T, VK, OK, TD, VD, ID, ContainsUnexpandedParameterPack),
2971      QuestionLoc(qloc), ColonLoc(cloc) {}
2972
2973  AbstractConditionalOperator(StmtClass SC, EmptyShell Empty)
2974    : Expr(SC, Empty) { }
2975
2976public:
2977  // getCond - Return the expression representing the condition for
2978  //   the ?: operator.
2979  Expr *getCond() const;
2980
2981  // getTrueExpr - Return the subexpression representing the value of
2982  //   the expression if the condition evaluates to true.
2983  Expr *getTrueExpr() const;
2984
2985  // getFalseExpr - Return the subexpression representing the value of
2986  //   the expression if the condition evaluates to false.  This is
2987  //   the same as getRHS.
2988  Expr *getFalseExpr() const;
2989
2990  SourceLocation getQuestionLoc() const { return QuestionLoc; }
2991  SourceLocation getColonLoc() const { return ColonLoc; }
2992
2993  static bool classof(const Stmt *T) {
2994    return T->getStmtClass() == ConditionalOperatorClass ||
2995           T->getStmtClass() == BinaryConditionalOperatorClass;
2996  }
2997  static bool classof(const AbstractConditionalOperator *) { return true; }
2998};
2999
3000/// ConditionalOperator - The ?: ternary operator.  The GNU "missing
3001/// middle" extension is a BinaryConditionalOperator.
3002class ConditionalOperator : public AbstractConditionalOperator {
3003  enum { COND, LHS, RHS, END_EXPR };
3004  Stmt* SubExprs[END_EXPR]; // Left/Middle/Right hand sides.
3005
3006  friend class ASTStmtReader;
3007public:
3008  ConditionalOperator(Expr *cond, SourceLocation QLoc, Expr *lhs,
3009                      SourceLocation CLoc, Expr *rhs,
3010                      QualType t, ExprValueKind VK, ExprObjectKind OK)
3011    : AbstractConditionalOperator(ConditionalOperatorClass, t, VK, OK,
3012           // FIXME: the type of the conditional operator doesn't
3013           // depend on the type of the conditional, but the standard
3014           // seems to imply that it could. File a bug!
3015           (lhs->isTypeDependent() || rhs->isTypeDependent()),
3016           (cond->isValueDependent() || lhs->isValueDependent() ||
3017            rhs->isValueDependent()),
3018           (cond->isInstantiationDependent() ||
3019            lhs->isInstantiationDependent() ||
3020            rhs->isInstantiationDependent()),
3021           (cond->containsUnexpandedParameterPack() ||
3022            lhs->containsUnexpandedParameterPack() ||
3023            rhs->containsUnexpandedParameterPack()),
3024                                  QLoc, CLoc) {
3025    SubExprs[COND] = cond;
3026    SubExprs[LHS] = lhs;
3027    SubExprs[RHS] = rhs;
3028  }
3029
3030  /// \brief Build an empty conditional operator.
3031  explicit ConditionalOperator(EmptyShell Empty)
3032    : AbstractConditionalOperator(ConditionalOperatorClass, Empty) { }
3033
3034  // getCond - Return the expression representing the condition for
3035  //   the ?: operator.
3036  Expr *getCond() const { return cast<Expr>(SubExprs[COND]); }
3037
3038  // getTrueExpr - Return the subexpression representing the value of
3039  //   the expression if the condition evaluates to true.
3040  Expr *getTrueExpr() const { return cast<Expr>(SubExprs[LHS]); }
3041
3042  // getFalseExpr - Return the subexpression representing the value of
3043  //   the expression if the condition evaluates to false.  This is
3044  //   the same as getRHS.
3045  Expr *getFalseExpr() const { return cast<Expr>(SubExprs[RHS]); }
3046
3047  Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); }
3048  Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); }
3049
3050  SourceRange getSourceRange() const LLVM_READONLY {
3051    return SourceRange(getCond()->getLocStart(), getRHS()->getLocEnd());
3052  }
3053  static bool classof(const Stmt *T) {
3054    return T->getStmtClass() == ConditionalOperatorClass;
3055  }
3056  static bool classof(const ConditionalOperator *) { return true; }
3057
3058  // Iterators
3059  child_range children() {
3060    return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR);
3061  }
3062};
3063
3064/// BinaryConditionalOperator - The GNU extension to the conditional
3065/// operator which allows the middle operand to be omitted.
3066///
3067/// This is a different expression kind on the assumption that almost
3068/// every client ends up needing to know that these are different.
3069class BinaryConditionalOperator : public AbstractConditionalOperator {
3070  enum { COMMON, COND, LHS, RHS, NUM_SUBEXPRS };
3071
3072  /// - the common condition/left-hand-side expression, which will be
3073  ///   evaluated as the opaque value
3074  /// - the condition, expressed in terms of the opaque value
3075  /// - the left-hand-side, expressed in terms of the opaque value
3076  /// - the right-hand-side
3077  Stmt *SubExprs[NUM_SUBEXPRS];
3078  OpaqueValueExpr *OpaqueValue;
3079
3080  friend class ASTStmtReader;
3081public:
3082  BinaryConditionalOperator(Expr *common, OpaqueValueExpr *opaqueValue,
3083                            Expr *cond, Expr *lhs, Expr *rhs,
3084                            SourceLocation qloc, SourceLocation cloc,
3085                            QualType t, ExprValueKind VK, ExprObjectKind OK)
3086    : AbstractConditionalOperator(BinaryConditionalOperatorClass, t, VK, OK,
3087           (common->isTypeDependent() || rhs->isTypeDependent()),
3088           (common->isValueDependent() || rhs->isValueDependent()),
3089           (common->isInstantiationDependent() ||
3090            rhs->isInstantiationDependent()),
3091           (common->containsUnexpandedParameterPack() ||
3092            rhs->containsUnexpandedParameterPack()),
3093                                  qloc, cloc),
3094      OpaqueValue(opaqueValue) {
3095    SubExprs[COMMON] = common;
3096    SubExprs[COND] = cond;
3097    SubExprs[LHS] = lhs;
3098    SubExprs[RHS] = rhs;
3099    assert(OpaqueValue->getSourceExpr() == common && "Wrong opaque value");
3100  }
3101
3102  /// \brief Build an empty conditional operator.
3103  explicit BinaryConditionalOperator(EmptyShell Empty)
3104    : AbstractConditionalOperator(BinaryConditionalOperatorClass, Empty) { }
3105
3106  /// \brief getCommon - Return the common expression, written to the
3107  ///   left of the condition.  The opaque value will be bound to the
3108  ///   result of this expression.
3109  Expr *getCommon() const { return cast<Expr>(SubExprs[COMMON]); }
3110
3111  /// \brief getOpaqueValue - Return the opaque value placeholder.
3112  OpaqueValueExpr *getOpaqueValue() const { return OpaqueValue; }
3113
3114  /// \brief getCond - Return the condition expression; this is defined
3115  ///   in terms of the opaque value.
3116  Expr *getCond() const { return cast<Expr>(SubExprs[COND]); }
3117
3118  /// \brief getTrueExpr - Return the subexpression which will be
3119  ///   evaluated if the condition evaluates to true;  this is defined
3120  ///   in terms of the opaque value.
3121  Expr *getTrueExpr() const {
3122    return cast<Expr>(SubExprs[LHS]);
3123  }
3124
3125  /// \brief getFalseExpr - Return the subexpression which will be
3126  ///   evaluated if the condnition evaluates to false; this is
3127  ///   defined in terms of the opaque value.
3128  Expr *getFalseExpr() const {
3129    return cast<Expr>(SubExprs[RHS]);
3130  }
3131
3132  SourceRange getSourceRange() const LLVM_READONLY {
3133    return SourceRange(getCommon()->getLocStart(), getFalseExpr()->getLocEnd());
3134  }
3135  static bool classof(const Stmt *T) {
3136    return T->getStmtClass() == BinaryConditionalOperatorClass;
3137  }
3138  static bool classof(const BinaryConditionalOperator *) { return true; }
3139
3140  // Iterators
3141  child_range children() {
3142    return child_range(SubExprs, SubExprs + NUM_SUBEXPRS);
3143  }
3144};
3145
3146inline Expr *AbstractConditionalOperator::getCond() const {
3147  if (const ConditionalOperator *co = dyn_cast<ConditionalOperator>(this))
3148    return co->getCond();
3149  return cast<BinaryConditionalOperator>(this)->getCond();
3150}
3151
3152inline Expr *AbstractConditionalOperator::getTrueExpr() const {
3153  if (const ConditionalOperator *co = dyn_cast<ConditionalOperator>(this))
3154    return co->getTrueExpr();
3155  return cast<BinaryConditionalOperator>(this)->getTrueExpr();
3156}
3157
3158inline Expr *AbstractConditionalOperator::getFalseExpr() const {
3159  if (const ConditionalOperator *co = dyn_cast<ConditionalOperator>(this))
3160    return co->getFalseExpr();
3161  return cast<BinaryConditionalOperator>(this)->getFalseExpr();
3162}
3163
3164/// AddrLabelExpr - The GNU address of label extension, representing &&label.
3165class AddrLabelExpr : public Expr {
3166  SourceLocation AmpAmpLoc, LabelLoc;
3167  LabelDecl *Label;
3168public:
3169  AddrLabelExpr(SourceLocation AALoc, SourceLocation LLoc, LabelDecl *L,
3170                QualType t)
3171    : Expr(AddrLabelExprClass, t, VK_RValue, OK_Ordinary, false, false, false,
3172           false),
3173      AmpAmpLoc(AALoc), LabelLoc(LLoc), Label(L) {}
3174
3175  /// \brief Build an empty address of a label expression.
3176  explicit AddrLabelExpr(EmptyShell Empty)
3177    : Expr(AddrLabelExprClass, Empty) { }
3178
3179  SourceLocation getAmpAmpLoc() const { return AmpAmpLoc; }
3180  void setAmpAmpLoc(SourceLocation L) { AmpAmpLoc = L; }
3181  SourceLocation getLabelLoc() const { return LabelLoc; }
3182  void setLabelLoc(SourceLocation L) { LabelLoc = L; }
3183
3184  SourceRange getSourceRange() const LLVM_READONLY {
3185    return SourceRange(AmpAmpLoc, LabelLoc);
3186  }
3187
3188  LabelDecl *getLabel() const { return Label; }
3189  void setLabel(LabelDecl *L) { Label = L; }
3190
3191  static bool classof(const Stmt *T) {
3192    return T->getStmtClass() == AddrLabelExprClass;
3193  }
3194  static bool classof(const AddrLabelExpr *) { return true; }
3195
3196  // Iterators
3197  child_range children() { return child_range(); }
3198};
3199
3200/// StmtExpr - This is the GNU Statement Expression extension: ({int X=4; X;}).
3201/// The StmtExpr contains a single CompoundStmt node, which it evaluates and
3202/// takes the value of the last subexpression.
3203///
3204/// A StmtExpr is always an r-value; values "returned" out of a
3205/// StmtExpr will be copied.
3206class StmtExpr : public Expr {
3207  Stmt *SubStmt;
3208  SourceLocation LParenLoc, RParenLoc;
3209public:
3210  // FIXME: Does type-dependence need to be computed differently?
3211  // FIXME: Do we need to compute instantiation instantiation-dependence for
3212  // statements? (ugh!)
3213  StmtExpr(CompoundStmt *substmt, QualType T,
3214           SourceLocation lp, SourceLocation rp) :
3215    Expr(StmtExprClass, T, VK_RValue, OK_Ordinary,
3216         T->isDependentType(), false, false, false),
3217    SubStmt(substmt), LParenLoc(lp), RParenLoc(rp) { }
3218
3219  /// \brief Build an empty statement expression.
3220  explicit StmtExpr(EmptyShell Empty) : Expr(StmtExprClass, Empty) { }
3221
3222  CompoundStmt *getSubStmt() { return cast<CompoundStmt>(SubStmt); }
3223  const CompoundStmt *getSubStmt() const { return cast<CompoundStmt>(SubStmt); }
3224  void setSubStmt(CompoundStmt *S) { SubStmt = S; }
3225
3226  SourceRange getSourceRange() const LLVM_READONLY {
3227    return SourceRange(LParenLoc, RParenLoc);
3228  }
3229
3230  SourceLocation getLParenLoc() const { return LParenLoc; }
3231  void setLParenLoc(SourceLocation L) { LParenLoc = L; }
3232  SourceLocation getRParenLoc() const { return RParenLoc; }
3233  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
3234
3235  static bool classof(const Stmt *T) {
3236    return T->getStmtClass() == StmtExprClass;
3237  }
3238  static bool classof(const StmtExpr *) { return true; }
3239
3240  // Iterators
3241  child_range children() { return child_range(&SubStmt, &SubStmt+1); }
3242};
3243
3244
3245/// ShuffleVectorExpr - clang-specific builtin-in function
3246/// __builtin_shufflevector.
3247/// This AST node represents a operator that does a constant
3248/// shuffle, similar to LLVM's shufflevector instruction. It takes
3249/// two vectors and a variable number of constant indices,
3250/// and returns the appropriately shuffled vector.
3251class ShuffleVectorExpr : public Expr {
3252  SourceLocation BuiltinLoc, RParenLoc;
3253
3254  // SubExprs - the list of values passed to the __builtin_shufflevector
3255  // function. The first two are vectors, and the rest are constant
3256  // indices.  The number of values in this list is always
3257  // 2+the number of indices in the vector type.
3258  Stmt **SubExprs;
3259  unsigned NumExprs;
3260
3261public:
3262  ShuffleVectorExpr(ASTContext &C, Expr **args, unsigned nexpr,
3263                    QualType Type, SourceLocation BLoc,
3264                    SourceLocation RP);
3265
3266  /// \brief Build an empty vector-shuffle expression.
3267  explicit ShuffleVectorExpr(EmptyShell Empty)
3268    : Expr(ShuffleVectorExprClass, Empty), SubExprs(0) { }
3269
3270  SourceLocation getBuiltinLoc() const { return BuiltinLoc; }
3271  void setBuiltinLoc(SourceLocation L) { BuiltinLoc = L; }
3272
3273  SourceLocation getRParenLoc() const { return RParenLoc; }
3274  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
3275
3276  SourceRange getSourceRange() const LLVM_READONLY {
3277    return SourceRange(BuiltinLoc, RParenLoc);
3278  }
3279  static bool classof(const Stmt *T) {
3280    return T->getStmtClass() == ShuffleVectorExprClass;
3281  }
3282  static bool classof(const ShuffleVectorExpr *) { return true; }
3283
3284  /// getNumSubExprs - Return the size of the SubExprs array.  This includes the
3285  /// constant expression, the actual arguments passed in, and the function
3286  /// pointers.
3287  unsigned getNumSubExprs() const { return NumExprs; }
3288
3289  /// \brief Retrieve the array of expressions.
3290  Expr **getSubExprs() { return reinterpret_cast<Expr **>(SubExprs); }
3291
3292  /// getExpr - Return the Expr at the specified index.
3293  Expr *getExpr(unsigned Index) {
3294    assert((Index < NumExprs) && "Arg access out of range!");
3295    return cast<Expr>(SubExprs[Index]);
3296  }
3297  const Expr *getExpr(unsigned Index) const {
3298    assert((Index < NumExprs) && "Arg access out of range!");
3299    return cast<Expr>(SubExprs[Index]);
3300  }
3301
3302  void setExprs(ASTContext &C, Expr ** Exprs, unsigned NumExprs);
3303
3304  unsigned getShuffleMaskIdx(ASTContext &Ctx, unsigned N) {
3305    assert((N < NumExprs - 2) && "Shuffle idx out of range!");
3306    return getExpr(N+2)->EvaluateKnownConstInt(Ctx).getZExtValue();
3307  }
3308
3309  // Iterators
3310  child_range children() {
3311    return child_range(&SubExprs[0], &SubExprs[0]+NumExprs);
3312  }
3313};
3314
3315/// ChooseExpr - GNU builtin-in function __builtin_choose_expr.
3316/// This AST node is similar to the conditional operator (?:) in C, with
3317/// the following exceptions:
3318/// - the test expression must be a integer constant expression.
3319/// - the expression returned acts like the chosen subexpression in every
3320///   visible way: the type is the same as that of the chosen subexpression,
3321///   and all predicates (whether it's an l-value, whether it's an integer
3322///   constant expression, etc.) return the same result as for the chosen
3323///   sub-expression.
3324class ChooseExpr : public Expr {
3325  enum { COND, LHS, RHS, END_EXPR };
3326  Stmt* SubExprs[END_EXPR]; // Left/Middle/Right hand sides.
3327  SourceLocation BuiltinLoc, RParenLoc;
3328public:
3329  ChooseExpr(SourceLocation BLoc, Expr *cond, Expr *lhs, Expr *rhs,
3330             QualType t, ExprValueKind VK, ExprObjectKind OK,
3331             SourceLocation RP, bool TypeDependent, bool ValueDependent)
3332    : Expr(ChooseExprClass, t, VK, OK, TypeDependent, ValueDependent,
3333           (cond->isInstantiationDependent() ||
3334            lhs->isInstantiationDependent() ||
3335            rhs->isInstantiationDependent()),
3336           (cond->containsUnexpandedParameterPack() ||
3337            lhs->containsUnexpandedParameterPack() ||
3338            rhs->containsUnexpandedParameterPack())),
3339      BuiltinLoc(BLoc), RParenLoc(RP) {
3340      SubExprs[COND] = cond;
3341      SubExprs[LHS] = lhs;
3342      SubExprs[RHS] = rhs;
3343    }
3344
3345  /// \brief Build an empty __builtin_choose_expr.
3346  explicit ChooseExpr(EmptyShell Empty) : Expr(ChooseExprClass, Empty) { }
3347
3348  /// isConditionTrue - Return whether the condition is true (i.e. not
3349  /// equal to zero).
3350  bool isConditionTrue(const ASTContext &C) const;
3351
3352  /// getChosenSubExpr - Return the subexpression chosen according to the
3353  /// condition.
3354  Expr *getChosenSubExpr(const ASTContext &C) const {
3355    return isConditionTrue(C) ? getLHS() : getRHS();
3356  }
3357
3358  Expr *getCond() const { return cast<Expr>(SubExprs[COND]); }
3359  void setCond(Expr *E) { SubExprs[COND] = E; }
3360  Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); }
3361  void setLHS(Expr *E) { SubExprs[LHS] = E; }
3362  Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); }
3363  void setRHS(Expr *E) { SubExprs[RHS] = E; }
3364
3365  SourceLocation getBuiltinLoc() const { return BuiltinLoc; }
3366  void setBuiltinLoc(SourceLocation L) { BuiltinLoc = L; }
3367
3368  SourceLocation getRParenLoc() const { return RParenLoc; }
3369  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
3370
3371  SourceRange getSourceRange() const LLVM_READONLY {
3372    return SourceRange(BuiltinLoc, RParenLoc);
3373  }
3374  static bool classof(const Stmt *T) {
3375    return T->getStmtClass() == ChooseExprClass;
3376  }
3377  static bool classof(const ChooseExpr *) { return true; }
3378
3379  // Iterators
3380  child_range children() {
3381    return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR);
3382  }
3383};
3384
3385/// GNUNullExpr - Implements the GNU __null extension, which is a name
3386/// for a null pointer constant that has integral type (e.g., int or
3387/// long) and is the same size and alignment as a pointer. The __null
3388/// extension is typically only used by system headers, which define
3389/// NULL as __null in C++ rather than using 0 (which is an integer
3390/// that may not match the size of a pointer).
3391class GNUNullExpr : public Expr {
3392  /// TokenLoc - The location of the __null keyword.
3393  SourceLocation TokenLoc;
3394
3395public:
3396  GNUNullExpr(QualType Ty, SourceLocation Loc)
3397    : Expr(GNUNullExprClass, Ty, VK_RValue, OK_Ordinary, false, false, false,
3398           false),
3399      TokenLoc(Loc) { }
3400
3401  /// \brief Build an empty GNU __null expression.
3402  explicit GNUNullExpr(EmptyShell Empty) : Expr(GNUNullExprClass, Empty) { }
3403
3404  /// getTokenLocation - The location of the __null token.
3405  SourceLocation getTokenLocation() const { return TokenLoc; }
3406  void setTokenLocation(SourceLocation L) { TokenLoc = L; }
3407
3408  SourceRange getSourceRange() const LLVM_READONLY {
3409    return SourceRange(TokenLoc);
3410  }
3411  static bool classof(const Stmt *T) {
3412    return T->getStmtClass() == GNUNullExprClass;
3413  }
3414  static bool classof(const GNUNullExpr *) { return true; }
3415
3416  // Iterators
3417  child_range children() { return child_range(); }
3418};
3419
3420/// VAArgExpr, used for the builtin function __builtin_va_arg.
3421class VAArgExpr : public Expr {
3422  Stmt *Val;
3423  TypeSourceInfo *TInfo;
3424  SourceLocation BuiltinLoc, RParenLoc;
3425public:
3426  VAArgExpr(SourceLocation BLoc, Expr* e, TypeSourceInfo *TInfo,
3427            SourceLocation RPLoc, QualType t)
3428    : Expr(VAArgExprClass, t, VK_RValue, OK_Ordinary,
3429           t->isDependentType(), false,
3430           (TInfo->getType()->isInstantiationDependentType() ||
3431            e->isInstantiationDependent()),
3432           (TInfo->getType()->containsUnexpandedParameterPack() ||
3433            e->containsUnexpandedParameterPack())),
3434      Val(e), TInfo(TInfo),
3435      BuiltinLoc(BLoc),
3436      RParenLoc(RPLoc) { }
3437
3438  /// \brief Create an empty __builtin_va_arg expression.
3439  explicit VAArgExpr(EmptyShell Empty) : Expr(VAArgExprClass, Empty) { }
3440
3441  const Expr *getSubExpr() const { return cast<Expr>(Val); }
3442  Expr *getSubExpr() { return cast<Expr>(Val); }
3443  void setSubExpr(Expr *E) { Val = E; }
3444
3445  TypeSourceInfo *getWrittenTypeInfo() const { return TInfo; }
3446  void setWrittenTypeInfo(TypeSourceInfo *TI) { TInfo = TI; }
3447
3448  SourceLocation getBuiltinLoc() const { return BuiltinLoc; }
3449  void setBuiltinLoc(SourceLocation L) { BuiltinLoc = L; }
3450
3451  SourceLocation getRParenLoc() const { return RParenLoc; }
3452  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
3453
3454  SourceRange getSourceRange() const LLVM_READONLY {
3455    return SourceRange(BuiltinLoc, RParenLoc);
3456  }
3457  static bool classof(const Stmt *T) {
3458    return T->getStmtClass() == VAArgExprClass;
3459  }
3460  static bool classof(const VAArgExpr *) { return true; }
3461
3462  // Iterators
3463  child_range children() { return child_range(&Val, &Val+1); }
3464};
3465
3466/// @brief Describes an C or C++ initializer list.
3467///
3468/// InitListExpr describes an initializer list, which can be used to
3469/// initialize objects of different types, including
3470/// struct/class/union types, arrays, and vectors. For example:
3471///
3472/// @code
3473/// struct foo x = { 1, { 2, 3 } };
3474/// @endcode
3475///
3476/// Prior to semantic analysis, an initializer list will represent the
3477/// initializer list as written by the user, but will have the
3478/// placeholder type "void". This initializer list is called the
3479/// syntactic form of the initializer, and may contain C99 designated
3480/// initializers (represented as DesignatedInitExprs), initializations
3481/// of subobject members without explicit braces, and so on. Clients
3482/// interested in the original syntax of the initializer list should
3483/// use the syntactic form of the initializer list.
3484///
3485/// After semantic analysis, the initializer list will represent the
3486/// semantic form of the initializer, where the initializations of all
3487/// subobjects are made explicit with nested InitListExpr nodes and
3488/// C99 designators have been eliminated by placing the designated
3489/// initializations into the subobject they initialize. Additionally,
3490/// any "holes" in the initialization, where no initializer has been
3491/// specified for a particular subobject, will be replaced with
3492/// implicitly-generated ImplicitValueInitExpr expressions that
3493/// value-initialize the subobjects. Note, however, that the
3494/// initializer lists may still have fewer initializers than there are
3495/// elements to initialize within the object.
3496///
3497/// Given the semantic form of the initializer list, one can retrieve
3498/// the original syntactic form of that initializer list (if it
3499/// exists) using getSyntacticForm(). Since many initializer lists
3500/// have the same syntactic and semantic forms, getSyntacticForm() may
3501/// return NULL, indicating that the current initializer list also
3502/// serves as its syntactic form.
3503class InitListExpr : public Expr {
3504  // FIXME: Eliminate this vector in favor of ASTContext allocation
3505  typedef ASTVector<Stmt *> InitExprsTy;
3506  InitExprsTy InitExprs;
3507  SourceLocation LBraceLoc, RBraceLoc;
3508
3509  /// Contains the initializer list that describes the syntactic form
3510  /// written in the source code.
3511  InitListExpr *SyntacticForm;
3512
3513  /// \brief Either:
3514  ///  If this initializer list initializes an array with more elements than
3515  ///  there are initializers in the list, specifies an expression to be used
3516  ///  for value initialization of the rest of the elements.
3517  /// Or
3518  ///  If this initializer list initializes a union, specifies which
3519  ///  field within the union will be initialized.
3520  llvm::PointerUnion<Expr *, FieldDecl *> ArrayFillerOrUnionFieldInit;
3521
3522public:
3523  InitListExpr(ASTContext &C, SourceLocation lbraceloc,
3524               Expr **initexprs, unsigned numinits,
3525               SourceLocation rbraceloc);
3526
3527  /// \brief Build an empty initializer list.
3528  explicit InitListExpr(ASTContext &C, EmptyShell Empty)
3529    : Expr(InitListExprClass, Empty), InitExprs(C) { }
3530
3531  unsigned getNumInits() const { return InitExprs.size(); }
3532
3533  /// \brief Retrieve the set of initializers.
3534  Expr **getInits() { return reinterpret_cast<Expr **>(InitExprs.data()); }
3535
3536  const Expr *getInit(unsigned Init) const {
3537    assert(Init < getNumInits() && "Initializer access out of range!");
3538    return cast_or_null<Expr>(InitExprs[Init]);
3539  }
3540
3541  Expr *getInit(unsigned Init) {
3542    assert(Init < getNumInits() && "Initializer access out of range!");
3543    return cast_or_null<Expr>(InitExprs[Init]);
3544  }
3545
3546  void setInit(unsigned Init, Expr *expr) {
3547    assert(Init < getNumInits() && "Initializer access out of range!");
3548    InitExprs[Init] = expr;
3549  }
3550
3551  /// \brief Reserve space for some number of initializers.
3552  void reserveInits(ASTContext &C, unsigned NumInits);
3553
3554  /// @brief Specify the number of initializers
3555  ///
3556  /// If there are more than @p NumInits initializers, the remaining
3557  /// initializers will be destroyed. If there are fewer than @p
3558  /// NumInits initializers, NULL expressions will be added for the
3559  /// unknown initializers.
3560  void resizeInits(ASTContext &Context, unsigned NumInits);
3561
3562  /// @brief Updates the initializer at index @p Init with the new
3563  /// expression @p expr, and returns the old expression at that
3564  /// location.
3565  ///
3566  /// When @p Init is out of range for this initializer list, the
3567  /// initializer list will be extended with NULL expressions to
3568  /// accommodate the new entry.
3569  Expr *updateInit(ASTContext &C, unsigned Init, Expr *expr);
3570
3571  /// \brief If this initializer list initializes an array with more elements
3572  /// than there are initializers in the list, specifies an expression to be
3573  /// used for value initialization of the rest of the elements.
3574  Expr *getArrayFiller() {
3575    return ArrayFillerOrUnionFieldInit.dyn_cast<Expr *>();
3576  }
3577  const Expr *getArrayFiller() const {
3578    return const_cast<InitListExpr *>(this)->getArrayFiller();
3579  }
3580  void setArrayFiller(Expr *filler);
3581
3582  /// \brief Return true if this is an array initializer and its array "filler"
3583  /// has been set.
3584  bool hasArrayFiller() const { return getArrayFiller(); }
3585
3586  /// \brief If this initializes a union, specifies which field in the
3587  /// union to initialize.
3588  ///
3589  /// Typically, this field is the first named field within the
3590  /// union. However, a designated initializer can specify the
3591  /// initialization of a different field within the union.
3592  FieldDecl *getInitializedFieldInUnion() {
3593    return ArrayFillerOrUnionFieldInit.dyn_cast<FieldDecl *>();
3594  }
3595  const FieldDecl *getInitializedFieldInUnion() const {
3596    return const_cast<InitListExpr *>(this)->getInitializedFieldInUnion();
3597  }
3598  void setInitializedFieldInUnion(FieldDecl *FD) {
3599    ArrayFillerOrUnionFieldInit = FD;
3600  }
3601
3602  // Explicit InitListExpr's originate from source code (and have valid source
3603  // locations). Implicit InitListExpr's are created by the semantic analyzer.
3604  bool isExplicit() {
3605    return LBraceLoc.isValid() && RBraceLoc.isValid();
3606  }
3607
3608  // Is this an initializer for an array of characters, initialized by a string
3609  // literal or an @encode?
3610  bool isStringLiteralInit() const;
3611
3612  SourceLocation getLBraceLoc() const { return LBraceLoc; }
3613  void setLBraceLoc(SourceLocation Loc) { LBraceLoc = Loc; }
3614  SourceLocation getRBraceLoc() const { return RBraceLoc; }
3615  void setRBraceLoc(SourceLocation Loc) { RBraceLoc = Loc; }
3616
3617  /// @brief Retrieve the initializer list that describes the
3618  /// syntactic form of the initializer.
3619  ///
3620  ///
3621  InitListExpr *getSyntacticForm() const { return SyntacticForm; }
3622  void setSyntacticForm(InitListExpr *Init) { SyntacticForm = Init; }
3623
3624  bool hadArrayRangeDesignator() const {
3625    return InitListExprBits.HadArrayRangeDesignator != 0;
3626  }
3627  void sawArrayRangeDesignator(bool ARD = true) {
3628    InitListExprBits.HadArrayRangeDesignator = ARD;
3629  }
3630
3631  bool initializesStdInitializerList() const {
3632    return InitListExprBits.InitializesStdInitializerList != 0;
3633  }
3634  void setInitializesStdInitializerList(bool ISIL = true) {
3635    InitListExprBits.InitializesStdInitializerList = ISIL;
3636  }
3637
3638  SourceRange getSourceRange() const LLVM_READONLY;
3639
3640  static bool classof(const Stmt *T) {
3641    return T->getStmtClass() == InitListExprClass;
3642  }
3643  static bool classof(const InitListExpr *) { return true; }
3644
3645  // Iterators
3646  child_range children() {
3647    if (InitExprs.empty()) return child_range();
3648    return child_range(&InitExprs[0], &InitExprs[0] + InitExprs.size());
3649  }
3650
3651  typedef InitExprsTy::iterator iterator;
3652  typedef InitExprsTy::const_iterator const_iterator;
3653  typedef InitExprsTy::reverse_iterator reverse_iterator;
3654  typedef InitExprsTy::const_reverse_iterator const_reverse_iterator;
3655
3656  iterator begin() { return InitExprs.begin(); }
3657  const_iterator begin() const { return InitExprs.begin(); }
3658  iterator end() { return InitExprs.end(); }
3659  const_iterator end() const { return InitExprs.end(); }
3660  reverse_iterator rbegin() { return InitExprs.rbegin(); }
3661  const_reverse_iterator rbegin() const { return InitExprs.rbegin(); }
3662  reverse_iterator rend() { return InitExprs.rend(); }
3663  const_reverse_iterator rend() const { return InitExprs.rend(); }
3664
3665  friend class ASTStmtReader;
3666  friend class ASTStmtWriter;
3667};
3668
3669/// @brief Represents a C99 designated initializer expression.
3670///
3671/// A designated initializer expression (C99 6.7.8) contains one or
3672/// more designators (which can be field designators, array
3673/// designators, or GNU array-range designators) followed by an
3674/// expression that initializes the field or element(s) that the
3675/// designators refer to. For example, given:
3676///
3677/// @code
3678/// struct point {
3679///   double x;
3680///   double y;
3681/// };
3682/// struct point ptarray[10] = { [2].y = 1.0, [2].x = 2.0, [0].x = 1.0 };
3683/// @endcode
3684///
3685/// The InitListExpr contains three DesignatedInitExprs, the first of
3686/// which covers @c [2].y=1.0. This DesignatedInitExpr will have two
3687/// designators, one array designator for @c [2] followed by one field
3688/// designator for @c .y. The initalization expression will be 1.0.
3689class DesignatedInitExpr : public Expr {
3690public:
3691  /// \brief Forward declaration of the Designator class.
3692  class Designator;
3693
3694private:
3695  /// The location of the '=' or ':' prior to the actual initializer
3696  /// expression.
3697  SourceLocation EqualOrColonLoc;
3698
3699  /// Whether this designated initializer used the GNU deprecated
3700  /// syntax rather than the C99 '=' syntax.
3701  bool GNUSyntax : 1;
3702
3703  /// The number of designators in this initializer expression.
3704  unsigned NumDesignators : 15;
3705
3706  /// The number of subexpressions of this initializer expression,
3707  /// which contains both the initializer and any additional
3708  /// expressions used by array and array-range designators.
3709  unsigned NumSubExprs : 16;
3710
3711  /// \brief The designators in this designated initialization
3712  /// expression.
3713  Designator *Designators;
3714
3715
3716  DesignatedInitExpr(ASTContext &C, QualType Ty, unsigned NumDesignators,
3717                     const Designator *Designators,
3718                     SourceLocation EqualOrColonLoc, bool GNUSyntax,
3719                     Expr **IndexExprs, unsigned NumIndexExprs,
3720                     Expr *Init);
3721
3722  explicit DesignatedInitExpr(unsigned NumSubExprs)
3723    : Expr(DesignatedInitExprClass, EmptyShell()),
3724      NumDesignators(0), NumSubExprs(NumSubExprs), Designators(0) { }
3725
3726public:
3727  /// A field designator, e.g., ".x".
3728  struct FieldDesignator {
3729    /// Refers to the field that is being initialized. The low bit
3730    /// of this field determines whether this is actually a pointer
3731    /// to an IdentifierInfo (if 1) or a FieldDecl (if 0). When
3732    /// initially constructed, a field designator will store an
3733    /// IdentifierInfo*. After semantic analysis has resolved that
3734    /// name, the field designator will instead store a FieldDecl*.
3735    uintptr_t NameOrField;
3736
3737    /// The location of the '.' in the designated initializer.
3738    unsigned DotLoc;
3739
3740    /// The location of the field name in the designated initializer.
3741    unsigned FieldLoc;
3742  };
3743
3744  /// An array or GNU array-range designator, e.g., "[9]" or "[10..15]".
3745  struct ArrayOrRangeDesignator {
3746    /// Location of the first index expression within the designated
3747    /// initializer expression's list of subexpressions.
3748    unsigned Index;
3749    /// The location of the '[' starting the array range designator.
3750    unsigned LBracketLoc;
3751    /// The location of the ellipsis separating the start and end
3752    /// indices. Only valid for GNU array-range designators.
3753    unsigned EllipsisLoc;
3754    /// The location of the ']' terminating the array range designator.
3755    unsigned RBracketLoc;
3756  };
3757
3758  /// @brief Represents a single C99 designator.
3759  ///
3760  /// @todo This class is infuriatingly similar to clang::Designator,
3761  /// but minor differences (storing indices vs. storing pointers)
3762  /// keep us from reusing it. Try harder, later, to rectify these
3763  /// differences.
3764  class Designator {
3765    /// @brief The kind of designator this describes.
3766    enum {
3767      FieldDesignator,
3768      ArrayDesignator,
3769      ArrayRangeDesignator
3770    } Kind;
3771
3772    union {
3773      /// A field designator, e.g., ".x".
3774      struct FieldDesignator Field;
3775      /// An array or GNU array-range designator, e.g., "[9]" or "[10..15]".
3776      struct ArrayOrRangeDesignator ArrayOrRange;
3777    };
3778    friend class DesignatedInitExpr;
3779
3780  public:
3781    Designator() {}
3782
3783    /// @brief Initializes a field designator.
3784    Designator(const IdentifierInfo *FieldName, SourceLocation DotLoc,
3785               SourceLocation FieldLoc)
3786      : Kind(FieldDesignator) {
3787      Field.NameOrField = reinterpret_cast<uintptr_t>(FieldName) | 0x01;
3788      Field.DotLoc = DotLoc.getRawEncoding();
3789      Field.FieldLoc = FieldLoc.getRawEncoding();
3790    }
3791
3792    /// @brief Initializes an array designator.
3793    Designator(unsigned Index, SourceLocation LBracketLoc,
3794               SourceLocation RBracketLoc)
3795      : Kind(ArrayDesignator) {
3796      ArrayOrRange.Index = Index;
3797      ArrayOrRange.LBracketLoc = LBracketLoc.getRawEncoding();
3798      ArrayOrRange.EllipsisLoc = SourceLocation().getRawEncoding();
3799      ArrayOrRange.RBracketLoc = RBracketLoc.getRawEncoding();
3800    }
3801
3802    /// @brief Initializes a GNU array-range designator.
3803    Designator(unsigned Index, SourceLocation LBracketLoc,
3804               SourceLocation EllipsisLoc, SourceLocation RBracketLoc)
3805      : Kind(ArrayRangeDesignator) {
3806      ArrayOrRange.Index = Index;
3807      ArrayOrRange.LBracketLoc = LBracketLoc.getRawEncoding();
3808      ArrayOrRange.EllipsisLoc = EllipsisLoc.getRawEncoding();
3809      ArrayOrRange.RBracketLoc = RBracketLoc.getRawEncoding();
3810    }
3811
3812    bool isFieldDesignator() const { return Kind == FieldDesignator; }
3813    bool isArrayDesignator() const { return Kind == ArrayDesignator; }
3814    bool isArrayRangeDesignator() const { return Kind == ArrayRangeDesignator; }
3815
3816    IdentifierInfo *getFieldName() const;
3817
3818    FieldDecl *getField() const {
3819      assert(Kind == FieldDesignator && "Only valid on a field designator");
3820      if (Field.NameOrField & 0x01)
3821        return 0;
3822      else
3823        return reinterpret_cast<FieldDecl *>(Field.NameOrField);
3824    }
3825
3826    void setField(FieldDecl *FD) {
3827      assert(Kind == FieldDesignator && "Only valid on a field designator");
3828      Field.NameOrField = reinterpret_cast<uintptr_t>(FD);
3829    }
3830
3831    SourceLocation getDotLoc() const {
3832      assert(Kind == FieldDesignator && "Only valid on a field designator");
3833      return SourceLocation::getFromRawEncoding(Field.DotLoc);
3834    }
3835
3836    SourceLocation getFieldLoc() const {
3837      assert(Kind == FieldDesignator && "Only valid on a field designator");
3838      return SourceLocation::getFromRawEncoding(Field.FieldLoc);
3839    }
3840
3841    SourceLocation getLBracketLoc() const {
3842      assert((Kind == ArrayDesignator || Kind == ArrayRangeDesignator) &&
3843             "Only valid on an array or array-range designator");
3844      return SourceLocation::getFromRawEncoding(ArrayOrRange.LBracketLoc);
3845    }
3846
3847    SourceLocation getRBracketLoc() const {
3848      assert((Kind == ArrayDesignator || Kind == ArrayRangeDesignator) &&
3849             "Only valid on an array or array-range designator");
3850      return SourceLocation::getFromRawEncoding(ArrayOrRange.RBracketLoc);
3851    }
3852
3853    SourceLocation getEllipsisLoc() const {
3854      assert(Kind == ArrayRangeDesignator &&
3855             "Only valid on an array-range designator");
3856      return SourceLocation::getFromRawEncoding(ArrayOrRange.EllipsisLoc);
3857    }
3858
3859    unsigned getFirstExprIndex() const {
3860      assert((Kind == ArrayDesignator || Kind == ArrayRangeDesignator) &&
3861             "Only valid on an array or array-range designator");
3862      return ArrayOrRange.Index;
3863    }
3864
3865    SourceLocation getStartLocation() const {
3866      if (Kind == FieldDesignator)
3867        return getDotLoc().isInvalid()? getFieldLoc() : getDotLoc();
3868      else
3869        return getLBracketLoc();
3870    }
3871    SourceLocation getEndLocation() const {
3872      return Kind == FieldDesignator ? getFieldLoc() : getRBracketLoc();
3873    }
3874    SourceRange getSourceRange() const LLVM_READONLY {
3875      return SourceRange(getStartLocation(), getEndLocation());
3876    }
3877  };
3878
3879  static DesignatedInitExpr *Create(ASTContext &C, Designator *Designators,
3880                                    unsigned NumDesignators,
3881                                    Expr **IndexExprs, unsigned NumIndexExprs,
3882                                    SourceLocation EqualOrColonLoc,
3883                                    bool GNUSyntax, Expr *Init);
3884
3885  static DesignatedInitExpr *CreateEmpty(ASTContext &C, unsigned NumIndexExprs);
3886
3887  /// @brief Returns the number of designators in this initializer.
3888  unsigned size() const { return NumDesignators; }
3889
3890  // Iterator access to the designators.
3891  typedef Designator *designators_iterator;
3892  designators_iterator designators_begin() { return Designators; }
3893  designators_iterator designators_end() {
3894    return Designators + NumDesignators;
3895  }
3896
3897  typedef const Designator *const_designators_iterator;
3898  const_designators_iterator designators_begin() const { return Designators; }
3899  const_designators_iterator designators_end() const {
3900    return Designators + NumDesignators;
3901  }
3902
3903  typedef std::reverse_iterator<designators_iterator>
3904          reverse_designators_iterator;
3905  reverse_designators_iterator designators_rbegin() {
3906    return reverse_designators_iterator(designators_end());
3907  }
3908  reverse_designators_iterator designators_rend() {
3909    return reverse_designators_iterator(designators_begin());
3910  }
3911
3912  typedef std::reverse_iterator<const_designators_iterator>
3913          const_reverse_designators_iterator;
3914  const_reverse_designators_iterator designators_rbegin() const {
3915    return const_reverse_designators_iterator(designators_end());
3916  }
3917  const_reverse_designators_iterator designators_rend() const {
3918    return const_reverse_designators_iterator(designators_begin());
3919  }
3920
3921  Designator *getDesignator(unsigned Idx) { return &designators_begin()[Idx]; }
3922
3923  void setDesignators(ASTContext &C, const Designator *Desigs,
3924                      unsigned NumDesigs);
3925
3926  Expr *getArrayIndex(const Designator& D);
3927  Expr *getArrayRangeStart(const Designator& D);
3928  Expr *getArrayRangeEnd(const Designator& D);
3929
3930  /// @brief Retrieve the location of the '=' that precedes the
3931  /// initializer value itself, if present.
3932  SourceLocation getEqualOrColonLoc() const { return EqualOrColonLoc; }
3933  void setEqualOrColonLoc(SourceLocation L) { EqualOrColonLoc = L; }
3934
3935  /// @brief Determines whether this designated initializer used the
3936  /// deprecated GNU syntax for designated initializers.
3937  bool usesGNUSyntax() const { return GNUSyntax; }
3938  void setGNUSyntax(bool GNU) { GNUSyntax = GNU; }
3939
3940  /// @brief Retrieve the initializer value.
3941  Expr *getInit() const {
3942    return cast<Expr>(*const_cast<DesignatedInitExpr*>(this)->child_begin());
3943  }
3944
3945  void setInit(Expr *init) {
3946    *child_begin() = init;
3947  }
3948
3949  /// \brief Retrieve the total number of subexpressions in this
3950  /// designated initializer expression, including the actual
3951  /// initialized value and any expressions that occur within array
3952  /// and array-range designators.
3953  unsigned getNumSubExprs() const { return NumSubExprs; }
3954
3955  Expr *getSubExpr(unsigned Idx) {
3956    assert(Idx < NumSubExprs && "Subscript out of range");
3957    char* Ptr = static_cast<char*>(static_cast<void *>(this));
3958    Ptr += sizeof(DesignatedInitExpr);
3959    return reinterpret_cast<Expr**>(reinterpret_cast<void**>(Ptr))[Idx];
3960  }
3961
3962  void setSubExpr(unsigned Idx, Expr *E) {
3963    assert(Idx < NumSubExprs && "Subscript out of range");
3964    char* Ptr = static_cast<char*>(static_cast<void *>(this));
3965    Ptr += sizeof(DesignatedInitExpr);
3966    reinterpret_cast<Expr**>(reinterpret_cast<void**>(Ptr))[Idx] = E;
3967  }
3968
3969  /// \brief Replaces the designator at index @p Idx with the series
3970  /// of designators in [First, Last).
3971  void ExpandDesignator(ASTContext &C, unsigned Idx, const Designator *First,
3972                        const Designator *Last);
3973
3974  SourceRange getDesignatorsSourceRange() const;
3975
3976  SourceRange getSourceRange() const LLVM_READONLY;
3977
3978  static bool classof(const Stmt *T) {
3979    return T->getStmtClass() == DesignatedInitExprClass;
3980  }
3981  static bool classof(const DesignatedInitExpr *) { return true; }
3982
3983  // Iterators
3984  child_range children() {
3985    Stmt **begin = reinterpret_cast<Stmt**>(this + 1);
3986    return child_range(begin, begin + NumSubExprs);
3987  }
3988};
3989
3990/// \brief Represents an implicitly-generated value initialization of
3991/// an object of a given type.
3992///
3993/// Implicit value initializations occur within semantic initializer
3994/// list expressions (InitListExpr) as placeholders for subobject
3995/// initializations not explicitly specified by the user.
3996///
3997/// \see InitListExpr
3998class ImplicitValueInitExpr : public Expr {
3999public:
4000  explicit ImplicitValueInitExpr(QualType ty)
4001    : Expr(ImplicitValueInitExprClass, ty, VK_RValue, OK_Ordinary,
4002           false, false, ty->isInstantiationDependentType(), false) { }
4003
4004  /// \brief Construct an empty implicit value initialization.
4005  explicit ImplicitValueInitExpr(EmptyShell Empty)
4006    : Expr(ImplicitValueInitExprClass, Empty) { }
4007
4008  static bool classof(const Stmt *T) {
4009    return T->getStmtClass() == ImplicitValueInitExprClass;
4010  }
4011  static bool classof(const ImplicitValueInitExpr *) { return true; }
4012
4013  SourceRange getSourceRange() const LLVM_READONLY {
4014    return SourceRange();
4015  }
4016
4017  // Iterators
4018  child_range children() { return child_range(); }
4019};
4020
4021
4022class ParenListExpr : public Expr {
4023  Stmt **Exprs;
4024  unsigned NumExprs;
4025  SourceLocation LParenLoc, RParenLoc;
4026
4027public:
4028  ParenListExpr(ASTContext& C, SourceLocation lparenloc, Expr **exprs,
4029                unsigned numexprs, SourceLocation rparenloc);
4030
4031  /// \brief Build an empty paren list.
4032  explicit ParenListExpr(EmptyShell Empty) : Expr(ParenListExprClass, Empty) { }
4033
4034  unsigned getNumExprs() const { return NumExprs; }
4035
4036  const Expr* getExpr(unsigned Init) const {
4037    assert(Init < getNumExprs() && "Initializer access out of range!");
4038    return cast_or_null<Expr>(Exprs[Init]);
4039  }
4040
4041  Expr* getExpr(unsigned Init) {
4042    assert(Init < getNumExprs() && "Initializer access out of range!");
4043    return cast_or_null<Expr>(Exprs[Init]);
4044  }
4045
4046  Expr **getExprs() { return reinterpret_cast<Expr **>(Exprs); }
4047
4048  SourceLocation getLParenLoc() const { return LParenLoc; }
4049  SourceLocation getRParenLoc() const { return RParenLoc; }
4050
4051  SourceRange getSourceRange() const LLVM_READONLY {
4052    return SourceRange(LParenLoc, RParenLoc);
4053  }
4054  static bool classof(const Stmt *T) {
4055    return T->getStmtClass() == ParenListExprClass;
4056  }
4057  static bool classof(const ParenListExpr *) { return true; }
4058
4059  // Iterators
4060  child_range children() {
4061    return child_range(&Exprs[0], &Exprs[0]+NumExprs);
4062  }
4063
4064  friend class ASTStmtReader;
4065  friend class ASTStmtWriter;
4066};
4067
4068
4069/// \brief Represents a C11 generic selection.
4070///
4071/// A generic selection (C11 6.5.1.1) contains an unevaluated controlling
4072/// expression, followed by one or more generic associations.  Each generic
4073/// association specifies a type name and an expression, or "default" and an
4074/// expression (in which case it is known as a default generic association).
4075/// The type and value of the generic selection are identical to those of its
4076/// result expression, which is defined as the expression in the generic
4077/// association with a type name that is compatible with the type of the
4078/// controlling expression, or the expression in the default generic association
4079/// if no types are compatible.  For example:
4080///
4081/// @code
4082/// _Generic(X, double: 1, float: 2, default: 3)
4083/// @endcode
4084///
4085/// The above expression evaluates to 1 if 1.0 is substituted for X, 2 if 1.0f
4086/// or 3 if "hello".
4087///
4088/// As an extension, generic selections are allowed in C++, where the following
4089/// additional semantics apply:
4090///
4091/// Any generic selection whose controlling expression is type-dependent or
4092/// which names a dependent type in its association list is result-dependent,
4093/// which means that the choice of result expression is dependent.
4094/// Result-dependent generic associations are both type- and value-dependent.
4095class GenericSelectionExpr : public Expr {
4096  enum { CONTROLLING, END_EXPR };
4097  TypeSourceInfo **AssocTypes;
4098  Stmt **SubExprs;
4099  unsigned NumAssocs, ResultIndex;
4100  SourceLocation GenericLoc, DefaultLoc, RParenLoc;
4101
4102public:
4103  GenericSelectionExpr(ASTContext &Context,
4104                       SourceLocation GenericLoc, Expr *ControllingExpr,
4105                       TypeSourceInfo **AssocTypes, Expr **AssocExprs,
4106                       unsigned NumAssocs, SourceLocation DefaultLoc,
4107                       SourceLocation RParenLoc,
4108                       bool ContainsUnexpandedParameterPack,
4109                       unsigned ResultIndex);
4110
4111  /// This constructor is used in the result-dependent case.
4112  GenericSelectionExpr(ASTContext &Context,
4113                       SourceLocation GenericLoc, Expr *ControllingExpr,
4114                       TypeSourceInfo **AssocTypes, Expr **AssocExprs,
4115                       unsigned NumAssocs, SourceLocation DefaultLoc,
4116                       SourceLocation RParenLoc,
4117                       bool ContainsUnexpandedParameterPack);
4118
4119  explicit GenericSelectionExpr(EmptyShell Empty)
4120    : Expr(GenericSelectionExprClass, Empty) { }
4121
4122  unsigned getNumAssocs() const { return NumAssocs; }
4123
4124  SourceLocation getGenericLoc() const { return GenericLoc; }
4125  SourceLocation getDefaultLoc() const { return DefaultLoc; }
4126  SourceLocation getRParenLoc() const { return RParenLoc; }
4127
4128  const Expr *getAssocExpr(unsigned i) const {
4129    return cast<Expr>(SubExprs[END_EXPR+i]);
4130  }
4131  Expr *getAssocExpr(unsigned i) { return cast<Expr>(SubExprs[END_EXPR+i]); }
4132
4133  const TypeSourceInfo *getAssocTypeSourceInfo(unsigned i) const {
4134    return AssocTypes[i];
4135  }
4136  TypeSourceInfo *getAssocTypeSourceInfo(unsigned i) { return AssocTypes[i]; }
4137
4138  QualType getAssocType(unsigned i) const {
4139    if (const TypeSourceInfo *TS = getAssocTypeSourceInfo(i))
4140      return TS->getType();
4141    else
4142      return QualType();
4143  }
4144
4145  const Expr *getControllingExpr() const {
4146    return cast<Expr>(SubExprs[CONTROLLING]);
4147  }
4148  Expr *getControllingExpr() { return cast<Expr>(SubExprs[CONTROLLING]); }
4149
4150  /// Whether this generic selection is result-dependent.
4151  bool isResultDependent() const { return ResultIndex == -1U; }
4152
4153  /// The zero-based index of the result expression's generic association in
4154  /// the generic selection's association list.  Defined only if the
4155  /// generic selection is not result-dependent.
4156  unsigned getResultIndex() const {
4157    assert(!isResultDependent() && "Generic selection is result-dependent");
4158    return ResultIndex;
4159  }
4160
4161  /// The generic selection's result expression.  Defined only if the
4162  /// generic selection is not result-dependent.
4163  const Expr *getResultExpr() const { return getAssocExpr(getResultIndex()); }
4164  Expr *getResultExpr() { return getAssocExpr(getResultIndex()); }
4165
4166  SourceRange getSourceRange() const LLVM_READONLY {
4167    return SourceRange(GenericLoc, RParenLoc);
4168  }
4169  static bool classof(const Stmt *T) {
4170    return T->getStmtClass() == GenericSelectionExprClass;
4171  }
4172  static bool classof(const GenericSelectionExpr *) { return true; }
4173
4174  child_range children() {
4175    return child_range(SubExprs, SubExprs+END_EXPR+NumAssocs);
4176  }
4177
4178  friend class ASTStmtReader;
4179};
4180
4181//===----------------------------------------------------------------------===//
4182// Clang Extensions
4183//===----------------------------------------------------------------------===//
4184
4185
4186/// ExtVectorElementExpr - This represents access to specific elements of a
4187/// vector, and may occur on the left hand side or right hand side.  For example
4188/// the following is legal:  "V.xy = V.zw" if V is a 4 element extended vector.
4189///
4190/// Note that the base may have either vector or pointer to vector type, just
4191/// like a struct field reference.
4192///
4193class ExtVectorElementExpr : public Expr {
4194  Stmt *Base;
4195  IdentifierInfo *Accessor;
4196  SourceLocation AccessorLoc;
4197public:
4198  ExtVectorElementExpr(QualType ty, ExprValueKind VK, Expr *base,
4199                       IdentifierInfo &accessor, SourceLocation loc)
4200    : Expr(ExtVectorElementExprClass, ty, VK,
4201           (VK == VK_RValue ? OK_Ordinary : OK_VectorComponent),
4202           base->isTypeDependent(), base->isValueDependent(),
4203           base->isInstantiationDependent(),
4204           base->containsUnexpandedParameterPack()),
4205      Base(base), Accessor(&accessor), AccessorLoc(loc) {}
4206
4207  /// \brief Build an empty vector element expression.
4208  explicit ExtVectorElementExpr(EmptyShell Empty)
4209    : Expr(ExtVectorElementExprClass, Empty) { }
4210
4211  const Expr *getBase() const { return cast<Expr>(Base); }
4212  Expr *getBase() { return cast<Expr>(Base); }
4213  void setBase(Expr *E) { Base = E; }
4214
4215  IdentifierInfo &getAccessor() const { return *Accessor; }
4216  void setAccessor(IdentifierInfo *II) { Accessor = II; }
4217
4218  SourceLocation getAccessorLoc() const { return AccessorLoc; }
4219  void setAccessorLoc(SourceLocation L) { AccessorLoc = L; }
4220
4221  /// getNumElements - Get the number of components being selected.
4222  unsigned getNumElements() const;
4223
4224  /// containsDuplicateElements - Return true if any element access is
4225  /// repeated.
4226  bool containsDuplicateElements() const;
4227
4228  /// getEncodedElementAccess - Encode the elements accessed into an llvm
4229  /// aggregate Constant of ConstantInt(s).
4230  void getEncodedElementAccess(SmallVectorImpl<unsigned> &Elts) const;
4231
4232  SourceRange getSourceRange() const LLVM_READONLY {
4233    return SourceRange(getBase()->getLocStart(), AccessorLoc);
4234  }
4235
4236  /// isArrow - Return true if the base expression is a pointer to vector,
4237  /// return false if the base expression is a vector.
4238  bool isArrow() const;
4239
4240  static bool classof(const Stmt *T) {
4241    return T->getStmtClass() == ExtVectorElementExprClass;
4242  }
4243  static bool classof(const ExtVectorElementExpr *) { return true; }
4244
4245  // Iterators
4246  child_range children() { return child_range(&Base, &Base+1); }
4247};
4248
4249
4250/// BlockExpr - Adaptor class for mixing a BlockDecl with expressions.
4251/// ^{ statement-body }   or   ^(int arg1, float arg2){ statement-body }
4252class BlockExpr : public Expr {
4253protected:
4254  BlockDecl *TheBlock;
4255public:
4256  BlockExpr(BlockDecl *BD, QualType ty)
4257    : Expr(BlockExprClass, ty, VK_RValue, OK_Ordinary,
4258           ty->isDependentType(), ty->isDependentType(),
4259           ty->isInstantiationDependentType() || BD->isDependentContext(),
4260           false),
4261      TheBlock(BD) {}
4262
4263  /// \brief Build an empty block expression.
4264  explicit BlockExpr(EmptyShell Empty) : Expr(BlockExprClass, Empty) { }
4265
4266  const BlockDecl *getBlockDecl() const { return TheBlock; }
4267  BlockDecl *getBlockDecl() { return TheBlock; }
4268  void setBlockDecl(BlockDecl *BD) { TheBlock = BD; }
4269
4270  // Convenience functions for probing the underlying BlockDecl.
4271  SourceLocation getCaretLocation() const;
4272  const Stmt *getBody() const;
4273  Stmt *getBody();
4274
4275  SourceRange getSourceRange() const LLVM_READONLY {
4276    return SourceRange(getCaretLocation(), getBody()->getLocEnd());
4277  }
4278
4279  /// getFunctionType - Return the underlying function type for this block.
4280  const FunctionProtoType *getFunctionType() const;
4281
4282  static bool classof(const Stmt *T) {
4283    return T->getStmtClass() == BlockExprClass;
4284  }
4285  static bool classof(const BlockExpr *) { return true; }
4286
4287  // Iterators
4288  child_range children() { return child_range(); }
4289};
4290
4291/// AsTypeExpr - Clang builtin function __builtin_astype [OpenCL 6.2.4.2]
4292/// This AST node provides support for reinterpreting a type to another
4293/// type of the same size.
4294class AsTypeExpr : public Expr { // Should this be an ExplicitCastExpr?
4295private:
4296  Stmt *SrcExpr;
4297  SourceLocation BuiltinLoc, RParenLoc;
4298
4299  friend class ASTReader;
4300  friend class ASTStmtReader;
4301  explicit AsTypeExpr(EmptyShell Empty) : Expr(AsTypeExprClass, Empty) {}
4302
4303public:
4304  AsTypeExpr(Expr* SrcExpr, QualType DstType,
4305             ExprValueKind VK, ExprObjectKind OK,
4306             SourceLocation BuiltinLoc, SourceLocation RParenLoc)
4307    : Expr(AsTypeExprClass, DstType, VK, OK,
4308           DstType->isDependentType(),
4309           DstType->isDependentType() || SrcExpr->isValueDependent(),
4310           (DstType->isInstantiationDependentType() ||
4311            SrcExpr->isInstantiationDependent()),
4312           (DstType->containsUnexpandedParameterPack() ||
4313            SrcExpr->containsUnexpandedParameterPack())),
4314  SrcExpr(SrcExpr), BuiltinLoc(BuiltinLoc), RParenLoc(RParenLoc) {}
4315
4316  /// getSrcExpr - Return the Expr to be converted.
4317  Expr *getSrcExpr() const { return cast<Expr>(SrcExpr); }
4318
4319  /// getBuiltinLoc - Return the location of the __builtin_astype token.
4320  SourceLocation getBuiltinLoc() const { return BuiltinLoc; }
4321
4322  /// getRParenLoc - Return the location of final right parenthesis.
4323  SourceLocation getRParenLoc() const { return RParenLoc; }
4324
4325  SourceRange getSourceRange() const LLVM_READONLY {
4326    return SourceRange(BuiltinLoc, RParenLoc);
4327  }
4328
4329  static bool classof(const Stmt *T) {
4330    return T->getStmtClass() == AsTypeExprClass;
4331  }
4332  static bool classof(const AsTypeExpr *) { return true; }
4333
4334  // Iterators
4335  child_range children() { return child_range(&SrcExpr, &SrcExpr+1); }
4336};
4337
4338/// PseudoObjectExpr - An expression which accesses a pseudo-object
4339/// l-value.  A pseudo-object is an abstract object, accesses to which
4340/// are translated to calls.  The pseudo-object expression has a
4341/// syntactic form, which shows how the expression was actually
4342/// written in the source code, and a semantic form, which is a series
4343/// of expressions to be executed in order which detail how the
4344/// operation is actually evaluated.  Optionally, one of the semantic
4345/// forms may also provide a result value for the expression.
4346///
4347/// If any of the semantic-form expressions is an OpaqueValueExpr,
4348/// that OVE is required to have a source expression, and it is bound
4349/// to the result of that source expression.  Such OVEs may appear
4350/// only in subsequent semantic-form expressions and as
4351/// sub-expressions of the syntactic form.
4352///
4353/// PseudoObjectExpr should be used only when an operation can be
4354/// usefully described in terms of fairly simple rewrite rules on
4355/// objects and functions that are meant to be used by end-developers.
4356/// For example, under the Itanium ABI, dynamic casts are implemented
4357/// as a call to a runtime function called __dynamic_cast; using this
4358/// class to describe that would be inappropriate because that call is
4359/// not really part of the user-visible semantics, and instead the
4360/// cast is properly reflected in the AST and IR-generation has been
4361/// taught to generate the call as necessary.  In contrast, an
4362/// Objective-C property access is semantically defined to be
4363/// equivalent to a particular message send, and this is very much
4364/// part of the user model.  The name of this class encourages this
4365/// modelling design.
4366class PseudoObjectExpr : public Expr {
4367  // PseudoObjectExprBits.NumSubExprs - The number of sub-expressions.
4368  // Always at least two, because the first sub-expression is the
4369  // syntactic form.
4370
4371  // PseudoObjectExprBits.ResultIndex - The index of the
4372  // sub-expression holding the result.  0 means the result is void,
4373  // which is unambiguous because it's the index of the syntactic
4374  // form.  Note that this is therefore 1 higher than the value passed
4375  // in to Create, which is an index within the semantic forms.
4376  // Note also that ASTStmtWriter assumes this encoding.
4377
4378  Expr **getSubExprsBuffer() { return reinterpret_cast<Expr**>(this + 1); }
4379  const Expr * const *getSubExprsBuffer() const {
4380    return reinterpret_cast<const Expr * const *>(this + 1);
4381  }
4382
4383  friend class ASTStmtReader;
4384
4385  PseudoObjectExpr(QualType type, ExprValueKind VK,
4386                   Expr *syntactic, ArrayRef<Expr*> semantic,
4387                   unsigned resultIndex);
4388
4389  PseudoObjectExpr(EmptyShell shell, unsigned numSemanticExprs);
4390
4391  unsigned getNumSubExprs() const {
4392    return PseudoObjectExprBits.NumSubExprs;
4393  }
4394
4395public:
4396  /// NoResult - A value for the result index indicating that there is
4397  /// no semantic result.
4398  enum { NoResult = ~0U };
4399
4400  static PseudoObjectExpr *Create(ASTContext &Context, Expr *syntactic,
4401                                  ArrayRef<Expr*> semantic,
4402                                  unsigned resultIndex);
4403
4404  static PseudoObjectExpr *Create(ASTContext &Context, EmptyShell shell,
4405                                  unsigned numSemanticExprs);
4406
4407  /// Return the syntactic form of this expression, i.e. the
4408  /// expression it actually looks like.  Likely to be expressed in
4409  /// terms of OpaqueValueExprs bound in the semantic form.
4410  Expr *getSyntacticForm() { return getSubExprsBuffer()[0]; }
4411  const Expr *getSyntacticForm() const { return getSubExprsBuffer()[0]; }
4412
4413  /// Return the index of the result-bearing expression into the semantics
4414  /// expressions, or PseudoObjectExpr::NoResult if there is none.
4415  unsigned getResultExprIndex() const {
4416    if (PseudoObjectExprBits.ResultIndex == 0) return NoResult;
4417    return PseudoObjectExprBits.ResultIndex - 1;
4418  }
4419
4420  /// Return the result-bearing expression, or null if there is none.
4421  Expr *getResultExpr() {
4422    if (PseudoObjectExprBits.ResultIndex == 0)
4423      return 0;
4424    return getSubExprsBuffer()[PseudoObjectExprBits.ResultIndex];
4425  }
4426  const Expr *getResultExpr() const {
4427    return const_cast<PseudoObjectExpr*>(this)->getResultExpr();
4428  }
4429
4430  unsigned getNumSemanticExprs() const { return getNumSubExprs() - 1; }
4431
4432  typedef Expr * const *semantics_iterator;
4433  typedef const Expr * const *const_semantics_iterator;
4434  semantics_iterator semantics_begin() {
4435    return getSubExprsBuffer() + 1;
4436  }
4437  const_semantics_iterator semantics_begin() const {
4438    return getSubExprsBuffer() + 1;
4439  }
4440  semantics_iterator semantics_end() {
4441    return getSubExprsBuffer() + getNumSubExprs();
4442  }
4443  const_semantics_iterator semantics_end() const {
4444    return getSubExprsBuffer() + getNumSubExprs();
4445  }
4446  Expr *getSemanticExpr(unsigned index) {
4447    assert(index + 1 < getNumSubExprs());
4448    return getSubExprsBuffer()[index + 1];
4449  }
4450  const Expr *getSemanticExpr(unsigned index) const {
4451    return const_cast<PseudoObjectExpr*>(this)->getSemanticExpr(index);
4452  }
4453
4454  SourceLocation getExprLoc() const LLVM_READONLY {
4455    return getSyntacticForm()->getExprLoc();
4456  }
4457  SourceRange getSourceRange() const LLVM_READONLY {
4458    return getSyntacticForm()->getSourceRange();
4459  }
4460
4461  child_range children() {
4462    Stmt **cs = reinterpret_cast<Stmt**>(getSubExprsBuffer());
4463    return child_range(cs, cs + getNumSubExprs());
4464  }
4465
4466  static bool classof(const Stmt *T) {
4467    return T->getStmtClass() == PseudoObjectExprClass;
4468  }
4469  static bool classof(const PseudoObjectExpr *) { return true; }
4470};
4471
4472/// AtomicExpr - Variadic atomic builtins: __atomic_exchange, __atomic_fetch_*,
4473/// __atomic_load, __atomic_store, and __atomic_compare_exchange_*, for the
4474/// similarly-named C++11 instructions, and __c11 variants for <stdatomic.h>.
4475/// All of these instructions take one primary pointer and at least one memory
4476/// order.
4477class AtomicExpr : public Expr {
4478public:
4479  enum AtomicOp {
4480#define BUILTIN(ID, TYPE, ATTRS)
4481#define ATOMIC_BUILTIN(ID, TYPE, ATTRS) AO ## ID,
4482#include "clang/Basic/Builtins.def"
4483    // Avoid trailing comma
4484    BI_First = 0
4485  };
4486
4487private:
4488  enum { PTR, ORDER, VAL1, ORDER_FAIL, VAL2, WEAK, END_EXPR };
4489  Stmt* SubExprs[END_EXPR];
4490  unsigned NumSubExprs;
4491  SourceLocation BuiltinLoc, RParenLoc;
4492  AtomicOp Op;
4493
4494  friend class ASTStmtReader;
4495
4496public:
4497  AtomicExpr(SourceLocation BLoc, Expr **args, unsigned nexpr, QualType t,
4498             AtomicOp op, SourceLocation RP);
4499
4500  /// \brief Determine the number of arguments the specified atomic builtin
4501  /// should have.
4502  static unsigned getNumSubExprs(AtomicOp Op);
4503
4504  /// \brief Build an empty AtomicExpr.
4505  explicit AtomicExpr(EmptyShell Empty) : Expr(AtomicExprClass, Empty) { }
4506
4507  Expr *getPtr() const {
4508    return cast<Expr>(SubExprs[PTR]);
4509  }
4510  Expr *getOrder() const {
4511    return cast<Expr>(SubExprs[ORDER]);
4512  }
4513  Expr *getVal1() const {
4514    if (Op == AO__c11_atomic_init)
4515      return cast<Expr>(SubExprs[ORDER]);
4516    assert(NumSubExprs > VAL1);
4517    return cast<Expr>(SubExprs[VAL1]);
4518  }
4519  Expr *getOrderFail() const {
4520    assert(NumSubExprs > ORDER_FAIL);
4521    return cast<Expr>(SubExprs[ORDER_FAIL]);
4522  }
4523  Expr *getVal2() const {
4524    if (Op == AO__atomic_exchange)
4525      return cast<Expr>(SubExprs[ORDER_FAIL]);
4526    assert(NumSubExprs > VAL2);
4527    return cast<Expr>(SubExprs[VAL2]);
4528  }
4529  Expr *getWeak() const {
4530    assert(NumSubExprs > WEAK);
4531    return cast<Expr>(SubExprs[WEAK]);
4532  }
4533
4534  AtomicOp getOp() const { return Op; }
4535  unsigned getNumSubExprs() { return NumSubExprs; }
4536
4537  Expr **getSubExprs() { return reinterpret_cast<Expr **>(SubExprs); }
4538
4539  bool isVolatile() const {
4540    return getPtr()->getType()->getPointeeType().isVolatileQualified();
4541  }
4542
4543  bool isCmpXChg() const {
4544    return getOp() == AO__c11_atomic_compare_exchange_strong ||
4545           getOp() == AO__c11_atomic_compare_exchange_weak ||
4546           getOp() == AO__atomic_compare_exchange ||
4547           getOp() == AO__atomic_compare_exchange_n;
4548  }
4549
4550  SourceLocation getBuiltinLoc() const { return BuiltinLoc; }
4551  SourceLocation getRParenLoc() const { return RParenLoc; }
4552
4553  SourceRange getSourceRange() const LLVM_READONLY {
4554    return SourceRange(BuiltinLoc, RParenLoc);
4555  }
4556  static bool classof(const Stmt *T) {
4557    return T->getStmtClass() == AtomicExprClass;
4558  }
4559  static bool classof(const AtomicExpr *) { return true; }
4560
4561  // Iterators
4562  child_range children() {
4563    return child_range(SubExprs, SubExprs+NumSubExprs);
4564  }
4565};
4566}  // end namespace clang
4567
4568#endif
4569