Expr.h revision 8a99764f9b778a54e7440b1ee06a1e48f25d76d8
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.
72a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)//
8eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch//===----------------------------------------------------------------------===//
95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//
10010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)//  This file defines the Expr interface and subclasses.
11cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)//
125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)//===----------------------------------------------------------------------===//
137dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifndef LLVM_CLANG_AST_EXPR_H
155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define LLVM_CLANG_AST_EXPR_H
165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "clang/AST/Stmt.h"
182385ea399aae016c0806a4f9ef3c9cfe3d2a39dfBen Murdoch#include "clang/AST/Type.h"
195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "clang/AST/Decl.h"
205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "clang/AST/DeclObjC.h"
215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "clang/Basic/IdentifierTable.h"
225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "llvm/ADT/APSInt.h"
235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "llvm/ADT/APFloat.h"
24868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include <vector>
252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class llvm::Constant;
272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)namespace clang {
292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  class IdentifierInfo;
302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  class Selector;
312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  class Decl;
322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  class ASTContext;
332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)/// Expr - This represents one expression.  Note that Expr's are subclasses of
352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)/// Stmt.  This allows an expression to be transparently used any place a Stmt
365c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu/// is required.
375c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu///
382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class Expr : public Stmt {
392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  QualType TR;
402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)protected:
412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  Expr(StmtClass SC, QualType T) : Stmt(SC), TR(T) {}
422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)public:
432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  QualType getType() const { return TR; }
442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  void setType(QualType t) { TR = t; }
452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  /// SourceLocation tokens are not useful in isolation - they are low level
472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  /// value objects created/interpreted by SourceManager. We assume AST
482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  /// clients will have a pointer to the respective SourceManager.
492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual SourceRange getSourceRange() const = 0;
50a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
51a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  /// getExprLoc - Return the preferred location for the arrow when diagnosing
52a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  /// a problem with a generic expression.
53a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  virtual SourceLocation getExprLoc() const { return getLocStart(); }
54a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
55a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  /// hasLocalSideEffect - Return true if this immediate expression has side
56a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  /// effects, not counting any sub-expressions.
57a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  bool hasLocalSideEffect() const;
58a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
59a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  /// isLvalue - C99 6.3.2.1: an lvalue is an expression with an object type or
60a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  /// incomplete type other than void. Nonarray expressions that can be lvalues:
61a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  ///  - name, where name must be a variable
62a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  ///  - e[i]
63a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  ///  - (e), where e must be an lvalue
642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ///  - e.name, where e must be an lvalue
652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ///  - e->name
662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ///  - *e, the type of e cannot be a function type
67d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  ///  - string-constant
68d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  ///  - reference type [C++ [expr]]
69d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  ///
70d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  enum isLvalueResult {
71d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    LV_Valid,
725d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    LV_NotObjectType,
735d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    LV_IncompleteVoidType,
741e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    LV_DuplicateVectorComponents,
752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    LV_InvalidExpression
762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  };
772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  isLvalueResult isLvalue() const;
785d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
795d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  /// isModifiableLvalue - C99 6.3.2.1: an lvalue that does not have array type,
805d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  /// does not have an incomplete type, does not have a const-qualified type,
815d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  /// and if it is a structure or union, does not have any member (including,
82cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  /// recursively, any member or element of all contained aggregates or unions)
83cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  /// with a const-qualified type.
84a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  enum isModifiableLvalueResult {
85a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    MLV_Valid,
86d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    MLV_NotObjectType,
87d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    MLV_IncompleteVoidType,
88d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    MLV_DuplicateVectorComponents,
89d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    MLV_InvalidExpression,
900529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    MLV_IncompleteType,
910529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    MLV_ConstQualified,
920529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    MLV_ArrayType
930529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch  };
942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  isModifiableLvalueResult isModifiableLvalue() const;
952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  bool isNullPointerConstant(ASTContext &Ctx) const;
972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
98f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  /// isIntegerConstantExpr - Return true if this expression is a valid integer
995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// constant expression, and, if so, return its value in Result.  If not a
1002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  /// valid i-c-e, return false and fill in Loc (if specified) with the location
10190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  /// of the invalid expression.
102ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  bool isIntegerConstantExpr(llvm::APSInt &Result, ASTContext &Ctx,
1035d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                             SourceLocation *Loc = 0,
1042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                             bool isEvaluated = true) const;
105868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  bool isIntegerConstantExpr(ASTContext &Ctx, SourceLocation *Loc = 0) const {
1062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    llvm::APSInt X(32);
107d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    return isIntegerConstantExpr(X, Ctx, Loc);
108f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  }
1096d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  /// isConstantExpr - Return true if this expression is a valid constant expr.
1106d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  bool isConstantExpr(ASTContext &Ctx, SourceLocation *Loc) const;
1116d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)
1126d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  /// hasGlobalStorage - Return true if this expression has static storage
1136d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  /// duration.  This means that the address of this expression is a link-time
1146d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  /// constant.
1156d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  bool hasGlobalStorage() const;
1166d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)
1176d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  /// IgnoreParens - Ignore parentheses.  If this Expr is a ParenExpr, return
1186d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  ///  its subexpression.  If that subexpression is also a ParenExpr,
1196d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  ///  then this method recursively returns its subexpression, and so forth.
1205f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  ///  Otherwise, the method returns the current Expr.
121868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  Expr* IgnoreParens();
1225f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)
123868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  /// IgnoreParenCasts - Ignore parentheses and casts.  Strip off any ParenExpr
1240f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  /// or CastExprs or ImplicitCastExprs, returning their operand.
125ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  Expr *IgnoreParenCasts();
126ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch
127ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  const Expr* IgnoreParens() const {
128ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch    return const_cast<Expr*>(this)->IgnoreParens();
129a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  }
130a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  const Expr *IgnoreParenCasts() const {
131a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    return const_cast<Expr*>(this)->IgnoreParenCasts();
132a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  }
133a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
134a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  static bool classof(const Stmt *T) {
1355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    return T->getStmtClass() >= firstExprConstant &&
1365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)           T->getStmtClass() <= lastExprConstant;
1375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
1385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static bool classof(const Expr *) { return true; }
1392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  static inline Expr* Create(llvm::Deserializer& D, ASTContext& C) {
141f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)    return cast<Expr>(Stmt::Create(D, C));
142f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  }
143f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)};
144f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)
145f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)//===----------------------------------------------------------------------===//
1465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Primary Expressions.
1475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//===----------------------------------------------------------------------===//
1485c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu
1495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// DeclRefExpr - [C99 6.5.1p2] - A reference to a declared variable, function,
1505c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu/// enum, etc.
151f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)class DeclRefExpr : public Expr {
152f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  ValueDecl *D;
153424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  SourceLocation Loc;
154424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)public:
155f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  DeclRefExpr(ValueDecl *d, QualType t, SourceLocation l) :
156f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)    Expr(DeclRefExprClass, t), D(d), Loc(l) {}
157f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)
158f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  ValueDecl *getDecl() { return D; }
159f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  const ValueDecl *getDecl() const { return D; }
160f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
161f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)
162f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)
163f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  static bool classof(const Stmt *T) {
164f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)    return T->getStmtClass() == DeclRefExprClass;
165424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  }
166424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  static bool classof(const DeclRefExpr *) { return true; }
167424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)
1685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Iterators
1695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual child_iterator child_begin();
1705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual child_iterator child_end();
1715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
1725d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual void EmitImpl(llvm::Serializer& S) const;
1735d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  static DeclRefExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C);
1745d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)};
1755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
1765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)/// PreDefinedExpr - [C99 6.4.2.2] - A pre-defined identifier such as __func__.
1775d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)class PreDefinedExpr : public Expr {
1785d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)public:
1795d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  enum IdentType {
1805d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    Func,
1815d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    Function,
1825d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    PrettyFunction
1835d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  };
1845d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
1855d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)private:
1865d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  SourceLocation Loc;
1875d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  IdentType Type;
1885d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)public:
1895d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  PreDefinedExpr(SourceLocation l, QualType type, IdentType IT)
1905d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    : Expr(PreDefinedExprClass, type), Loc(l), Type(IT) {}
1915d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
1925d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  IdentType getIdentType() const { return Type; }
1935d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
1945d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
1955d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
1965d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  static bool classof(const Stmt *T) {
1975d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    return T->getStmtClass() == PreDefinedExprClass;
1985d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  }
1995d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  static bool classof(const PreDefinedExpr *) { return true; }
2005d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
2015d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Iterators
2025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual child_iterator child_begin();
2035d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual child_iterator child_end();
2045d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
2055d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual void EmitImpl(llvm::Serializer& S) const;
2065d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  static PreDefinedExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C);
2075d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)};
2085d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
209a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)class IntegerLiteral : public Expr {
2105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  llvm::APInt Value;
2115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  SourceLocation Loc;
2125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)public:
2135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // type should be IntTy, LongTy, LongLongTy, UnsignedIntTy, UnsignedLongTy,
2145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // or UnsignedLongLongTy
215f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  IntegerLiteral(const llvm::APInt &V, QualType type, SourceLocation l)
2165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    : Expr(IntegerLiteralClass, type), Value(V), Loc(l) {
2175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    assert(type->isIntegerType() && "Illegal type in IntegerLiteral");
218f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  }
219f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  const llvm::APInt &getValue() const { return Value; }
220f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
221f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)
2225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static bool classof(const Stmt *T) {
2235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return T->getStmtClass() == IntegerLiteralClass;
224a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  }
2255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  static bool classof(const IntegerLiteral *) { return true; }
2262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
2272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Iterators
2282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual child_iterator child_begin();
2292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual child_iterator child_end();
2302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
2315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void EmitImpl(llvm::Serializer& S) const;
2325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static IntegerLiteral* CreateImpl(llvm::Deserializer& D, ASTContext& C);
2331e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)};
234424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)
235868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)class CharacterLiteral : public Expr {
236868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  unsigned Value;
237868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  SourceLocation Loc;
238868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)public:
239a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // type should be IntTy
2405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  CharacterLiteral(unsigned value, QualType type, SourceLocation l)
2415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    : Expr(CharacterLiteralClass, type), Value(value), Loc(l) {
2421e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  }
2431e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  SourceLocation getLoc() const { return Loc; }
2445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2451e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
2461e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
2475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  unsigned getValue() const { return Value; }
2485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static bool classof(const Stmt *T) {
2505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return T->getStmtClass() == CharacterLiteralClass;
2515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
252a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  static bool classof(const CharacterLiteral *) { return true; }
253a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
254010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  // Iterators
255a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  virtual child_iterator child_begin();
256a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  virtual child_iterator child_end();
257a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
258a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  virtual void EmitImpl(llvm::Serializer& S) const;
259116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  static CharacterLiteral* CreateImpl(llvm::Deserializer& D, ASTContext& C);
260a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)};
261a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
262a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)class FloatingLiteral : public Expr {
263a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  llvm::APFloat Value;
264a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  bool IsExact : 1;
265f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  SourceLocation Loc;
266cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)public:
267010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  FloatingLiteral(const llvm::APFloat &V, bool* isexact,
268010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)                  QualType Type, SourceLocation L)
269a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    : Expr(FloatingLiteralClass, Type), Value(V), IsExact(*isexact), Loc(L) {}
270a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
271a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  const llvm::APFloat &getValue() const { return Value; }
272116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
273116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  bool isExact() const { return IsExact; }
274116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
275116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  /// getValueAsDouble - This returns the value as an inaccurate double.  Note
276116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  /// that this may cause loss of precision, but is useful for debugging dumps
277116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  /// etc.
278116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  double getValueAsDouble() const {
279116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    // FIXME: We need something for long double here.
280a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    if (cast<BuiltinType>(getType())->getKind() == BuiltinType::Float)
281a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      return Value.convertToFloat();
282a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    else
283a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      return Value.convertToDouble();
284010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  }
285010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
286010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
287010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
288010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  static bool classof(const Stmt *T) {
289010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)    return T->getStmtClass() == FloatingLiteralClass;
290a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  }
291a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  static bool classof(const FloatingLiteral *) { return true; }
292a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
293a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // Iterators
294a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  virtual child_iterator child_begin();
295a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  virtual child_iterator child_end();
296a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
297a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  virtual void EmitImpl(llvm::Serializer& S) const;
298a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  static FloatingLiteral* CreateImpl(llvm::Deserializer& D, ASTContext& C);
299a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)};
300a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
301a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)/// ImaginaryLiteral - We support imaginary integer and floating point literals,
302a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)/// like "1.0i".  We represent these as a wrapper around FloatingLiteral and
303a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)/// IntegerLiteral classes.  Instances of this class always have a Complex type
304cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)/// whose element type matches the subexpression.
305cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)///
306cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)class ImaginaryLiteral : public Expr {
307a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  Expr *Val;
308cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)public:
309cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  ImaginaryLiteral(Expr *val, QualType Ty)
310cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)    : Expr(ImaginaryLiteralClass, Ty), Val(val) {}
311cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
312cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  const Expr *getSubExpr() const { return Val; }
313cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  Expr *getSubExpr() { return Val; }
314cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
315cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  virtual SourceRange getSourceRange() const { return Val->getSourceRange(); }
316cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  static bool classof(const Stmt *T) {
317cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)    return T->getStmtClass() == ImaginaryLiteralClass;
318cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  }
319cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  static bool classof(const ImaginaryLiteral *) { return true; }
3200529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch
3210529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch  // Iterators
3220529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch  virtual child_iterator child_begin();
3232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual child_iterator child_end();
3240529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch
3250529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch  virtual void EmitImpl(llvm::Serializer& S) const;
326a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  static ImaginaryLiteral* CreateImpl(llvm::Deserializer& D, ASTContext& C);
327cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)};
328cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
329010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)/// StringLiteral - This represents a string literal expression, e.g. "foo"
330d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)/// or L"bar" (wide strings).  The actual string is returned by getStrData()
331d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)/// is NOT null-terminated, and the length of the string is determined by
332a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)/// calling getByteLength().  The C type for a string is always a
333a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)/// ConstantArrayType.
334a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)class StringLiteral : public Expr {
335a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  const char *StrData;
3363551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  unsigned ByteLength;
3375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  bool IsWide;
338d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  // if the StringLiteral was composed using token pasting, both locations
339d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  // are needed. If not (the common case), firstTokLoc == lastTokLoc.
340d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  // FIXME: if space becomes an issue, we should create a sub-class.
341d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  SourceLocation firstTokLoc, lastTokLoc;
3420529e5d033099cbfc42635f6f6183833b09dff6eBen Murdochpublic:
3432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  StringLiteral(const char *strData, unsigned byteLength, bool Wide,
3442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                QualType t, SourceLocation b, SourceLocation e);
3452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual ~StringLiteral();
3462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
3472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  const char *getStrData() const { return StrData; }
348a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  unsigned getByteLength() const { return ByteLength; }
3492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  bool isWide() const { return IsWide; }
350cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
351cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  virtual SourceRange getSourceRange() const {
352cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)    return SourceRange(firstTokLoc,lastTokLoc);
353cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  }
354cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  static bool classof(const Stmt *T) {
355cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)    return T->getStmtClass() == StringLiteralClass;
356cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  }
357cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  static bool classof(const StringLiteral *) { return true; }
3582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
3592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Iterators
360d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  virtual child_iterator child_begin();
361d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  virtual child_iterator child_end();
362d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
363d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  virtual void EmitImpl(llvm::Serializer& S) const;
3640529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch  static StringLiteral* CreateImpl(llvm::Deserializer& D, ASTContext& C);
3650529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch};
3660529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch
3670529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch/// ParenExpr - This represents a parethesized expression, e.g. "(1)".  This
368f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)/// AST node is only formed if full location information is requested.
369f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)class ParenExpr : public Expr {
370a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  SourceLocation L, R;
371f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  Expr *Val;
372f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)public:
373f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  ParenExpr(SourceLocation l, SourceLocation r, Expr *val)
374f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    : Expr(ParenExprClass, val->getType()), L(l), R(r), Val(val) {}
375f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)
376f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  const Expr *getSubExpr() const { return Val; }
3775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Expr *getSubExpr() { return Val; }
3785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual SourceRange getSourceRange() const { return SourceRange(L, R); }
37923730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)
38023730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)  static bool classof(const Stmt *T) {
38123730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)    return T->getStmtClass() == ParenExprClass;
38223730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)  }
38323730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)  static bool classof(const ParenExpr *) { return true; }
38423730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)
3855d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Iterators
3865d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual child_iterator child_begin();
3875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual child_iterator child_end();
3885d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
3895d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual void EmitImpl(llvm::Serializer& S) const;
390c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  static ParenExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C);
3910529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch};
392c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch
393c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch
394424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)/// UnaryOperator - This represents the unary-expression's (except sizeof of
3955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// types), the postinc/postdec operators from postfix-expression, and various
3965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// extensions.
3972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)///
398a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)/// Notes on various nodes:
399a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)///
400a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)/// Real/Imag - These return the real/imag part of a complex operand.  If
4012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)///   applied to a non-complex value, the former returns its operand and the
4022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)///   later returns zero in the type of the operand.
4032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)///
4042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)/// __builtin_offsetof(type, a.b[10]) is represented as a unary operator whose
4055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)///   subexpression is a compound literal with the various MemberExpr and
406424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)///   ArraySubscriptExpr's applied to it.
407424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)///
408424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)class UnaryOperator : public Expr {
409424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)public:
410424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  // Note that additions to this should also update the StmtVisitor class.
411f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  enum Opcode {
4125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    PostInc, PostDec, // [C99 6.5.2.4] Postfix increment and decrement operators
4135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    PreInc, PreDec,   // [C99 6.5.3.1] Prefix increment and decrement operators.
4145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    AddrOf, Deref,    // [C99 6.5.3.2] Address and indirection operators.
415f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    Plus, Minus,      // [C99 6.5.3.3] Unary arithmetic operators.
4165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    Not, LNot,        // [C99 6.5.3.3] Unary arithmetic operators.
4175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    SizeOf, AlignOf,  // [C99 6.5.3.4] Sizeof (expr, not type) operator.
4185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    Real, Imag,       // "__real expr"/"__imag expr" Extension.
4195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    Extension,        // __extension__ marker.
4205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    OffsetOf          // __builtin_offsetof
4215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  };
4225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)private:
4235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  Expr *Val;
4245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  Opcode Opc;
4252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  SourceLocation Loc;
426f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)public:
427f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)
428f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  UnaryOperator(Expr *input, Opcode opc, QualType type, SourceLocation l)
429f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)    : Expr(UnaryOperatorClass, type), Val(input), Opc(opc), Loc(l) {}
430f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)
431f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  Opcode getOpcode() const { return Opc; }
432f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  Expr *getSubExpr() const { return Val; }
433f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)
434f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  /// getOperatorLoc - Return the location of the operator.
435f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  SourceLocation getOperatorLoc() const { return Loc; }
436f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)
4375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// isPostfix - Return true if this is a postfix operation, like x++.
438c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  static bool isPostfix(Opcode Op);
4395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool isPostfix() const { return isPostfix(Opc); }
441f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  bool isIncrementOp() const {return Opc==PreInc || Opc==PostInc; }
442f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  bool isIncrementDecrementOp() const { return Opc>=PostInc && Opc<=PreDec; }
443f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  bool isSizeOfAlignOfOp() const { return Opc == SizeOf || Opc == AlignOf; }
444f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  bool isOffsetOfOp() const { return Opc == OffsetOf; }
445f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  static bool isArithmeticOp(Opcode Op) { return Op >= Plus && Op <= LNot; }
446f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)
447f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  /// getOpcodeStr - Turn an Opcode enum value into the punctuation char it
448f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  /// corresponds to, e.g. "sizeof" or "[pre]++"
449f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  static const char *getOpcodeStr(Opcode Op);
450f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)
451f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  virtual SourceRange getSourceRange() const {
452f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)    if (isPostfix())
453f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)      return SourceRange(Val->getLocStart(), Loc);
454f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)    else
455f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)      return SourceRange(Loc, Val->getLocEnd());
456f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  }
457f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  virtual SourceLocation getExprLoc() const { return Loc; }
458f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)
459f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  static bool classof(const Stmt *T) {
460f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)    return T->getStmtClass() == UnaryOperatorClass;
461f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  }
462f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  static bool classof(const UnaryOperator *) { return true; }
463f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)
464f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  int64_t evaluateOffsetOf(ASTContext& C) const;
465f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)
466f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  // Iterators
467f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  virtual child_iterator child_begin();
468f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  virtual child_iterator child_end();
469f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)
470c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  virtual void EmitImpl(llvm::Serializer& S) const;
471c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  static UnaryOperator* CreateImpl(llvm::Deserializer& D, ASTContext& C);
4725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
4735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
474c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)/// SizeOfAlignOfTypeExpr - [C99 6.5.3.4] - This is only for sizeof/alignof of
475c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)/// *types*.  sizeof(expr) is handled by UnaryOperator.
476c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)class SizeOfAlignOfTypeExpr : public Expr {
477c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  bool isSizeof;  // true if sizeof, false if alignof.
4780f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  QualType Ty;
4790f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  SourceLocation OpLoc, RParenLoc;
4806d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)public:
481116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  SizeOfAlignOfTypeExpr(bool issizeof, QualType argType, QualType resultType,
4826d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)                        SourceLocation op, SourceLocation rp) :
4836d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)    Expr(SizeOfAlignOfTypeExprClass, resultType),
4846d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)    isSizeof(issizeof), Ty(argType), OpLoc(op), RParenLoc(rp) {}
4856d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)
4866d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  bool isSizeOf() const { return isSizeof; }
4876d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  QualType getArgumentType() const { return Ty; }
4886d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)
4896d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  SourceLocation getOperatorLoc() const { return OpLoc; }
4906d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)
4916d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  virtual SourceRange getSourceRange() const {
4926d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)    return SourceRange(OpLoc, RParenLoc);
4936d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  }
4946d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)
4956d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  static bool classof(const Stmt *T) {
4966d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)    return T->getStmtClass() == SizeOfAlignOfTypeExprClass;
4976d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  }
4986d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  static bool classof(const SizeOfAlignOfTypeExpr *) { return true; }
4996d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)
5006d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  // Iterators
5016d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  virtual child_iterator child_begin();
5026d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  virtual child_iterator child_end();
5036d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)
5046d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  virtual void EmitImpl(llvm::Serializer& S) const;
5056d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  static SizeOfAlignOfTypeExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C);
5066d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)};
5076d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)
5086d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)//===----------------------------------------------------------------------===//
5096d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)// Postfix Operators.
510f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)//===----------------------------------------------------------------------===//
511f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)
512f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)/// ArraySubscriptExpr - [C99 6.5.2.1] Array Subscripting.
513f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)class ArraySubscriptExpr : public Expr {
514f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  enum { LHS, RHS, END_EXPR=2 };
515f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  Expr* SubExprs[END_EXPR];
516f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  SourceLocation RBracketLoc;
517f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)public:
518f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  ArraySubscriptExpr(Expr *lhs, Expr *rhs, QualType t,
51946d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)                     SourceLocation rbracketloc)
520e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch  : Expr(ArraySubscriptExprClass, t), RBracketLoc(rbracketloc) {
521f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)    SubExprs[LHS] = lhs;
522f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)    SubExprs[RHS] = rhs;
523010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  }
524116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
525116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  /// An array access can be written A[4] or 4[A] (both are equivalent).
526116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  /// - getBase() and getIdx() always present the normalized view: A[4].
527116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  ///    In this case getBase() returns "A" and getIdx() returns "4".
528116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  /// - getLHS() and getRHS() present the syntactic view. e.g. for
529f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  ///    4[A] getLHS() returns "4".
530f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  /// Note: Because vector element access is also written A[4] we must
531f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  /// predicate the format conversion in getBase and getIdx only on the
532e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch  /// the type of the RHS, as it is possible for the LHS to be a vector of
5330f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  /// integer type
5340f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  Expr *getLHS() { return SubExprs[LHS]; }
535f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  const Expr *getLHS() const { return SubExprs[LHS]; }
536f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)
537f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  Expr *getRHS() { return SubExprs[RHS]; }
538f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  const Expr *getRHS() const { return SubExprs[RHS]; }
539f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)
540f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  Expr *getBase() {
541f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)    return (getRHS()->getType()->isIntegerType()) ? getLHS() : getRHS();
542f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  }
543f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)
544f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  const Expr *getBase() const {
545f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)    return (getRHS()->getType()->isIntegerType()) ? getLHS() : getRHS();
546f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  }
547f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)
548f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  Expr *getIdx() {
549c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    return (getRHS()->getType()->isIntegerType()) ? getRHS() : getLHS();
55090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  }
55190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
55290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  const Expr *getIdx() const {
55390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    return (getRHS()->getType()->isIntegerType()) ? getRHS() : getLHS();
55490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  }
55590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
55690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  virtual SourceRange getSourceRange() const {
55790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    return SourceRange(getLHS()->getLocStart(), RBracketLoc);
55890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  }
559a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
56090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  virtual SourceLocation getExprLoc() const { return RBracketLoc; }
56190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
56290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  static bool classof(const Stmt *T) {
563868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    return T->getStmtClass() == ArraySubscriptExprClass;
56490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  }
5655c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  static bool classof(const ArraySubscriptExpr *) { return true; }
5665c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu
567cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // Iterators
568868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  virtual child_iterator child_begin();
56990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  virtual child_iterator child_end();
57090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
57190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  virtual void EmitImpl(llvm::Serializer& S) const;
57290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  static ArraySubscriptExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C);
573868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)};
574b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)
5752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
5762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)/// CallExpr - [C99 6.5.2.2] Function Calls.
5773551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)///
5783551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)class CallExpr : public Expr {
5793551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  enum { FN=0, ARGS_START=1 };
5803551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  Expr **SubExprs;
5813551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  unsigned NumArgs;
5823551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  SourceLocation RParenLoc;
5833551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
5843551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  // This version of the ctor is for deserialization.
58590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  CallExpr(Expr** subexprs, unsigned numargs, QualType t,
58690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)           SourceLocation rparenloc)
58790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  : Expr(CallExprClass,t), SubExprs(subexprs),
58890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    NumArgs(numargs), RParenLoc(rparenloc) {}
5895d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
590f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)public:
591a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  CallExpr(Expr *fn, Expr **args, unsigned numargs, QualType t,
592d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)           SourceLocation rparenloc);
5935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ~CallExpr() {
5945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    delete [] SubExprs;
5955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
5965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  const Expr *getCallee() const { return SubExprs[FN]; }
5985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Expr *getCallee() { return SubExprs[FN]; }
5995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void setCallee(Expr *F) { SubExprs[FN] = F; }
6005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// getNumArgs - Return the number of actual arguments to this call.
6025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ///
6035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  unsigned getNumArgs() const { return NumArgs; }
6045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// getArg - Return the specified argument.
606a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  Expr *getArg(unsigned Arg) {
6075d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    assert(Arg < NumArgs && "Arg access out of range!");
6085d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    return SubExprs[Arg+ARGS_START];
6095d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  }
6105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  const Expr *getArg(unsigned Arg) const {
6115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    assert(Arg < NumArgs && "Arg access out of range!");
6125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    return SubExprs[Arg+ARGS_START];
6135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  }
6145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  /// setArg - Set the specified argument.
6155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  void setArg(unsigned Arg, Expr *ArgExpr) {
6165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    assert(Arg < NumArgs && "Arg access out of range!");
617a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    SubExprs[Arg+ARGS_START] = ArgExpr;
6185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  }
6195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
6205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  /// setNumArgs - This changes the number of arguments present in this call.
6215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// Any orphaned expressions are deleted by this, and any new operands are set
6225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  /// to null.
6235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void setNumArgs(unsigned NumArgs);
6245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  typedef Expr **arg_iterator;
6265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  typedef Expr * const *arg_const_iterator;
6272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  arg_iterator arg_begin() { return SubExprs+ARGS_START; }
6282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  arg_iterator arg_end() { return SubExprs+ARGS_START+getNumArgs(); }
6292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  arg_const_iterator arg_begin() const { return SubExprs+ARGS_START; }
6302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  arg_const_iterator arg_end() const { return SubExprs+ARGS_START+getNumArgs(); }
6315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// getNumCommas - Return the number of commas that must have been present in
6345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  /// this function call.
6355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  unsigned getNumCommas() const { return NumArgs ? NumArgs - 1 : 0; }
6365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
6375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool isBuiltinClassifyType(llvm::APSInt &Result) const;
6385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /// isBuiltinConstantExpr - Return true if this built-in call is constant.
6405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  bool isBuiltinConstantExpr() const;
6415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  SourceLocation getRParenLoc() const { return RParenLoc; }
6435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
6445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual SourceRange getSourceRange() const {
6455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return SourceRange(getCallee()->getLocStart(), RParenLoc);
6465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
6475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static bool classof(const Stmt *T) {
6495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return T->getStmtClass() == CallExprClass;
6505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
651e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch  static bool classof(const CallExpr *) { return true; }
652e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch
653e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch  // Iterators
654e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch  virtual child_iterator child_begin();
655e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch  virtual child_iterator child_end();
656e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch
657e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch  virtual void EmitImpl(llvm::Serializer& S) const;
658e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch  static CallExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C);
659e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch};
6605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// MemberExpr - [C99 6.5.2.3] Structure and Union Members.
66258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)///
663a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)class MemberExpr : public Expr {
6645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  Expr *Base;
6655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  FieldDecl *MemberDecl;
6665d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  SourceLocation MemberLoc;
6675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  bool IsArrow;      // True if this is "X->F", false if this is "X.F".
66858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)public:
66958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  MemberExpr(Expr *base, bool isarrow, FieldDecl *memberdecl, SourceLocation l,
67058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)             QualType ty)
67158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    : Expr(MemberExprClass, ty),
67258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)      Base(base), MemberDecl(memberdecl), MemberLoc(l), IsArrow(isarrow) {}
6735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Expr *getBase() const { return Base; }
6755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  FieldDecl *getMemberDecl() const { return MemberDecl; }
6765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  bool isArrow() const { return IsArrow; }
6775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual SourceRange getSourceRange() const {
6795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return SourceRange(getBase()->getLocStart(), MemberLoc);
6805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
6815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual SourceLocation getExprLoc() const { return MemberLoc; }
6835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static bool classof(const Stmt *T) {
6855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return T->getStmtClass() == MemberExprClass;
6865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
6875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static bool classof(const MemberExpr *) { return true; }
6885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
689a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // Iterators
690a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  virtual child_iterator child_begin();
691424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  virtual child_iterator child_end();
692424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)
6935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void EmitImpl(llvm::Serializer& S) const;
6945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static MemberExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C);
6955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
6965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// ExtVectorElementExpr - This represents access to specific elements of a
6985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// vector, and may occur on the left hand side or right hand side.  For example
6995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// the following is legal:  "V.xy = V.zw" if V is a 4 element extended vector.
7005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)///
7015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class ExtVectorElementExpr : public Expr {
7025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Expr *Base;
7032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  IdentifierInfo &Accessor;
7042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  SourceLocation AccessorLoc;
7052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)public:
7065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ExtVectorElementExpr(QualType ty, Expr *base, IdentifierInfo &accessor,
7072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                       SourceLocation loc)
708a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    : Expr(ExtVectorElementExprClass, ty),
7095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      Base(base), Accessor(accessor), AccessorLoc(loc) {}
7105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
711d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  const Expr *getBase() const { return Base; }
7125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  Expr *getBase() { return Base; }
7135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
7145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  IdentifierInfo &getAccessor() const { return Accessor; }
7155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
7160529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch  /// getNumElements - Get the number of components being selected.
7175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  unsigned getNumElements() const;
7185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
7195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  /// containsDuplicateElements - Return true if any element access is
7205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  /// repeated.
7215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  bool containsDuplicateElements() const;
7225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
7235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  /// getEncodedElementAccess - Encode the elements accessed into an llvm
724d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  /// aggregate Constant of ConstantInt(s).
725d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  llvm::Constant *getEncodedElementAccess() const;
726d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
727d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  /// getAccessedFieldNo - Given an encoded value and a result number, return
728d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  /// the input field number being accessed.
729d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  static unsigned getAccessedFieldNo(unsigned Idx,
730d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)                                     const llvm::Constant *Elts);
731d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
732a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  virtual SourceRange getSourceRange() const {
7332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    return SourceRange(getBase()->getLocStart(), AccessorLoc);
7342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
7355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
736cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  static bool classof(const Stmt *T) {
737cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)    return T->getStmtClass() == ExtVectorElementExprClass;
738cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  }
739f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  static bool classof(const ExtVectorElementExpr *) { return true; }
740f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
74123730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)  // Iterators
7427dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  virtual child_iterator child_begin();
7437dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  virtual child_iterator child_end();
7447dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch};
7457dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
7462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)/// CompoundLiteralExpr - [C99 6.5.2.5]
7472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)///
7482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class CompoundLiteralExpr : public Expr {
7492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  /// LParenLoc - If non-null, this is the location of the left paren in a
7502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  /// compound literal like "(int){4}".  This can be null if this is a
751cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  /// synthesized compound expression.
752cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  SourceLocation LParenLoc;
753cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  Expr *Init;
754cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  bool FileScope;
75546d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)public:
756116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  CompoundLiteralExpr(SourceLocation lparenloc, QualType ty, Expr *init, bool fileScope) :
757116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    Expr(CompoundLiteralExprClass, ty), LParenLoc(lparenloc), Init(init), FileScope(fileScope) {}
758116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
759116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  const Expr *getInitializer() const { return Init; }
760116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  Expr *getInitializer() { return Init; }
761116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
76246d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  bool isFileScope() const { return FileScope; }
76346d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)
764116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  SourceLocation getLParenLoc() const { return LParenLoc; }
76546d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)
76646d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  virtual SourceRange getSourceRange() const {
76746d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)    // FIXME: Init should never be null.
768cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)    if (!Init)
769cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)      return SourceRange();
7705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    if (LParenLoc.isInvalid())
771      return Init->getSourceRange();
772    return SourceRange(LParenLoc, Init->getLocEnd());
773  }
774
775  static bool classof(const Stmt *T) {
776    return T->getStmtClass() == CompoundLiteralExprClass;
777  }
778  static bool classof(const CompoundLiteralExpr *) { return true; }
779
780  // Iterators
781  virtual child_iterator child_begin();
782  virtual child_iterator child_end();
783
784  virtual void EmitImpl(llvm::Serializer& S) const;
785  static CompoundLiteralExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C);
786};
787
788/// ImplicitCastExpr - Allows us to explicitly represent implicit type
789/// conversions. For example: converting T[]->T*, void f()->void (*f)(),
790/// float->double, short->int, etc.
791///
792class ImplicitCastExpr : public Expr {
793  Expr *Op;
794public:
795  ImplicitCastExpr(QualType ty, Expr *op) :
796    Expr(ImplicitCastExprClass, ty), Op(op) {}
797
798  Expr *getSubExpr() { return Op; }
799  const Expr *getSubExpr() const { return Op; }
800
801  virtual SourceRange getSourceRange() const { return Op->getSourceRange(); }
802
803  static bool classof(const Stmt *T) {
804    return T->getStmtClass() == ImplicitCastExprClass;
805  }
806  static bool classof(const ImplicitCastExpr *) { return true; }
807
808  // Iterators
809  virtual child_iterator child_begin();
810  virtual child_iterator child_end();
811
812  virtual void EmitImpl(llvm::Serializer& S) const;
813  static ImplicitCastExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C);
814};
815
816/// CastExpr - [C99 6.5.4] Cast Operators.
817///
818class CastExpr : public Expr {
819  Expr *Op;
820  SourceLocation Loc; // the location of the left paren
821public:
822  CastExpr(QualType ty, Expr *op, SourceLocation l) :
823    Expr(CastExprClass, ty), Op(op), Loc(l) {}
824
825  SourceLocation getLParenLoc() const { return Loc; }
826
827  Expr *getSubExpr() const { return Op; }
828
829  virtual SourceRange getSourceRange() const {
830    return SourceRange(Loc, getSubExpr()->getSourceRange().getEnd());
831  }
832  static bool classof(const Stmt *T) {
833    return T->getStmtClass() == CastExprClass;
834  }
835  static bool classof(const CastExpr *) { return true; }
836
837  // Iterators
838  virtual child_iterator child_begin();
839  virtual child_iterator child_end();
840
841  virtual void EmitImpl(llvm::Serializer& S) const;
842  static CastExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C);
843};
844
845class BinaryOperator : public Expr {
846public:
847  enum Opcode {
848    // Operators listed in order of precedence.
849    // Note that additions to this should also update the StmtVisitor class.
850    Mul, Div, Rem,    // [C99 6.5.5] Multiplicative operators.
851    Add, Sub,         // [C99 6.5.6] Additive operators.
852    Shl, Shr,         // [C99 6.5.7] Bitwise shift operators.
853    LT, GT, LE, GE,   // [C99 6.5.8] Relational operators.
854    EQ, NE,           // [C99 6.5.9] Equality operators.
855    And,              // [C99 6.5.10] Bitwise AND operator.
856    Xor,              // [C99 6.5.11] Bitwise XOR operator.
857    Or,               // [C99 6.5.12] Bitwise OR operator.
858    LAnd,             // [C99 6.5.13] Logical AND operator.
859    LOr,              // [C99 6.5.14] Logical OR operator.
860    Assign, MulAssign,// [C99 6.5.16] Assignment operators.
861    DivAssign, RemAssign,
862    AddAssign, SubAssign,
863    ShlAssign, ShrAssign,
864    AndAssign, XorAssign,
865    OrAssign,
866    Comma             // [C99 6.5.17] Comma operator.
867  };
868private:
869  enum { LHS, RHS, END_EXPR };
870  Expr* SubExprs[END_EXPR];
871  Opcode Opc;
872  SourceLocation OpLoc;
873public:
874
875  BinaryOperator(Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy,
876                 SourceLocation opLoc)
877    : Expr(BinaryOperatorClass, ResTy), Opc(opc), OpLoc(opLoc) {
878    SubExprs[LHS] = lhs;
879    SubExprs[RHS] = rhs;
880    assert(!isCompoundAssignmentOp() &&
881           "Use ArithAssignBinaryOperator for compound assignments");
882  }
883
884  SourceLocation getOperatorLoc() const { return OpLoc; }
885  Opcode getOpcode() const { return Opc; }
886  Expr *getLHS() const { return SubExprs[LHS]; }
887  Expr *getRHS() const { return SubExprs[RHS]; }
888  virtual SourceRange getSourceRange() const {
889    return SourceRange(getLHS()->getLocStart(), getRHS()->getLocEnd());
890  }
891
892  /// getOpcodeStr - Turn an Opcode enum value into the punctuation char it
893  /// corresponds to, e.g. "<<=".
894  static const char *getOpcodeStr(Opcode Op);
895
896  /// predicates to categorize the respective opcodes.
897  bool isMultiplicativeOp() const { return Opc >= Mul && Opc <= Rem; }
898  bool isAdditiveOp() const { return Opc == Add || Opc == Sub; }
899  bool isShiftOp() const { return Opc == Shl || Opc == Shr; }
900  bool isBitwiseOp() const { return Opc >= And && Opc <= Or; }
901  bool isRelationalOp() const { return Opc >= LT && Opc <= GE; }
902  bool isEqualityOp() const { return Opc == EQ || Opc == NE; }
903  bool isLogicalOp() const { return Opc == LAnd || Opc == LOr; }
904  bool isAssignmentOp() const { return Opc >= Assign && Opc <= OrAssign; }
905  bool isCompoundAssignmentOp() const { return Opc > Assign && Opc <= OrAssign;}
906  bool isShiftAssignOp() const { return Opc == ShlAssign || Opc == ShrAssign; }
907
908  static bool classof(const Stmt *S) {
909    return S->getStmtClass() == BinaryOperatorClass ||
910           S->getStmtClass() == CompoundAssignOperatorClass;
911  }
912  static bool classof(const BinaryOperator *) { return true; }
913
914  // Iterators
915  virtual child_iterator child_begin();
916  virtual child_iterator child_end();
917
918  virtual void EmitImpl(llvm::Serializer& S) const;
919  static BinaryOperator* CreateImpl(llvm::Deserializer& D, ASTContext& C);
920
921protected:
922  BinaryOperator(Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy,
923                 SourceLocation oploc, bool dead)
924    : Expr(CompoundAssignOperatorClass, ResTy), Opc(opc), OpLoc(oploc) {
925    SubExprs[LHS] = lhs;
926    SubExprs[RHS] = rhs;
927  }
928};
929
930/// CompoundAssignOperator - For compound assignments (e.g. +=), we keep
931/// track of the type the operation is performed in.  Due to the semantics of
932/// these operators, the operands are promoted, the aritmetic performed, an
933/// implicit conversion back to the result type done, then the assignment takes
934/// place.  This captures the intermediate type which the computation is done
935/// in.
936class CompoundAssignOperator : public BinaryOperator {
937  QualType ComputationType;
938public:
939  CompoundAssignOperator(Expr *lhs, Expr *rhs, Opcode opc,
940                         QualType ResType, QualType CompType,
941                         SourceLocation OpLoc)
942    : BinaryOperator(lhs, rhs, opc, ResType, OpLoc, true),
943      ComputationType(CompType) {
944    assert(isCompoundAssignmentOp() &&
945           "Only should be used for compound assignments");
946  }
947
948  QualType getComputationType() const { return ComputationType; }
949
950  static bool classof(const CompoundAssignOperator *) { return true; }
951  static bool classof(const Stmt *S) {
952    return S->getStmtClass() == CompoundAssignOperatorClass;
953  }
954
955  virtual void EmitImpl(llvm::Serializer& S) const;
956  static CompoundAssignOperator* CreateImpl(llvm::Deserializer& D,
957                                            ASTContext& C);
958};
959
960/// ConditionalOperator - The ?: operator.  Note that LHS may be null when the
961/// GNU "missing LHS" extension is in use.
962///
963class ConditionalOperator : public Expr {
964  enum { COND, LHS, RHS, END_EXPR };
965  Expr* SubExprs[END_EXPR]; // Left/Middle/Right hand sides.
966public:
967  ConditionalOperator(Expr *cond, Expr *lhs, Expr *rhs, QualType t)
968    : Expr(ConditionalOperatorClass, t) {
969    SubExprs[COND] = cond;
970    SubExprs[LHS] = lhs;
971    SubExprs[RHS] = rhs;
972  }
973
974  // getCond - Return the expression representing the condition for
975  //  the ?: operator.
976  Expr *getCond() const { return SubExprs[COND]; }
977
978  // getTrueExpr - Return the subexpression representing the value of the ?:
979  //  expression if the condition evaluates to true.  In most cases this value
980  //  will be the same as getLHS() except a GCC extension allows the left
981  //  subexpression to be omitted, and instead of the condition be returned.
982  //  e.g: x ?: y is shorthand for x ? x : y, except that the expression "x"
983  //  is only evaluated once.
984  Expr *getTrueExpr() const {
985    return SubExprs[LHS] ? SubExprs[COND] : SubExprs[LHS];
986  }
987
988  // getTrueExpr - Return the subexpression representing the value of the ?:
989  // expression if the condition evaluates to false. This is the same as getRHS.
990  Expr *getFalseExpr() const { return SubExprs[RHS]; }
991
992  Expr *getLHS() const { return SubExprs[LHS]; }
993  Expr *getRHS() const { return SubExprs[RHS]; }
994
995  virtual SourceRange getSourceRange() const {
996    return SourceRange(getCond()->getLocStart(), getRHS()->getLocEnd());
997  }
998  static bool classof(const Stmt *T) {
999    return T->getStmtClass() == ConditionalOperatorClass;
1000  }
1001  static bool classof(const ConditionalOperator *) { return true; }
1002
1003  // Iterators
1004  virtual child_iterator child_begin();
1005  virtual child_iterator child_end();
1006
1007  virtual void EmitImpl(llvm::Serializer& S) const;
1008  static ConditionalOperator* CreateImpl(llvm::Deserializer& D, ASTContext& C);
1009};
1010
1011/// AddrLabelExpr - The GNU address of label extension, representing &&label.
1012class AddrLabelExpr : public Expr {
1013  SourceLocation AmpAmpLoc, LabelLoc;
1014  LabelStmt *Label;
1015public:
1016  AddrLabelExpr(SourceLocation AALoc, SourceLocation LLoc, LabelStmt *L,
1017                QualType t)
1018    : Expr(AddrLabelExprClass, t), AmpAmpLoc(AALoc), LabelLoc(LLoc), Label(L) {}
1019
1020  virtual SourceRange getSourceRange() const {
1021    return SourceRange(AmpAmpLoc, LabelLoc);
1022  }
1023
1024  LabelStmt *getLabel() const { return Label; }
1025
1026  static bool classof(const Stmt *T) {
1027    return T->getStmtClass() == AddrLabelExprClass;
1028  }
1029  static bool classof(const AddrLabelExpr *) { return true; }
1030
1031  // Iterators
1032  virtual child_iterator child_begin();
1033  virtual child_iterator child_end();
1034
1035  virtual void EmitImpl(llvm::Serializer& S) const;
1036  static AddrLabelExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C);
1037};
1038
1039/// StmtExpr - This is the GNU Statement Expression extension: ({int X=4; X;}).
1040/// The StmtExpr contains a single CompoundStmt node, which it evaluates and
1041/// takes the value of the last subexpression.
1042class StmtExpr : public Expr {
1043  CompoundStmt *SubStmt;
1044  SourceLocation LParenLoc, RParenLoc;
1045public:
1046  StmtExpr(CompoundStmt *substmt, QualType T,
1047           SourceLocation lp, SourceLocation rp) :
1048    Expr(StmtExprClass, T), SubStmt(substmt),  LParenLoc(lp), RParenLoc(rp) { }
1049
1050  CompoundStmt *getSubStmt() { return SubStmt; }
1051  const CompoundStmt *getSubStmt() const { return SubStmt; }
1052
1053  virtual SourceRange getSourceRange() const {
1054    return SourceRange(LParenLoc, RParenLoc);
1055  }
1056
1057  static bool classof(const Stmt *T) {
1058    return T->getStmtClass() == StmtExprClass;
1059  }
1060  static bool classof(const StmtExpr *) { return true; }
1061
1062  // Iterators
1063  virtual child_iterator child_begin();
1064  virtual child_iterator child_end();
1065
1066  virtual void EmitImpl(llvm::Serializer& S) const;
1067  static StmtExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C);
1068};
1069
1070/// TypesCompatibleExpr - GNU builtin-in function __builtin_type_compatible_p.
1071/// This AST node represents a function that returns 1 if two *types* (not
1072/// expressions) are compatible. The result of this built-in function can be
1073/// used in integer constant expressions.
1074class TypesCompatibleExpr : public Expr {
1075  QualType Type1;
1076  QualType Type2;
1077  SourceLocation BuiltinLoc, RParenLoc;
1078public:
1079  TypesCompatibleExpr(QualType ReturnType, SourceLocation BLoc,
1080                      QualType t1, QualType t2, SourceLocation RP) :
1081    Expr(TypesCompatibleExprClass, ReturnType), Type1(t1), Type2(t2),
1082    BuiltinLoc(BLoc), RParenLoc(RP) {}
1083
1084  QualType getArgType1() const { return Type1; }
1085  QualType getArgType2() const { return Type2; }
1086
1087  virtual SourceRange getSourceRange() const {
1088    return SourceRange(BuiltinLoc, RParenLoc);
1089  }
1090  static bool classof(const Stmt *T) {
1091    return T->getStmtClass() == TypesCompatibleExprClass;
1092  }
1093  static bool classof(const TypesCompatibleExpr *) { return true; }
1094
1095  // Iterators
1096  virtual child_iterator child_begin();
1097  virtual child_iterator child_end();
1098};
1099
1100/// ChooseExpr - GNU builtin-in function __builtin_choose_expr.
1101/// This AST node is similar to the conditional operator (?:) in C, with
1102/// the following exceptions:
1103/// - the test expression much be a constant expression.
1104/// - the expression returned has it's type unaltered by promotion rules.
1105/// - does not evaluate the expression that was not chosen.
1106class ChooseExpr : public Expr {
1107  enum { COND, LHS, RHS, END_EXPR };
1108  Expr* SubExprs[END_EXPR]; // Left/Middle/Right hand sides.
1109  SourceLocation BuiltinLoc, RParenLoc;
1110public:
1111  ChooseExpr(SourceLocation BLoc, Expr *cond, Expr *lhs, Expr *rhs, QualType t,
1112             SourceLocation RP)
1113    : Expr(ChooseExprClass, t),
1114      BuiltinLoc(BLoc), RParenLoc(RP) {
1115      SubExprs[COND] = cond;
1116      SubExprs[LHS] = lhs;
1117      SubExprs[RHS] = rhs;
1118    }
1119
1120  /// isConditionTrue - Return true if the condition is true.  This is always
1121  /// statically knowable for a well-formed choosexpr.
1122  bool isConditionTrue(ASTContext &C) const;
1123
1124  Expr *getCond() const { return SubExprs[COND]; }
1125  Expr *getLHS() const { return SubExprs[LHS]; }
1126  Expr *getRHS() const { return SubExprs[RHS]; }
1127
1128  virtual SourceRange getSourceRange() const {
1129    return SourceRange(BuiltinLoc, RParenLoc);
1130  }
1131  static bool classof(const Stmt *T) {
1132    return T->getStmtClass() == ChooseExprClass;
1133  }
1134  static bool classof(const ChooseExpr *) { return true; }
1135
1136  // Iterators
1137  virtual child_iterator child_begin();
1138  virtual child_iterator child_end();
1139};
1140
1141/// OverloadExpr - Clang builtin function __builtin_overload.
1142/// This AST node provides a way to overload functions in C.
1143///
1144/// The first argument is required to be a constant expression, for the number
1145/// of arguments passed to each candidate function.
1146///
1147/// The next N arguments, where N is the value of the constant expression,
1148/// are the values to be passed as arguments.
1149///
1150/// The rest of the arguments are values of pointer to function type, which
1151/// are the candidate functions for overloading.
1152///
1153/// The result is a equivalent to a CallExpr taking N arguments to the
1154/// candidate function whose parameter types match the types of the N arguments.
1155///
1156/// example: float Z = __builtin_overload(2, X, Y, modf, mod, modl);
1157/// If X and Y are long doubles, Z will assigned the result of modl(X, Y);
1158/// If X and Y are floats, Z will be assigned the result of modf(X, Y);
1159class OverloadExpr : public Expr {
1160  // SubExprs - the list of values passed to the __builtin_overload function.
1161  // SubExpr[0] is a constant expression
1162  // SubExpr[1-N] are the parameters to pass to the matching function call
1163  // SubExpr[N-...] are the candidate functions, of type pointer to function.
1164  Expr **SubExprs;
1165
1166  // NumExprs - the size of the SubExprs array
1167  unsigned NumExprs;
1168
1169  // The index of the matching candidate function
1170  unsigned FnIndex;
1171
1172  SourceLocation BuiltinLoc;
1173  SourceLocation RParenLoc;
1174public:
1175  OverloadExpr(Expr **args, unsigned nexprs, unsigned idx, QualType t,
1176               SourceLocation bloc, SourceLocation rploc)
1177    : Expr(OverloadExprClass, t), NumExprs(nexprs), FnIndex(idx),
1178      BuiltinLoc(bloc), RParenLoc(rploc) {
1179    SubExprs = new Expr*[nexprs];
1180    for (unsigned i = 0; i != nexprs; ++i)
1181      SubExprs[i] = args[i];
1182  }
1183  ~OverloadExpr() {
1184    delete [] SubExprs;
1185  }
1186
1187  /// arg_begin - Return a pointer to the list of arguments that will be passed
1188  /// to the matching candidate function, skipping over the initial constant
1189  /// expression.
1190  typedef Expr * const *arg_const_iterator;
1191  arg_const_iterator arg_begin() const { return SubExprs+1; }
1192
1193  /// getNumArgs - Return the number of arguments to pass to the candidate
1194  /// functions.
1195  unsigned getNumArgs(ASTContext &Ctx) const {
1196    llvm::APSInt constEval(32);
1197    (void) SubExprs[0]->isIntegerConstantExpr(constEval, Ctx);
1198    return constEval.getZExtValue();
1199  }
1200
1201  /// getNumSubExprs - Return the size of the SubExprs array.  This includes the
1202  /// constant expression, the actual arguments passed in, and the function
1203  /// pointers.
1204  unsigned getNumSubExprs() const { return NumExprs; }
1205
1206  /// getExpr - Return the Expr at the specified index.
1207  Expr *getExpr(unsigned Index) {
1208    assert((Index < NumExprs) && "Arg access out of range!");
1209    return SubExprs[Index];
1210  }
1211
1212  /// getFn - Return the matching candidate function for this OverloadExpr.
1213  Expr *getFn() const { return SubExprs[FnIndex]; }
1214
1215  virtual SourceRange getSourceRange() const {
1216    return SourceRange(BuiltinLoc, RParenLoc);
1217  }
1218  static bool classof(const Stmt *T) {
1219    return T->getStmtClass() == OverloadExprClass;
1220  }
1221  static bool classof(const OverloadExpr *) { return true; }
1222
1223  // Iterators
1224  virtual child_iterator child_begin();
1225  virtual child_iterator child_end();
1226};
1227
1228/// VAArgExpr, used for the builtin function __builtin_va_start.
1229class VAArgExpr : public Expr {
1230  Expr *Val;
1231  SourceLocation BuiltinLoc, RParenLoc;
1232public:
1233  VAArgExpr(SourceLocation BLoc, Expr* e, QualType t, SourceLocation RPLoc)
1234    : Expr(VAArgExprClass, t),
1235      Val(e),
1236      BuiltinLoc(BLoc),
1237      RParenLoc(RPLoc) { }
1238
1239  const Expr *getSubExpr() const { return Val; }
1240  Expr *getSubExpr() { return Val; }
1241  virtual SourceRange getSourceRange() const {
1242    return SourceRange(BuiltinLoc, RParenLoc);
1243  }
1244  static bool classof(const Stmt *T) {
1245    return T->getStmtClass() == VAArgExprClass;
1246  }
1247  static bool classof(const VAArgExpr *) { return true; }
1248
1249  // Iterators
1250  virtual child_iterator child_begin();
1251  virtual child_iterator child_end();
1252};
1253
1254/// InitListExpr - used for struct and array initializers, such as:
1255///    struct foo x = { 1, { 2, 3 } };
1256///
1257/// Because C is somewhat loose with braces, the AST does not necessarily
1258/// directly model the C source.  Instead, the semantic analyzer aims to make
1259/// the InitListExprs match up with the type of the decl being initialized.  We
1260/// have the following exceptions:
1261///
1262///  1. Elements at the end of the list may be dropped from the initializer.
1263///     These elements are defined to be initialized to zero.  For example:
1264///         int x[20] = { 1 };
1265///  2. Initializers may have excess initializers which are to be ignored by the
1266///     compiler.  For example:
1267///         int x[1] = { 1, 2 };
1268///  3. Redundant InitListExprs may be present around scalar elements.  These
1269///     always have a single element whose type is the same as the InitListExpr.
1270///     this can only happen for Type::isScalarType() types.
1271///         int x = { 1 };  int y[2] = { {1}, {2} };
1272///
1273class InitListExpr : public Expr {
1274  std::vector<Expr *> InitExprs;
1275  SourceLocation LBraceLoc, RBraceLoc;
1276public:
1277  InitListExpr(SourceLocation lbraceloc, Expr **initexprs, unsigned numinits,
1278               SourceLocation rbraceloc);
1279
1280  unsigned getNumInits() const { return InitExprs.size(); }
1281
1282  const Expr* getInit(unsigned Init) const {
1283    assert(Init < getNumInits() && "Initializer access out of range!");
1284    return InitExprs[Init];
1285  }
1286
1287  Expr* getInit(unsigned Init) {
1288    assert(Init < getNumInits() && "Initializer access out of range!");
1289    return InitExprs[Init];
1290  }
1291
1292  void setInit(unsigned Init, Expr *expr) {
1293    assert(Init < getNumInits() && "Initializer access out of range!");
1294    InitExprs[Init] = expr;
1295  }
1296
1297  // Dynamic removal/addition (for constructing implicit InitExpr's).
1298  void removeInit(unsigned Init) {
1299    InitExprs.erase(InitExprs.begin()+Init);
1300  }
1301  void addInit(unsigned Init, Expr *expr) {
1302    InitExprs.insert(InitExprs.begin()+Init, expr);
1303  }
1304
1305  // Explicit InitListExpr's originate from source code (and have valid source
1306  // locations). Implicit InitListExpr's are created by the semantic analyzer.
1307  bool isExplicit() {
1308    return LBraceLoc.isValid() && RBraceLoc.isValid();
1309  }
1310
1311  virtual SourceRange getSourceRange() const {
1312    return SourceRange(LBraceLoc, RBraceLoc);
1313  }
1314  static bool classof(const Stmt *T) {
1315    return T->getStmtClass() == InitListExprClass;
1316  }
1317  static bool classof(const InitListExpr *) { return true; }
1318
1319  // Iterators
1320  virtual child_iterator child_begin();
1321  virtual child_iterator child_end();
1322
1323  virtual void EmitImpl(llvm::Serializer& S) const;
1324  static InitListExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C);
1325
1326private:
1327  // Used by serializer.
1328  InitListExpr() : Expr(InitListExprClass, QualType()) {}
1329};
1330
1331/// ObjCStringLiteral, used for Objective-C string literals
1332/// i.e. @"foo".
1333class ObjCStringLiteral : public Expr {
1334  StringLiteral *String;
1335  SourceLocation AtLoc;
1336public:
1337  ObjCStringLiteral(StringLiteral *SL, QualType T, SourceLocation L)
1338    : Expr(ObjCStringLiteralClass, T), String(SL), AtLoc(L) {}
1339
1340  StringLiteral* getString() { return String; }
1341
1342  const StringLiteral* getString() const { return String; }
1343
1344  SourceLocation getAtLoc() const { return AtLoc; }
1345
1346  virtual SourceRange getSourceRange() const {
1347    return SourceRange(AtLoc, String->getLocEnd());
1348  }
1349
1350  static bool classof(const Stmt *T) {
1351    return T->getStmtClass() == ObjCStringLiteralClass;
1352  }
1353  static bool classof(const ObjCStringLiteral *) { return true; }
1354
1355  // Iterators
1356  virtual child_iterator child_begin();
1357  virtual child_iterator child_end();
1358
1359  virtual void EmitImpl(llvm::Serializer& S) const;
1360  static ObjCStringLiteral* CreateImpl(llvm::Deserializer& D, ASTContext& C);
1361};
1362
1363/// ObjCEncodeExpr, used for @encode in Objective-C.
1364class ObjCEncodeExpr : public Expr {
1365  QualType EncType;
1366  SourceLocation AtLoc, RParenLoc;
1367public:
1368  ObjCEncodeExpr(QualType T, QualType ET,
1369                 SourceLocation at, SourceLocation rp)
1370    : Expr(ObjCEncodeExprClass, T), EncType(ET), AtLoc(at), RParenLoc(rp) {}
1371
1372  SourceLocation getAtLoc() const { return AtLoc; }
1373  SourceLocation getRParenLoc() const { return RParenLoc; }
1374
1375  virtual SourceRange getSourceRange() const {
1376    return SourceRange(AtLoc, RParenLoc);
1377  }
1378
1379  QualType getEncodedType() const { return EncType; }
1380
1381  static bool classof(const Stmt *T) {
1382    return T->getStmtClass() == ObjCEncodeExprClass;
1383  }
1384  static bool classof(const ObjCEncodeExpr *) { return true; }
1385
1386  // Iterators
1387  virtual child_iterator child_begin();
1388  virtual child_iterator child_end();
1389
1390  virtual void EmitImpl(llvm::Serializer& S) const;
1391  static ObjCEncodeExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C);
1392};
1393
1394/// ObjCSelectorExpr used for @selector in Objective-C.
1395class ObjCSelectorExpr : public Expr {
1396  Selector SelName;
1397  SourceLocation AtLoc, RParenLoc;
1398public:
1399  ObjCSelectorExpr(QualType T, Selector selInfo,
1400                   SourceLocation at, SourceLocation rp)
1401  : Expr(ObjCSelectorExprClass, T), SelName(selInfo),
1402  AtLoc(at), RParenLoc(rp) {}
1403
1404  Selector getSelector() const { return SelName; }
1405
1406  SourceLocation getAtLoc() const { return AtLoc; }
1407  SourceLocation getRParenLoc() const { return RParenLoc; }
1408
1409  virtual SourceRange getSourceRange() const {
1410    return SourceRange(AtLoc, RParenLoc);
1411  }
1412
1413  /// getNumArgs - Return the number of actual arguments to this call.
1414  unsigned getNumArgs() const { return SelName.getNumArgs(); }
1415
1416  static bool classof(const Stmt *T) {
1417    return T->getStmtClass() == ObjCSelectorExprClass;
1418  }
1419  static bool classof(const ObjCSelectorExpr *) { return true; }
1420
1421  // Iterators
1422  virtual child_iterator child_begin();
1423  virtual child_iterator child_end();
1424
1425  virtual void EmitImpl(llvm::Serializer& S) const;
1426  static ObjCSelectorExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C);
1427};
1428
1429/// ObjCProtocolExpr used for protocol in Objective-C.
1430class ObjCProtocolExpr : public Expr {
1431  ObjCProtocolDecl *Protocol;
1432  SourceLocation AtLoc, RParenLoc;
1433public:
1434  ObjCProtocolExpr(QualType T, ObjCProtocolDecl *protocol,
1435                   SourceLocation at, SourceLocation rp)
1436  : Expr(ObjCProtocolExprClass, T), Protocol(protocol),
1437  AtLoc(at), RParenLoc(rp) {}
1438
1439  ObjCProtocolDecl *getProtocol() const { return Protocol; }
1440
1441  SourceLocation getAtLoc() const { return AtLoc; }
1442  SourceLocation getRParenLoc() const { return RParenLoc; }
1443
1444  virtual SourceRange getSourceRange() const {
1445    return SourceRange(AtLoc, RParenLoc);
1446  }
1447
1448  static bool classof(const Stmt *T) {
1449    return T->getStmtClass() == ObjCProtocolExprClass;
1450  }
1451  static bool classof(const ObjCProtocolExpr *) { return true; }
1452
1453  // Iterators
1454  virtual child_iterator child_begin();
1455  virtual child_iterator child_end();
1456};
1457
1458/// ObjCIvarRefExpr - A reference to an ObjC instance variable.
1459class ObjCIvarRefExpr : public Expr {
1460  class ObjCIvarDecl *D;
1461  SourceLocation Loc;
1462  Expr *Base;
1463  bool IsArrow:1;      // True if this is "X->F", false if this is "X.F".
1464  bool IsFreeIvar:1;   // True if ivar reference has no base (self assumed).
1465
1466public:
1467  ObjCIvarRefExpr(ObjCIvarDecl *d, QualType t, SourceLocation l, Expr *base=0,
1468                  bool arrow = false, bool freeIvar = false) :
1469    Expr(ObjCIvarRefExprClass, t), D(d), Loc(l), Base(base), IsArrow(arrow),
1470    IsFreeIvar(freeIvar) {}
1471
1472  ObjCIvarDecl *getDecl() { return D; }
1473  const ObjCIvarDecl *getDecl() const { return D; }
1474  virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
1475  const Expr *getBase() const { return Base; }
1476  Expr *getBase() { return Base; }
1477  void setBase(Expr * base) { Base = base; }
1478  bool isArrow() const { return IsArrow; }
1479  bool isFreeIvar() const { return IsFreeIvar; }
1480
1481  SourceLocation getLocation() const { return Loc; }
1482
1483  static bool classof(const Stmt *T) {
1484    return T->getStmtClass() == ObjCIvarRefExprClass;
1485  }
1486  static bool classof(const ObjCIvarRefExpr *) { return true; }
1487
1488  // Iterators
1489  virtual child_iterator child_begin();
1490  virtual child_iterator child_end();
1491
1492  virtual void EmitImpl(llvm::Serializer& S) const;
1493  static ObjCIvarRefExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C);
1494};
1495
1496class ObjCMessageExpr : public Expr {
1497  enum { RECEIVER=0, ARGS_START=1 };
1498
1499  Expr **SubExprs;
1500
1501  unsigned NumArgs;
1502
1503  // A unigue name for this message.
1504  Selector SelName;
1505
1506  // A method prototype for this message (optional).
1507  // FIXME: Since method decls contain the selector, and most messages have a
1508  // prototype, consider devising a scheme for unifying SelName/MethodProto.
1509  ObjCMethodDecl *MethodProto;
1510
1511  SourceLocation LBracloc, RBracloc;
1512
1513  // constructor used during deserialization
1514  ObjCMessageExpr(Selector selInfo, QualType retType,
1515                  SourceLocation LBrac, SourceLocation RBrac,
1516                  Expr **ArgExprs, unsigned nargs)
1517  : Expr(ObjCMessageExprClass, retType), NumArgs(nargs), SelName(selInfo),
1518    MethodProto(NULL), LBracloc(LBrac), RBracloc(RBrac) {}
1519
1520public:
1521  // constructor for class messages.
1522  // FIXME: clsName should be typed to ObjCInterfaceType
1523  ObjCMessageExpr(IdentifierInfo *clsName, Selector selInfo,
1524                  QualType retType, ObjCMethodDecl *methDecl,
1525                  SourceLocation LBrac, SourceLocation RBrac,
1526                  Expr **ArgExprs, unsigned NumArgs);
1527  // constructor for instance messages.
1528  ObjCMessageExpr(Expr *receiver, Selector selInfo,
1529                  QualType retType, ObjCMethodDecl *methDecl,
1530                  SourceLocation LBrac, SourceLocation RBrac,
1531                  Expr **ArgExprs, unsigned NumArgs);
1532
1533  ~ObjCMessageExpr() {
1534    delete [] SubExprs;
1535  }
1536
1537  /// getReceiver - Returns the receiver of the message expression.
1538  ///  This can be NULL if the message is for instance methods.  For
1539  ///  instance methods, use getClassName.
1540  Expr *getReceiver() {
1541    uintptr_t x = (uintptr_t) SubExprs[RECEIVER];
1542    return x & 0x1 ? NULL : (Expr*) x;
1543  }
1544  const Expr *getReceiver() const {
1545    return const_cast<ObjCMessageExpr*>(this)->getReceiver();
1546  }
1547
1548  Selector getSelector() const { return SelName; }
1549
1550  const ObjCMethodDecl *getMethodDecl() const { return MethodProto; }
1551  ObjCMethodDecl *getMethodDecl() { return MethodProto; }
1552
1553  /// getClassName - For instance methods, this returns the invoked class,
1554  ///  and returns NULL otherwise.  For regular methods, use getReceiver.
1555  IdentifierInfo *getClassName() {
1556    uintptr_t x = (uintptr_t) SubExprs[RECEIVER];
1557    return x & 0x1 ? (IdentifierInfo*) (x & ~0x1) : NULL;
1558  }
1559  const IdentifierInfo *getClassName() const {
1560    return const_cast<ObjCMessageExpr*>(this)->getClassName();
1561  }
1562
1563  /// getNumArgs - Return the number of actual arguments to this call.
1564  unsigned getNumArgs() const { return NumArgs; }
1565
1566  /// getArg - Return the specified argument.
1567  Expr *getArg(unsigned Arg) {
1568    assert(Arg < NumArgs && "Arg access out of range!");
1569    return SubExprs[Arg+ARGS_START];
1570  }
1571  const Expr *getArg(unsigned Arg) const {
1572    assert(Arg < NumArgs && "Arg access out of range!");
1573    return SubExprs[Arg+ARGS_START];
1574  }
1575  /// setArg - Set the specified argument.
1576  void setArg(unsigned Arg, Expr *ArgExpr) {
1577    assert(Arg < NumArgs && "Arg access out of range!");
1578    SubExprs[Arg+ARGS_START] = ArgExpr;
1579  }
1580
1581  virtual SourceRange getSourceRange() const {
1582    return SourceRange(LBracloc, RBracloc);
1583  }
1584
1585  static bool classof(const Stmt *T) {
1586    return T->getStmtClass() == ObjCMessageExprClass;
1587  }
1588  static bool classof(const ObjCMessageExpr *) { return true; }
1589
1590  // Iterators
1591  virtual child_iterator child_begin();
1592  virtual child_iterator child_end();
1593
1594  typedef Expr** arg_iterator;
1595  typedef const Expr* const* const_arg_iterator;
1596
1597  arg_iterator arg_begin() { return &SubExprs[ARGS_START]; }
1598  arg_iterator arg_end()   { return arg_begin() + NumArgs; }
1599  const_arg_iterator arg_begin() const { return &SubExprs[ARGS_START]; }
1600  const_arg_iterator arg_end() const { return arg_begin() + NumArgs; }
1601
1602  // Serialization.
1603  virtual void EmitImpl(llvm::Serializer& S) const;
1604  static ObjCMessageExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C);
1605};
1606
1607}  // end namespace clang
1608
1609#endif
1610