Expr.h revision 5b54b88c4082bb81b8b341b622fda9a85cbd5fad
15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//===--- Expr.h - Classes for representing expressions ----------*- C++ -*-===//
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//                     The LLVM Compiler Infrastructure
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//
52a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// This file is distributed under the University of Illinois Open Source
62a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// License. See LICENSE.TXT for details.
72a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)//
82a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)//===----------------------------------------------------------------------===//
92a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)//
105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//  This file defines the Expr interface and subclasses.
115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//
125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//===----------------------------------------------------------------------===//
135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#ifndef LLVM_CLANG_AST_EXPR_H
152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#define LLVM_CLANG_AST_EXPR_H
162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "clang/AST/APValue.h"
185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "clang/AST/Stmt.h"
192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "clang/AST/Type.h"
205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "llvm/ADT/APSInt.h"
212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "llvm/ADT/APFloat.h"
22c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "llvm/ADT/SmallVector.h"
235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <vector>
242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace clang {
265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  class ASTContext;
275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  class APValue;
285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  class Decl;
2990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  class IdentifierInfo;
3090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  class ParmVarDecl;
3190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  class NamedDecl;
3290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  class ValueDecl;
3390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  class BlockDecl;
3490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  class CXXOperatorCallExpr;
3590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  class CXXMemberCallExpr;
3690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
3790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)/// Expr - This represents one expression.  Note that Expr's are subclasses of
3890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)/// Stmt.  This allows an expression to be transparently used any place a Stmt
3990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)/// is required.
402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)///
412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class Expr : public Stmt {
422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  QualType TR;
432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  /// TypeDependent - Whether this expression is type-dependent
452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  /// (C++ [temp.dep.expr]).
462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  bool TypeDependent : 1;
472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
484e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  /// ValueDependent - Whether this expression is value-dependent
495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// (C++ [temp.dep.constexpr]).
505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool ValueDependent : 1;
514e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)protected:
532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // FIXME: Eventually, this constructor should go away and we should
542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // require every subclass to provide type/value-dependence
552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // information.
565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Expr(StmtClass SC, QualType T)
575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    : Stmt(SC), TypeDependent(false), ValueDependent(false) {
585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    setType(T);
595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Expr(StmtClass SC, QualType T, bool TD, bool VD)
625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    : Stmt(SC), TypeDependent(TD), ValueDependent(VD) {
635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    setType(T);
645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// \brief Construct an empty expression.
675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  explicit Expr(StmtClass SC, EmptyShell) : Stmt(SC) { }
685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)public:
705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  QualType getType() const { return TR; }
715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void setType(QualType t) {
725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // In C++, the type of an expression is always adjusted so that it
735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // will not have reference type an expression will never have
745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // reference type (C++ [expr]p6). Use
755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // QualType::getNonReferenceType() to retrieve the non-reference
765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // type. Additionally, inspect Expr::isLvalue to determine whether
775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // an expression that is adjusted in this manner should be
785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // considered an lvalue.
795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    assert((TR.isNull() || !TR->isReferenceType()) &&
805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)           "Expressions can't have reference type");
815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    TR = t;
835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// isValueDependent - Determines whether this expression is
865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// value-dependent (C++ [temp.dep.constexpr]). For example, the
875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// array bound of "Chars" in the following example is
885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// value-dependent.
895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// @code
905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// template<int Size, char (&Chars)[Size]> struct meta_string;
915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// @endcode
925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool isValueDependent() const { return ValueDependent; }
935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// \brief Set whether this expression is value-dependent or not.
955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void setValueDependent(bool VD) { ValueDependent = VD; }
965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// isTypeDependent - Determines whether this expression is
985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// type-dependent (C++ [temp.dep.expr]), which means that its type
995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// could change from one template instantiation to the next. For
1005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// example, the expressions "x" and "x + y" are type-dependent in
1015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// the following code, but "y" is not type-dependent:
1025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// @code
1035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// template<typename T>
1045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// void add(T x, int y) {
1055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ///   x + y;
1065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// }
1075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// @endcode
1085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool isTypeDependent() const { return TypeDependent; }
1095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// \brief Set whether this expression is type-dependent or not.
1115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void setTypeDependent(bool TD) { TypeDependent = TD; }
1125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// SourceLocation tokens are not useful in isolation - they are low level
1145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// value objects created/interpreted by SourceManager. We assume AST
1155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// clients will have a pointer to the respective SourceManager.
1165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual SourceRange getSourceRange() const = 0;
1175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// getExprLoc - Return the preferred location for the arrow when diagnosing
1195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// a problem with a generic expression.
1205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual SourceLocation getExprLoc() const { return getLocStart(); }
1215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// isUnusedResultAWarning - Return true if this immediate expression should
1235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// be warned about if the result is unused.  If so, fill in Loc and Ranges
1245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// with location to warn on and the source range[s] to report with the
1255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// warning.
1265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool isUnusedResultAWarning(SourceLocation &Loc, SourceRange &R1,
1275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                              SourceRange &R2) const;
1285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// isLvalue - C99 6.3.2.1: an lvalue is an expression with an object type or
1305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// incomplete type other than void. Nonarray expressions that can be lvalues:
1315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ///  - name, where name must be a variable
1325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ///  - e[i]
1335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ///  - (e), where e must be an lvalue
1345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ///  - e.name, where e must be an lvalue
1355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ///  - e->name
1365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ///  - *e, the type of e cannot be a function type
1375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ///  - string-constant
1385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ///  - reference type [C++ [expr]]
1395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ///  - b ? x : y, where x and y are lvalues of suitable types [C++]
1405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ///
1415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  enum isLvalueResult {
1425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    LV_Valid,
1435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    LV_NotObjectType,
1445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    LV_IncompleteVoidType,
1455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    LV_DuplicateVectorComponents,
1465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    LV_InvalidExpression,
1475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    LV_MemberFunction
1485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  };
1495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  isLvalueResult isLvalue(ASTContext &Ctx) const;
1505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// isModifiableLvalue - C99 6.3.2.1: an lvalue that does not have array type,
1525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// does not have an incomplete type, does not have a const-qualified type,
1535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// and if it is a structure or union, does not have any member (including,
1545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// recursively, any member or element of all contained aggregates or unions)
1555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// with a const-qualified type.
1565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ///
1575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// \param Loc [in] [out] - A source location which *may* be filled
1585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// in with the location of the expression making this a
1595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// non-modifiable lvalue, if specified.
1605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  enum isModifiableLvalueResult {
1615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    MLV_Valid,
1625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    MLV_NotObjectType,
1635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    MLV_IncompleteVoidType,
1645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    MLV_DuplicateVectorComponents,
1655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    MLV_InvalidExpression,
1665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    MLV_LValueCast,           // Specialized form of MLV_InvalidExpression.
1675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    MLV_IncompleteType,
1685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    MLV_ConstQualified,
1695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    MLV_ArrayType,
1705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    MLV_NotBlockQualified,
1715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    MLV_ReadonlyProperty,
1725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    MLV_NoSetterProperty,
1735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    MLV_MemberFunction
1745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  };
1755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  isModifiableLvalueResult isModifiableLvalue(ASTContext &Ctx,
1765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                              SourceLocation *Loc = 0) const;
1775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool isBitField();
1795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// getIntegerConstantExprValue() - Return the value of an integer
1815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// constant expression. The expression must be a valid integer
1825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// constant expression as determined by isIntegerConstantExpr.
1835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  llvm::APSInt getIntegerConstantExprValue(ASTContext &Ctx) const {
1845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    llvm::APSInt X;
1855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    bool success = isIntegerConstantExpr(X, Ctx);
1865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    success = success;
1875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    assert(success && "Illegal argument to getIntegerConstantExpr");
1885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return X;
1895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
1905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// isIntegerConstantExpr - Return true if this expression is a valid integer
1925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// constant expression, and, if so, return its value in Result.  If not a
1935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// valid i-c-e, return false and fill in Loc (if specified) with the location
1945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// of the invalid expression.
1955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool isIntegerConstantExpr(llvm::APSInt &Result, ASTContext &Ctx,
1965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                             SourceLocation *Loc = 0,
1975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                             bool isEvaluated = true) const;
1985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool isIntegerConstantExprInternal(llvm::APSInt &Result, ASTContext &Ctx,
1995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                             SourceLocation *Loc = 0,
2005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                             bool isEvaluated = true) const;
2015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool isIntegerConstantExpr(ASTContext &Ctx, SourceLocation *Loc = 0) const {
2025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    llvm::APSInt X;
2035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return isIntegerConstantExpr(X, Ctx, Loc);
2045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
2055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// isConstantInitializer - Returns true if this expression is a constant
2065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// initializer, which can be emitted at compile-time.
2075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool isConstantInitializer(ASTContext &Ctx) const;
2085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// EvalResult is a struct with detailed info about an evaluated expression.
2105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  struct EvalResult {
2115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    /// Val - This is the value the expression can be folded to.
2125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    APValue Val;
2135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    /// HasSideEffects - Whether the evaluated expression has side effects.
2155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    /// For example, (f() && 0) can be folded, but it still has side effects.
2165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    bool HasSideEffects;
2175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    /// Diag - If the expression is unfoldable, then Diag contains a note
2195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    /// diagnostic indicating why it's not foldable. DiagLoc indicates a caret
2205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    /// position for the error, and DiagExpr is the expression that caused
2215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    /// the error.
2225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    /// If the expression is foldable, but not an integer constant expression,
2235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    /// Diag contains a note diagnostic that describes why it isn't an integer
2245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    /// constant expression. If the expression *is* an integer constant
2255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    /// expression, then Diag will be zero.
2265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    unsigned Diag;
2275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    const Expr *DiagExpr;
2285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    SourceLocation DiagLoc;
2295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    EvalResult() : HasSideEffects(false), Diag(0), DiagExpr(0) {}
2315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  };
2325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// Evaluate - Return true if this is a constant which we can fold using
2345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// any crazy technique (that has nothing to do with language standards) that
2355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// we want to.  If this function returns true, it returns the folded constant
2365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// in Result.
2375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool Evaluate(EvalResult &Result, ASTContext &Ctx) const;
2385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// isEvaluatable - Call Evaluate to see if this expression can be constant
2405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// folded, but discard the result.
2415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool isEvaluatable(ASTContext &Ctx) const;
2425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// EvaluateAsInt - Call Evaluate and return the folded integer. This
2445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// must be called on an expression that constant folds to an integer.
2455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  llvm::APSInt EvaluateAsInt(ASTContext &Ctx) const;
2465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// EvaluateAsLValue - Evaluate an expression to see if it's a valid LValue.
2485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool EvaluateAsLValue(EvalResult &Result, ASTContext &Ctx) const;
2495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// isNullPointerConstant - C99 6.3.2.3p3 -  Return true if this is either an
2515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// integer constant expression with the value zero, or if this is one that is
2525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// cast to void*.
2535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool isNullPointerConstant(ASTContext &Ctx) const;
2545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// hasGlobalStorage - Return true if this expression has static storage
2565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// duration.  This means that the address of this expression is a link-time
2575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// constant.
258a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  bool hasGlobalStorage() const;
259a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
260a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  /// isOBJCGCCandidate - Return true if this expression may be used in a read/
2612385ea399aae016c0806a4f9ef3c9cfe3d2a39dfBen Murdoch  /// write barrier.
2622385ea399aae016c0806a4f9ef3c9cfe3d2a39dfBen Murdoch  bool isOBJCGCCandidate() const;
2632385ea399aae016c0806a4f9ef3c9cfe3d2a39dfBen Murdoch
2642385ea399aae016c0806a4f9ef3c9cfe3d2a39dfBen Murdoch  /// IgnoreParens - Ignore parentheses.  If this Expr is a ParenExpr, return
2652385ea399aae016c0806a4f9ef3c9cfe3d2a39dfBen Murdoch  ///  its subexpression.  If that subexpression is also a ParenExpr,
2662385ea399aae016c0806a4f9ef3c9cfe3d2a39dfBen Murdoch  ///  then this method recursively returns its subexpression, and so forth.
2672385ea399aae016c0806a4f9ef3c9cfe3d2a39dfBen Murdoch  ///  Otherwise, the method returns the current Expr.
2682385ea399aae016c0806a4f9ef3c9cfe3d2a39dfBen Murdoch  Expr* IgnoreParens();
269a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
270a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  /// IgnoreParenCasts - Ignore parentheses and casts.  Strip off any ParenExpr
271a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  /// or CastExprs, returning their operand.
272c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  Expr *IgnoreParenCasts();
273c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
274c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  /// IgnoreParenNoopCasts - Ignore parentheses and casts that do not change the
2755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// value (including ptr->int casts of the same size).  Strip off any
276c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  /// ParenExpr or CastExprs, returning their operand.
2775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Expr *IgnoreParenNoopCasts(ASTContext &Ctx);
2785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  const Expr* IgnoreParens() const {
2805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return const_cast<Expr*>(this)->IgnoreParens();
2815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
2825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  const Expr *IgnoreParenCasts() const {
2835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return const_cast<Expr*>(this)->IgnoreParenCasts();
2845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
2855d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  const Expr *IgnoreParenNoopCasts(ASTContext &Ctx) const {
286868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    return const_cast<Expr*>(this)->IgnoreParenNoopCasts(Ctx);
2877dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  }
288a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
289a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  static bool hasAnyTypeDependentArguments(Expr** Exprs, unsigned NumExprs);
2905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static bool hasAnyValueDependentArguments(Expr** Exprs, unsigned NumExprs);
2915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static bool classof(const Stmt *T) {
2935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return T->getStmtClass() >= firstExprConstant &&
2945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)           T->getStmtClass() <= lastExprConstant;
2955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
2965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static bool classof(const Expr *) { return true; }
2975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static inline Expr* Create(llvm::Deserializer& D, ASTContext& C) {
2995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return cast<Expr>(Stmt::Create(D, C));
3005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
3015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
3025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//===----------------------------------------------------------------------===//
305a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// Primary Expressions.
306a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)//===----------------------------------------------------------------------===//
307a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
308a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)/// DeclRefExpr - [C99 6.5.1p2] - A reference to a declared variable, function,
3095d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)/// enum, etc.
310a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)class DeclRefExpr : public Expr {
311a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  NamedDecl *D;
312a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  SourceLocation Loc;
313a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
314a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)protected:
315a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // FIXME: Eventually, this constructor will go away and all subclasses
3165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // will have to provide the type- and value-dependent flags.
3175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  DeclRefExpr(StmtClass SC, NamedDecl *d, QualType t, SourceLocation l) :
3185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    Expr(SC, t), D(d), Loc(l) {}
3195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  DeclRefExpr(StmtClass SC, NamedDecl *d, QualType t, SourceLocation l, bool TD,
3215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)              bool VD) :
3225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    Expr(SC, t, TD, VD), D(d), Loc(l) {}
323a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
324a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)public:
325a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // FIXME: Eventually, this constructor will go away and all clients
326a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // will have to provide the type- and value-dependent flags.
3275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  DeclRefExpr(NamedDecl *d, QualType t, SourceLocation l) :
3285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    Expr(DeclRefExprClass, t), D(d), Loc(l) {}
3295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  DeclRefExpr(NamedDecl *d, QualType t, SourceLocation l, bool TD, bool VD) :
3315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    Expr(DeclRefExprClass, t, TD, VD), D(d), Loc(l) {}
3325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// \brief Construct an empty declaration reference expression.
3345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  explicit DeclRefExpr(EmptyShell Empty)
3355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    : Expr(DeclRefExprClass, Empty) { }
3365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  NamedDecl *getDecl() { return D; }
3385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  const NamedDecl *getDecl() const { return D; }
3395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void setDecl(NamedDecl *NewD) { D = NewD; }
3405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  SourceLocation getLocation() const { return Loc; }
3425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void setLocation(SourceLocation L) { Loc = L; }
3435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
3445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static bool classof(const Stmt *T) {
3465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return T->getStmtClass() == DeclRefExprClass ||
3475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)           T->getStmtClass() == CXXConditionDeclExprClass ||
3485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)           T->getStmtClass() == QualifiedDeclRefExprClass;
3492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
3502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  static bool classof(const DeclRefExpr *) { return true; }
3512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
3522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Iterators
3532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual child_iterator child_begin();
3542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual child_iterator child_end();
3552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
3562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void EmitImpl(llvm::Serializer& S) const;
3572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  static DeclRefExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C);
3582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)};
3592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
3602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)/// PredefinedExpr - [C99 6.4.2.2] - A predefined identifier such as __func__.
3612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class PredefinedExpr : public Expr {
3622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)public:
3632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  enum IdentType {
3642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    Func,
3652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    Function,
3662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    PrettyFunction
3675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  };
3685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)private:
3705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  SourceLocation Loc;
3715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  IdentType Type;
3725d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)public:
3735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  PredefinedExpr(SourceLocation l, QualType type, IdentType IT)
3745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    : Expr(PredefinedExprClass, type), Loc(l), Type(IT) {}
3755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
376a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  /// \brief Construct an empty predefined expression.
3775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  explicit PredefinedExpr(EmptyShell Empty)
3785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    : Expr(PredefinedExprClass, Empty) { }
3795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  IdentType getIdentType() const { return Type; }
3815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void setIdentType(IdentType IT) { Type = IT; }
3825d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
3835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  SourceLocation getLocation() const { return Loc; }
3842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  void setLocation(SourceLocation L) { Loc = L; }
3852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
3865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
387eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
3885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static bool classof(const Stmt *T) {
3892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    return T->getStmtClass() == PredefinedExprClass;
3902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
3912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  static bool classof(const PredefinedExpr *) { return true; }
3925d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
3932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Iterators
3942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual child_iterator child_begin();
3955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual child_iterator child_end();
396eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
397eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  virtual void EmitImpl(llvm::Serializer& S) const;
3982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  static PredefinedExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C);
3992a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)};
4005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class IntegerLiteral : public Expr {
4022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  llvm::APInt Value;
4035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  SourceLocation Loc;
4045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)public:
4052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // type should be IntTy, LongTy, LongLongTy, UnsignedIntTy, UnsignedLongTy,
4062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // or UnsignedLongLongTy
4075d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  IntegerLiteral(const llvm::APInt &V, QualType type, SourceLocation l)
4085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    : Expr(IntegerLiteralClass, type), Value(V), Loc(l) {
4092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    assert(type->isIntegerType() && "Illegal type in IntegerLiteral");
4102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
4112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
4122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  /// \brief Construct an empty integer literal.
4132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  explicit IntegerLiteral(EmptyShell Empty)
4145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    : Expr(IntegerLiteralClass, Empty) { }
4155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  IntegerLiteral* Clone(ASTContext &C) const;
4172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
4182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  const llvm::APInt &getValue() const { return Value; }
4195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
4205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  /// \brief Retrieve the location of the literal.
4222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  SourceLocation getLocation() const { return Loc; }
4235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  void setValue(const llvm::APInt &Val) { Value = Val; }
4252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  void setLocation(SourceLocation Location) { Loc = Location; }
4265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  static bool classof(const Stmt *T) {
4282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    return T->getStmtClass() == IntegerLiteralClass;
4295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  }
4302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  static bool classof(const IntegerLiteral *) { return true; }
4312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
4322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Iterators
4332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual child_iterator child_begin();
4345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual child_iterator child_end();
4355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void EmitImpl(llvm::Serializer& S) const;
4372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  static IntegerLiteral* CreateImpl(llvm::Deserializer& D, ASTContext& C);
4382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)};
4395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class CharacterLiteral : public Expr {
4412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  unsigned Value;
4422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  SourceLocation Loc;
4432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  bool IsWide;
4445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)public:
4455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // type should be IntTy
4462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  CharacterLiteral(unsigned value, bool iswide, QualType type, SourceLocation l)
4472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    : Expr(CharacterLiteralClass, type), Value(value), Loc(l), IsWide(iswide) {
4482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
4492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
4505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// \brief Construct an empty character literal.
4512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  CharacterLiteral(EmptyShell Empty) : Expr(CharacterLiteralClass, Empty) { }
4522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
4535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  SourceLocation getLoc() const { return Loc; }
4545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  bool isWide() const { return IsWide; }
4555d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
4565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
4575d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
4582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  unsigned getValue() const { return Value; }
4592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
4602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  void setLocation(SourceLocation Location) { Loc = Location; }
4615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void setWide(bool W) { IsWide = W; }
4625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void setValue(unsigned Val) { Value = Val; }
4632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
4642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  static bool classof(const Stmt *T) {
4652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    return T->getStmtClass() == CharacterLiteralClass;
4665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
4675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static bool classof(const CharacterLiteral *) { return true; }
4682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
4692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Iterators
4702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual child_iterator child_begin();
4715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual child_iterator child_end();
4725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void EmitImpl(llvm::Serializer& S) const;
4742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  static CharacterLiteral* CreateImpl(llvm::Deserializer& D, ASTContext& C);
4755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
4762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
4772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class FloatingLiteral : public Expr {
4785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  llvm::APFloat Value;
4792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  bool IsExact : 1;
4802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  SourceLocation Loc;
4815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)public:
4822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  FloatingLiteral(const llvm::APFloat &V, bool* isexact,
4835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                  QualType Type, SourceLocation L)
4842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    : Expr(FloatingLiteralClass, Type), Value(V), IsExact(*isexact), Loc(L) {}
4855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  /// \brief Construct an empty floating-point literal.
4872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  FloatingLiteral(EmptyShell Empty)
4882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    : Expr(FloatingLiteralClass, Empty), Value(0.0) { }
4892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
4905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  const llvm::APFloat &getValue() const { return Value; }
4915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void setValue(const llvm::APFloat &Val) { Value = Val; }
4922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
4932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  bool isExact() const { return IsExact; }
4942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  void setExact(bool E) { IsExact = E; }
4952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
4965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// getValueAsApproximateDouble - This returns the value as an inaccurate
4975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// double.  Note that this may cause loss of precision, but is useful for
498eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  /// debugging dumps, etc.
499eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  double getValueAsApproximateDouble() const;
5005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  SourceLocation getLocation() const { return Loc; }
5022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  void setLocation(SourceLocation L) { Loc = L; }
5032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
5042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
5052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
5065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static bool classof(const Stmt *T) {
5075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return T->getStmtClass() == FloatingLiteralClass;
508eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  }
509eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  static bool classof(const FloatingLiteral *) { return true; }
5105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Iterators
5122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual child_iterator child_begin();
5132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual child_iterator child_end();
5142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
5152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void EmitImpl(llvm::Serializer& S) const;
5162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  static FloatingLiteral* CreateImpl(llvm::Deserializer& D, ASTContext& C);
5172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)};
5182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
5192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)/// ImaginaryLiteral - We support imaginary integer and floating point literals,
5202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)/// like "1.0i".  We represent these as a wrapper around FloatingLiteral and
5212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)/// IntegerLiteral classes.  Instances of this class always have a Complex type
5222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)/// whose element type matches the subexpression.
5232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)///
5242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class ImaginaryLiteral : public Expr {
5252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  Stmt *Val;
5262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)public:
5275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ImaginaryLiteral(Expr *val, QualType Ty)
5285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    : Expr(ImaginaryLiteralClass, Ty), Val(val) {}
529eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
530eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  /// \brief Build an empty imaginary literal.
5312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  explicit ImaginaryLiteral(EmptyShell Empty)
5322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    : Expr(ImaginaryLiteralClass, Empty) { }
5332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
5342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  const Expr *getSubExpr() const { return cast<Expr>(Val); }
5355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Expr *getSubExpr() { return cast<Expr>(Val); }
5362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  void setSubExpr(Expr *E) { Val = E; }
5372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
5385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual SourceRange getSourceRange() const { return Val->getSourceRange(); }
5395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  static bool classof(const Stmt *T) {
5402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    return T->getStmtClass() == ImaginaryLiteralClass;
5412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
5422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  static bool classof(const ImaginaryLiteral *) { return true; }
5435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
544eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  // Iterators
545eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  virtual child_iterator child_begin();
5465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual child_iterator child_end();
5472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
5485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void EmitImpl(llvm::Serializer& S) const;
5495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static ImaginaryLiteral* CreateImpl(llvm::Deserializer& D, ASTContext& C);
5505d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)};
5515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)/// StringLiteral - This represents a string literal expression, e.g. "foo"
5535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)/// or L"bar" (wide strings).  The actual string is returned by getStrData()
5545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)/// is NOT null-terminated, and the length of the string is determined by
5555d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)/// calling getByteLength().  The C type for a string is always a
5565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)/// ConstantArrayType.  In C++, the char type is const qualified, in C it is
5572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)/// not.
5582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)///
5595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// Note that strings in C can be formed by concatenation of multiple string
5602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)/// literal pptokens in translation phase #6.  This keeps track of the locations
5612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)/// of each of these pieces.
5622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)///
5632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)/// Strings in C can also be truncated and extended by assigning into arrays,
5645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// e.g. with constructs like:
5655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)///   char X[2] = "foobar";
5665d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)/// In this case, getByteLength() will return 6, but the string literal will
5675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)/// have type "char[2]".
5685d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)class StringLiteral : public Expr {
5695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  const char *StrData;
5705d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  unsigned ByteLength;
5715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  bool IsWide;
572eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  unsigned NumConcatenated;
573eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  SourceLocation TokLocs[1];
5745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  StringLiteral(QualType Ty) : Expr(StringLiteralClass, Ty) {}
5765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)public:
5772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  /// This is the "fully general" constructor that allows representation of
5782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  /// strings formed from multiple concatenated tokens.
5795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static StringLiteral *Create(ASTContext &C, const char *StrData,
5805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                               unsigned ByteLength, bool Wide, QualType Ty,
5815d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                               const SourceLocation *Loc, unsigned NumStrs);
5825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  /// Simple constructor for string literals made from one token.
5842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  static StringLiteral *Create(ASTContext &C, const char *StrData,
5852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                               unsigned ByteLength,
5862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                               bool Wide, QualType Ty, SourceLocation Loc) {
5872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    return Create(C, StrData, ByteLength, Wide, Ty, &Loc, 1);
5882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
5892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
5902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  /// \brief Construct an empty string literal.
5912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  static StringLiteral *CreateEmpty(ASTContext &C, unsigned NumStrs);
5922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
5935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  StringLiteral* Clone(ASTContext &C) const;
5942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  void Destroy(ASTContext &C);
5955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  const char *getStrData() const { return StrData; }
5975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  unsigned getByteLength() const { return ByteLength; }
5982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
5992a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  /// \brief Sets the string data to the given string data.
6002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  void setStrData(ASTContext &C, const char *Str, unsigned Len);
6012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
6022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  bool isWide() const { return IsWide; }
6032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  void setWide(bool W) { IsWide = W; }
6042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
6052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  bool containsNonAsciiOrNull() const {
6062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    for (unsigned i = 0; i < getByteLength(); ++i)
6072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      if (!isascii(getStrData()[i]) || !getStrData()[i])
6082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)        return true;
6095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return false;
610a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  }
6112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  /// getNumConcatenated - Get the number of string literal tokens that were
6122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  /// concatenated in translation phase #6 to form this string literal.
6132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  unsigned getNumConcatenated() const { return NumConcatenated; }
6145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
615a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  SourceLocation getStrTokenLoc(unsigned TokNum) const {
616a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    assert(TokNum < NumConcatenated && "Invalid tok number");
617a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    return TokLocs[TokNum];
618a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  }
6195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void setStrTokenLoc(unsigned TokNum, SourceLocation L) {
620eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch    assert(TokNum < NumConcatenated && "Invalid tok number");
621eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch    TokLocs[TokNum] = L;
6225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
6232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
6242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  typedef const SourceLocation *tokloc_iterator;
625a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  tokloc_iterator tokloc_begin() const { return TokLocs; }
6262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  tokloc_iterator tokloc_end() const { return TokLocs+NumConcatenated; }
6272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
6285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual SourceRange getSourceRange() const {
6295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return SourceRange(TokLocs[0], TokLocs[NumConcatenated-1]);
6305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  }
6315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static bool classof(const Stmt *T) {
632a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    return T->getStmtClass() == StringLiteralClass;
6332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
6345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static bool classof(const StringLiteral *) { return true; }
635a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
636a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // Iterators
637a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  virtual child_iterator child_begin();
638a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  virtual child_iterator child_end();
639eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
640eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  virtual void EmitImpl(llvm::Serializer& S) const;
6415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static StringLiteral* CreateImpl(llvm::Deserializer& D, ASTContext& C);
6422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)};
643a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
6442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)/// ParenExpr - This represents a parethesized expression, e.g. "(1)".  This
6452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)/// AST node is only formed if full location information is requested.
6465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class ParenExpr : public Expr {
6475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  SourceLocation L, R;
6485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  Stmt *Val;
6495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)public:
6505d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  ParenExpr(SourceLocation l, SourceLocation r, Expr *val)
6515d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    : Expr(ParenExprClass, val->getType(),
6525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)           val->isTypeDependent(), val->isValueDependent()),
6532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      L(l), R(r), Val(val) {}
6542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
6552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  /// \brief Construct an empty parenthesized expression.
6562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  explicit ParenExpr(EmptyShell Empty)
6572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    : Expr(ParenExprClass, Empty) { }
6582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
6592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  const Expr *getSubExpr() const { return cast<Expr>(Val); }
6602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  Expr *getSubExpr() { return cast<Expr>(Val); }
6612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  void setSubExpr(Expr *E) { Val = E; }
6622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
6635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual SourceRange getSourceRange() const { return SourceRange(L, R); }
6645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  /// \brief Get the location of the left parentheses '('.
6665d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  SourceLocation getLParen() const { return L; }
667eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  void setLParen(SourceLocation Loc) { L = Loc; }
668eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
6695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// \brief Get the location of the right parentheses ')'.
6702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  SourceLocation getRParen() const { return R; }
6712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  void setRParen(SourceLocation Loc) { R = Loc; }
6725d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
6732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  static bool classof(const Stmt *T) {
6742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    return T->getStmtClass() == ParenExprClass;
6755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
6765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static bool classof(const ParenExpr *) { return true; }
6775d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
6785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Iterators
6792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual child_iterator child_begin();
680a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  virtual child_iterator child_end();
681a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
682a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  virtual void EmitImpl(llvm::Serializer& S) const;
683a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  static ParenExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C);
6845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
685eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
686eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
687a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)/// UnaryOperator - This represents the unary-expression's (except sizeof and
688a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)/// alignof), the postinc/postdec operators from postfix-expression, and various
689a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)/// extensions.
690a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)///
691a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)/// Notes on various nodes:
692a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)///
693a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)/// Real/Imag - These return the real/imag part of a complex operand.  If
6945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)///   applied to a non-complex value, the former returns its operand and the
695a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)///   later returns zero in the type of the operand.
696a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)///
697a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)/// __builtin_offsetof(type, a.b[10]) is represented as a unary operator whose
698a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)///   subexpression is a compound literal with the various MemberExpr and
6992a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)///   ArraySubscriptExpr's applied to it.
7005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)///
7015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class UnaryOperator : public Expr {
7025d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)public:
7035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Note that additions to this should also update the StmtVisitor class.
7042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  enum Opcode {
7052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    PostInc, PostDec, // [C99 6.5.2.4] Postfix increment and decrement operators
7062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    PreInc, PreDec,   // [C99 6.5.3.1] Prefix increment and decrement operators.
7075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    AddrOf, Deref,    // [C99 6.5.3.2] Address and indirection operators.
7082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    Plus, Minus,      // [C99 6.5.3.3] Unary arithmetic operators.
7092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    Not, LNot,        // [C99 6.5.3.3] Unary arithmetic operators.
7102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    Real, Imag,       // "__real expr"/"__imag expr" Extension.
7112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    Extension,        // __extension__ marker.
7122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    OffsetOf          // __builtin_offsetof
7135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  };
7145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)private:
715eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  Stmt *Val;
716eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  Opcode Opc;
7175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  SourceLocation Loc;
7182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)public:
7192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
7202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  UnaryOperator(Expr *input, Opcode opc, QualType type, SourceLocation l)
7215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    : Expr(UnaryOperatorClass, type,
7225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)           input->isTypeDependent() && opc != OffsetOf,
723eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch           input->isValueDependent()),
724eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch      Val(input), Opc(opc), Loc(l) {}
7255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
7265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  /// \brief Build an empty unary operator.
7275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  explicit UnaryOperator(EmptyShell Empty)
728868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    : Expr(UnaryOperatorClass, Empty), Opc(AddrOf) { }
729eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
730eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  Opcode getOpcode() const { return Opc; }
7315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  void setOpcode(Opcode O) { Opc = O; }
7325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
733868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  Expr *getSubExpr() const { return cast<Expr>(Val); }
734868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  void setSubExpr(Expr *E) { Val = E; }
7355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
7365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  /// getOperatorLoc - Return the location of the operator.
7377dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  SourceLocation getOperatorLoc() const { return Loc; }
7387dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  void setOperatorLoc(SourceLocation L) { Loc = L; }
7397dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
740a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  /// isPostfix - Return true if this is a postfix operation, like x++.
741a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  static bool isPostfix(Opcode Op) {
7427dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch    return Op == PostInc || Op == PostDec;
7437dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  }
744a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
745a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  /// isPostfix - Return true if this is a prefix operation, like --x.
746a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  static bool isPrefix(Opcode Op) {
747a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    return Op == PreInc || Op == PreDec;
7487dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  }
7497dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
7507dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  bool isPrefix() const { return isPrefix(Opc); }
7517dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  bool isPostfix() const { return isPostfix(Opc); }
7527dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  bool isIncrementOp() const {return Opc==PreInc || Opc==PostInc; }
753a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  bool isIncrementDecrementOp() const { return Opc>=PostInc && Opc<=PreDec; }
7547dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  bool isOffsetOfOp() const { return Opc == OffsetOf; }
7557dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  static bool isArithmeticOp(Opcode Op) { return Op >= Plus && Op <= LNot; }
7567dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
75723730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)  /// getOpcodeStr - Turn an Opcode enum value into the punctuation char it
75823730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)  /// corresponds to, e.g. "sizeof" or "[pre]++"
759a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  static const char *getOpcodeStr(Opcode Op);
760a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
761a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  /// \brief Retrieve the unary opcode that corresponds to the given
762a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  /// overloaded operator.
763a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  static Opcode getOverloadedOpcode(OverloadedOperatorKind OO, bool Postfix);
764a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
765a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  /// \brief Retrieve the overloaded operator kind that corresponds to
766a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  /// the given unary opcode.
767a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  static OverloadedOperatorKind getOverloadedOperator(Opcode Opc);
768a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
769a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  virtual SourceRange getSourceRange() const {
770a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    if (isPostfix())
771a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      return SourceRange(Val->getLocStart(), Loc);
772a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    else
773a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      return SourceRange(Loc, Val->getLocEnd());
774a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  }
7757dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  virtual SourceLocation getExprLoc() const { return Loc; }
7762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
7772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  static bool classof(const Stmt *T) {
7785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return T->getStmtClass() == UnaryOperatorClass;
7792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
7802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  static bool classof(const UnaryOperator *) { return true; }
7812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
7822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Iterators
7832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual child_iterator child_begin();
7842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual child_iterator child_end();
7852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
7862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void EmitImpl(llvm::Serializer& S) const;
7872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  static UnaryOperator* CreateImpl(llvm::Deserializer& D, ASTContext& C);
7882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)};
7892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
7902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)/// SizeOfAlignOfExpr - [C99 6.5.3.4] - This is for sizeof/alignof, both of
7912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)/// types and expressions.
7922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class SizeOfAlignOfExpr : public Expr {
7932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  bool isSizeof : 1;  // true if sizeof, false if alignof.
7945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool isType : 1;    // true if operand is a type, false if an expression
7955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  union {
7962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    void *Ty;
7972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    Stmt *Ex;
7982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  } Argument;
7992a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  SourceLocation OpLoc, RParenLoc;
8002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)public:
8015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  SizeOfAlignOfExpr(bool issizeof, QualType T,
8025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                    QualType resultType, SourceLocation op,
8032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                    SourceLocation rp) :
8042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      Expr(SizeOfAlignOfExprClass, resultType,
8052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)           false, // Never type-dependent (C++ [temp.dep.expr]p3).
8065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)           // Value-dependent if the argument is type-dependent.
8072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)           T->isDependentType()),
8082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      isSizeof(issizeof), isType(true), OpLoc(op), RParenLoc(rp) {
8095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    Argument.Ty = T.getAsOpaquePtr();
8102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
8112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
8125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  SizeOfAlignOfExpr(bool issizeof, Expr *E,
8135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                    QualType resultType, SourceLocation op,
8142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                    SourceLocation rp) :
8152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      Expr(SizeOfAlignOfExprClass, resultType,
8162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)           false, // Never type-dependent (C++ [temp.dep.expr]p3).
8175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)           // Value-dependent if the argument is type-dependent.
8185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)           E->isTypeDependent()),
819eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch      isSizeof(issizeof), isType(false), OpLoc(op), RParenLoc(rp) {
820eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch    Argument.Ex = E;
821eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  }
822eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
823eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  /// \brief Construct an empty sizeof/alignof expression.
824eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  explicit SizeOfAlignOfExpr(EmptyShell Empty)
825eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch    : Expr(SizeOfAlignOfExprClass, Empty) { }
826eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
827eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  virtual void Destroy(ASTContext& C);
828eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
829eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  bool isSizeOf() const { return isSizeof; }
830eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  void setSizeof(bool S) { isSizeof = S; }
831eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
832eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  bool isArgumentType() const { return isType; }
833eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  QualType getArgumentType() const {
8347dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch    assert(isArgumentType() && "calling getArgumentType() when arg is expr");
835a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    return QualType::getFromOpaquePtr(Argument.Ty);
836eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  }
837eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  Expr *getArgumentExpr() {
838eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch    assert(!isArgumentType() && "calling getArgumentExpr() when arg is type");
839eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch    return static_cast<Expr*>(Argument.Ex);
840eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  }
841eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  const Expr *getArgumentExpr() const {
842eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch    return const_cast<SizeOfAlignOfExpr*>(this)->getArgumentExpr();
843eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  }
844eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
845eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  void setArgument(Expr *E) { Argument.Ex = E; isType = false; }
8465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void setArgument(QualType T) {
8475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    Argument.Ty = T.getAsOpaquePtr();
8485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    isType = true;
849  }
850
851  /// Gets the argument type, or the type of the argument expression, whichever
852  /// is appropriate.
853  QualType getTypeOfArgument() const {
854    return isArgumentType() ? getArgumentType() : getArgumentExpr()->getType();
855  }
856
857  SourceLocation getOperatorLoc() const { return OpLoc; }
858  void setOperatorLoc(SourceLocation L) { OpLoc = L; }
859
860  SourceLocation getRParenLoc() const { return RParenLoc; }
861  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
862
863  virtual SourceRange getSourceRange() const {
864    return SourceRange(OpLoc, RParenLoc);
865  }
866
867  static bool classof(const Stmt *T) {
868    return T->getStmtClass() == SizeOfAlignOfExprClass;
869  }
870  static bool classof(const SizeOfAlignOfExpr *) { return true; }
871
872  // Iterators
873  virtual child_iterator child_begin();
874  virtual child_iterator child_end();
875
876  virtual void EmitImpl(llvm::Serializer& S) const;
877  static SizeOfAlignOfExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C);
878};
879
880//===----------------------------------------------------------------------===//
881// Postfix Operators.
882//===----------------------------------------------------------------------===//
883
884/// ArraySubscriptExpr - [C99 6.5.2.1] Array Subscripting.
885class ArraySubscriptExpr : public Expr {
886  enum { LHS, RHS, END_EXPR=2 };
887  Stmt* SubExprs[END_EXPR];
888  SourceLocation RBracketLoc;
889public:
890  ArraySubscriptExpr(Expr *lhs, Expr *rhs, QualType t,
891                     SourceLocation rbracketloc)
892  : Expr(ArraySubscriptExprClass, t,
893         lhs->isTypeDependent() || rhs->isTypeDependent(),
894         lhs->isValueDependent() || rhs->isValueDependent()),
895    RBracketLoc(rbracketloc) {
896    SubExprs[LHS] = lhs;
897    SubExprs[RHS] = rhs;
898  }
899
900  /// \brief Create an empty array subscript expression.
901  explicit ArraySubscriptExpr(EmptyShell Shell)
902    : Expr(ArraySubscriptExprClass, Shell) { }
903
904  /// An array access can be written A[4] or 4[A] (both are equivalent).
905  /// - getBase() and getIdx() always present the normalized view: A[4].
906  ///    In this case getBase() returns "A" and getIdx() returns "4".
907  /// - getLHS() and getRHS() present the syntactic view. e.g. for
908  ///    4[A] getLHS() returns "4".
909  /// Note: Because vector element access is also written A[4] we must
910  /// predicate the format conversion in getBase and getIdx only on the
911  /// the type of the RHS, as it is possible for the LHS to be a vector of
912  /// integer type
913  Expr *getLHS() { return cast<Expr>(SubExprs[LHS]); }
914  const Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); }
915  void setLHS(Expr *E) { SubExprs[LHS] = E; }
916
917  Expr *getRHS() { return cast<Expr>(SubExprs[RHS]); }
918  const Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); }
919  void setRHS(Expr *E) { SubExprs[RHS] = E; }
920
921  Expr *getBase() {
922    return cast<Expr>(getRHS()->getType()->isIntegerType() ? getLHS():getRHS());
923  }
924
925  const Expr *getBase() const {
926    return cast<Expr>(getRHS()->getType()->isIntegerType() ? getLHS():getRHS());
927  }
928
929  Expr *getIdx() {
930    return cast<Expr>(getRHS()->getType()->isIntegerType() ? getRHS():getLHS());
931  }
932
933  const Expr *getIdx() const {
934    return cast<Expr>(getRHS()->getType()->isIntegerType() ? getRHS():getLHS());
935  }
936
937  virtual SourceRange getSourceRange() const {
938    return SourceRange(getLHS()->getLocStart(), RBracketLoc);
939  }
940
941  SourceLocation getRBracketLoc() const { return RBracketLoc; }
942  void setRBracketLoc(SourceLocation L) { RBracketLoc = L; }
943
944  virtual SourceLocation getExprLoc() const { return getBase()->getExprLoc(); }
945
946  static bool classof(const Stmt *T) {
947    return T->getStmtClass() == ArraySubscriptExprClass;
948  }
949  static bool classof(const ArraySubscriptExpr *) { return true; }
950
951  // Iterators
952  virtual child_iterator child_begin();
953  virtual child_iterator child_end();
954
955  virtual void EmitImpl(llvm::Serializer& S) const;
956  static ArraySubscriptExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C);
957};
958
959
960/// CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
961/// CallExpr itself represents a normal function call, e.g., "f(x, 2)",
962/// while its subclasses may represent alternative syntax that (semantically)
963/// results in a function call. For example, CXXOperatorCallExpr is
964/// a subclass for overloaded operator calls that use operator syntax, e.g.,
965/// "str1 + str2" to resolve to a function call.
966class CallExpr : public Expr {
967  enum { FN=0, ARGS_START=1 };
968  Stmt **SubExprs;
969  unsigned NumArgs;
970  SourceLocation RParenLoc;
971
972  // This version of the ctor is for deserialization.
973  CallExpr(StmtClass SC, Stmt** subexprs, unsigned numargs, QualType t,
974           SourceLocation rparenloc)
975  : Expr(SC,t), SubExprs(subexprs),
976    NumArgs(numargs), RParenLoc(rparenloc) {}
977
978protected:
979  // This version of the constructor is for derived classes.
980  CallExpr(ASTContext& C, StmtClass SC, Expr *fn, Expr **args, unsigned numargs,
981           QualType t, SourceLocation rparenloc);
982
983public:
984  CallExpr(ASTContext& C, Expr *fn, Expr **args, unsigned numargs, QualType t,
985           SourceLocation rparenloc);
986
987  /// \brief Build an empty call expression.
988  CallExpr(ASTContext &C, EmptyShell Empty);
989
990  ~CallExpr() {}
991
992  void Destroy(ASTContext& C);
993
994  const Expr *getCallee() const { return cast<Expr>(SubExprs[FN]); }
995  Expr *getCallee() { return cast<Expr>(SubExprs[FN]); }
996  void setCallee(Expr *F) { SubExprs[FN] = F; }
997
998  /// getNumArgs - Return the number of actual arguments to this call.
999  ///
1000  unsigned getNumArgs() const { return NumArgs; }
1001
1002  /// getArg - Return the specified argument.
1003  Expr *getArg(unsigned Arg) {
1004    assert(Arg < NumArgs && "Arg access out of range!");
1005    return cast<Expr>(SubExprs[Arg+ARGS_START]);
1006  }
1007  const Expr *getArg(unsigned Arg) const {
1008    assert(Arg < NumArgs && "Arg access out of range!");
1009    return cast<Expr>(SubExprs[Arg+ARGS_START]);
1010  }
1011
1012  /// setArg - Set the specified argument.
1013  void setArg(unsigned Arg, Expr *ArgExpr) {
1014    assert(Arg < NumArgs && "Arg access out of range!");
1015    SubExprs[Arg+ARGS_START] = ArgExpr;
1016  }
1017
1018  /// setNumArgs - This changes the number of arguments present in this call.
1019  /// Any orphaned expressions are deleted by this, and any new operands are set
1020  /// to null.
1021  void setNumArgs(ASTContext& C, unsigned NumArgs);
1022
1023  typedef ExprIterator arg_iterator;
1024  typedef ConstExprIterator const_arg_iterator;
1025
1026  arg_iterator arg_begin() { return SubExprs+ARGS_START; }
1027  arg_iterator arg_end() { return SubExprs+ARGS_START+getNumArgs(); }
1028  const_arg_iterator arg_begin() const { return SubExprs+ARGS_START; }
1029  const_arg_iterator arg_end() const { return SubExprs+ARGS_START+getNumArgs();}
1030
1031  /// getNumCommas - Return the number of commas that must have been present in
1032  /// this function call.
1033  unsigned getNumCommas() const { return NumArgs ? NumArgs - 1 : 0; }
1034
1035  /// isBuiltinCall - If this is a call to a builtin, return the builtin ID.  If
1036  /// not, return 0.
1037  unsigned isBuiltinCall(ASTContext &Context) const;
1038
1039  SourceLocation getRParenLoc() const { return RParenLoc; }
1040  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
1041
1042  virtual SourceRange getSourceRange() const {
1043    return SourceRange(getCallee()->getLocStart(), RParenLoc);
1044  }
1045
1046  static bool classof(const Stmt *T) {
1047    return T->getStmtClass() == CallExprClass ||
1048           T->getStmtClass() == CXXOperatorCallExprClass ||
1049           T->getStmtClass() == CXXMemberCallExprClass;
1050  }
1051  static bool classof(const CallExpr *) { return true; }
1052  static bool classof(const CXXOperatorCallExpr *) { return true; }
1053  static bool classof(const CXXMemberCallExpr *) { return true; }
1054
1055  // Iterators
1056  virtual child_iterator child_begin();
1057  virtual child_iterator child_end();
1058
1059  virtual void EmitImpl(llvm::Serializer& S) const;
1060  static CallExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C,
1061                              StmtClass SC);
1062};
1063
1064/// MemberExpr - [C99 6.5.2.3] Structure and Union Members.  X->F and X.F.
1065///
1066class MemberExpr : public Expr {
1067  /// Base - the expression for the base pointer or structure references.  In
1068  /// X.F, this is "X".
1069  Stmt *Base;
1070
1071  /// MemberDecl - This is the decl being referenced by the field/member name.
1072  /// In X.F, this is the decl referenced by F.
1073  NamedDecl *MemberDecl;
1074
1075  /// MemberLoc - This is the location of the member name.
1076  SourceLocation MemberLoc;
1077
1078  /// IsArrow - True if this is "X->F", false if this is "X.F".
1079  bool IsArrow;
1080public:
1081  MemberExpr(Expr *base, bool isarrow, NamedDecl *memberdecl, SourceLocation l,
1082             QualType ty)
1083    : Expr(MemberExprClass, ty),
1084      Base(base), MemberDecl(memberdecl), MemberLoc(l), IsArrow(isarrow) {}
1085
1086  /// \brief Build an empty member reference expression.
1087  explicit MemberExpr(EmptyShell Empty) : Expr(MemberExprClass, Empty) { }
1088
1089  void setBase(Expr *E) { Base = E; }
1090  Expr *getBase() const { return cast<Expr>(Base); }
1091
1092  /// \brief Retrieve the member declaration to which this expression refers.
1093  ///
1094  /// The returned declaration will either be a FieldDecl or (in C++)
1095  /// a CXXMethodDecl.
1096  NamedDecl *getMemberDecl() const { return MemberDecl; }
1097  void setMemberDecl(NamedDecl *D) { MemberDecl = D; }
1098
1099  bool isArrow() const { return IsArrow; }
1100  void setArrow(bool A) { IsArrow = A; }
1101
1102  /// getMemberLoc - Return the location of the "member", in X->F, it is the
1103  /// location of 'F'.
1104  SourceLocation getMemberLoc() const { return MemberLoc; }
1105  void setMemberLoc(SourceLocation L) { MemberLoc = L; }
1106
1107  virtual SourceRange getSourceRange() const {
1108    return SourceRange(getBase()->getLocStart(), MemberLoc);
1109  }
1110
1111  virtual SourceLocation getExprLoc() const { return MemberLoc; }
1112
1113  static bool classof(const Stmt *T) {
1114    return T->getStmtClass() == MemberExprClass;
1115  }
1116  static bool classof(const MemberExpr *) { return true; }
1117
1118  // Iterators
1119  virtual child_iterator child_begin();
1120  virtual child_iterator child_end();
1121
1122  virtual void EmitImpl(llvm::Serializer& S) const;
1123  static MemberExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C);
1124};
1125
1126/// CompoundLiteralExpr - [C99 6.5.2.5]
1127///
1128class CompoundLiteralExpr : public Expr {
1129  /// LParenLoc - If non-null, this is the location of the left paren in a
1130  /// compound literal like "(int){4}".  This can be null if this is a
1131  /// synthesized compound expression.
1132  SourceLocation LParenLoc;
1133  Stmt *Init;
1134  bool FileScope;
1135public:
1136  CompoundLiteralExpr(SourceLocation lparenloc, QualType ty, Expr *init,
1137                      bool fileScope)
1138    : Expr(CompoundLiteralExprClass, ty), LParenLoc(lparenloc), Init(init),
1139      FileScope(fileScope) {}
1140
1141  /// \brief Construct an empty compound literal.
1142  explicit CompoundLiteralExpr(EmptyShell Empty)
1143    : Expr(CompoundLiteralExprClass, Empty) { }
1144
1145  const Expr *getInitializer() const { return cast<Expr>(Init); }
1146  Expr *getInitializer() { return cast<Expr>(Init); }
1147  void setInitializer(Expr *E) { Init = E; }
1148
1149  bool isFileScope() const { return FileScope; }
1150  void setFileScope(bool FS) { FileScope = FS; }
1151
1152  SourceLocation getLParenLoc() const { return LParenLoc; }
1153  void setLParenLoc(SourceLocation L) { LParenLoc = L; }
1154
1155  virtual SourceRange getSourceRange() const {
1156    // FIXME: Init should never be null.
1157    if (!Init)
1158      return SourceRange();
1159    if (LParenLoc.isInvalid())
1160      return Init->getSourceRange();
1161    return SourceRange(LParenLoc, Init->getLocEnd());
1162  }
1163
1164  static bool classof(const Stmt *T) {
1165    return T->getStmtClass() == CompoundLiteralExprClass;
1166  }
1167  static bool classof(const CompoundLiteralExpr *) { return true; }
1168
1169  // Iterators
1170  virtual child_iterator child_begin();
1171  virtual child_iterator child_end();
1172
1173  virtual void EmitImpl(llvm::Serializer& S) const;
1174  static CompoundLiteralExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C);
1175};
1176
1177/// CastExpr - Base class for type casts, including both implicit
1178/// casts (ImplicitCastExpr) and explicit casts that have some
1179/// representation in the source code (ExplicitCastExpr's derived
1180/// classes).
1181class CastExpr : public Expr {
1182  Stmt *Op;
1183protected:
1184  CastExpr(StmtClass SC, QualType ty, Expr *op) :
1185    Expr(SC, ty,
1186         // Cast expressions are type-dependent if the type is
1187         // dependent (C++ [temp.dep.expr]p3).
1188         ty->isDependentType(),
1189         // Cast expressions are value-dependent if the type is
1190         // dependent or if the subexpression is value-dependent.
1191         ty->isDependentType() || (op && op->isValueDependent())),
1192    Op(op) {}
1193
1194  /// \brief Construct an empty cast.
1195  CastExpr(StmtClass SC, EmptyShell Empty)
1196    : Expr(SC, Empty) { }
1197
1198public:
1199  Expr *getSubExpr() { return cast<Expr>(Op); }
1200  const Expr *getSubExpr() const { return cast<Expr>(Op); }
1201  void setSubExpr(Expr *E) { Op = E; }
1202
1203  static bool classof(const Stmt *T) {
1204    StmtClass SC = T->getStmtClass();
1205    if (SC >= CXXNamedCastExprClass && SC <= CXXFunctionalCastExprClass)
1206      return true;
1207
1208    if (SC >= ImplicitCastExprClass && SC <= CStyleCastExprClass)
1209      return true;
1210
1211    return false;
1212  }
1213  static bool classof(const CastExpr *) { return true; }
1214
1215  // Iterators
1216  virtual child_iterator child_begin();
1217  virtual child_iterator child_end();
1218};
1219
1220/// ImplicitCastExpr - Allows us to explicitly represent implicit type
1221/// conversions, which have no direct representation in the original
1222/// source code. For example: converting T[]->T*, void f()->void
1223/// (*f)(), float->double, short->int, etc.
1224///
1225/// In C, implicit casts always produce rvalues. However, in C++, an
1226/// implicit cast whose result is being bound to a reference will be
1227/// an lvalue. For example:
1228///
1229/// @code
1230/// class Base { };
1231/// class Derived : public Base { };
1232/// void f(Derived d) {
1233///   Base& b = d; // initializer is an ImplicitCastExpr to an lvalue of type Base
1234/// }
1235/// @endcode
1236class ImplicitCastExpr : public CastExpr {
1237  /// LvalueCast - Whether this cast produces an lvalue.
1238  bool LvalueCast;
1239
1240public:
1241  ImplicitCastExpr(QualType ty, Expr *op, bool Lvalue) :
1242    CastExpr(ImplicitCastExprClass, ty, op), LvalueCast(Lvalue) { }
1243
1244  /// \brief Construct an empty implicit cast.
1245  explicit ImplicitCastExpr(EmptyShell Shell)
1246    : CastExpr(ImplicitCastExprClass, Shell) { }
1247
1248
1249  virtual SourceRange getSourceRange() const {
1250    return getSubExpr()->getSourceRange();
1251  }
1252
1253  /// isLvalueCast - Whether this cast produces an lvalue.
1254  bool isLvalueCast() const { return LvalueCast; }
1255
1256  /// setLvalueCast - Set whether this cast produces an lvalue.
1257  void setLvalueCast(bool Lvalue) { LvalueCast = Lvalue; }
1258
1259  static bool classof(const Stmt *T) {
1260    return T->getStmtClass() == ImplicitCastExprClass;
1261  }
1262  static bool classof(const ImplicitCastExpr *) { return true; }
1263
1264  virtual void EmitImpl(llvm::Serializer& S) const;
1265  static ImplicitCastExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C);
1266};
1267
1268/// ExplicitCastExpr - An explicit cast written in the source
1269/// code.
1270///
1271/// This class is effectively an abstract class, because it provides
1272/// the basic representation of an explicitly-written cast without
1273/// specifying which kind of cast (C cast, functional cast, static
1274/// cast, etc.) was written; specific derived classes represent the
1275/// particular style of cast and its location information.
1276///
1277/// Unlike implicit casts, explicit cast nodes have two different
1278/// types: the type that was written into the source code, and the
1279/// actual type of the expression as determined by semantic
1280/// analysis. These types may differ slightly. For example, in C++ one
1281/// can cast to a reference type, which indicates that the resulting
1282/// expression will be an lvalue. The reference type, however, will
1283/// not be used as the type of the expression.
1284class ExplicitCastExpr : public CastExpr {
1285  /// TypeAsWritten - The type that this expression is casting to, as
1286  /// written in the source code.
1287  QualType TypeAsWritten;
1288
1289protected:
1290  ExplicitCastExpr(StmtClass SC, QualType exprTy, Expr *op, QualType writtenTy)
1291    : CastExpr(SC, exprTy, op), TypeAsWritten(writtenTy) {}
1292
1293  /// \brief Construct an empty explicit cast.
1294  ExplicitCastExpr(StmtClass SC, EmptyShell Shell)
1295    : CastExpr(SC, Shell) { }
1296
1297public:
1298  /// getTypeAsWritten - Returns the type that this expression is
1299  /// casting to, as written in the source code.
1300  QualType getTypeAsWritten() const { return TypeAsWritten; }
1301  void setTypeAsWritten(QualType T) { TypeAsWritten = T; }
1302
1303  static bool classof(const Stmt *T) {
1304    StmtClass SC = T->getStmtClass();
1305    if (SC >= ExplicitCastExprClass && SC <= CStyleCastExprClass)
1306      return true;
1307    if (SC >= CXXNamedCastExprClass && SC <= CXXFunctionalCastExprClass)
1308      return true;
1309
1310    return false;
1311  }
1312  static bool classof(const ExplicitCastExpr *) { return true; }
1313};
1314
1315/// CStyleCastExpr - An explicit cast in C (C99 6.5.4) or a C-style
1316/// cast in C++ (C++ [expr.cast]), which uses the syntax
1317/// (Type)expr. For example: @c (int)f.
1318class CStyleCastExpr : public ExplicitCastExpr {
1319  SourceLocation LPLoc; // the location of the left paren
1320  SourceLocation RPLoc; // the location of the right paren
1321public:
1322  CStyleCastExpr(QualType exprTy, Expr *op, QualType writtenTy,
1323                    SourceLocation l, SourceLocation r) :
1324    ExplicitCastExpr(CStyleCastExprClass, exprTy, op, writtenTy),
1325    LPLoc(l), RPLoc(r) {}
1326
1327  /// \brief Construct an empty C-style explicit cast.
1328  explicit CStyleCastExpr(EmptyShell Shell)
1329    : ExplicitCastExpr(CStyleCastExprClass, Shell) { }
1330
1331  SourceLocation getLParenLoc() const { return LPLoc; }
1332  void setLParenLoc(SourceLocation L) { LPLoc = L; }
1333
1334  SourceLocation getRParenLoc() const { return RPLoc; }
1335  void setRParenLoc(SourceLocation L) { RPLoc = L; }
1336
1337  virtual SourceRange getSourceRange() const {
1338    return SourceRange(LPLoc, getSubExpr()->getSourceRange().getEnd());
1339  }
1340  static bool classof(const Stmt *T) {
1341    return T->getStmtClass() == CStyleCastExprClass;
1342  }
1343  static bool classof(const CStyleCastExpr *) { return true; }
1344
1345  virtual void EmitImpl(llvm::Serializer& S) const;
1346  static CStyleCastExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C);
1347};
1348
1349/// \brief A builtin binary operation expression such as "x + y" or "x <= y".
1350///
1351/// This expression node kind describes a builtin binary operation,
1352/// such as "x + y" for integer values "x" and "y". The operands will
1353/// already have been converted to appropriate types (e.g., by
1354/// performing promotions or conversions).
1355///
1356/// In C++, where operators may be overloaded, a different kind of
1357/// expression node (CXXOperatorCallExpr) is used to express the
1358/// invocation of an overloaded operator with operator syntax. Within
1359/// a C++ template, whether BinaryOperator or CXXOperatorCallExpr is
1360/// used to store an expression "x + y" depends on the subexpressions
1361/// for x and y. If neither x or y is type-dependent, and the "+"
1362/// operator resolves to a built-in operation, BinaryOperator will be
1363/// used to express the computation (x and y may still be
1364/// value-dependent). If either x or y is type-dependent, or if the
1365/// "+" resolves to an overloaded operator, CXXOperatorCallExpr will
1366/// be used to express the computation.
1367class BinaryOperator : public Expr {
1368public:
1369  enum Opcode {
1370    // Operators listed in order of precedence.
1371    // Note that additions to this should also update the StmtVisitor class.
1372    PtrMemD, PtrMemI, // [C++ 5.5] Pointer-to-member operators.
1373    Mul, Div, Rem,    // [C99 6.5.5] Multiplicative operators.
1374    Add, Sub,         // [C99 6.5.6] Additive operators.
1375    Shl, Shr,         // [C99 6.5.7] Bitwise shift operators.
1376    LT, GT, LE, GE,   // [C99 6.5.8] Relational operators.
1377    EQ, NE,           // [C99 6.5.9] Equality operators.
1378    And,              // [C99 6.5.10] Bitwise AND operator.
1379    Xor,              // [C99 6.5.11] Bitwise XOR operator.
1380    Or,               // [C99 6.5.12] Bitwise OR operator.
1381    LAnd,             // [C99 6.5.13] Logical AND operator.
1382    LOr,              // [C99 6.5.14] Logical OR operator.
1383    Assign, MulAssign,// [C99 6.5.16] Assignment operators.
1384    DivAssign, RemAssign,
1385    AddAssign, SubAssign,
1386    ShlAssign, ShrAssign,
1387    AndAssign, XorAssign,
1388    OrAssign,
1389    Comma             // [C99 6.5.17] Comma operator.
1390  };
1391private:
1392  enum { LHS, RHS, END_EXPR };
1393  Stmt* SubExprs[END_EXPR];
1394  Opcode Opc;
1395  SourceLocation OpLoc;
1396public:
1397
1398  BinaryOperator(Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy,
1399                 SourceLocation opLoc)
1400    : Expr(BinaryOperatorClass, ResTy,
1401           lhs->isTypeDependent() || rhs->isTypeDependent(),
1402           lhs->isValueDependent() || rhs->isValueDependent()),
1403      Opc(opc), OpLoc(opLoc) {
1404    SubExprs[LHS] = lhs;
1405    SubExprs[RHS] = rhs;
1406    assert(!isCompoundAssignmentOp() &&
1407           "Use ArithAssignBinaryOperator for compound assignments");
1408  }
1409
1410  /// \brief Construct an empty binary operator.
1411  explicit BinaryOperator(EmptyShell Empty)
1412    : Expr(BinaryOperatorClass, Empty), Opc(Comma) { }
1413
1414  SourceLocation getOperatorLoc() const { return OpLoc; }
1415  void setOperatorLoc(SourceLocation L) { OpLoc = L; }
1416
1417  Opcode getOpcode() const { return Opc; }
1418  void setOpcode(Opcode O) { Opc = O; }
1419
1420  Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); }
1421  void setLHS(Expr *E) { SubExprs[LHS] = E; }
1422  Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); }
1423  void setRHS(Expr *E) { SubExprs[RHS] = E; }
1424
1425  virtual SourceRange getSourceRange() const {
1426    return SourceRange(getLHS()->getLocStart(), getRHS()->getLocEnd());
1427  }
1428
1429  /// getOpcodeStr - Turn an Opcode enum value into the punctuation char it
1430  /// corresponds to, e.g. "<<=".
1431  static const char *getOpcodeStr(Opcode Op);
1432
1433  /// \brief Retrieve the binary opcode that corresponds to the given
1434  /// overloaded operator.
1435  static Opcode getOverloadedOpcode(OverloadedOperatorKind OO);
1436
1437  /// \brief Retrieve the overloaded operator kind that corresponds to
1438  /// the given binary opcode.
1439  static OverloadedOperatorKind getOverloadedOperator(Opcode Opc);
1440
1441  /// predicates to categorize the respective opcodes.
1442  bool isMultiplicativeOp() const { return Opc >= Mul && Opc <= Rem; }
1443  bool isAdditiveOp() const { return Opc == Add || Opc == Sub; }
1444  bool isShiftOp() const { return Opc == Shl || Opc == Shr; }
1445  bool isBitwiseOp() const { return Opc >= And && Opc <= Or; }
1446
1447  static bool isRelationalOp(Opcode Opc) { return Opc >= LT && Opc <= GE; }
1448  bool isRelationalOp() const { return isRelationalOp(Opc); }
1449
1450  static bool isEqualityOp(Opcode Opc) { return Opc == EQ || Opc == NE; }
1451  bool isEqualityOp() const { return isEqualityOp(Opc); }
1452
1453  static bool isLogicalOp(Opcode Opc) { return Opc == LAnd || Opc == LOr; }
1454  bool isLogicalOp() const { return isLogicalOp(Opc); }
1455
1456  bool isAssignmentOp() const { return Opc >= Assign && Opc <= OrAssign; }
1457  bool isCompoundAssignmentOp() const { return Opc > Assign && Opc <= OrAssign;}
1458  bool isShiftAssignOp() const { return Opc == ShlAssign || Opc == ShrAssign; }
1459
1460  static bool classof(const Stmt *S) {
1461    return S->getStmtClass() == BinaryOperatorClass ||
1462           S->getStmtClass() == CompoundAssignOperatorClass;
1463  }
1464  static bool classof(const BinaryOperator *) { return true; }
1465
1466  // Iterators
1467  virtual child_iterator child_begin();
1468  virtual child_iterator child_end();
1469
1470  virtual void EmitImpl(llvm::Serializer& S) const;
1471  static BinaryOperator* CreateImpl(llvm::Deserializer& D, ASTContext& C);
1472
1473protected:
1474  BinaryOperator(Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy,
1475                 SourceLocation oploc, bool dead)
1476    : Expr(CompoundAssignOperatorClass, ResTy), Opc(opc), OpLoc(oploc) {
1477    SubExprs[LHS] = lhs;
1478    SubExprs[RHS] = rhs;
1479  }
1480
1481  BinaryOperator(StmtClass SC, EmptyShell Empty)
1482    : Expr(SC, Empty), Opc(MulAssign) { }
1483};
1484
1485/// CompoundAssignOperator - For compound assignments (e.g. +=), we keep
1486/// track of the type the operation is performed in.  Due to the semantics of
1487/// these operators, the operands are promoted, the aritmetic performed, an
1488/// implicit conversion back to the result type done, then the assignment takes
1489/// place.  This captures the intermediate type which the computation is done
1490/// in.
1491class CompoundAssignOperator : public BinaryOperator {
1492  QualType ComputationLHSType;
1493  QualType ComputationResultType;
1494public:
1495  CompoundAssignOperator(Expr *lhs, Expr *rhs, Opcode opc,
1496                         QualType ResType, QualType CompLHSType,
1497                         QualType CompResultType,
1498                         SourceLocation OpLoc)
1499    : BinaryOperator(lhs, rhs, opc, ResType, OpLoc, true),
1500      ComputationLHSType(CompLHSType),
1501      ComputationResultType(CompResultType) {
1502    assert(isCompoundAssignmentOp() &&
1503           "Only should be used for compound assignments");
1504  }
1505
1506  /// \brief Build an empty compound assignment operator expression.
1507  explicit CompoundAssignOperator(EmptyShell Empty)
1508    : BinaryOperator(CompoundAssignOperatorClass, Empty) { }
1509
1510  // The two computation types are the type the LHS is converted
1511  // to for the computation and the type of the result; the two are
1512  // distinct in a few cases (specifically, int+=ptr and ptr-=ptr).
1513  QualType getComputationLHSType() const { return ComputationLHSType; }
1514  void setComputationLHSType(QualType T) { ComputationLHSType = T; }
1515
1516  QualType getComputationResultType() const { return ComputationResultType; }
1517  void setComputationResultType(QualType T) { ComputationResultType = T; }
1518
1519  static bool classof(const CompoundAssignOperator *) { return true; }
1520  static bool classof(const Stmt *S) {
1521    return S->getStmtClass() == CompoundAssignOperatorClass;
1522  }
1523
1524  virtual void EmitImpl(llvm::Serializer& S) const;
1525  static CompoundAssignOperator* CreateImpl(llvm::Deserializer& D,
1526                                            ASTContext& C);
1527};
1528
1529/// ConditionalOperator - The ?: operator.  Note that LHS may be null when the
1530/// GNU "missing LHS" extension is in use.
1531///
1532class ConditionalOperator : public Expr {
1533  enum { COND, LHS, RHS, END_EXPR };
1534  Stmt* SubExprs[END_EXPR]; // Left/Middle/Right hand sides.
1535public:
1536  ConditionalOperator(Expr *cond, Expr *lhs, Expr *rhs, QualType t)
1537    : Expr(ConditionalOperatorClass, t,
1538           // FIXME: the type of the conditional operator doesn't
1539           // depend on the type of the conditional, but the standard
1540           // seems to imply that it could. File a bug!
1541           ((lhs && lhs->isTypeDependent()) || (rhs && rhs->isTypeDependent())),
1542           (cond->isValueDependent() ||
1543            (lhs && lhs->isValueDependent()) ||
1544            (rhs && rhs->isValueDependent()))) {
1545    SubExprs[COND] = cond;
1546    SubExprs[LHS] = lhs;
1547    SubExprs[RHS] = rhs;
1548  }
1549
1550  /// \brief Build an empty conditional operator.
1551  explicit ConditionalOperator(EmptyShell Empty)
1552    : Expr(ConditionalOperatorClass, Empty) { }
1553
1554  // getCond - Return the expression representing the condition for
1555  //  the ?: operator.
1556  Expr *getCond() const { return cast<Expr>(SubExprs[COND]); }
1557  void setCond(Expr *E) { SubExprs[COND] = E; }
1558
1559  // getTrueExpr - Return the subexpression representing the value of the ?:
1560  //  expression if the condition evaluates to true.  In most cases this value
1561  //  will be the same as getLHS() except a GCC extension allows the left
1562  //  subexpression to be omitted, and instead of the condition be returned.
1563  //  e.g: x ?: y is shorthand for x ? x : y, except that the expression "x"
1564  //  is only evaluated once.
1565  Expr *getTrueExpr() const {
1566    return cast<Expr>(SubExprs[LHS] ? SubExprs[LHS] : SubExprs[COND]);
1567  }
1568
1569  // getTrueExpr - Return the subexpression representing the value of the ?:
1570  // expression if the condition evaluates to false. This is the same as getRHS.
1571  Expr *getFalseExpr() const { return cast<Expr>(SubExprs[RHS]); }
1572
1573  Expr *getLHS() const { return cast_or_null<Expr>(SubExprs[LHS]); }
1574  void setLHS(Expr *E) { SubExprs[LHS] = E; }
1575
1576  Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); }
1577  void setRHS(Expr *E) { SubExprs[RHS] = E; }
1578
1579  virtual SourceRange getSourceRange() const {
1580    return SourceRange(getCond()->getLocStart(), getRHS()->getLocEnd());
1581  }
1582  static bool classof(const Stmt *T) {
1583    return T->getStmtClass() == ConditionalOperatorClass;
1584  }
1585  static bool classof(const ConditionalOperator *) { return true; }
1586
1587  // Iterators
1588  virtual child_iterator child_begin();
1589  virtual child_iterator child_end();
1590
1591  virtual void EmitImpl(llvm::Serializer& S) const;
1592  static ConditionalOperator* CreateImpl(llvm::Deserializer& D, ASTContext& C);
1593};
1594
1595/// AddrLabelExpr - The GNU address of label extension, representing &&label.
1596class AddrLabelExpr : public Expr {
1597  SourceLocation AmpAmpLoc, LabelLoc;
1598  LabelStmt *Label;
1599public:
1600  AddrLabelExpr(SourceLocation AALoc, SourceLocation LLoc, LabelStmt *L,
1601                QualType t)
1602    : Expr(AddrLabelExprClass, t), AmpAmpLoc(AALoc), LabelLoc(LLoc), Label(L) {}
1603
1604  /// \brief Build an empty address of a label expression.
1605  explicit AddrLabelExpr(EmptyShell Empty)
1606    : Expr(AddrLabelExprClass, Empty) { }
1607
1608  SourceLocation getAmpAmpLoc() const { return AmpAmpLoc; }
1609  void setAmpAmpLoc(SourceLocation L) { AmpAmpLoc = L; }
1610  SourceLocation getLabelLoc() const { return LabelLoc; }
1611  void setLabelLoc(SourceLocation L) { LabelLoc = L; }
1612
1613  virtual SourceRange getSourceRange() const {
1614    return SourceRange(AmpAmpLoc, LabelLoc);
1615  }
1616
1617  LabelStmt *getLabel() const { return Label; }
1618  void setLabel(LabelStmt *S) { Label = S; }
1619
1620  static bool classof(const Stmt *T) {
1621    return T->getStmtClass() == AddrLabelExprClass;
1622  }
1623  static bool classof(const AddrLabelExpr *) { return true; }
1624
1625  // Iterators
1626  virtual child_iterator child_begin();
1627  virtual child_iterator child_end();
1628
1629  virtual void EmitImpl(llvm::Serializer& S) const;
1630  static AddrLabelExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C);
1631};
1632
1633/// StmtExpr - This is the GNU Statement Expression extension: ({int X=4; X;}).
1634/// The StmtExpr contains a single CompoundStmt node, which it evaluates and
1635/// takes the value of the last subexpression.
1636class StmtExpr : public Expr {
1637  Stmt *SubStmt;
1638  SourceLocation LParenLoc, RParenLoc;
1639public:
1640  StmtExpr(CompoundStmt *substmt, QualType T,
1641           SourceLocation lp, SourceLocation rp) :
1642    Expr(StmtExprClass, T), SubStmt(substmt),  LParenLoc(lp), RParenLoc(rp) { }
1643
1644  /// \brief Build an empty statement expression.
1645  explicit StmtExpr(EmptyShell Empty) : Expr(StmtExprClass, Empty) { }
1646
1647  CompoundStmt *getSubStmt() { return cast<CompoundStmt>(SubStmt); }
1648  const CompoundStmt *getSubStmt() const { return cast<CompoundStmt>(SubStmt); }
1649  void setSubStmt(CompoundStmt *S) { SubStmt = S; }
1650
1651  virtual SourceRange getSourceRange() const {
1652    return SourceRange(LParenLoc, RParenLoc);
1653  }
1654
1655  SourceLocation getLParenLoc() const { return LParenLoc; }
1656  void setLParenLoc(SourceLocation L) { LParenLoc = L; }
1657  SourceLocation getRParenLoc() const { return RParenLoc; }
1658  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
1659
1660  static bool classof(const Stmt *T) {
1661    return T->getStmtClass() == StmtExprClass;
1662  }
1663  static bool classof(const StmtExpr *) { return true; }
1664
1665  // Iterators
1666  virtual child_iterator child_begin();
1667  virtual child_iterator child_end();
1668
1669  virtual void EmitImpl(llvm::Serializer& S) const;
1670  static StmtExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C);
1671};
1672
1673/// TypesCompatibleExpr - GNU builtin-in function __builtin_type_compatible_p.
1674/// This AST node represents a function that returns 1 if two *types* (not
1675/// expressions) are compatible. The result of this built-in function can be
1676/// used in integer constant expressions.
1677class TypesCompatibleExpr : public Expr {
1678  QualType Type1;
1679  QualType Type2;
1680  SourceLocation BuiltinLoc, RParenLoc;
1681public:
1682  TypesCompatibleExpr(QualType ReturnType, SourceLocation BLoc,
1683                      QualType t1, QualType t2, SourceLocation RP) :
1684    Expr(TypesCompatibleExprClass, ReturnType), Type1(t1), Type2(t2),
1685    BuiltinLoc(BLoc), RParenLoc(RP) {}
1686
1687  /// \brief Build an empty __builtin_type_compatible_p expression.
1688  explicit TypesCompatibleExpr(EmptyShell Empty)
1689    : Expr(TypesCompatibleExprClass, Empty) { }
1690
1691  QualType getArgType1() const { return Type1; }
1692  void setArgType1(QualType T) { Type1 = T; }
1693  QualType getArgType2() const { return Type2; }
1694  void setArgType2(QualType T) { Type2 = T; }
1695
1696  SourceLocation getBuiltinLoc() const { return BuiltinLoc; }
1697  void setBuiltinLoc(SourceLocation L) { BuiltinLoc = L; }
1698
1699  SourceLocation getRParenLoc() const { return RParenLoc; }
1700  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
1701
1702  virtual SourceRange getSourceRange() const {
1703    return SourceRange(BuiltinLoc, RParenLoc);
1704  }
1705  static bool classof(const Stmt *T) {
1706    return T->getStmtClass() == TypesCompatibleExprClass;
1707  }
1708  static bool classof(const TypesCompatibleExpr *) { return true; }
1709
1710  // Iterators
1711  virtual child_iterator child_begin();
1712  virtual child_iterator child_end();
1713
1714  virtual void EmitImpl(llvm::Serializer& S) const;
1715  static TypesCompatibleExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C);
1716};
1717
1718/// ShuffleVectorExpr - clang-specific builtin-in function
1719/// __builtin_shufflevector.
1720/// This AST node represents a operator that does a constant
1721/// shuffle, similar to LLVM's shufflevector instruction. It takes
1722/// two vectors and a variable number of constant indices,
1723/// and returns the appropriately shuffled vector.
1724class ShuffleVectorExpr : public Expr {
1725  SourceLocation BuiltinLoc, RParenLoc;
1726
1727  // SubExprs - the list of values passed to the __builtin_shufflevector
1728  // function. The first two are vectors, and the rest are constant
1729  // indices.  The number of values in this list is always
1730  // 2+the number of indices in the vector type.
1731  Stmt **SubExprs;
1732  unsigned NumExprs;
1733
1734public:
1735  ShuffleVectorExpr(Expr **args, unsigned nexpr,
1736                    QualType Type, SourceLocation BLoc,
1737                    SourceLocation RP) :
1738    Expr(ShuffleVectorExprClass, Type), BuiltinLoc(BLoc),
1739    RParenLoc(RP), NumExprs(nexpr) {
1740
1741    SubExprs = new Stmt*[nexpr];
1742    for (unsigned i = 0; i < nexpr; i++)
1743      SubExprs[i] = args[i];
1744  }
1745
1746  /// \brief Build an empty vector-shuffle expression.
1747  explicit ShuffleVectorExpr(EmptyShell Empty)
1748    : Expr(ShuffleVectorExprClass, Empty), SubExprs(0) { }
1749
1750  SourceLocation getBuiltinLoc() const { return BuiltinLoc; }
1751  void setBuiltinLoc(SourceLocation L) { BuiltinLoc = L; }
1752
1753  SourceLocation getRParenLoc() const { return RParenLoc; }
1754  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
1755
1756  virtual SourceRange getSourceRange() const {
1757    return SourceRange(BuiltinLoc, RParenLoc);
1758  }
1759  static bool classof(const Stmt *T) {
1760    return T->getStmtClass() == ShuffleVectorExprClass;
1761  }
1762  static bool classof(const ShuffleVectorExpr *) { return true; }
1763
1764  ~ShuffleVectorExpr() {
1765    delete [] SubExprs;
1766  }
1767
1768  /// getNumSubExprs - Return the size of the SubExprs array.  This includes the
1769  /// constant expression, the actual arguments passed in, and the function
1770  /// pointers.
1771  unsigned getNumSubExprs() const { return NumExprs; }
1772
1773  /// getExpr - Return the Expr at the specified index.
1774  Expr *getExpr(unsigned Index) {
1775    assert((Index < NumExprs) && "Arg access out of range!");
1776    return cast<Expr>(SubExprs[Index]);
1777  }
1778  const Expr *getExpr(unsigned Index) const {
1779    assert((Index < NumExprs) && "Arg access out of range!");
1780    return cast<Expr>(SubExprs[Index]);
1781  }
1782
1783  void setExprs(Expr ** Exprs, unsigned NumExprs);
1784
1785  unsigned getShuffleMaskIdx(ASTContext &Ctx, unsigned N) {
1786    assert((N < NumExprs - 2) && "Shuffle idx out of range!");
1787    return getExpr(N+2)->getIntegerConstantExprValue(Ctx).getZExtValue();
1788  }
1789
1790  // Iterators
1791  virtual child_iterator child_begin();
1792  virtual child_iterator child_end();
1793
1794  virtual void EmitImpl(llvm::Serializer& S) const;
1795  static ShuffleVectorExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C);
1796};
1797
1798/// ChooseExpr - GNU builtin-in function __builtin_choose_expr.
1799/// This AST node is similar to the conditional operator (?:) in C, with
1800/// the following exceptions:
1801/// - the test expression must be a integer constant expression.
1802/// - the expression returned acts like the chosen subexpression in every
1803///   visible way: the type is the same as that of the chosen subexpression,
1804///   and all predicates (whether it's an l-value, whether it's an integer
1805///   constant expression, etc.) return the same result as for the chosen
1806///   sub-expression.
1807class ChooseExpr : public Expr {
1808  enum { COND, LHS, RHS, END_EXPR };
1809  Stmt* SubExprs[END_EXPR]; // Left/Middle/Right hand sides.
1810  SourceLocation BuiltinLoc, RParenLoc;
1811public:
1812  ChooseExpr(SourceLocation BLoc, Expr *cond, Expr *lhs, Expr *rhs, QualType t,
1813             SourceLocation RP)
1814    : Expr(ChooseExprClass, t),
1815      BuiltinLoc(BLoc), RParenLoc(RP) {
1816      SubExprs[COND] = cond;
1817      SubExprs[LHS] = lhs;
1818      SubExprs[RHS] = rhs;
1819    }
1820
1821  /// \brief Build an empty __builtin_choose_expr.
1822  explicit ChooseExpr(EmptyShell Empty) : Expr(ChooseExprClass, Empty) { }
1823
1824  /// isConditionTrue - Return whether the condition is true (i.e. not
1825  /// equal to zero).
1826  bool isConditionTrue(ASTContext &C) const;
1827
1828  /// getChosenSubExpr - Return the subexpression chosen according to the
1829  /// condition.
1830  Expr *getChosenSubExpr(ASTContext &C) const {
1831    return isConditionTrue(C) ? getLHS() : getRHS();
1832  }
1833
1834  Expr *getCond() const { return cast<Expr>(SubExprs[COND]); }
1835  void setCond(Expr *E) { SubExprs[COND] = E; }
1836  Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); }
1837  void setLHS(Expr *E) { SubExprs[LHS] = E; }
1838  Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); }
1839  void setRHS(Expr *E) { SubExprs[RHS] = E; }
1840
1841  SourceLocation getBuiltinLoc() const { return BuiltinLoc; }
1842  void setBuiltinLoc(SourceLocation L) { BuiltinLoc = L; }
1843
1844  SourceLocation getRParenLoc() const { return RParenLoc; }
1845  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
1846
1847  virtual SourceRange getSourceRange() const {
1848    return SourceRange(BuiltinLoc, RParenLoc);
1849  }
1850  static bool classof(const Stmt *T) {
1851    return T->getStmtClass() == ChooseExprClass;
1852  }
1853  static bool classof(const ChooseExpr *) { return true; }
1854
1855  // Iterators
1856  virtual child_iterator child_begin();
1857  virtual child_iterator child_end();
1858
1859  virtual void EmitImpl(llvm::Serializer& S) const;
1860  static ChooseExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C);
1861};
1862
1863/// GNUNullExpr - Implements the GNU __null extension, which is a name
1864/// for a null pointer constant that has integral type (e.g., int or
1865/// long) and is the same size and alignment as a pointer. The __null
1866/// extension is typically only used by system headers, which define
1867/// NULL as __null in C++ rather than using 0 (which is an integer
1868/// that may not match the size of a pointer).
1869class GNUNullExpr : public Expr {
1870  /// TokenLoc - The location of the __null keyword.
1871  SourceLocation TokenLoc;
1872
1873public:
1874  GNUNullExpr(QualType Ty, SourceLocation Loc)
1875    : Expr(GNUNullExprClass, Ty), TokenLoc(Loc) { }
1876
1877  /// \brief Build an empty GNU __null expression.
1878  explicit GNUNullExpr(EmptyShell Empty) : Expr(GNUNullExprClass, Empty) { }
1879
1880  /// getTokenLocation - The location of the __null token.
1881  SourceLocation getTokenLocation() const { return TokenLoc; }
1882  void setTokenLocation(SourceLocation L) { TokenLoc = L; }
1883
1884  virtual SourceRange getSourceRange() const {
1885    return SourceRange(TokenLoc);
1886  }
1887  static bool classof(const Stmt *T) {
1888    return T->getStmtClass() == GNUNullExprClass;
1889  }
1890  static bool classof(const GNUNullExpr *) { return true; }
1891
1892  // Iterators
1893  virtual child_iterator child_begin();
1894  virtual child_iterator child_end();
1895
1896  virtual void EmitImpl(llvm::Serializer& S) const;
1897  static GNUNullExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C);
1898};
1899
1900/// VAArgExpr, used for the builtin function __builtin_va_start.
1901class VAArgExpr : public Expr {
1902  Stmt *Val;
1903  SourceLocation BuiltinLoc, RParenLoc;
1904public:
1905  VAArgExpr(SourceLocation BLoc, Expr* e, QualType t, SourceLocation RPLoc)
1906    : Expr(VAArgExprClass, t),
1907      Val(e),
1908      BuiltinLoc(BLoc),
1909      RParenLoc(RPLoc) { }
1910
1911  /// \brief Create an empty __builtin_va_start expression.
1912  explicit VAArgExpr(EmptyShell Empty) : Expr(VAArgExprClass, Empty) { }
1913
1914  const Expr *getSubExpr() const { return cast<Expr>(Val); }
1915  Expr *getSubExpr() { return cast<Expr>(Val); }
1916  void setSubExpr(Expr *E) { Val = E; }
1917
1918  SourceLocation getBuiltinLoc() const { return BuiltinLoc; }
1919  void setBuiltinLoc(SourceLocation L) { BuiltinLoc = L; }
1920
1921  SourceLocation getRParenLoc() const { return RParenLoc; }
1922  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
1923
1924  virtual SourceRange getSourceRange() const {
1925    return SourceRange(BuiltinLoc, RParenLoc);
1926  }
1927  static bool classof(const Stmt *T) {
1928    return T->getStmtClass() == VAArgExprClass;
1929  }
1930  static bool classof(const VAArgExpr *) { return true; }
1931
1932  // Iterators
1933  virtual child_iterator child_begin();
1934  virtual child_iterator child_end();
1935
1936  virtual void EmitImpl(llvm::Serializer& S) const;
1937  static VAArgExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C);
1938};
1939
1940/// @brief Describes an C or C++ initializer list.
1941///
1942/// InitListExpr describes an initializer list, which can be used to
1943/// initialize objects of different types, including
1944/// struct/class/union types, arrays, and vectors. For example:
1945///
1946/// @code
1947/// struct foo x = { 1, { 2, 3 } };
1948/// @endcode
1949///
1950/// Prior to semantic analysis, an initializer list will represent the
1951/// initializer list as written by the user, but will have the
1952/// placeholder type "void". This initializer list is called the
1953/// syntactic form of the initializer, and may contain C99 designated
1954/// initializers (represented as DesignatedInitExprs), initializations
1955/// of subobject members without explicit braces, and so on. Clients
1956/// interested in the original syntax of the initializer list should
1957/// use the syntactic form of the initializer list.
1958///
1959/// After semantic analysis, the initializer list will represent the
1960/// semantic form of the initializer, where the initializations of all
1961/// subobjects are made explicit with nested InitListExpr nodes and
1962/// C99 designators have been eliminated by placing the designated
1963/// initializations into the subobject they initialize. Additionally,
1964/// any "holes" in the initialization, where no initializer has been
1965/// specified for a particular subobject, will be replaced with
1966/// implicitly-generated ImplicitValueInitExpr expressions that
1967/// value-initialize the subobjects. Note, however, that the
1968/// initializer lists may still have fewer initializers than there are
1969/// elements to initialize within the object.
1970///
1971/// Given the semantic form of the initializer list, one can retrieve
1972/// the original syntactic form of that initializer list (if it
1973/// exists) using getSyntacticForm(). Since many initializer lists
1974/// have the same syntactic and semantic forms, getSyntacticForm() may
1975/// return NULL, indicating that the current initializer list also
1976/// serves as its syntactic form.
1977class InitListExpr : public Expr {
1978  std::vector<Stmt *> InitExprs;
1979  SourceLocation LBraceLoc, RBraceLoc;
1980
1981  /// Contains the initializer list that describes the syntactic form
1982  /// written in the source code.
1983  InitListExpr *SyntacticForm;
1984
1985  /// If this initializer list initializes a union, specifies which
1986  /// field within the union will be initialized.
1987  FieldDecl *UnionFieldInit;
1988
1989  /// Whether this initializer list originally had a GNU array-range
1990  /// designator in it. This is a temporary marker used by CodeGen.
1991  bool HadArrayRangeDesignator;
1992
1993public:
1994  InitListExpr(SourceLocation lbraceloc, Expr **initexprs, unsigned numinits,
1995               SourceLocation rbraceloc);
1996
1997  /// \brief Build an empty initializer list.
1998  explicit InitListExpr(EmptyShell Empty) : Expr(InitListExprClass, Empty) { }
1999
2000  unsigned getNumInits() const { return InitExprs.size(); }
2001
2002  const Expr* getInit(unsigned Init) const {
2003    assert(Init < getNumInits() && "Initializer access out of range!");
2004    return cast_or_null<Expr>(InitExprs[Init]);
2005  }
2006
2007  Expr* getInit(unsigned Init) {
2008    assert(Init < getNumInits() && "Initializer access out of range!");
2009    return cast_or_null<Expr>(InitExprs[Init]);
2010  }
2011
2012  void setInit(unsigned Init, Expr *expr) {
2013    assert(Init < getNumInits() && "Initializer access out of range!");
2014    InitExprs[Init] = expr;
2015  }
2016
2017  /// \brief Reserve space for some number of initializers.
2018  void reserveInits(unsigned NumInits);
2019
2020  /// @brief Specify the number of initializers
2021  ///
2022  /// If there are more than @p NumInits initializers, the remaining
2023  /// initializers will be destroyed. If there are fewer than @p
2024  /// NumInits initializers, NULL expressions will be added for the
2025  /// unknown initializers.
2026  void resizeInits(ASTContext &Context, unsigned NumInits);
2027
2028  /// @brief Updates the initializer at index @p Init with the new
2029  /// expression @p expr, and returns the old expression at that
2030  /// location.
2031  ///
2032  /// When @p Init is out of range for this initializer list, the
2033  /// initializer list will be extended with NULL expressions to
2034  /// accomodate the new entry.
2035  Expr *updateInit(unsigned Init, Expr *expr);
2036
2037  /// \brief If this initializes a union, specifies which field in the
2038  /// union to initialize.
2039  ///
2040  /// Typically, this field is the first named field within the
2041  /// union. However, a designated initializer can specify the
2042  /// initialization of a different field within the union.
2043  FieldDecl *getInitializedFieldInUnion() { return UnionFieldInit; }
2044  void setInitializedFieldInUnion(FieldDecl *FD) { UnionFieldInit = FD; }
2045
2046  // Explicit InitListExpr's originate from source code (and have valid source
2047  // locations). Implicit InitListExpr's are created by the semantic analyzer.
2048  bool isExplicit() {
2049    return LBraceLoc.isValid() && RBraceLoc.isValid();
2050  }
2051
2052  SourceLocation getLBraceLoc() const { return LBraceLoc; }
2053  void setLBraceLoc(SourceLocation Loc) { LBraceLoc = Loc; }
2054  SourceLocation getRBraceLoc() const { return RBraceLoc; }
2055  void setRBraceLoc(SourceLocation Loc) { RBraceLoc = Loc; }
2056
2057  /// @brief Retrieve the initializer list that describes the
2058  /// syntactic form of the initializer.
2059  ///
2060  ///
2061  InitListExpr *getSyntacticForm() const { return SyntacticForm; }
2062  void setSyntacticForm(InitListExpr *Init) { SyntacticForm = Init; }
2063
2064  bool hadArrayRangeDesignator() const { return HadArrayRangeDesignator; }
2065  void sawArrayRangeDesignator(bool ARD = true) {
2066    HadArrayRangeDesignator = ARD;
2067  }
2068
2069  virtual SourceRange getSourceRange() const {
2070    return SourceRange(LBraceLoc, RBraceLoc);
2071  }
2072  static bool classof(const Stmt *T) {
2073    return T->getStmtClass() == InitListExprClass;
2074  }
2075  static bool classof(const InitListExpr *) { return true; }
2076
2077  // Iterators
2078  virtual child_iterator child_begin();
2079  virtual child_iterator child_end();
2080
2081  typedef std::vector<Stmt *>::iterator iterator;
2082  typedef std::vector<Stmt *>::reverse_iterator reverse_iterator;
2083
2084  iterator begin() { return InitExprs.begin(); }
2085  iterator end() { return InitExprs.end(); }
2086  reverse_iterator rbegin() { return InitExprs.rbegin(); }
2087  reverse_iterator rend() { return InitExprs.rend(); }
2088
2089  // Serailization.
2090  virtual void EmitImpl(llvm::Serializer& S) const;
2091  static InitListExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C);
2092
2093private:
2094  // Used by serializer.
2095  InitListExpr() : Expr(InitListExprClass, QualType()) {}
2096};
2097
2098/// @brief Represents a C99 designated initializer expression.
2099///
2100/// A designated initializer expression (C99 6.7.8) contains one or
2101/// more designators (which can be field designators, array
2102/// designators, or GNU array-range designators) followed by an
2103/// expression that initializes the field or element(s) that the
2104/// designators refer to. For example, given:
2105///
2106/// @code
2107/// struct point {
2108///   double x;
2109///   double y;
2110/// };
2111/// struct point ptarray[10] = { [2].y = 1.0, [2].x = 2.0, [0].x = 1.0 };
2112/// @endcode
2113///
2114/// The InitListExpr contains three DesignatedInitExprs, the first of
2115/// which covers @c [2].y=1.0. This DesignatedInitExpr will have two
2116/// designators, one array designator for @c [2] followed by one field
2117/// designator for @c .y. The initalization expression will be 1.0.
2118class DesignatedInitExpr : public Expr {
2119public:
2120  /// \brief Forward declaration of the Designator class.
2121  class Designator;
2122
2123private:
2124  /// The location of the '=' or ':' prior to the actual initializer
2125  /// expression.
2126  SourceLocation EqualOrColonLoc;
2127
2128  /// Whether this designated initializer used the GNU deprecated
2129  /// syntax rather than the C99 '=' syntax.
2130  bool GNUSyntax : 1;
2131
2132  /// The number of designators in this initializer expression.
2133  unsigned NumDesignators : 15;
2134
2135  /// \brief The designators in this designated initialization
2136  /// expression.
2137  Designator *Designators;
2138
2139  /// The number of subexpressions of this initializer expression,
2140  /// which contains both the initializer and any additional
2141  /// expressions used by array and array-range designators.
2142  unsigned NumSubExprs : 16;
2143
2144
2145  DesignatedInitExpr(QualType Ty, unsigned NumDesignators,
2146                     const Designator *Designators,
2147                     SourceLocation EqualOrColonLoc, bool GNUSyntax,
2148                     unsigned NumSubExprs);
2149
2150  explicit DesignatedInitExpr(unsigned NumSubExprs)
2151    : Expr(DesignatedInitExprClass, EmptyShell()),
2152      NumDesignators(0), Designators(0), NumSubExprs(NumSubExprs) { }
2153
2154public:
2155  /// A field designator, e.g., ".x".
2156  struct FieldDesignator {
2157    /// Refers to the field that is being initialized. The low bit
2158    /// of this field determines whether this is actually a pointer
2159    /// to an IdentifierInfo (if 1) or a FieldDecl (if 0). When
2160    /// initially constructed, a field designator will store an
2161    /// IdentifierInfo*. After semantic analysis has resolved that
2162    /// name, the field designator will instead store a FieldDecl*.
2163    uintptr_t NameOrField;
2164
2165    /// The location of the '.' in the designated initializer.
2166    unsigned DotLoc;
2167
2168    /// The location of the field name in the designated initializer.
2169    unsigned FieldLoc;
2170  };
2171
2172  /// An array or GNU array-range designator, e.g., "[9]" or "[10..15]".
2173  struct ArrayOrRangeDesignator {
2174    /// Location of the first index expression within the designated
2175    /// initializer expression's list of subexpressions.
2176    unsigned Index;
2177    /// The location of the '[' starting the array range designator.
2178    unsigned LBracketLoc;
2179    /// The location of the ellipsis separating the start and end
2180    /// indices. Only valid for GNU array-range designators.
2181    unsigned EllipsisLoc;
2182    /// The location of the ']' terminating the array range designator.
2183    unsigned RBracketLoc;
2184  };
2185
2186  /// @brief Represents a single C99 designator.
2187  ///
2188  /// @todo This class is infuriatingly similar to clang::Designator,
2189  /// but minor differences (storing indices vs. storing pointers)
2190  /// keep us from reusing it. Try harder, later, to rectify these
2191  /// differences.
2192  class Designator {
2193    /// @brief The kind of designator this describes.
2194    enum {
2195      FieldDesignator,
2196      ArrayDesignator,
2197      ArrayRangeDesignator
2198    } Kind;
2199
2200    union {
2201      /// A field designator, e.g., ".x".
2202      struct FieldDesignator Field;
2203      /// An array or GNU array-range designator, e.g., "[9]" or "[10..15]".
2204      struct ArrayOrRangeDesignator ArrayOrRange;
2205    };
2206    friend class DesignatedInitExpr;
2207
2208  public:
2209    Designator() {}
2210
2211    /// @brief Initializes a field designator.
2212    Designator(const IdentifierInfo *FieldName, SourceLocation DotLoc,
2213               SourceLocation FieldLoc)
2214      : Kind(FieldDesignator) {
2215      Field.NameOrField = reinterpret_cast<uintptr_t>(FieldName) | 0x01;
2216      Field.DotLoc = DotLoc.getRawEncoding();
2217      Field.FieldLoc = FieldLoc.getRawEncoding();
2218    }
2219
2220    /// @brief Initializes an array designator.
2221    Designator(unsigned Index, SourceLocation LBracketLoc,
2222               SourceLocation RBracketLoc)
2223      : Kind(ArrayDesignator) {
2224      ArrayOrRange.Index = Index;
2225      ArrayOrRange.LBracketLoc = LBracketLoc.getRawEncoding();
2226      ArrayOrRange.EllipsisLoc = SourceLocation().getRawEncoding();
2227      ArrayOrRange.RBracketLoc = RBracketLoc.getRawEncoding();
2228    }
2229
2230    /// @brief Initializes a GNU array-range designator.
2231    Designator(unsigned Index, SourceLocation LBracketLoc,
2232               SourceLocation EllipsisLoc, SourceLocation RBracketLoc)
2233      : Kind(ArrayRangeDesignator) {
2234      ArrayOrRange.Index = Index;
2235      ArrayOrRange.LBracketLoc = LBracketLoc.getRawEncoding();
2236      ArrayOrRange.EllipsisLoc = EllipsisLoc.getRawEncoding();
2237      ArrayOrRange.RBracketLoc = RBracketLoc.getRawEncoding();
2238    }
2239
2240    bool isFieldDesignator() const { return Kind == FieldDesignator; }
2241    bool isArrayDesignator() const { return Kind == ArrayDesignator; }
2242    bool isArrayRangeDesignator() const { return Kind == ArrayRangeDesignator; }
2243
2244    IdentifierInfo * getFieldName();
2245
2246    FieldDecl *getField() {
2247      assert(Kind == FieldDesignator && "Only valid on a field designator");
2248      if (Field.NameOrField & 0x01)
2249        return 0;
2250      else
2251        return reinterpret_cast<FieldDecl *>(Field.NameOrField);
2252    }
2253
2254    void setField(FieldDecl *FD) {
2255      assert(Kind == FieldDesignator && "Only valid on a field designator");
2256      Field.NameOrField = reinterpret_cast<uintptr_t>(FD);
2257    }
2258
2259    SourceLocation getDotLoc() const {
2260      assert(Kind == FieldDesignator && "Only valid on a field designator");
2261      return SourceLocation::getFromRawEncoding(Field.DotLoc);
2262    }
2263
2264    SourceLocation getFieldLoc() const {
2265      assert(Kind == FieldDesignator && "Only valid on a field designator");
2266      return SourceLocation::getFromRawEncoding(Field.FieldLoc);
2267    }
2268
2269    SourceLocation getLBracketLoc() const {
2270      assert((Kind == ArrayDesignator || Kind == ArrayRangeDesignator) &&
2271             "Only valid on an array or array-range designator");
2272      return SourceLocation::getFromRawEncoding(ArrayOrRange.LBracketLoc);
2273    }
2274
2275    SourceLocation getRBracketLoc() const {
2276      assert((Kind == ArrayDesignator || Kind == ArrayRangeDesignator) &&
2277             "Only valid on an array or array-range designator");
2278      return SourceLocation::getFromRawEncoding(ArrayOrRange.RBracketLoc);
2279    }
2280
2281    SourceLocation getEllipsisLoc() const {
2282      assert(Kind == ArrayRangeDesignator &&
2283             "Only valid on an array-range designator");
2284      return SourceLocation::getFromRawEncoding(ArrayOrRange.EllipsisLoc);
2285    }
2286
2287    unsigned getFirstExprIndex() const {
2288      assert((Kind == ArrayDesignator || Kind == ArrayRangeDesignator) &&
2289             "Only valid on an array or array-range designator");
2290      return ArrayOrRange.Index;
2291    }
2292
2293    SourceLocation getStartLocation() const {
2294      if (Kind == FieldDesignator)
2295        return getDotLoc().isInvalid()? getFieldLoc() : getDotLoc();
2296      else
2297        return getLBracketLoc();
2298    }
2299  };
2300
2301  static DesignatedInitExpr *Create(ASTContext &C, Designator *Designators,
2302                                    unsigned NumDesignators,
2303                                    Expr **IndexExprs, unsigned NumIndexExprs,
2304                                    SourceLocation EqualOrColonLoc,
2305                                    bool GNUSyntax, Expr *Init);
2306
2307  static DesignatedInitExpr *CreateEmpty(ASTContext &C, unsigned NumIndexExprs);
2308
2309  /// @brief Returns the number of designators in this initializer.
2310  unsigned size() const { return NumDesignators; }
2311
2312  // Iterator access to the designators.
2313  typedef Designator* designators_iterator;
2314  designators_iterator designators_begin() { return Designators; }
2315  designators_iterator designators_end() {
2316    return Designators + NumDesignators;
2317  }
2318
2319  Designator *getDesignator(unsigned Idx) { return &designators_begin()[Idx]; }
2320
2321  void setDesignators(const Designator *Desigs, unsigned NumDesigs);
2322
2323  Expr *getArrayIndex(const Designator& D);
2324  Expr *getArrayRangeStart(const Designator& D);
2325  Expr *getArrayRangeEnd(const Designator& D);
2326
2327  /// @brief Retrieve the location of the '=' that precedes the
2328  /// initializer value itself, if present.
2329  SourceLocation getEqualOrColonLoc() const { return EqualOrColonLoc; }
2330  void setEqualOrColonLoc(SourceLocation L) { EqualOrColonLoc = L; }
2331
2332  /// @brief Determines whether this designated initializer used the
2333  /// deprecated GNU syntax for designated initializers.
2334  bool usesGNUSyntax() const { return GNUSyntax; }
2335  void setGNUSyntax(bool GNU) { GNUSyntax = GNU; }
2336
2337  /// @brief Retrieve the initializer value.
2338  Expr *getInit() const {
2339    return cast<Expr>(*const_cast<DesignatedInitExpr*>(this)->child_begin());
2340  }
2341
2342  void setInit(Expr *init) {
2343    *child_begin() = init;
2344  }
2345
2346  /// \brief Retrieve the total number of subexpressions in this
2347  /// designated initializer expression, including the actual
2348  /// initialized value and any expressions that occur within array
2349  /// and array-range designators.
2350  unsigned getNumSubExprs() const { return NumSubExprs; }
2351
2352  Expr *getSubExpr(unsigned Idx) {
2353    assert(Idx < NumSubExprs && "Subscript out of range");
2354    char* Ptr = static_cast<char*>(static_cast<void *>(this));
2355    Ptr += sizeof(DesignatedInitExpr);
2356    return reinterpret_cast<Expr**>(reinterpret_cast<void**>(Ptr))[Idx];
2357  }
2358
2359  void setSubExpr(unsigned Idx, Expr *E) {
2360    assert(Idx < NumSubExprs && "Subscript out of range");
2361    char* Ptr = static_cast<char*>(static_cast<void *>(this));
2362    Ptr += sizeof(DesignatedInitExpr);
2363    reinterpret_cast<Expr**>(reinterpret_cast<void**>(Ptr))[Idx] = E;
2364  }
2365
2366  /// \brief Replaces the designator at index @p Idx with the series
2367  /// of designators in [First, Last).
2368  void ExpandDesignator(unsigned Idx, const Designator *First,
2369                        const Designator *Last);
2370
2371  virtual SourceRange getSourceRange() const;
2372
2373  virtual void Destroy(ASTContext &C);
2374
2375  static bool classof(const Stmt *T) {
2376    return T->getStmtClass() == DesignatedInitExprClass;
2377  }
2378  static bool classof(const DesignatedInitExpr *) { return true; }
2379
2380  // Iterators
2381  virtual child_iterator child_begin();
2382  virtual child_iterator child_end();
2383};
2384
2385/// \brief Represents an implicitly-generated value initialization of
2386/// an object of a given type.
2387///
2388/// Implicit value initializations occur within semantic initializer
2389/// list expressions (InitListExpr) as placeholders for subobject
2390/// initializations not explicitly specified by the user.
2391///
2392/// \see InitListExpr
2393class ImplicitValueInitExpr : public Expr {
2394public:
2395  explicit ImplicitValueInitExpr(QualType ty)
2396    : Expr(ImplicitValueInitExprClass, ty) { }
2397
2398  /// \brief Construct an empty implicit value initialization.
2399  explicit ImplicitValueInitExpr(EmptyShell Empty)
2400    : Expr(ImplicitValueInitExprClass, Empty) { }
2401
2402  static bool classof(const Stmt *T) {
2403    return T->getStmtClass() == ImplicitValueInitExprClass;
2404  }
2405  static bool classof(const ImplicitValueInitExpr *) { return true; }
2406
2407  virtual SourceRange getSourceRange() const {
2408    return SourceRange();
2409  }
2410
2411  // Iterators
2412  virtual child_iterator child_begin();
2413  virtual child_iterator child_end();
2414};
2415
2416//===----------------------------------------------------------------------===//
2417// Clang Extensions
2418//===----------------------------------------------------------------------===//
2419
2420
2421/// ExtVectorElementExpr - This represents access to specific elements of a
2422/// vector, and may occur on the left hand side or right hand side.  For example
2423/// the following is legal:  "V.xy = V.zw" if V is a 4 element extended vector.
2424///
2425/// Note that the base may have either vector or pointer to vector type, just
2426/// like a struct field reference.
2427///
2428class ExtVectorElementExpr : public Expr {
2429  Stmt *Base;
2430  IdentifierInfo *Accessor;
2431  SourceLocation AccessorLoc;
2432public:
2433  ExtVectorElementExpr(QualType ty, Expr *base, IdentifierInfo &accessor,
2434                       SourceLocation loc)
2435    : Expr(ExtVectorElementExprClass, ty),
2436      Base(base), Accessor(&accessor), AccessorLoc(loc) {}
2437
2438  /// \brief Build an empty vector element expression.
2439  explicit ExtVectorElementExpr(EmptyShell Empty)
2440    : Expr(ExtVectorElementExprClass, Empty) { }
2441
2442  const Expr *getBase() const { return cast<Expr>(Base); }
2443  Expr *getBase() { return cast<Expr>(Base); }
2444  void setBase(Expr *E) { Base = E; }
2445
2446  IdentifierInfo &getAccessor() const { return *Accessor; }
2447  void setAccessor(IdentifierInfo *II) { Accessor = II; }
2448
2449  SourceLocation getAccessorLoc() const { return AccessorLoc; }
2450  void setAccessorLoc(SourceLocation L) { AccessorLoc = L; }
2451
2452  /// getNumElements - Get the number of components being selected.
2453  unsigned getNumElements() const;
2454
2455  /// containsDuplicateElements - Return true if any element access is
2456  /// repeated.
2457  bool containsDuplicateElements() const;
2458
2459  /// getEncodedElementAccess - Encode the elements accessed into an llvm
2460  /// aggregate Constant of ConstantInt(s).
2461  void getEncodedElementAccess(llvm::SmallVectorImpl<unsigned> &Elts) const;
2462
2463  virtual SourceRange getSourceRange() const {
2464    return SourceRange(getBase()->getLocStart(), AccessorLoc);
2465  }
2466
2467  /// isArrow - Return true if the base expression is a pointer to vector,
2468  /// return false if the base expression is a vector.
2469  bool isArrow() const;
2470
2471  static bool classof(const Stmt *T) {
2472    return T->getStmtClass() == ExtVectorElementExprClass;
2473  }
2474  static bool classof(const ExtVectorElementExpr *) { return true; }
2475
2476  // Iterators
2477  virtual child_iterator child_begin();
2478  virtual child_iterator child_end();
2479
2480  virtual void EmitImpl(llvm::Serializer& S) const;
2481  static ExtVectorElementExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C);
2482};
2483
2484
2485/// BlockExpr - Adaptor class for mixing a BlockDecl with expressions.
2486/// ^{ statement-body }   or   ^(int arg1, float arg2){ statement-body }
2487class BlockExpr : public Expr {
2488protected:
2489  BlockDecl *TheBlock;
2490  bool HasBlockDeclRefExprs;
2491public:
2492  BlockExpr(BlockDecl *BD, QualType ty, bool hasBlockDeclRefExprs)
2493    : Expr(BlockExprClass, ty),
2494      TheBlock(BD), HasBlockDeclRefExprs(hasBlockDeclRefExprs) {}
2495
2496  /// \brief Build an empty block expression.
2497  explicit BlockExpr(EmptyShell Empty) : Expr(BlockExprClass, Empty) { }
2498
2499  const BlockDecl *getBlockDecl() const { return TheBlock; }
2500  BlockDecl *getBlockDecl() { return TheBlock; }
2501  void setBlockDecl(BlockDecl *BD) { TheBlock = BD; }
2502
2503  // Convenience functions for probing the underlying BlockDecl.
2504  SourceLocation getCaretLocation() const;
2505  const Stmt *getBody() const;
2506  Stmt *getBody();
2507
2508  const Stmt *getBody(ASTContext &C) const { return getBody(); }
2509  Stmt *getBody(ASTContext &C) { return getBody(); }
2510
2511  virtual SourceRange getSourceRange() const {
2512    return SourceRange(getCaretLocation(), getBody()->getLocEnd());
2513  }
2514
2515  /// getFunctionType - Return the underlying function type for this block.
2516  const FunctionType *getFunctionType() const;
2517
2518  /// hasBlockDeclRefExprs - Return true iff the block has BlockDeclRefExpr
2519  /// inside of the block that reference values outside the block.
2520  bool hasBlockDeclRefExprs() const { return HasBlockDeclRefExprs; }
2521  void setHasBlockDeclRefExprs(bool BDRE) { HasBlockDeclRefExprs = BDRE; }
2522
2523  static bool classof(const Stmt *T) {
2524    return T->getStmtClass() == BlockExprClass;
2525  }
2526  static bool classof(const BlockExpr *) { return true; }
2527
2528  // Iterators
2529  virtual child_iterator child_begin();
2530  virtual child_iterator child_end();
2531
2532  virtual void EmitImpl(llvm::Serializer& S) const;
2533  static BlockExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C);
2534};
2535
2536/// BlockDeclRefExpr - A reference to a declared variable, function,
2537/// enum, etc.
2538class BlockDeclRefExpr : public Expr {
2539  ValueDecl *D;
2540  SourceLocation Loc;
2541  bool IsByRef;
2542public:
2543  BlockDeclRefExpr(ValueDecl *d, QualType t, SourceLocation l, bool ByRef) :
2544       Expr(BlockDeclRefExprClass, t), D(d), Loc(l), IsByRef(ByRef) {}
2545
2546  // \brief Build an empty reference to a declared variable in a
2547  // block.
2548  explicit BlockDeclRefExpr(EmptyShell Empty)
2549    : Expr(BlockDeclRefExprClass, Empty) { }
2550
2551  ValueDecl *getDecl() { return D; }
2552  const ValueDecl *getDecl() const { return D; }
2553  void setDecl(ValueDecl *VD) { D = VD; }
2554
2555  SourceLocation getLocation() const { return Loc; }
2556  void setLocation(SourceLocation L) { Loc = L; }
2557
2558  virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
2559
2560  bool isByRef() const { return IsByRef; }
2561  void setByRef(bool BR) { IsByRef = BR; }
2562
2563  static bool classof(const Stmt *T) {
2564    return T->getStmtClass() == BlockDeclRefExprClass;
2565  }
2566  static bool classof(const BlockDeclRefExpr *) { return true; }
2567
2568  // Iterators
2569  virtual child_iterator child_begin();
2570  virtual child_iterator child_end();
2571
2572  virtual void EmitImpl(llvm::Serializer& S) const;
2573  static BlockDeclRefExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C);
2574};
2575
2576}  // end namespace clang
2577
2578#endif
2579