Expr.h revision e2563ca02a519c2ad6d64dfed87d6e86c5d3c072
15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//===--- Expr.h - Classes for representing expressions ----------*- C++ -*-===//
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//                     The LLVM Compiler Infrastructure
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//
55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// This file is distributed under the University of Illinois Open Source
65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// License. See LICENSE.TXT for details.
75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//
85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//===----------------------------------------------------------------------===//
95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//
10a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)//  This file defines the Expr interface and subclasses.
112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)//
122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)//===----------------------------------------------------------------------===//
132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifndef LLVM_CLANG_AST_EXPR_H
15868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#define LLVM_CLANG_AST_EXPR_H
162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "clang/AST/Stmt.h"
187dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch#include "clang/AST/Type.h"
195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "clang/AST/Decl.h"
205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "clang/AST/DeclObjC.h"
214e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#include "clang/Basic/IdentifierTable.h"
225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "llvm/ADT/APSInt.h"
235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "llvm/ADT/APFloat.h"
242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace clang {
265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  class IdentifierInfo;
275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  class Selector;
285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  class Decl;
295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  class ASTContext;
305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// Expr - This represents one expression.  Note that Expr's are subclasses of
325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// Stmt.  This allows an expression to be transparently used any place a Stmt
335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// is required.
345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)///
35c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)class Expr : public Stmt {
365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  QualType TR;
375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)protected:
385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Expr(StmtClass SC, QualType T) : Stmt(SC), TR(T) {}
392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)public:
40a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  QualType getType() const { return TR; }
415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void setType(QualType t) { TR = t; }
425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  /// SourceLocation tokens are not useful in isolation - they are low level
442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  /// value objects created/interpreted by SourceManager. We assume AST
455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// clients will have a pointer to the respective SourceManager.
46868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  virtual SourceRange getSourceRange() const = 0;
475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
481e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  /// getExprLoc - Return the preferred location for the arrow when diagnosing
491e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  /// a problem with a generic expression.
5090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  virtual SourceLocation getExprLoc() const { return getLocStart(); }
5190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
52a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  /// hasLocalSideEffect - Return true if this immediate expression has side
53a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  /// effects, not counting any sub-expressions.
54a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  bool hasLocalSideEffect() const;
55a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
56a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  /// isLvalue - C99 6.3.2.1: an lvalue is an expression with an object type or
57a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  /// incomplete type other than void. Nonarray expressions that can be lvalues:
58a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  ///  - name, where name must be a variable
59a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  ///  - e[i]
60a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  ///  - (e), where e must be an lvalue
61a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  ///  - e.name, where e must be an lvalue
62a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  ///  - e->name
63a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  ///  - *e, the type of e cannot be a function type
64a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  ///  - string-constant
65a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  ///  - reference type [C++ [expr]]
661e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  ///
671e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  enum isLvalueResult {
681e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    LV_Valid,
691e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    LV_NotObjectType,
701e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    LV_IncompleteVoidType,
711e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    LV_DuplicateVectorComponents,
721e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    LV_InvalidExpression
73a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  };
74a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  isLvalueResult isLvalue() const;
75a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
76a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  /// isModifiableLvalue - C99 6.3.2.1: an lvalue that does not have array type,
77a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  /// does not have an incomplete type, does not have a const-qualified type,
781e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  /// and if it is a structure or union, does not have any member (including,
79a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  /// recursively, any member or element of all contained aggregates or unions)
80a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  /// with a const-qualified type.
81a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  enum isModifiableLvalueResult {
82a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    MLV_Valid,
835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    MLV_NotObjectType,
845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    MLV_IncompleteVoidType,
855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    MLV_DuplicateVectorComponents,
865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    MLV_InvalidExpression,
875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    MLV_IncompleteType,
885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    MLV_ConstQualified,
895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    MLV_ArrayType
905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  };
915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  isModifiableLvalueResult isModifiableLvalue() const;
925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool isNullPointerConstant(ASTContext &Ctx) const;
945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
95b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  /// isIntegerConstantExpr - Return true if this expression is a valid integer
965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// constant expression, and, if so, return its value in Result.  If not a
975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// valid i-c-e, return false and fill in Loc (if specified) with the location
984e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  /// of the invalid expression.
994e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  bool isIntegerConstantExpr(llvm::APSInt &Result, ASTContext &Ctx,
1004e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)                             SourceLocation *Loc = 0,
1014e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)                             bool isEvaluated = true) const;
1024e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  bool isIntegerConstantExpr(ASTContext &Ctx, SourceLocation *Loc = 0) const {
1034e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    llvm::APSInt X(32);
1044e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    return isIntegerConstantExpr(X, Ctx, Loc);
1054e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  }
1064e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  /// isConstantExpr - Return true if this expression is a valid constant expr.
1075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool isConstantExpr(ASTContext &Ctx, SourceLocation *Loc) const;
1085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  /// hasGlobalStorage - Return true if this expression has static storage
1102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  /// duration.  This means that the address of this expression is a link-time
1115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// constant.
1125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool hasGlobalStorage() const;
1135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// IgnoreParens - Ignore parentheses.  If this Expr is a ParenExpr, return
1152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ///  its subexpression.  If that subexpression is also a ParenExpr,
1162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ///  then this method recursively returns its subexpression, and so forth.
1172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ///  Otherwise, the method returns the current Expr.
1185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Expr* IgnoreParens();
1192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// IgnoreParenCasts - Ignore parentheses and casts.  Strip off any ParenExpr
1212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  /// or CastExprs or ImplicitCastExprs, returning their operand.
1222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  Expr *IgnoreParenCasts();
1232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  const Expr* IgnoreParens() const {
1255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return const_cast<Expr*>(this)->IgnoreParens();
1265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
1275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  const Expr *IgnoreParenCasts() const {
128b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)    return const_cast<Expr*>(this)->IgnoreParenCasts();
1295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
1305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static bool classof(const Stmt *T) {
1325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return T->getStmtClass() >= firstExprConstant &&
1335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)           T->getStmtClass() <= lastExprConstant;
1345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
1355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static bool classof(const Expr *) { return true; }
1365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static inline Expr* Create(llvm::Deserializer& D, ASTContext& C) {
1385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return cast<Expr>(Stmt::Create(D, C));
1395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
1405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
1415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//===----------------------------------------------------------------------===//
1435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Primary Expressions.
1445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//===----------------------------------------------------------------------===//
1455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// DeclRefExpr - [C99 6.5.1p2] - A reference to a declared variable, function,
1475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// enum, etc.
1485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class DeclRefExpr : public Expr {
1495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ValueDecl *D;
1505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  SourceLocation Loc;
1515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)public:
1525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  DeclRefExpr(ValueDecl *d, QualType t, SourceLocation l) :
1535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    Expr(DeclRefExprClass, t), D(d), Loc(l) {}
1545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ValueDecl *getDecl() { return D; }
1565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  const ValueDecl *getDecl() const { return D; }
1575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
1585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static bool classof(const Stmt *T) {
1615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return T->getStmtClass() == DeclRefExprClass;
1625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
1635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static bool classof(const DeclRefExpr *) { return true; }
1645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Iterators
1665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual child_iterator child_begin();
1675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual child_iterator child_end();
1685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void EmitImpl(llvm::Serializer& S) const;
1705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static DeclRefExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C);
1715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
1725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// PreDefinedExpr - [C99 6.4.2.2] - A pre-defined identifier such as __func__.
1742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class PreDefinedExpr : public Expr {
1752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)public:
1762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  enum IdentType {
1772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    Func,
1785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    Function,
1795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    PrettyFunction
180868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  };
1814e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
1822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)private:
1835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  SourceLocation Loc;
184868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  IdentType Type;
185868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)public:
186868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  PreDefinedExpr(SourceLocation l, QualType type, IdentType IT)
187868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    : Expr(PreDefinedExprClass, type), Loc(l), Type(IT) {}
188868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
1892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  IdentType getIdentType() const { return Type; }
1902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
1922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  static bool classof(const Stmt *T) {
1945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return T->getStmtClass() == PreDefinedExprClass;
1955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
1965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static bool classof(const PreDefinedExpr *) { return true; }
1975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Iterators
1995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual child_iterator child_begin();
2005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual child_iterator child_end();
201868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
2025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void EmitImpl(llvm::Serializer& S) const;
2034e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  static PreDefinedExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C);
2045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
2055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class IntegerLiteral : public Expr {
2075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  llvm::APInt Value;
2085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  SourceLocation Loc;
2095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)public:
2105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // type should be IntTy, LongTy, LongLongTy, UnsignedIntTy, UnsignedLongTy,
2115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // or UnsignedLongLongTy
212868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  IntegerLiteral(const llvm::APInt &V, QualType type, SourceLocation l)
2135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    : Expr(IntegerLiteralClass, type), Value(V), Loc(l) {
2144e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    assert(type->isIntegerType() && "Illegal type in IntegerLiteral");
2155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
2165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  const llvm::APInt &getValue() const { return Value; }
2175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
2185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static bool classof(const Stmt *T) {
2202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    return T->getStmtClass() == IntegerLiteralClass;
2212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
2222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  static bool classof(const IntegerLiteral *) { return true; }
2232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
2245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Iterators
2255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual child_iterator child_begin();
2265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual child_iterator child_end();
2275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void EmitImpl(llvm::Serializer& S) const;
2295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static IntegerLiteral* CreateImpl(llvm::Deserializer& D, ASTContext& C);
2305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
2315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class CharacterLiteral : public Expr {
2335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  unsigned Value;
2345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  SourceLocation Loc;
2355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)public:
2365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // type should be IntTy
2372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  CharacterLiteral(unsigned value, QualType type, SourceLocation l)
2385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    : Expr(CharacterLiteralClass, type), Value(value), Loc(l) {
2395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
2402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  SourceLocation getLoc() const { return Loc; }
2415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2424e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
2435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  unsigned getValue() const { return Value; }
2452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
2465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static bool classof(const Stmt *T) {
2475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return T->getStmtClass() == CharacterLiteralClass;
2485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
2495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static bool classof(const CharacterLiteral *) { return true; }
2505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Iterators
2525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual child_iterator child_begin();
2532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual child_iterator child_end();
2545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void EmitImpl(llvm::Serializer& S) const;
2565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static CharacterLiteral* CreateImpl(llvm::Deserializer& D, ASTContext& C);
2575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
2585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class FloatingLiteral : public Expr {
2605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  llvm::APFloat Value;
2615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool IsExact : 1;
2625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  SourceLocation Loc;
2635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)public:
2645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  FloatingLiteral(const llvm::APFloat &V, bool* isexact,
2655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                  QualType Type, SourceLocation L)
2665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    : Expr(FloatingLiteralClass, Type), Value(V), IsExact(*isexact), Loc(L) {}
2675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  const llvm::APFloat &getValue() const { return Value; }
2695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  bool isExact() const { return IsExact; }
2712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
2722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  /// getValueAsDouble - This returns the value as an inaccurate double.  Note
273868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  /// that this may cause loss of precision, but is useful for debugging dumps
2745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// etc.
2754e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  double getValueAsDouble() const {
2765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // FIXME: We need something for long double here.
2775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    if (cast<BuiltinType>(getType())->getKind() == BuiltinType::Float)
2785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      return Value.convertToFloat();
2795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    else
2805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      return Value.convertToDouble();
2815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
2825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
2845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static bool classof(const Stmt *T) {
2865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return T->getStmtClass() == FloatingLiteralClass;
2875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
2885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static bool classof(const FloatingLiteral *) { return true; }
2895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Iterators
2915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual child_iterator child_begin();
2925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual child_iterator child_end();
2935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void EmitImpl(llvm::Serializer& S) const;
2955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static FloatingLiteral* CreateImpl(llvm::Deserializer& D, ASTContext& C);
2965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
2975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// ImaginaryLiteral - We support imaginary integer and floating point literals,
2995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// like "1.0i".  We represent these as a wrapper around FloatingLiteral and
3005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// IntegerLiteral classes.  Instances of this class always have a Complex type
3015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// whose element type matches the subexpression.
3025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)///
3035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class ImaginaryLiteral : public Expr {
3045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Expr *Val;
3052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)public:
3062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ImaginaryLiteral(Expr *val, QualType Ty)
3072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    : Expr(ImaginaryLiteralClass, Ty), Val(val) {}
308ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch
309ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  const Expr *getSubExpr() const { return Val; }
3105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Expr *getSubExpr() { return Val; }
3112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
3125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual SourceRange getSourceRange() const { return Val->getSourceRange(); }
3135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static bool classof(const Stmt *T) {
3142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    return T->getStmtClass() == ImaginaryLiteralClass;
3155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
3162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  static bool classof(const ImaginaryLiteral *) { return true; }
3175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Iterators
3195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual child_iterator child_begin();
3205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual child_iterator child_end();
3215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void EmitImpl(llvm::Serializer& S) const;
3235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static ImaginaryLiteral* CreateImpl(llvm::Deserializer& D, ASTContext& C);
3245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
3255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// StringLiteral - This represents a string literal expression, e.g. "foo"
3275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// or L"bar" (wide strings).  The actual string is returned by getStrData()
3285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// is NOT null-terminated, and the length of the string is determined by
3295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// calling getByteLength().  The C type for a string is always a
3305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// ConstantArrayType.
3312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class StringLiteral : public Expr {
33258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  const char *StrData;
33358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  unsigned ByteLength;
33458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  bool IsWide;
3355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // if the StringLiteral was composed using token pasting, both locations
3365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // are needed. If not (the common case), firstTokLoc == lastTokLoc.
3375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // FIXME: if space becomes an issue, we should create a sub-class.
338b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  SourceLocation firstTokLoc, lastTokLoc;
3395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)public:
3405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  StringLiteral(const char *strData, unsigned byteLength, bool Wide,
3415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                QualType t, SourceLocation b, SourceLocation e);
3422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual ~StringLiteral();
3432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
3442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  const char *getStrData() const { return StrData; }
3455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  unsigned getByteLength() const { return ByteLength; }
3465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool isWide() const { return IsWide; }
3475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual SourceRange getSourceRange() const {
3495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return SourceRange(firstTokLoc,lastTokLoc);
3505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
35158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  static bool classof(const Stmt *T) {
3525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return T->getStmtClass() == StringLiteralClass;
3535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
3542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  static bool classof(const StringLiteral *) { return true; }
3552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
3565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Iterators
3575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual child_iterator child_begin();
3585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual child_iterator child_end();
3595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void EmitImpl(llvm::Serializer& S) const;
3612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  static StringLiteral* CreateImpl(llvm::Deserializer& D, ASTContext& C);
3625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
3635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// ParenExpr - This represents a parethesized expression, e.g. "(1)".  This
3655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// AST node is only formed if full location information is requested.
3665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class ParenExpr : public Expr {
3675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  SourceLocation L, R;
3685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Expr *Val;
3692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)public:
3705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ParenExpr(SourceLocation l, SourceLocation r, Expr *val)
3715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    : Expr(ParenExprClass, val->getType()), L(l), R(r), Val(val) {}
3725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  const Expr *getSubExpr() const { return Val; }
3745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Expr *getSubExpr() { return Val; }
3755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  SourceRange getSourceRange() const { return SourceRange(L, R); }
3765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static bool classof(const Stmt *T) {
3785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return T->getStmtClass() == ParenExprClass;
3795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
3805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static bool classof(const ParenExpr *) { return true; }
3815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Iterators
3835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual child_iterator child_begin();
3845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual child_iterator child_end();
3855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void EmitImpl(llvm::Serializer& S) const;
3875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static ParenExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C);
3885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
389868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
3905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// UnaryOperator - This represents the unary-expression's (except sizeof of
3925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// types), the postinc/postdec operators from postfix-expression, and various
3935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// extensions.
3945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)///
3955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// Notes on various nodes:
3965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)///
397868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)/// Real/Imag - These return the real/imag part of a complex operand.  If
3985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)///   applied to a non-complex value, the former returns its operand and the
3995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)///   later returns zero in the type of the operand.
400c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)///
401c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)/// __builtin_offsetof(type, a.b[10]) is represented as a unary operator whose
402c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)///   subexpression is a compound literal with the various MemberExpr and
403868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)///   ArraySubscriptExpr's applied to it.
4040f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)///
4055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class UnaryOperator : public Expr {
4065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)public:
4075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Note that additions to this should also update the StmtVisitor class.
408868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  enum Opcode {
4095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    PostInc, PostDec, // [C99 6.5.2.4] Postfix increment and decrement operators
4105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    PreInc, PreDec,   // [C99 6.5.3.1] Prefix increment and decrement operators.
4115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    AddrOf, Deref,    // [C99 6.5.3.2] Address and indirection operators.
4125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    Plus, Minus,      // [C99 6.5.3.3] Unary arithmetic operators.
4135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    Not, LNot,        // [C99 6.5.3.3] Unary arithmetic operators.
4145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    SizeOf, AlignOf,  // [C99 6.5.3.4] Sizeof (expr, not type) operator.
4155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    Real, Imag,       // "__real expr"/"__imag expr" Extension.
4165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    Extension,        // __extension__ marker.
4174e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    OffsetOf          // __builtin_offsetof
4184e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  };
419868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)private:
4205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Expr *Val;
4215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Opcode Opc;
4225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  SourceLocation Loc;
4235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)public:
4245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  UnaryOperator(Expr *input, Opcode opc, QualType type, SourceLocation l)
4265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    : Expr(UnaryOperatorClass, type), Val(input), Opc(opc), Loc(l) {}
4275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Opcode getOpcode() const { return Opc; }
4295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Expr *getSubExpr() const { return Val; }
4305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
431a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  /// getOperatorLoc - Return the location of the operator.
4325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  SourceLocation getOperatorLoc() const { return Loc; }
4335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4347d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  /// isPostfix - Return true if this is a postfix operation, like x++.
4357d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  static bool isPostfix(Opcode Op);
4365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool isPostfix() const { return isPostfix(Opc); }
4385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool isIncrementOp() const {return Opc==PreInc || Opc==PostInc; }
4395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool isIncrementDecrementOp() const { return Opc>=PostInc && Opc<=PreDec; }
4405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool isSizeOfAlignOfOp() const { return Opc == SizeOf || Opc == AlignOf; }
4415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool isOffsetOfOp() const { return Opc == OffsetOf; }
4421e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  static bool isArithmeticOp(Opcode Op) { return Op >= Plus && Op <= LNot; }
4431e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
4441e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  /// getOpcodeStr - Turn an Opcode enum value into the punctuation char it
44590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  /// corresponds to, e.g. "sizeof" or "[pre]++"
44690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  static const char *getOpcodeStr(Opcode Op);
4475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual SourceRange getSourceRange() const {
4495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    if (isPostfix())
4505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      return SourceRange(Val->getLocStart(), Loc);
4515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    else
4525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      return SourceRange(Loc, Val->getLocEnd());
4535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
4545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual SourceLocation getExprLoc() const { return Loc; }
4555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static bool classof(const Stmt *T) {
4575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return T->getStmtClass() == UnaryOperatorClass;
4585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
4595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static bool classof(const UnaryOperator *) { return true; }
4605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  int64_t evaluateOffsetOf(ASTContext& C) const;
4622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
4632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Iterators
4642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual child_iterator child_begin();
4652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual child_iterator child_end();
4662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
467b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  virtual void EmitImpl(llvm::Serializer& S) const;
4682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  static UnaryOperator* CreateImpl(llvm::Deserializer& D, ASTContext& C);
4692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)};
4702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
4712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)/// SizeOfAlignOfTypeExpr - [C99 6.5.3.4] - This is only for sizeof/alignof of
4722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)/// *types*.  sizeof(expr) is handled by UnaryOperator.
4732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class SizeOfAlignOfTypeExpr : public Expr {
4742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  bool isSizeof;  // true if sizeof, false if alignof.
4752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  QualType Ty;
4762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  SourceLocation OpLoc, RParenLoc;
4772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)public:
4782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  SizeOfAlignOfTypeExpr(bool issizeof, QualType argType, QualType resultType,
4792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                        SourceLocation op, SourceLocation rp) :
4802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    Expr(SizeOfAlignOfTypeExprClass, resultType),
4812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    isSizeof(issizeof), Ty(argType), OpLoc(op), RParenLoc(rp) {}
4822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
4832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  bool isSizeOf() const { return isSizeof; }
4842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  QualType getArgumentType() const { return Ty; }
4852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
4862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  SourceLocation getOperatorLoc() const { return OpLoc; }
4872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  SourceRange getSourceRange() const { return SourceRange(OpLoc, RParenLoc); }
4882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
4892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  static bool classof(const Stmt *T) {
4902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    return T->getStmtClass() == SizeOfAlignOfTypeExprClass;
4912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
4922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  static bool classof(const SizeOfAlignOfTypeExpr *) { return true; }
4932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
4942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Iterators
4952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual child_iterator child_begin();
4962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual child_iterator child_end();
497c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
498c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  virtual void EmitImpl(llvm::Serializer& S) const;
499c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  static SizeOfAlignOfTypeExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C);
500c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)};
501c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
5020f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)//===----------------------------------------------------------------------===//
5032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Postfix Operators.
5042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)//===----------------------------------------------------------------------===//
5052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
506c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)/// ArraySubscriptExpr - [C99 6.5.2.1] Array Subscripting.
5072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class ArraySubscriptExpr : public Expr {
5082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  enum { LHS, RHS, END_EXPR=2 };
5095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Expr* SubExprs[END_EXPR];
5105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  SourceLocation RBracketLoc;
5115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)public:
5125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ArraySubscriptExpr(Expr *lhs, Expr *rhs, QualType t,
5135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                     SourceLocation rbracketloc)
5145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  : Expr(ArraySubscriptExprClass, t), RBracketLoc(rbracketloc) {
5155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    SubExprs[LHS] = lhs;
5165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    SubExprs[RHS] = rhs;
5172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
5182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
5197d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  /// An array access can be written A[4] or 4[A] (both are equivalent).
5202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  /// - getBase() and getIdx() always present the normalized view: A[4].
521b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  ///    In this case getBase() returns "A" and getIdx() returns "4".
5225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// - getLHS() and getRHS() present the syntactic view. e.g. for
5235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ///    4[A] getLHS() returns "4".
5245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// Note: Because vector element access is also written A[4] we must
5255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// predicate the format conversion in getBase and getIdx only on the
5265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// the type of the RHS, as it is possible for the LHS to be a vector of
5275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// integer type
5285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Expr *getLHS() { return SubExprs[LHS]; }
5292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  const Expr *getLHS() const { return SubExprs[LHS]; }
5302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
5312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  Expr *getRHS() { return SubExprs[RHS]; }
5325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  const Expr *getRHS() const { return SubExprs[RHS]; }
5335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Expr *getBase() {
5355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return (getRHS()->getType()->isIntegerType()) ? getLHS() : getRHS();
5362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
5375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  const Expr *getBase() const {
5392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    return (getRHS()->getType()->isIntegerType()) ? getLHS() : getRHS();
5405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
5415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Expr *getIdx() {
54358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    return (getRHS()->getType()->isIntegerType()) ? getRHS() : getLHS();
5445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
5455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  const Expr *getIdx() const {
5475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return (getRHS()->getType()->isIntegerType()) ? getRHS() : getLHS();
5485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
5495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  SourceRange getSourceRange() const {
5525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return SourceRange(getLHS()->getLocStart(), RBracketLoc);
553a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  }
5545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual SourceLocation getExprLoc() const { return RBracketLoc; }
5555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5567d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  static bool classof(const Stmt *T) {
5577d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    return T->getStmtClass() == ArraySubscriptExprClass;
5585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
5595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static bool classof(const ArraySubscriptExpr *) { return true; }
5605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Iterators
5625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual child_iterator child_begin();
5635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual child_iterator child_end();
5645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void EmitImpl(llvm::Serializer& S) const;
5665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static ArraySubscriptExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C);
5675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
5685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// CallExpr - [C99 6.5.2.2] Function Calls.
5715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)///
5725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class CallExpr : public Expr {
5735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  enum { FN=0, ARGS_START=1 };
5745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Expr **SubExprs;
5755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  unsigned NumArgs;
5765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  SourceLocation RParenLoc;
5775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
578868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  // This version of the ctor is for deserialization.
5795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  CallExpr(Expr** subexprs, unsigned numargs, QualType t,
5805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)           SourceLocation rparenloc)
5815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  : Expr(CallExprClass,t), SubExprs(subexprs),
5825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    NumArgs(numargs), RParenLoc(rparenloc) {}
5835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
584c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)public:
585c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  CallExpr(Expr *fn, Expr **args, unsigned numargs, QualType t,
586c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)           SourceLocation rparenloc);
587c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  ~CallExpr() {
5880f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)    delete [] SubExprs;
5895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
5905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  const Expr *getCallee() const { return SubExprs[FN]; }
592868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  Expr *getCallee() { return SubExprs[FN]; }
5935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void setCallee(Expr *F) { SubExprs[FN] = F; }
5945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// getNumArgs - Return the number of actual arguments to this call.
5962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ///
5972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  unsigned getNumArgs() const { return NumArgs; }
5982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
5994e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  /// getArg - Return the specified argument.
6004e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  Expr *getArg(unsigned Arg) {
6014e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    assert(Arg < NumArgs && "Arg access out of range!");
6024e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    return SubExprs[Arg+ARGS_START];
6034e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  }
6042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  const Expr *getArg(unsigned Arg) const {
6055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    assert(Arg < NumArgs && "Arg access out of range!");
6065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return SubExprs[Arg+ARGS_START];
6075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
6085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// setArg - Set the specified argument.
6095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void setArg(unsigned Arg, Expr *ArgExpr) {
6105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    assert(Arg < NumArgs && "Arg access out of range!");
6115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    SubExprs[Arg+ARGS_START] = ArgExpr;
6125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
6135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// setNumArgs - This changes the number of arguments present in this call.
6155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// Any orphaned expressions are deleted by this, and any new operands are set
6165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// to null.
6173551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  void setNumArgs(unsigned NumArgs);
6183551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
6193551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  typedef Expr **arg_iterator;
6203551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  typedef Expr * const *arg_const_iterator;
6213551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  arg_iterator arg_begin() { return SubExprs+ARGS_START; }
6223551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  arg_iterator arg_end() { return SubExprs+ARGS_START+getNumArgs(); }
6233551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  arg_const_iterator arg_begin() const { return SubExprs+ARGS_START; }
6245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  arg_const_iterator arg_end() const { return SubExprs+ARGS_START+getNumArgs(); }
6252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
6265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// getNumCommas - Return the number of commas that must have been present in
6285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// this function call.
6295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  unsigned getNumCommas() const { return NumArgs ? NumArgs - 1 : 0; }
6305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool isBuiltinClassifyType(llvm::APSInt &Result) const;
6325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// isBuiltinConstantExpr - Return true if this built-in call is constant.
6345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool isBuiltinConstantExpr() const;
6355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  SourceLocation getRParenLoc() const { return RParenLoc; }
6375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  SourceRange getSourceRange() const {
6385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return SourceRange(getCallee()->getLocStart(), RParenLoc);
639a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  }
6405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static bool classof(const Stmt *T) {
6427d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    return T->getStmtClass() == CallExprClass;
6437d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  }
6445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static bool classof(const CallExpr *) { return true; }
6455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Iterators
6475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual child_iterator child_begin();
6485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual child_iterator child_end();
6495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void EmitImpl(llvm::Serializer& S) const;
6515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static CallExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C);
6525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
6535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// MemberExpr - [C99 6.5.2.3] Structure and Union Members.
6555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)///
6565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class MemberExpr : public Expr {
6575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Expr *Base;
6585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  FieldDecl *MemberDecl;
6595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  SourceLocation MemberLoc;
6605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool IsArrow;      // True if this is "X->F", false if this is "X.F".
6615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)public:
6625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  MemberExpr(Expr *base, bool isarrow, FieldDecl *memberdecl, SourceLocation l,
663b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)             QualType ty)
6645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    : Expr(MemberExprClass, ty),
6655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      Base(base), MemberDecl(memberdecl), MemberLoc(l), IsArrow(isarrow) {}
6665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Expr *getBase() const { return Base; }
6685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  FieldDecl *getMemberDecl() const { return MemberDecl; }
6695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool isArrow() const { return IsArrow; }
6705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual SourceRange getSourceRange() const {
6722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    return SourceRange(getBase()->getLocStart(), MemberLoc);
6732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
6745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual SourceLocation getExprLoc() const { return MemberLoc; }
6755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static bool classof(const Stmt *T) {
6772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    return T->getStmtClass() == MemberExprClass;
6782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
6795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static bool classof(const MemberExpr *) { return true; }
6805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Iterators
6825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual child_iterator child_begin();
6835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual child_iterator child_end();
6845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void EmitImpl(llvm::Serializer& S) const;
6865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static MemberExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C);
6875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
6885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// OCUVectorElementExpr - This represents access to specific elements of a
6905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// vector, and may occur on the left hand side or right hand side.  For example
6915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// the following is legal:  "V.xy = V.zw" if V is a 4 element ocu vector.
6925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)///
6935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class OCUVectorElementExpr : public Expr {
6945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Expr *Base;
6955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  IdentifierInfo &Accessor;
6965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  SourceLocation AccessorLoc;
6975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)public:
6985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  enum ElementType {
6995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    Point,   // xywz
7005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    Color,   // rgba
7015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    Texture  // stpq
7025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  };
7032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  OCUVectorElementExpr(QualType ty, Expr *base, IdentifierInfo &accessor,
7045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                       SourceLocation loc)
7055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    : Expr(OCUVectorElementExprClass, ty),
7062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      Base(base), Accessor(accessor), AccessorLoc(loc) {}
7072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
7082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  const Expr *getBase() const { return Base; }
7092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  Expr *getBase() { return Base; }
7105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
711  IdentifierInfo &getAccessor() const { return Accessor; }
712
713  /// getNumElements - Get the number of components being selected.
714  unsigned getNumElements() const;
715
716  /// getElementType - Determine whether the components of this access are
717  /// "point" "color" or "texture" elements.
718  ElementType getElementType() const;
719
720  /// containsDuplicateElements - Return true if any element access is
721  /// repeated.
722  bool containsDuplicateElements() const;
723
724  /// getEncodedElementAccess - Encode the elements accessed into a bit vector.
725  /// The encoding currently uses 2-bit bitfields, but clients should use the
726  /// accessors below to access them.
727  ///
728  unsigned getEncodedElementAccess() const;
729
730  /// getAccessedFieldNo - Given an encoded value and a result number, return
731  /// the input field number being accessed.
732  static unsigned getAccessedFieldNo(unsigned Idx, unsigned EncodedVal) {
733    return (EncodedVal >> (Idx*2)) & 3;
734  }
735
736  virtual SourceRange getSourceRange() const {
737    return SourceRange(getBase()->getLocStart(), AccessorLoc);
738  }
739  static bool classof(const Stmt *T) {
740    return T->getStmtClass() == OCUVectorElementExprClass;
741  }
742  static bool classof(const OCUVectorElementExpr *) { return true; }
743
744  // Iterators
745  virtual child_iterator child_begin();
746  virtual child_iterator child_end();
747};
748
749/// CompoundLiteralExpr - [C99 6.5.2.5]
750///
751class CompoundLiteralExpr : public Expr {
752  /// LParenLoc - If non-null, this is the location of the left paren in a
753  /// compound literal like "(int){4}".  This can be null if this is a
754  /// synthesized compound expression.
755  SourceLocation LParenLoc;
756  Expr *Init;
757  bool FileScope;
758public:
759  CompoundLiteralExpr(SourceLocation lparenloc, QualType ty, Expr *init, bool fileScope) :
760    Expr(CompoundLiteralExprClass, ty), LParenLoc(lparenloc), Init(init), FileScope(fileScope) {}
761
762  const Expr *getInitializer() const { return Init; }
763  Expr *getInitializer() { return Init; }
764
765  bool isFileScope() const { return FileScope; }
766
767  SourceLocation getLParenLoc() const { return LParenLoc; }
768
769  virtual SourceRange getSourceRange() const {
770    // FIXME: Init should never be null.
771    if (!Init)
772      return SourceRange();
773    if (LParenLoc.isInvalid())
774      return Init->getSourceRange();
775    return SourceRange(LParenLoc, Init->getLocEnd());
776  }
777
778  static bool classof(const Stmt *T) {
779    return T->getStmtClass() == CompoundLiteralExprClass;
780  }
781  static bool classof(const CompoundLiteralExpr *) { return true; }
782
783  // Iterators
784  virtual child_iterator child_begin();
785  virtual child_iterator child_end();
786
787  virtual void EmitImpl(llvm::Serializer& S) const;
788  static CompoundLiteralExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C);
789};
790
791/// ImplicitCastExpr - Allows us to explicitly represent implicit type
792/// conversions. For example: converting T[]->T*, void f()->void (*f)(),
793/// float->double, short->int, etc.
794///
795class ImplicitCastExpr : public Expr {
796  Expr *Op;
797public:
798  ImplicitCastExpr(QualType ty, Expr *op) :
799    Expr(ImplicitCastExprClass, ty), Op(op) {}
800
801  Expr *getSubExpr() { return Op; }
802  const Expr *getSubExpr() const { return Op; }
803
804  virtual SourceRange getSourceRange() const { return Op->getSourceRange(); }
805
806  static bool classof(const Stmt *T) {
807    return T->getStmtClass() == ImplicitCastExprClass;
808  }
809  static bool classof(const ImplicitCastExpr *) { return true; }
810
811  // Iterators
812  virtual child_iterator child_begin();
813  virtual child_iterator child_end();
814
815  virtual void EmitImpl(llvm::Serializer& S) const;
816  static ImplicitCastExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C);
817};
818
819/// CastExpr - [C99 6.5.4] Cast Operators.
820///
821class CastExpr : public Expr {
822  Expr *Op;
823  SourceLocation Loc; // the location of the left paren
824public:
825  CastExpr(QualType ty, Expr *op, SourceLocation l) :
826    Expr(CastExprClass, ty), Op(op), Loc(l) {}
827
828  SourceLocation getLParenLoc() const { return Loc; }
829
830  Expr *getSubExpr() const { return Op; }
831
832  virtual SourceRange getSourceRange() const {
833    return SourceRange(Loc, getSubExpr()->getSourceRange().getEnd());
834  }
835  static bool classof(const Stmt *T) {
836    return T->getStmtClass() == CastExprClass;
837  }
838  static bool classof(const CastExpr *) { return true; }
839
840  // Iterators
841  virtual child_iterator child_begin();
842  virtual child_iterator child_end();
843
844  virtual void EmitImpl(llvm::Serializer& S) const;
845  static CastExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C);
846};
847
848class BinaryOperator : public Expr {
849public:
850  enum Opcode {
851    // Operators listed in order of precedence.
852    // Note that additions to this should also update the StmtVisitor class.
853    Mul, Div, Rem,    // [C99 6.5.5] Multiplicative operators.
854    Add, Sub,         // [C99 6.5.6] Additive operators.
855    Shl, Shr,         // [C99 6.5.7] Bitwise shift operators.
856    LT, GT, LE, GE,   // [C99 6.5.8] Relational operators.
857    EQ, NE,           // [C99 6.5.9] Equality operators.
858    And,              // [C99 6.5.10] Bitwise AND operator.
859    Xor,              // [C99 6.5.11] Bitwise XOR operator.
860    Or,               // [C99 6.5.12] Bitwise OR operator.
861    LAnd,             // [C99 6.5.13] Logical AND operator.
862    LOr,              // [C99 6.5.14] Logical OR operator.
863    Assign, MulAssign,// [C99 6.5.16] Assignment operators.
864    DivAssign, RemAssign,
865    AddAssign, SubAssign,
866    ShlAssign, ShrAssign,
867    AndAssign, XorAssign,
868    OrAssign,
869    Comma             // [C99 6.5.17] Comma operator.
870  };
871private:
872  enum { LHS, RHS, END_EXPR };
873  Expr* SubExprs[END_EXPR];
874  Opcode Opc;
875  SourceLocation OpLoc;
876public:
877
878  BinaryOperator(Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy,
879                 SourceLocation opLoc)
880    : Expr(BinaryOperatorClass, ResTy), Opc(opc), OpLoc(opLoc) {
881    SubExprs[LHS] = lhs;
882    SubExprs[RHS] = rhs;
883    assert(!isCompoundAssignmentOp() &&
884           "Use ArithAssignBinaryOperator for compound assignments");
885  }
886
887  SourceLocation getOperatorLoc() const { return OpLoc; }
888  Opcode getOpcode() const { return Opc; }
889  Expr *getLHS() const { return SubExprs[LHS]; }
890  Expr *getRHS() const { return SubExprs[RHS]; }
891  virtual SourceRange getSourceRange() const {
892    return SourceRange(getLHS()->getLocStart(), getRHS()->getLocEnd());
893  }
894
895  /// getOpcodeStr - Turn an Opcode enum value into the punctuation char it
896  /// corresponds to, e.g. "<<=".
897  static const char *getOpcodeStr(Opcode Op);
898
899  /// predicates to categorize the respective opcodes.
900  bool isMultiplicativeOp() const { return Opc >= Mul && Opc <= Rem; }
901  bool isAdditiveOp() const { return Opc == Add || Opc == Sub; }
902  bool isShiftOp() const { return Opc == Shl || Opc == Shr; }
903  bool isBitwiseOp() const { return Opc >= And && Opc <= Or; }
904  bool isRelationalOp() const { return Opc >= LT && Opc <= GE; }
905  bool isEqualityOp() const { return Opc == EQ || Opc == NE; }
906  bool isLogicalOp() const { return Opc == LAnd || Opc == LOr; }
907  bool isAssignmentOp() const { return Opc >= Assign && Opc <= OrAssign; }
908  bool isCompoundAssignmentOp() const { return Opc > Assign && Opc <= OrAssign;}
909  bool isShiftAssignOp() const { return Opc == ShlAssign || Opc == ShrAssign; }
910
911  static bool classof(const Stmt *S) {
912    return S->getStmtClass() == BinaryOperatorClass ||
913           S->getStmtClass() == CompoundAssignOperatorClass;
914  }
915  static bool classof(const BinaryOperator *) { return true; }
916
917  // Iterators
918  virtual child_iterator child_begin();
919  virtual child_iterator child_end();
920
921  virtual void EmitImpl(llvm::Serializer& S) const;
922  static BinaryOperator* CreateImpl(llvm::Deserializer& D, ASTContext& C);
923
924protected:
925  BinaryOperator(Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy,
926                 SourceLocation oploc, bool dead)
927    : Expr(CompoundAssignOperatorClass, ResTy), Opc(opc), OpLoc(oploc) {
928    SubExprs[LHS] = lhs;
929    SubExprs[RHS] = rhs;
930  }
931};
932
933/// CompoundAssignOperator - For compound assignments (e.g. +=), we keep
934/// track of the type the operation is performed in.  Due to the semantics of
935/// these operators, the operands are promoted, the aritmetic performed, an
936/// implicit conversion back to the result type done, then the assignment takes
937/// place.  This captures the intermediate type which the computation is done
938/// in.
939class CompoundAssignOperator : public BinaryOperator {
940  QualType ComputationType;
941public:
942  CompoundAssignOperator(Expr *lhs, Expr *rhs, Opcode opc,
943                         QualType ResType, QualType CompType,
944                         SourceLocation OpLoc)
945    : BinaryOperator(lhs, rhs, opc, ResType, OpLoc, true),
946      ComputationType(CompType) {
947    assert(isCompoundAssignmentOp() &&
948           "Only should be used for compound assignments");
949  }
950
951  QualType getComputationType() const { return ComputationType; }
952
953  static bool classof(const CompoundAssignOperator *) { return true; }
954  static bool classof(const Stmt *S) {
955    return S->getStmtClass() == CompoundAssignOperatorClass;
956  }
957
958  virtual void EmitImpl(llvm::Serializer& S) const;
959  static CompoundAssignOperator* CreateImpl(llvm::Deserializer& D,
960                                            ASTContext& C);
961};
962
963/// ConditionalOperator - The ?: operator.  Note that LHS may be null when the
964/// GNU "missing LHS" extension is in use.
965///
966class ConditionalOperator : public Expr {
967  enum { COND, LHS, RHS, END_EXPR };
968  Expr* SubExprs[END_EXPR]; // Left/Middle/Right hand sides.
969public:
970  ConditionalOperator(Expr *cond, Expr *lhs, Expr *rhs, QualType t)
971    : Expr(ConditionalOperatorClass, t) {
972    SubExprs[COND] = cond;
973    SubExprs[LHS] = lhs;
974    SubExprs[RHS] = rhs;
975  }
976
977  // getCond - Return the expression representing the condition for
978  //  the ?: operator.
979  Expr *getCond() const { return SubExprs[COND]; }
980
981  // getTrueExpr - Return the subexpression representing the value of the ?:
982  //  expression if the condition evaluates to true.  In most cases this value
983  //  will be the same as getLHS() except a GCC extension allows the left
984  //  subexpression to be omitted, and instead of the condition be returned.
985  //  e.g: x ?: y is shorthand for x ? x : y, except that the expression "x"
986  //  is only evaluated once.
987  Expr *getTrueExpr() const {
988    return SubExprs[LHS] ? SubExprs[COND] : SubExprs[LHS];
989  }
990
991  // getTrueExpr - Return the subexpression representing the value of the ?:
992  // expression if the condition evaluates to false. This is the same as getRHS.
993  Expr *getFalseExpr() const { return SubExprs[RHS]; }
994
995  Expr *getLHS() const { return SubExprs[LHS]; }
996  Expr *getRHS() const { return SubExprs[RHS]; }
997
998  virtual SourceRange getSourceRange() const {
999    return SourceRange(getCond()->getLocStart(), getRHS()->getLocEnd());
1000  }
1001  static bool classof(const Stmt *T) {
1002    return T->getStmtClass() == ConditionalOperatorClass;
1003  }
1004  static bool classof(const ConditionalOperator *) { return true; }
1005
1006  // Iterators
1007  virtual child_iterator child_begin();
1008  virtual child_iterator child_end();
1009
1010  virtual void EmitImpl(llvm::Serializer& S) const;
1011  static ConditionalOperator* CreateImpl(llvm::Deserializer& D, ASTContext& C);
1012};
1013
1014/// AddrLabelExpr - The GNU address of label extension, representing &&label.
1015class AddrLabelExpr : public Expr {
1016  SourceLocation AmpAmpLoc, LabelLoc;
1017  LabelStmt *Label;
1018public:
1019  AddrLabelExpr(SourceLocation AALoc, SourceLocation LLoc, LabelStmt *L,
1020                QualType t)
1021    : Expr(AddrLabelExprClass, t), AmpAmpLoc(AALoc), LabelLoc(LLoc), Label(L) {}
1022
1023  virtual SourceRange getSourceRange() const {
1024    return SourceRange(AmpAmpLoc, LabelLoc);
1025  }
1026
1027  LabelStmt *getLabel() const { return Label; }
1028
1029  static bool classof(const Stmt *T) {
1030    return T->getStmtClass() == AddrLabelExprClass;
1031  }
1032  static bool classof(const AddrLabelExpr *) { return true; }
1033
1034  // Iterators
1035  virtual child_iterator child_begin();
1036  virtual child_iterator child_end();
1037
1038  virtual void EmitImpl(llvm::Serializer& S) const;
1039  static AddrLabelExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C);
1040};
1041
1042/// StmtExpr - This is the GNU Statement Expression extension: ({int X=4; X;}).
1043/// The StmtExpr contains a single CompoundStmt node, which it evaluates and
1044/// takes the value of the last subexpression.
1045class StmtExpr : public Expr {
1046  CompoundStmt *SubStmt;
1047  SourceLocation LParenLoc, RParenLoc;
1048public:
1049  StmtExpr(CompoundStmt *substmt, QualType T,
1050           SourceLocation lp, SourceLocation rp) :
1051    Expr(StmtExprClass, T), SubStmt(substmt),  LParenLoc(lp), RParenLoc(rp) { }
1052
1053  CompoundStmt *getSubStmt() { return SubStmt; }
1054  const CompoundStmt *getSubStmt() const { return SubStmt; }
1055
1056  virtual SourceRange getSourceRange() const {
1057    return SourceRange(LParenLoc, RParenLoc);
1058  }
1059
1060  static bool classof(const Stmt *T) {
1061    return T->getStmtClass() == StmtExprClass;
1062  }
1063  static bool classof(const StmtExpr *) { return true; }
1064
1065  // Iterators
1066  virtual child_iterator child_begin();
1067  virtual child_iterator child_end();
1068
1069  virtual void EmitImpl(llvm::Serializer& S) const;
1070  static StmtExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C);
1071};
1072
1073/// TypesCompatibleExpr - GNU builtin-in function __builtin_type_compatible_p.
1074/// This AST node represents a function that returns 1 if two *types* (not
1075/// expressions) are compatible. The result of this built-in function can be
1076/// used in integer constant expressions.
1077class TypesCompatibleExpr : public Expr {
1078  QualType Type1;
1079  QualType Type2;
1080  SourceLocation BuiltinLoc, RParenLoc;
1081public:
1082  TypesCompatibleExpr(QualType ReturnType, SourceLocation BLoc,
1083                      QualType t1, QualType t2, SourceLocation RP) :
1084    Expr(TypesCompatibleExprClass, ReturnType), Type1(t1), Type2(t2),
1085    BuiltinLoc(BLoc), RParenLoc(RP) {}
1086
1087  QualType getArgType1() const { return Type1; }
1088  QualType getArgType2() const { return Type2; }
1089
1090  virtual SourceRange getSourceRange() const {
1091    return SourceRange(BuiltinLoc, RParenLoc);
1092  }
1093  static bool classof(const Stmt *T) {
1094    return T->getStmtClass() == TypesCompatibleExprClass;
1095  }
1096  static bool classof(const TypesCompatibleExpr *) { return true; }
1097
1098  // Iterators
1099  virtual child_iterator child_begin();
1100  virtual child_iterator child_end();
1101};
1102
1103/// ChooseExpr - GNU builtin-in function __builtin_choose_expr.
1104/// This AST node is similar to the conditional operator (?:) in C, with
1105/// the following exceptions:
1106/// - the test expression much be a constant expression.
1107/// - the expression returned has it's type unaltered by promotion rules.
1108/// - does not evaluate the expression that was not chosen.
1109class ChooseExpr : public Expr {
1110  enum { COND, LHS, RHS, END_EXPR };
1111  Expr* SubExprs[END_EXPR]; // Left/Middle/Right hand sides.
1112  SourceLocation BuiltinLoc, RParenLoc;
1113public:
1114  ChooseExpr(SourceLocation BLoc, Expr *cond, Expr *lhs, Expr *rhs, QualType t,
1115             SourceLocation RP)
1116    : Expr(ChooseExprClass, t),
1117      BuiltinLoc(BLoc), RParenLoc(RP) {
1118      SubExprs[COND] = cond;
1119      SubExprs[LHS] = lhs;
1120      SubExprs[RHS] = rhs;
1121    }
1122
1123  /// isConditionTrue - Return true if the condition is true.  This is always
1124  /// statically knowable for a well-formed choosexpr.
1125  bool isConditionTrue(ASTContext &C) const;
1126
1127  Expr *getCond() const { return SubExprs[COND]; }
1128  Expr *getLHS() const { return SubExprs[LHS]; }
1129  Expr *getRHS() const { return SubExprs[RHS]; }
1130
1131  virtual SourceRange getSourceRange() const {
1132    return SourceRange(BuiltinLoc, RParenLoc);
1133  }
1134  static bool classof(const Stmt *T) {
1135    return T->getStmtClass() == ChooseExprClass;
1136  }
1137  static bool classof(const ChooseExpr *) { return true; }
1138
1139  // Iterators
1140  virtual child_iterator child_begin();
1141  virtual child_iterator child_end();
1142};
1143
1144/// OverloadExpr - Clang builtin function __builtin_overload.
1145/// This AST node provides a way to overload functions in C.
1146///
1147/// The first argument is required to be a constant expression, for the number
1148/// of arguments passed to each candidate function.
1149///
1150/// The next N arguments, where N is the value of the constant expression,
1151/// are the values to be passed as arguments.
1152///
1153/// The rest of the arguments are values of pointer to function type, which
1154/// are the candidate functions for overloading.
1155///
1156/// The result is a equivalent to a CallExpr taking N arguments to the
1157/// candidate function whose parameter types match the types of the N arguments.
1158///
1159/// example: float Z = __builtin_overload(2, X, Y, modf, mod, modl);
1160/// If X and Y are long doubles, Z will assigned the result of modl(X, Y);
1161/// If X and Y are floats, Z will be assigned the result of modf(X, Y);
1162class OverloadExpr : public Expr {
1163  // SubExprs - the list of values passed to the __builtin_overload function.
1164  // SubExpr[0] is a constant expression
1165  // SubExpr[1-N] are the parameters to pass to the matching function call
1166  // SubExpr[N-...] are the candidate functions, of type pointer to function.
1167  Expr **SubExprs;
1168
1169  // NumExprs - the size of the SubExprs array
1170  unsigned NumExprs;
1171
1172  // The index of the matching candidate function
1173  unsigned FnIndex;
1174
1175  SourceLocation BuiltinLoc;
1176  SourceLocation RParenLoc;
1177public:
1178  OverloadExpr(Expr **args, unsigned nexprs, unsigned idx, QualType t,
1179               SourceLocation bloc, SourceLocation rploc)
1180    : Expr(OverloadExprClass, t), NumExprs(nexprs), FnIndex(idx),
1181      BuiltinLoc(bloc), RParenLoc(rploc) {
1182    SubExprs = new Expr*[nexprs];
1183    for (unsigned i = 0; i != nexprs; ++i)
1184      SubExprs[i] = args[i];
1185  }
1186  ~OverloadExpr() {
1187    delete [] SubExprs;
1188  }
1189
1190  /// arg_begin - Return a pointer to the list of arguments that will be passed
1191  /// to the matching candidate function, skipping over the initial constant
1192  /// expression.
1193  typedef Expr * const *arg_const_iterator;
1194  arg_const_iterator arg_begin() const { return SubExprs+1; }
1195
1196  /// getNumArgs - Return the number of arguments to pass to the candidate
1197  /// functions.
1198  unsigned getNumArgs(ASTContext &Ctx) const {
1199    llvm::APSInt constEval(32);
1200    (void) SubExprs[0]->isIntegerConstantExpr(constEval, Ctx);
1201    return constEval.getZExtValue();
1202  }
1203
1204  /// getNumSubExprs - Return the size of the SubExprs array.  This includes the
1205  /// constant expression, the actual arguments passed in, and the function
1206  /// pointers.
1207  unsigned getNumSubExprs() const { return NumExprs; }
1208
1209  /// getExpr - Return the Expr at the specified index.
1210  Expr *getExpr(unsigned Index) {
1211    assert((Index < NumExprs) && "Arg access out of range!");
1212    return SubExprs[Index];
1213  }
1214
1215  /// getFn - Return the matching candidate function for this OverloadExpr.
1216  Expr *getFn() const { return SubExprs[FnIndex]; }
1217
1218  virtual SourceRange getSourceRange() const {
1219    return SourceRange(BuiltinLoc, RParenLoc);
1220  }
1221  static bool classof(const Stmt *T) {
1222    return T->getStmtClass() == OverloadExprClass;
1223  }
1224  static bool classof(const OverloadExpr *) { return true; }
1225
1226  // Iterators
1227  virtual child_iterator child_begin();
1228  virtual child_iterator child_end();
1229};
1230
1231/// VAArgExpr, used for the builtin function __builtin_va_start.
1232class VAArgExpr : public Expr {
1233  Expr *Val;
1234  SourceLocation BuiltinLoc, RParenLoc;
1235public:
1236  VAArgExpr(SourceLocation BLoc, Expr* e, QualType t, SourceLocation RPLoc)
1237    : Expr(VAArgExprClass, t),
1238      Val(e),
1239      BuiltinLoc(BLoc),
1240      RParenLoc(RPLoc) { }
1241
1242  const Expr *getSubExpr() const { return Val; }
1243  Expr *getSubExpr() { return Val; }
1244  virtual SourceRange getSourceRange() const {
1245    return SourceRange(BuiltinLoc, RParenLoc);
1246  }
1247  static bool classof(const Stmt *T) {
1248    return T->getStmtClass() == VAArgExprClass;
1249  }
1250  static bool classof(const VAArgExpr *) { return true; }
1251
1252  // Iterators
1253  virtual child_iterator child_begin();
1254  virtual child_iterator child_end();
1255};
1256
1257/// InitListExpr - used for struct and array initializers, such as:
1258///    struct foo x = { 1, { 2, 3 } };
1259///
1260/// Because C is somewhat loose with braces, the AST does not necessarily
1261/// directly model the C source.  Instead, the semantic analyzer aims to make
1262/// the InitListExprs match up with the type of the decl being initialized.  We
1263/// have the following exceptions:
1264///
1265///  1. Elements at the end of the list may be dropped from the initializer.
1266///     These elements are defined to be initialized to zero.  For example:
1267///         int x[20] = { 1 };
1268///  2. Initializers may have excess initializers which are to be ignored by the
1269///     compiler.  For example:
1270///         int x[1] = { 1, 2 };
1271///  3. Redundant InitListExprs may be present around scalar elements.  These
1272///     always have a single element whose type is the same as the InitListExpr.
1273///     this can only happen for Type::isScalarType() types.
1274///         int x = { 1 };  int y[2] = { {1}, {2} };
1275///
1276class InitListExpr : public Expr {
1277  Expr **InitExprs;
1278  unsigned NumInits;
1279  SourceLocation LBraceLoc, RBraceLoc;
1280public:
1281  InitListExpr(SourceLocation lbraceloc, Expr **initexprs, unsigned numinits,
1282               SourceLocation rbraceloc);
1283  ~InitListExpr() {
1284    delete [] InitExprs;
1285  }
1286
1287  unsigned getNumInits() const { return NumInits; }
1288
1289  const Expr* getInit(unsigned Init) const {
1290    assert(Init < NumInits && "Initializer access out of range!");
1291    return InitExprs[Init];
1292  }
1293
1294  Expr* getInit(unsigned Init) {
1295    assert(Init < NumInits && "Initializer access out of range!");
1296    return InitExprs[Init];
1297  }
1298
1299  void setInit(unsigned Init, Expr *expr) {
1300    assert(Init < NumInits && "Initializer access out of range!");
1301    InitExprs[Init] = expr;
1302  }
1303
1304  virtual SourceRange getSourceRange() const {
1305    return SourceRange(LBraceLoc, RBraceLoc);
1306  }
1307  static bool classof(const Stmt *T) {
1308    return T->getStmtClass() == InitListExprClass;
1309  }
1310  static bool classof(const InitListExpr *) { return true; }
1311
1312  // Iterators
1313  virtual child_iterator child_begin();
1314  virtual child_iterator child_end();
1315
1316  virtual void EmitImpl(llvm::Serializer& S) const;
1317  static InitListExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C);
1318
1319private:
1320  // Used by serializer.
1321  InitListExpr() : Expr(InitListExprClass, QualType()),
1322                   InitExprs(NULL), NumInits(0) {}
1323};
1324
1325/// ObjCStringLiteral, used for Objective-C string literals
1326/// i.e. @"foo".
1327class ObjCStringLiteral : public Expr {
1328  StringLiteral *String;
1329  SourceLocation AtLoc;
1330public:
1331  ObjCStringLiteral(StringLiteral *SL, QualType T, SourceLocation L)
1332    : Expr(ObjCStringLiteralClass, T), String(SL), AtLoc(L) {}
1333
1334  StringLiteral* getString() { return String; }
1335
1336  const StringLiteral* getString() const { return String; }
1337
1338  SourceLocation getAtLoc() const { return AtLoc; }
1339
1340  virtual SourceRange getSourceRange() const {
1341    return SourceRange(AtLoc, String->getLocEnd());
1342  }
1343
1344  static bool classof(const Stmt *T) {
1345    return T->getStmtClass() == ObjCStringLiteralClass;
1346  }
1347  static bool classof(const ObjCStringLiteral *) { return true; }
1348
1349  // Iterators
1350  virtual child_iterator child_begin();
1351  virtual child_iterator child_end();
1352
1353  virtual void EmitImpl(llvm::Serializer& S) const;
1354  static ObjCStringLiteral* CreateImpl(llvm::Deserializer& D, ASTContext& C);
1355};
1356
1357/// ObjCEncodeExpr, used for @encode in Objective-C.
1358class ObjCEncodeExpr : public Expr {
1359  QualType EncType;
1360  SourceLocation AtLoc, RParenLoc;
1361public:
1362  ObjCEncodeExpr(QualType T, QualType ET,
1363                 SourceLocation at, SourceLocation rp)
1364    : Expr(ObjCEncodeExprClass, T), EncType(ET), AtLoc(at), RParenLoc(rp) {}
1365
1366  SourceLocation getAtLoc() const { return AtLoc; }
1367  SourceLocation getRParenLoc() const { return RParenLoc; }
1368
1369  SourceRange getSourceRange() const { return SourceRange(AtLoc, RParenLoc); }
1370
1371  QualType getEncodedType() const { return EncType; }
1372
1373  static bool classof(const Stmt *T) {
1374    return T->getStmtClass() == ObjCEncodeExprClass;
1375  }
1376  static bool classof(const ObjCEncodeExpr *) { return true; }
1377
1378  // Iterators
1379  virtual child_iterator child_begin();
1380  virtual child_iterator child_end();
1381
1382  virtual void EmitImpl(llvm::Serializer& S) const;
1383  static ObjCEncodeExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C);
1384};
1385
1386/// ObjCSelectorExpr used for @selector in Objective-C.
1387class ObjCSelectorExpr : public Expr {
1388  Selector SelName;
1389  SourceLocation AtLoc, RParenLoc;
1390public:
1391  ObjCSelectorExpr(QualType T, Selector selInfo,
1392                   SourceLocation at, SourceLocation rp)
1393  : Expr(ObjCSelectorExprClass, T), SelName(selInfo),
1394  AtLoc(at), RParenLoc(rp) {}
1395
1396  const Selector &getSelector() const { return SelName; }
1397  Selector &getSelector() { return SelName; }
1398
1399  SourceLocation getAtLoc() const { return AtLoc; }
1400  SourceLocation getRParenLoc() const { return RParenLoc; }
1401  SourceRange getSourceRange() const { return SourceRange(AtLoc, RParenLoc); }
1402
1403  /// getNumArgs - Return the number of actual arguments to this call.
1404  unsigned getNumArgs() const { return SelName.getNumArgs(); }
1405
1406  static bool classof(const Stmt *T) {
1407    return T->getStmtClass() == ObjCSelectorExprClass;
1408  }
1409  static bool classof(const ObjCSelectorExpr *) { return true; }
1410
1411  // Iterators
1412  virtual child_iterator child_begin();
1413  virtual child_iterator child_end();
1414
1415  virtual void EmitImpl(llvm::Serializer& S) const;
1416  static ObjCSelectorExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C);
1417};
1418
1419/// ObjCProtocolExpr used for protocol in Objective-C.
1420class ObjCProtocolExpr : public Expr {
1421  ObjCProtocolDecl *Protocol;
1422  SourceLocation AtLoc, RParenLoc;
1423public:
1424  ObjCProtocolExpr(QualType T, ObjCProtocolDecl *protocol,
1425                   SourceLocation at, SourceLocation rp)
1426  : Expr(ObjCProtocolExprClass, T), Protocol(protocol),
1427  AtLoc(at), RParenLoc(rp) {}
1428
1429  ObjCProtocolDecl *getProtocol() const { return Protocol; }
1430
1431  SourceLocation getAtLoc() const { return AtLoc; }
1432  SourceLocation getRParenLoc() const { return RParenLoc; }
1433  SourceRange getSourceRange() const { return SourceRange(AtLoc, RParenLoc); }
1434
1435  static bool classof(const Stmt *T) {
1436    return T->getStmtClass() == ObjCProtocolExprClass;
1437  }
1438  static bool classof(const ObjCProtocolExpr *) { return true; }
1439
1440  // Iterators
1441  virtual child_iterator child_begin();
1442  virtual child_iterator child_end();
1443};
1444
1445/// ObjCIvarRefExpr - A reference to an ObjC instance variable.
1446class ObjCIvarRefExpr : public Expr {
1447  class ObjCIvarDecl *D;
1448  SourceLocation Loc;
1449  Expr *Base;
1450  bool IsArrow:1;      // True if this is "X->F", false if this is "X.F".
1451  bool IsFreeIvar:1;   // True if ivar reference has no base (self assumed).
1452
1453public:
1454  ObjCIvarRefExpr(ObjCIvarDecl *d, QualType t, SourceLocation l, Expr *base=0,
1455                  bool arrow = false, bool freeIvar = false) :
1456    Expr(ObjCIvarRefExprClass, t), D(d), Loc(l), Base(base), IsArrow(arrow),
1457    IsFreeIvar(freeIvar) {}
1458
1459  ObjCIvarDecl *getDecl() { return D; }
1460  const ObjCIvarDecl *getDecl() const { return D; }
1461  virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
1462  const Expr *getBase() const { return Base; }
1463  Expr *getBase() { return Base; }
1464  void setBase(Expr * base) { Base = base; }
1465  bool isArrow() const { return IsArrow; }
1466  bool isFreeIvar() const { return IsFreeIvar; }
1467
1468  SourceLocation getLocation() const { return Loc; }
1469
1470  static bool classof(const Stmt *T) {
1471    return T->getStmtClass() == ObjCIvarRefExprClass;
1472  }
1473  static bool classof(const ObjCIvarRefExpr *) { return true; }
1474
1475  // Iterators
1476  virtual child_iterator child_begin();
1477  virtual child_iterator child_end();
1478
1479  virtual void EmitImpl(llvm::Serializer& S) const;
1480  static ObjCIvarRefExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C);
1481};
1482
1483class ObjCMessageExpr : public Expr {
1484  enum { RECEIVER=0, ARGS_START=1 };
1485
1486  Expr **SubExprs;
1487
1488  unsigned NumArgs;
1489
1490  // A unigue name for this message.
1491  Selector SelName;
1492
1493  // A method prototype for this message (optional).
1494  // FIXME: Since method decls contain the selector, and most messages have a
1495  // prototype, consider devising a scheme for unifying SelName/MethodProto.
1496  ObjCMethodDecl *MethodProto;
1497
1498  IdentifierInfo *ClassName; // optional - 0 for instance messages.
1499
1500  SourceLocation LBracloc, RBracloc;
1501public:
1502  // constructor for class messages.
1503  // FIXME: clsName should be typed to ObjCInterfaceType
1504  ObjCMessageExpr(IdentifierInfo *clsName, Selector selInfo,
1505                  QualType retType, ObjCMethodDecl *methDecl,
1506                  SourceLocation LBrac, SourceLocation RBrac,
1507                  Expr **ArgExprs, unsigned NumArgs);
1508  // constructor for instance messages.
1509  ObjCMessageExpr(Expr *receiver, Selector selInfo,
1510                  QualType retType, ObjCMethodDecl *methDecl,
1511                  SourceLocation LBrac, SourceLocation RBrac,
1512                  Expr **ArgExprs, unsigned NumArgs);
1513  ~ObjCMessageExpr() {
1514    delete [] SubExprs;
1515  }
1516
1517  const Expr *getReceiver() const { return SubExprs[RECEIVER]; }
1518  Expr *getReceiver() { return SubExprs[RECEIVER]; }
1519
1520  Selector getSelector() const { return SelName; }
1521  Selector &getSelector() { return SelName; }
1522
1523  const ObjCMethodDecl *getMethodDecl() const { return MethodProto; }
1524  ObjCMethodDecl *getMethodDecl() { return MethodProto; }
1525
1526  const IdentifierInfo *getClassName() const { return ClassName; }
1527  IdentifierInfo *getClassName() { return ClassName; }
1528
1529  /// getNumArgs - Return the number of actual arguments to this call.
1530  unsigned getNumArgs() const { return NumArgs; }
1531
1532/// getArg - Return the specified argument.
1533  Expr *getArg(unsigned Arg) {
1534    assert(Arg < NumArgs && "Arg access out of range!");
1535    return SubExprs[Arg+ARGS_START];
1536  }
1537  const Expr *getArg(unsigned Arg) const {
1538    assert(Arg < NumArgs && "Arg access out of range!");
1539    return SubExprs[Arg+ARGS_START];
1540  }
1541  /// setArg - Set the specified argument.
1542  void setArg(unsigned Arg, Expr *ArgExpr) {
1543    assert(Arg < NumArgs && "Arg access out of range!");
1544    SubExprs[Arg+ARGS_START] = ArgExpr;
1545  }
1546  SourceRange getSourceRange() const { return SourceRange(LBracloc, RBracloc); }
1547
1548  static bool classof(const Stmt *T) {
1549    return T->getStmtClass() == ObjCMessageExprClass;
1550  }
1551  static bool classof(const ObjCMessageExpr *) { return true; }
1552
1553  // Iterators
1554  virtual child_iterator child_begin();
1555  virtual child_iterator child_end();
1556
1557  typedef Expr** arg_iterator;
1558  typedef const Expr* const* const_arg_iterator;
1559
1560  arg_iterator arg_begin() { return &SubExprs[ARGS_START]; }
1561  arg_iterator arg_end()   { return arg_begin() + NumArgs; }
1562  const_arg_iterator arg_begin() const { return &SubExprs[ARGS_START]; }
1563  const_arg_iterator arg_end() const { return arg_begin() + NumArgs; }
1564};
1565
1566}  // end namespace clang
1567
1568#endif
1569