Expr.h revision ea2fe9b435e1b55135de32dcac97366554706ac4
1//===--- Expr.h - Classes for representing expressions ----------*- C++ -*-===//
2//
3//                     The LLVM Compiler Infrastructure
4//
5// This file was developed by Chris Lattner and is distributed under
6// the University of Illinois Open Source License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10//  This file defines the Expr interface and subclasses.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_CLANG_AST_EXPR_H
15#define LLVM_CLANG_AST_EXPR_H
16
17#include "clang/AST/Stmt.h"
18#include "clang/AST/Type.h"
19#include "clang/AST/Decl.h"
20#include "clang/Basic/IdentifierTable.h"
21#include "llvm/ADT/APSInt.h"
22#include "llvm/ADT/APFloat.h"
23
24namespace clang {
25  class IdentifierInfo;
26  class Selector;
27  class Decl;
28  class ASTContext;
29
30/// Expr - This represents one expression.  Note that Expr's are subclasses of
31/// Stmt.  This allows an expression to be transparently used any place a Stmt
32/// is required.
33///
34class Expr : public Stmt {
35  QualType TR;
36protected:
37  Expr(StmtClass SC, QualType T) : Stmt(SC), TR(T) {}
38public:
39  QualType getType() const { return TR; }
40  void setType(QualType t) { TR = t; }
41
42  /// SourceLocation tokens are not useful in isolation - they are low level
43  /// value objects created/interpreted by SourceManager. We assume AST
44  /// clients will have a pointer to the respective SourceManager.
45  virtual SourceRange getSourceRange() const = 0;
46
47  /// getExprLoc - Return the preferred location for the arrow when diagnosing
48  /// a problem with a generic expression.
49  virtual SourceLocation getExprLoc() const { return getLocStart(); }
50
51  /// hasLocalSideEffect - Return true if this immediate expression has side
52  /// effects, not counting any sub-expressions.
53  bool hasLocalSideEffect() const;
54
55  /// isLvalue - C99 6.3.2.1: an lvalue is an expression with an object type or
56  /// incomplete type other than void. Nonarray expressions that can be lvalues:
57  ///  - name, where name must be a variable
58  ///  - e[i]
59  ///  - (e), where e must be an lvalue
60  ///  - e.name, where e must be an lvalue
61  ///  - e->name
62  ///  - *e, the type of e cannot be a function type
63  ///  - string-constant
64  ///  - reference type [C++ [expr]]
65  ///
66  enum isLvalueResult {
67    LV_Valid,
68    LV_NotObjectType,
69    LV_IncompleteVoidType,
70    LV_DuplicateVectorComponents,
71    LV_InvalidExpression
72  };
73  isLvalueResult isLvalue() const;
74
75  /// isModifiableLvalue - C99 6.3.2.1: an lvalue that does not have array type,
76  /// does not have an incomplete type, does not have a const-qualified type,
77  /// and if it is a structure or union, does not have any member (including,
78  /// recursively, any member or element of all contained aggregates or unions)
79  /// with a const-qualified type.
80  enum isModifiableLvalueResult {
81    MLV_Valid,
82    MLV_NotObjectType,
83    MLV_IncompleteVoidType,
84    MLV_DuplicateVectorComponents,
85    MLV_InvalidExpression,
86    MLV_IncompleteType,
87    MLV_ConstQualified,
88    MLV_ArrayType
89  };
90  isModifiableLvalueResult isModifiableLvalue() const;
91
92  bool isNullPointerConstant(ASTContext &Ctx) const;
93
94  /// isIntegerConstantExpr - Return true if this expression is a valid integer
95  /// constant expression, and, if so, return its value in Result.  If not a
96  /// valid i-c-e, return false and fill in Loc (if specified) with the location
97  /// of the invalid expression.
98  bool isIntegerConstantExpr(llvm::APSInt &Result, ASTContext &Ctx,
99                             SourceLocation *Loc = 0,
100                             bool isEvaluated = true) const;
101  bool isIntegerConstantExpr(ASTContext &Ctx, SourceLocation *Loc = 0) const {
102    llvm::APSInt X(32);
103    return isIntegerConstantExpr(X, Ctx, Loc);
104  }
105  /// isConstantExpr - Return true if this expression is a valid constant expr.
106  bool isConstantExpr(ASTContext &Ctx, SourceLocation *Loc) const;
107
108  /// hasStaticStorage - Return true if this expression has static storage
109  /// duration.
110  bool hasStaticStorage() const;
111
112  static bool classof(const Stmt *T) {
113    return T->getStmtClass() >= firstExprConstant &&
114           T->getStmtClass() <= lastExprConstant;
115  }
116  static bool classof(const Expr *) { return true; }
117
118  static inline Expr* Create(llvm::Deserializer& D) {
119    return cast<Expr>(Stmt::Create(D));
120  }
121};
122
123//===----------------------------------------------------------------------===//
124// Primary Expressions.
125//===----------------------------------------------------------------------===//
126
127/// DeclRefExpr - [C99 6.5.1p2] - A reference to a declared variable, function,
128/// enum, etc.
129class DeclRefExpr : public Expr {
130  ValueDecl *D;
131  SourceLocation Loc;
132public:
133  DeclRefExpr(ValueDecl *d, QualType t, SourceLocation l) :
134    Expr(DeclRefExprClass, t), D(d), Loc(l) {}
135
136  ValueDecl *getDecl() { return D; }
137  const ValueDecl *getDecl() const { return D; }
138  virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
139
140
141  static bool classof(const Stmt *T) {
142    return T->getStmtClass() == DeclRefExprClass;
143  }
144  static bool classof(const DeclRefExpr *) { return true; }
145
146  // Iterators
147  virtual child_iterator child_begin();
148  virtual child_iterator child_end();
149
150  virtual void EmitImpl(llvm::Serializer& S) const;
151  static DeclRefExpr* CreateImpl(llvm::Deserializer& D);
152};
153
154/// PreDefinedExpr - [C99 6.4.2.2] - A pre-defined identifier such as __func__.
155class PreDefinedExpr : public Expr {
156public:
157  enum IdentType {
158    Func,
159    Function,
160    PrettyFunction
161  };
162
163private:
164  SourceLocation Loc;
165  IdentType Type;
166public:
167  PreDefinedExpr(SourceLocation l, QualType type, IdentType IT)
168    : Expr(PreDefinedExprClass, type), Loc(l), Type(IT) {}
169
170  IdentType getIdentType() const { return Type; }
171
172  virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
173
174  static bool classof(const Stmt *T) {
175    return T->getStmtClass() == PreDefinedExprClass;
176  }
177  static bool classof(const PreDefinedExpr *) { return true; }
178
179  // Iterators
180  virtual child_iterator child_begin();
181  virtual child_iterator child_end();
182
183  virtual void EmitImpl(llvm::Serializer& S) const;
184  static PreDefinedExpr* CreateImpl(llvm::Deserializer& D);
185};
186
187class IntegerLiteral : public Expr {
188  llvm::APInt Value;
189  SourceLocation Loc;
190public:
191  // type should be IntTy, LongTy, LongLongTy, UnsignedIntTy, UnsignedLongTy,
192  // or UnsignedLongLongTy
193  IntegerLiteral(const llvm::APInt &V, QualType type, SourceLocation l)
194    : Expr(IntegerLiteralClass, type), Value(V), Loc(l) {
195    assert(type->isIntegerType() && "Illegal type in IntegerLiteral");
196  }
197  const llvm::APInt &getValue() const { return Value; }
198  virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
199
200  static bool classof(const Stmt *T) {
201    return T->getStmtClass() == IntegerLiteralClass;
202  }
203  static bool classof(const IntegerLiteral *) { return true; }
204
205  // Iterators
206  virtual child_iterator child_begin();
207  virtual child_iterator child_end();
208
209  virtual void EmitImpl(llvm::Serializer& S) const;
210  static IntegerLiteral* CreateImpl(llvm::Deserializer& D);
211};
212
213class CharacterLiteral : public Expr {
214  unsigned Value;
215  SourceLocation Loc;
216public:
217  // type should be IntTy
218  CharacterLiteral(unsigned value, QualType type, SourceLocation l)
219    : Expr(CharacterLiteralClass, type), Value(value), Loc(l) {
220  }
221  SourceLocation getLoc() const { return Loc; }
222
223  virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
224
225  unsigned getValue() const { return Value; }
226
227  static bool classof(const Stmt *T) {
228    return T->getStmtClass() == CharacterLiteralClass;
229  }
230  static bool classof(const CharacterLiteral *) { return true; }
231
232  // Iterators
233  virtual child_iterator child_begin();
234  virtual child_iterator child_end();
235
236  virtual void EmitImpl(llvm::Serializer& S) const;
237  static CharacterLiteral* CreateImpl(llvm::Deserializer& D);
238};
239
240class FloatingLiteral : public Expr {
241  llvm::APFloat Value;
242  SourceLocation Loc;
243public:
244  FloatingLiteral(const llvm::APFloat &V, QualType Type, SourceLocation L)
245    : Expr(FloatingLiteralClass, Type), Value(V), Loc(L) {}
246
247  const llvm::APFloat &getValue() const { return Value; }
248
249  /// getValueAsDouble - This returns the value as an inaccurate double.  Note
250  /// that this may cause loss of precision, but is useful for debugging dumps
251  /// etc.
252  double getValueAsDouble() const {
253    // FIXME: We need something for long double here.
254    if (cast<BuiltinType>(getType())->getKind() == BuiltinType::Float)
255      return Value.convertToFloat();
256    else
257      return Value.convertToDouble();
258  }
259
260  virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
261
262  static bool classof(const Stmt *T) {
263    return T->getStmtClass() == FloatingLiteralClass;
264  }
265  static bool classof(const FloatingLiteral *) { return true; }
266
267  // Iterators
268  virtual child_iterator child_begin();
269  virtual child_iterator child_end();
270
271  virtual void EmitImpl(llvm::Serializer& S) const;
272  static FloatingLiteral* CreateImpl(llvm::Deserializer& D);
273};
274
275/// ImaginaryLiteral - We support imaginary integer and floating point literals,
276/// like "1.0i".  We represent these as a wrapper around FloatingLiteral and
277/// IntegerLiteral classes.  Instances of this class always have a Complex type
278/// whose element type matches the subexpression.
279///
280class ImaginaryLiteral : public Expr {
281  Expr *Val;
282public:
283  ImaginaryLiteral(Expr *val, QualType Ty)
284    : Expr(ImaginaryLiteralClass, Ty), Val(val) {}
285
286  const Expr *getSubExpr() const { return Val; }
287  Expr *getSubExpr() { return Val; }
288
289  virtual SourceRange getSourceRange() const { return Val->getSourceRange(); }
290  static bool classof(const Stmt *T) {
291    return T->getStmtClass() == ImaginaryLiteralClass;
292  }
293  static bool classof(const ImaginaryLiteral *) { return true; }
294
295  // Iterators
296  virtual child_iterator child_begin();
297  virtual child_iterator child_end();
298
299  virtual void EmitImpl(llvm::Serializer& S) const;
300  static ImaginaryLiteral* CreateImpl(llvm::Deserializer& D);
301};
302
303/// StringLiteral - This represents a string literal expression, e.g. "foo"
304/// or L"bar" (wide strings).  The actual string is returned by getStrData()
305/// is NOT null-terminated, and the length of the string is determined by
306/// calling getByteLength().
307class StringLiteral : public Expr {
308  const char *StrData;
309  unsigned ByteLength;
310  bool IsWide;
311  // if the StringLiteral was composed using token pasting, both locations
312  // are needed. If not (the common case), firstTokLoc == lastTokLoc.
313  // FIXME: if space becomes an issue, we should create a sub-class.
314  SourceLocation firstTokLoc, lastTokLoc;
315public:
316  StringLiteral(const char *strData, unsigned byteLength, bool Wide,
317                QualType t, SourceLocation b, SourceLocation e);
318  virtual ~StringLiteral();
319
320  const char *getStrData() const { return StrData; }
321  unsigned getByteLength() const { return ByteLength; }
322  bool isWide() const { return IsWide; }
323
324  virtual SourceRange getSourceRange() const {
325    return SourceRange(firstTokLoc,lastTokLoc);
326  }
327  static bool classof(const Stmt *T) {
328    return T->getStmtClass() == StringLiteralClass;
329  }
330  static bool classof(const StringLiteral *) { return true; }
331
332  // Iterators
333  virtual child_iterator child_begin();
334  virtual child_iterator child_end();
335
336  virtual void EmitImpl(llvm::Serializer& S) const;
337  static StringLiteral* CreateImpl(llvm::Deserializer& D);
338};
339
340/// ParenExpr - This represents a parethesized expression, e.g. "(1)".  This
341/// AST node is only formed if full location information is requested.
342class ParenExpr : public Expr {
343  SourceLocation L, R;
344  Expr *Val;
345public:
346  ParenExpr(SourceLocation l, SourceLocation r, Expr *val)
347    : Expr(ParenExprClass, val->getType()), L(l), R(r), Val(val) {}
348
349  const Expr *getSubExpr() const { return Val; }
350  Expr *getSubExpr() { return Val; }
351  SourceRange getSourceRange() const { return SourceRange(L, R); }
352
353  static bool classof(const Stmt *T) {
354    return T->getStmtClass() == ParenExprClass;
355  }
356  static bool classof(const ParenExpr *) { return true; }
357
358  // Iterators
359  virtual child_iterator child_begin();
360  virtual child_iterator child_end();
361
362  virtual void EmitImpl(llvm::Serializer& S) const;
363  static ParenExpr* CreateImpl(llvm::Deserializer& D);
364};
365
366
367/// UnaryOperator - This represents the unary-expression's (except sizeof of
368/// types), the postinc/postdec operators from postfix-expression, and various
369/// extensions.
370///
371/// Notes on various nodes:
372///
373/// Real/Imag - These return the real/imag part of a complex operand.  If
374///   applied to a non-complex value, the former returns its operand and the
375///   later returns zero in the type of the operand.
376///
377/// __builtin_offsetof(type, a.b[10]) is represented as a unary operator whose
378///   subexpression is a compound literal with the various MemberExpr and
379///   ArraySubscriptExpr's applied to it.
380///
381class UnaryOperator : public Expr {
382public:
383  // Note that additions to this should also update the StmtVisitor class.
384  enum Opcode {
385    PostInc, PostDec, // [C99 6.5.2.4] Postfix increment and decrement operators
386    PreInc, PreDec,   // [C99 6.5.3.1] Prefix increment and decrement operators.
387    AddrOf, Deref,    // [C99 6.5.3.2] Address and indirection operators.
388    Plus, Minus,      // [C99 6.5.3.3] Unary arithmetic operators.
389    Not, LNot,        // [C99 6.5.3.3] Unary arithmetic operators.
390    SizeOf, AlignOf,  // [C99 6.5.3.4] Sizeof (expr, not type) operator.
391    Real, Imag,       // "__real expr"/"__imag expr" Extension.
392    Extension,        // __extension__ marker.
393    OffsetOf          // __builtin_offsetof
394  };
395private:
396  Expr *Val;
397  Opcode Opc;
398  SourceLocation Loc;
399public:
400
401  UnaryOperator(Expr *input, Opcode opc, QualType type, SourceLocation l)
402    : Expr(UnaryOperatorClass, type), Val(input), Opc(opc), Loc(l) {}
403
404  Opcode getOpcode() const { return Opc; }
405  Expr *getSubExpr() const { return Val; }
406
407  /// getOperatorLoc - Return the location of the operator.
408  SourceLocation getOperatorLoc() const { return Loc; }
409
410  /// isPostfix - Return true if this is a postfix operation, like x++.
411  static bool isPostfix(Opcode Op);
412
413  bool isPostfix() const { return isPostfix(Opc); }
414  bool isIncrementDecrementOp() const { return Opc>=PostInc && Opc<=PreDec; }
415  bool isSizeOfAlignOfOp() const { return Opc == SizeOf || Opc == AlignOf; }
416  static bool isArithmeticOp(Opcode Op) { return Op >= Plus && Op <= LNot; }
417
418  /// getOpcodeStr - Turn an Opcode enum value into the punctuation char it
419  /// corresponds to, e.g. "sizeof" or "[pre]++"
420  static const char *getOpcodeStr(Opcode Op);
421
422  virtual SourceRange getSourceRange() const {
423    if (isPostfix())
424      return SourceRange(Val->getLocStart(), Loc);
425    else
426      return SourceRange(Loc, Val->getLocEnd());
427  }
428  virtual SourceLocation getExprLoc() const { return Loc; }
429
430  static bool classof(const Stmt *T) {
431    return T->getStmtClass() == UnaryOperatorClass;
432  }
433  static bool classof(const UnaryOperator *) { return true; }
434
435  // Iterators
436  virtual child_iterator child_begin();
437  virtual child_iterator child_end();
438
439  virtual void EmitImpl(llvm::Serializer& S) const;
440  static UnaryOperator* CreateImpl(llvm::Deserializer& D);
441};
442
443/// SizeOfAlignOfTypeExpr - [C99 6.5.3.4] - This is only for sizeof/alignof of
444/// *types*.  sizeof(expr) is handled by UnaryOperator.
445class SizeOfAlignOfTypeExpr : public Expr {
446  bool isSizeof;  // true if sizeof, false if alignof.
447  QualType Ty;
448  SourceLocation OpLoc, RParenLoc;
449public:
450  SizeOfAlignOfTypeExpr(bool issizeof, QualType argType, QualType resultType,
451                        SourceLocation op, SourceLocation rp) :
452    Expr(SizeOfAlignOfTypeExprClass, resultType),
453    isSizeof(issizeof), Ty(argType), OpLoc(op), RParenLoc(rp) {}
454
455  bool isSizeOf() const { return isSizeof; }
456  QualType getArgumentType() const { return Ty; }
457
458  SourceLocation getOperatorLoc() const { return OpLoc; }
459  SourceRange getSourceRange() const { return SourceRange(OpLoc, RParenLoc); }
460
461  static bool classof(const Stmt *T) {
462    return T->getStmtClass() == SizeOfAlignOfTypeExprClass;
463  }
464  static bool classof(const SizeOfAlignOfTypeExpr *) { return true; }
465
466  // Iterators
467  virtual child_iterator child_begin();
468  virtual child_iterator child_end();
469
470  virtual void EmitImpl(llvm::Serializer& S) const;
471  static SizeOfAlignOfTypeExpr* CreateImpl(llvm::Deserializer& D);
472};
473
474//===----------------------------------------------------------------------===//
475// Postfix Operators.
476//===----------------------------------------------------------------------===//
477
478/// ArraySubscriptExpr - [C99 6.5.2.1] Array Subscripting.
479class ArraySubscriptExpr : public Expr {
480  enum { LHS, RHS, END_EXPR=2 };
481  Expr* SubExprs[END_EXPR];
482  SourceLocation RBracketLoc;
483public:
484  ArraySubscriptExpr(Expr *lhs, Expr *rhs, QualType t,
485                     SourceLocation rbracketloc)
486  : Expr(ArraySubscriptExprClass, t), RBracketLoc(rbracketloc) {
487    SubExprs[LHS] = lhs;
488    SubExprs[RHS] = rhs;
489  }
490
491  /// An array access can be written A[4] or 4[A] (both are equivalent).
492  /// - getBase() and getIdx() always present the normalized view: A[4].
493  ///    In this case getBase() returns "A" and getIdx() returns "4".
494  /// - getLHS() and getRHS() present the syntactic view. e.g. for
495  ///    4[A] getLHS() returns "4".
496
497  Expr *getLHS() { return SubExprs[LHS]; }
498  const Expr *getLHS() const { return SubExprs[LHS]; }
499
500  Expr *getRHS() { return SubExprs[RHS]; }
501  const Expr *getRHS() const { return SubExprs[RHS]; }
502
503  Expr *getBase() {
504    return (getLHS()->getType()->isIntegerType()) ? getRHS() : getLHS();
505  }
506
507  const Expr *getBase() const {
508    return (getLHS()->getType()->isIntegerType()) ? getRHS() : getLHS();
509  }
510
511  Expr *getIdx() {
512    return (getLHS()->getType()->isIntegerType()) ? getLHS() : getRHS();
513  }
514
515  const Expr *getIdx() const {
516    return (getLHS()->getType()->isIntegerType()) ? getLHS() : getRHS();
517  }
518
519
520  SourceRange getSourceRange() const {
521    return SourceRange(getLHS()->getLocStart(), RBracketLoc);
522  }
523  virtual SourceLocation getExprLoc() const { return RBracketLoc; }
524
525  static bool classof(const Stmt *T) {
526    return T->getStmtClass() == ArraySubscriptExprClass;
527  }
528  static bool classof(const ArraySubscriptExpr *) { return true; }
529
530  // Iterators
531  virtual child_iterator child_begin();
532  virtual child_iterator child_end();
533
534  virtual void EmitImpl(llvm::Serializer& S) const;
535  static ArraySubscriptExpr* CreateImpl(llvm::Deserializer& D);
536};
537
538
539/// CallExpr - [C99 6.5.2.2] Function Calls.
540///
541class CallExpr : public Expr {
542  enum { FN=0, ARGS_START=1 };
543  Expr **SubExprs;
544  unsigned NumArgs;
545  SourceLocation RParenLoc;
546
547  // This version of the ctor is for deserialization.
548  CallExpr(Expr** subexprs, unsigned numargs, QualType t,
549           SourceLocation rparenloc)
550  : Expr(CallExprClass,t), SubExprs(subexprs),
551    NumArgs(numargs), RParenLoc(rparenloc) {}
552
553public:
554  CallExpr(Expr *fn, Expr **args, unsigned numargs, QualType t,
555           SourceLocation rparenloc);
556  ~CallExpr() {
557    delete [] SubExprs;
558  }
559
560  const Expr *getCallee() const { return SubExprs[FN]; }
561  Expr *getCallee() { return SubExprs[FN]; }
562
563  /// getNumArgs - Return the number of actual arguments to this call.
564  ///
565  unsigned getNumArgs() const { return NumArgs; }
566
567  /// getArg - Return the specified argument.
568  Expr *getArg(unsigned Arg) {
569    assert(Arg < NumArgs && "Arg access out of range!");
570    return SubExprs[Arg+ARGS_START];
571  }
572  const Expr *getArg(unsigned Arg) const {
573    assert(Arg < NumArgs && "Arg access out of range!");
574    return SubExprs[Arg+ARGS_START];
575  }
576  /// setArg - Set the specified argument.
577  void setArg(unsigned Arg, Expr *ArgExpr) {
578    assert(Arg < NumArgs && "Arg access out of range!");
579    SubExprs[Arg+ARGS_START] = ArgExpr;
580  }
581  /// getNumCommas - Return the number of commas that must have been present in
582  /// this function call.
583  unsigned getNumCommas() const { return NumArgs ? NumArgs - 1 : 0; }
584
585  bool isBuiltinClassifyType(llvm::APSInt &Result) const;
586
587  SourceRange getSourceRange() const {
588    return SourceRange(getCallee()->getLocStart(), RParenLoc);
589  }
590
591  static bool classof(const Stmt *T) {
592    return T->getStmtClass() == CallExprClass;
593  }
594  static bool classof(const CallExpr *) { return true; }
595
596  // Iterators
597  virtual child_iterator child_begin();
598  virtual child_iterator child_end();
599
600  virtual void EmitImpl(llvm::Serializer& S) const;
601  static CallExpr* CreateImpl(llvm::Deserializer& D);
602};
603
604/// MemberExpr - [C99 6.5.2.3] Structure and Union Members.
605///
606class MemberExpr : public Expr {
607  Expr *Base;
608  FieldDecl *MemberDecl;
609  SourceLocation MemberLoc;
610  bool IsArrow;      // True if this is "X->F", false if this is "X.F".
611public:
612  MemberExpr(Expr *base, bool isarrow, FieldDecl *memberdecl, SourceLocation l)
613    : Expr(MemberExprClass, memberdecl->getType()),
614      Base(base), MemberDecl(memberdecl), MemberLoc(l), IsArrow(isarrow) {}
615
616  Expr *getBase() const { return Base; }
617  FieldDecl *getMemberDecl() const { return MemberDecl; }
618  bool isArrow() const { return IsArrow; }
619
620  virtual SourceRange getSourceRange() const {
621    return SourceRange(getBase()->getLocStart(), MemberLoc);
622  }
623  virtual SourceLocation getExprLoc() const { return MemberLoc; }
624
625  static bool classof(const Stmt *T) {
626    return T->getStmtClass() == MemberExprClass;
627  }
628  static bool classof(const MemberExpr *) { return true; }
629
630  // Iterators
631  virtual child_iterator child_begin();
632  virtual child_iterator child_end();
633
634  virtual void EmitImpl(llvm::Serializer& S) const;
635  static MemberExpr* CreateImpl(llvm::Deserializer& D);
636};
637
638/// OCUVectorElementExpr - This represents access to specific elements of a
639/// vector, and may occur on the left hand side or right hand side.  For example
640/// the following is legal:  "V.xy = V.zw" if V is a 4 element ocu vector.
641///
642class OCUVectorElementExpr : public Expr {
643  Expr *Base;
644  IdentifierInfo &Accessor;
645  SourceLocation AccessorLoc;
646public:
647  enum ElementType {
648    Point,   // xywz
649    Color,   // rgba
650    Texture  // stpq
651  };
652  OCUVectorElementExpr(QualType ty, Expr *base, IdentifierInfo &accessor,
653                       SourceLocation loc)
654    : Expr(OCUVectorElementExprClass, ty),
655      Base(base), Accessor(accessor), AccessorLoc(loc) {}
656
657  const Expr *getBase() const { return Base; }
658  Expr *getBase() { return Base; }
659
660  IdentifierInfo &getAccessor() const { return Accessor; }
661
662  /// getNumElements - Get the number of components being selected.
663  unsigned getNumElements() const;
664
665  /// getElementType - Determine whether the components of this access are
666  /// "point" "color" or "texture" elements.
667  ElementType getElementType() const;
668
669  /// containsDuplicateElements - Return true if any element access is
670  /// repeated.
671  bool containsDuplicateElements() const;
672
673  /// getEncodedElementAccess - Encode the elements accessed into a bit vector.
674  /// The encoding currently uses 2-bit bitfields, but clients should use the
675  /// accessors below to access them.
676  ///
677  unsigned getEncodedElementAccess() const;
678
679  /// getAccessedFieldNo - Given an encoded value and a result number, return
680  /// the input field number being accessed.
681  static unsigned getAccessedFieldNo(unsigned Idx, unsigned EncodedVal) {
682    return (EncodedVal >> (Idx*2)) & 3;
683  }
684
685  virtual SourceRange getSourceRange() const {
686    return SourceRange(getBase()->getLocStart(), AccessorLoc);
687  }
688  static bool classof(const Stmt *T) {
689    return T->getStmtClass() == OCUVectorElementExprClass;
690  }
691  static bool classof(const OCUVectorElementExpr *) { return true; }
692
693  // Iterators
694  virtual child_iterator child_begin();
695  virtual child_iterator child_end();
696};
697
698/// CompoundLiteralExpr - [C99 6.5.2.5]
699///
700class CompoundLiteralExpr : public Expr {
701  Expr *Init;
702public:
703  CompoundLiteralExpr(QualType ty, Expr *init) :
704    Expr(CompoundLiteralExprClass, ty), Init(init) {}
705
706  const Expr *getInitializer() const { return Init; }
707  Expr *getInitializer() { return Init; }
708
709  virtual SourceRange getSourceRange() const {
710    if (Init)
711      return Init->getSourceRange();
712    return SourceRange();
713  }
714
715  static bool classof(const Stmt *T) {
716    return T->getStmtClass() == CompoundLiteralExprClass;
717  }
718  static bool classof(const CompoundLiteralExpr *) { return true; }
719
720  // Iterators
721  virtual child_iterator child_begin();
722  virtual child_iterator child_end();
723};
724
725/// ImplicitCastExpr - Allows us to explicitly represent implicit type
726/// conversions. For example: converting T[]->T*, void f()->void (*f)(),
727/// float->double, short->int, etc.
728///
729class ImplicitCastExpr : public Expr {
730  Expr *Op;
731public:
732  ImplicitCastExpr(QualType ty, Expr *op) :
733    Expr(ImplicitCastExprClass, ty), Op(op) {}
734
735  Expr *getSubExpr() { return Op; }
736  const Expr *getSubExpr() const { return Op; }
737
738  virtual SourceRange getSourceRange() const { return Op->getSourceRange(); }
739
740  static bool classof(const Stmt *T) {
741    return T->getStmtClass() == ImplicitCastExprClass;
742  }
743  static bool classof(const ImplicitCastExpr *) { return true; }
744
745  // Iterators
746  virtual child_iterator child_begin();
747  virtual child_iterator child_end();
748
749  virtual void EmitImpl(llvm::Serializer& S) const;
750  static ImplicitCastExpr* CreateImpl(llvm::Deserializer& D);
751};
752
753/// CastExpr - [C99 6.5.4] Cast Operators.
754///
755class CastExpr : public Expr {
756  Expr *Op;
757  SourceLocation Loc; // the location of the left paren
758public:
759  CastExpr(QualType ty, Expr *op, SourceLocation l) :
760    Expr(CastExprClass, ty), Op(op), Loc(l) {}
761
762  SourceLocation getLParenLoc() const { return Loc; }
763
764  Expr *getSubExpr() const { return Op; }
765
766  virtual SourceRange getSourceRange() const {
767    return SourceRange(Loc, getSubExpr()->getSourceRange().getEnd());
768  }
769  static bool classof(const Stmt *T) {
770    return T->getStmtClass() == CastExprClass;
771  }
772  static bool classof(const CastExpr *) { return true; }
773
774  // Iterators
775  virtual child_iterator child_begin();
776  virtual child_iterator child_end();
777
778  virtual void EmitImpl(llvm::Serializer& S) const;
779  static CastExpr* CreateImpl(llvm::Deserializer& D);
780};
781
782class BinaryOperator : public Expr {
783public:
784  enum Opcode {
785    // Operators listed in order of precedence.
786    // Note that additions to this should also update the StmtVisitor class.
787    Mul, Div, Rem,    // [C99 6.5.5] Multiplicative operators.
788    Add, Sub,         // [C99 6.5.6] Additive operators.
789    Shl, Shr,         // [C99 6.5.7] Bitwise shift operators.
790    LT, GT, LE, GE,   // [C99 6.5.8] Relational operators.
791    EQ, NE,           // [C99 6.5.9] Equality operators.
792    And,              // [C99 6.5.10] Bitwise AND operator.
793    Xor,              // [C99 6.5.11] Bitwise XOR operator.
794    Or,               // [C99 6.5.12] Bitwise OR operator.
795    LAnd,             // [C99 6.5.13] Logical AND operator.
796    LOr,              // [C99 6.5.14] Logical OR operator.
797    Assign, MulAssign,// [C99 6.5.16] Assignment operators.
798    DivAssign, RemAssign,
799    AddAssign, SubAssign,
800    ShlAssign, ShrAssign,
801    AndAssign, XorAssign,
802    OrAssign,
803    Comma             // [C99 6.5.17] Comma operator.
804  };
805private:
806  enum { LHS, RHS, END_EXPR };
807  Expr* SubExprs[END_EXPR];
808  Opcode Opc;
809  SourceLocation OpLoc;
810public:
811
812  BinaryOperator(Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy,
813                 SourceLocation opLoc)
814    : Expr(BinaryOperatorClass, ResTy), Opc(opc), OpLoc(opLoc) {
815    SubExprs[LHS] = lhs;
816    SubExprs[RHS] = rhs;
817    assert(!isCompoundAssignmentOp() &&
818           "Use ArithAssignBinaryOperator for compound assignments");
819  }
820
821  SourceLocation getOperatorLoc() const { return OpLoc; }
822  Opcode getOpcode() const { return Opc; }
823  Expr *getLHS() const { return SubExprs[LHS]; }
824  Expr *getRHS() const { return SubExprs[RHS]; }
825  virtual SourceRange getSourceRange() const {
826    return SourceRange(getLHS()->getLocStart(), getRHS()->getLocEnd());
827  }
828
829  /// getOpcodeStr - Turn an Opcode enum value into the punctuation char it
830  /// corresponds to, e.g. "<<=".
831  static const char *getOpcodeStr(Opcode Op);
832
833  /// predicates to categorize the respective opcodes.
834  bool isMultiplicativeOp() const { return Opc >= Mul && Opc <= Rem; }
835  bool isAdditiveOp() const { return Opc == Add || Opc == Sub; }
836  bool isShiftOp() const { return Opc == Shl || Opc == Shr; }
837  bool isBitwiseOp() const { return Opc >= And && Opc <= Or; }
838  bool isRelationalOp() const { return Opc >= LT && Opc <= GE; }
839  bool isEqualityOp() const { return Opc == EQ || Opc == NE; }
840  bool isLogicalOp() const { return Opc == LAnd || Opc == LOr; }
841  bool isAssignmentOp() const { return Opc >= Assign && Opc <= OrAssign; }
842  bool isCompoundAssignmentOp() const { return Opc > Assign && Opc <= OrAssign;}
843  bool isShiftAssignOp() const { return Opc == ShlAssign || Opc == ShrAssign; }
844
845  static bool classof(const Stmt *S) {
846    return S->getStmtClass() == BinaryOperatorClass ||
847           S->getStmtClass() == CompoundAssignOperatorClass;
848  }
849  static bool classof(const BinaryOperator *) { return true; }
850
851  // Iterators
852  virtual child_iterator child_begin();
853  virtual child_iterator child_end();
854
855  virtual void EmitImpl(llvm::Serializer& S) const;
856  static BinaryOperator* CreateImpl(llvm::Deserializer& D);
857
858protected:
859  BinaryOperator(Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy,
860                 SourceLocation oploc, bool dead)
861    : Expr(CompoundAssignOperatorClass, ResTy), Opc(opc), OpLoc(oploc) {
862    SubExprs[LHS] = lhs;
863    SubExprs[RHS] = rhs;
864  }
865};
866
867/// CompoundAssignOperator - For compound assignments (e.g. +=), we keep
868/// track of the type the operation is performed in.  Due to the semantics of
869/// these operators, the operands are promoted, the aritmetic performed, an
870/// implicit conversion back to the result type done, then the assignment takes
871/// place.  This captures the intermediate type which the computation is done
872/// in.
873class CompoundAssignOperator : public BinaryOperator {
874  QualType ComputationType;
875public:
876  CompoundAssignOperator(Expr *lhs, Expr *rhs, Opcode opc,
877                         QualType ResType, QualType CompType,
878                         SourceLocation OpLoc)
879    : BinaryOperator(lhs, rhs, opc, ResType, OpLoc, true),
880      ComputationType(CompType) {
881    assert(isCompoundAssignmentOp() &&
882           "Only should be used for compound assignments");
883  }
884
885  QualType getComputationType() const { return ComputationType; }
886
887  static bool classof(const CompoundAssignOperator *) { return true; }
888  static bool classof(const Stmt *S) {
889    return S->getStmtClass() == CompoundAssignOperatorClass;
890  }
891
892  virtual void EmitImpl(llvm::Serializer& S) const;
893  static CompoundAssignOperator* CreateImpl(llvm::Deserializer& D);
894};
895
896/// ConditionalOperator - The ?: operator.  Note that LHS may be null when the
897/// GNU "missing LHS" extension is in use.
898///
899class ConditionalOperator : public Expr {
900  enum { COND, LHS, RHS, END_EXPR };
901  Expr* SubExprs[END_EXPR]; // Left/Middle/Right hand sides.
902public:
903  ConditionalOperator(Expr *cond, Expr *lhs, Expr *rhs, QualType t)
904    : Expr(ConditionalOperatorClass, t) {
905    SubExprs[COND] = cond;
906    SubExprs[LHS] = lhs;
907    SubExprs[RHS] = rhs;
908  }
909
910  Expr *getCond() const { return SubExprs[COND]; }
911  Expr *getLHS() const { return SubExprs[LHS]; }
912  Expr *getRHS() const { return SubExprs[RHS]; }
913
914  virtual SourceRange getSourceRange() const {
915    return SourceRange(getCond()->getLocStart(), getRHS()->getLocEnd());
916  }
917  static bool classof(const Stmt *T) {
918    return T->getStmtClass() == ConditionalOperatorClass;
919  }
920  static bool classof(const ConditionalOperator *) { return true; }
921
922  // Iterators
923  virtual child_iterator child_begin();
924  virtual child_iterator child_end();
925
926  virtual void EmitImpl(llvm::Serializer& S) const;
927  static ConditionalOperator* CreateImpl(llvm::Deserializer& D);
928};
929
930/// AddrLabelExpr - The GNU address of label extension, representing &&label.
931class AddrLabelExpr : public Expr {
932  SourceLocation AmpAmpLoc, LabelLoc;
933  LabelStmt *Label;
934public:
935  AddrLabelExpr(SourceLocation AALoc, SourceLocation LLoc, LabelStmt *L,
936                QualType t)
937    : Expr(AddrLabelExprClass, t), AmpAmpLoc(AALoc), LabelLoc(LLoc), Label(L) {}
938
939  virtual SourceRange getSourceRange() const {
940    return SourceRange(AmpAmpLoc, LabelLoc);
941  }
942
943  LabelStmt *getLabel() const { return Label; }
944
945  static bool classof(const Stmt *T) {
946    return T->getStmtClass() == AddrLabelExprClass;
947  }
948  static bool classof(const AddrLabelExpr *) { return true; }
949
950  // Iterators
951  virtual child_iterator child_begin();
952  virtual child_iterator child_end();
953
954  virtual void EmitImpl(llvm::Serializer& S) const;
955  static AddrLabelExpr* CreateImpl(llvm::Deserializer& D);
956};
957
958/// StmtExpr - This is the GNU Statement Expression extension: ({int X=4; X;}).
959/// The StmtExpr contains a single CompoundStmt node, which it evaluates and
960/// takes the value of the last subexpression.
961class StmtExpr : public Expr {
962  CompoundStmt *SubStmt;
963  SourceLocation LParenLoc, RParenLoc;
964public:
965  StmtExpr(CompoundStmt *substmt, QualType T,
966           SourceLocation lp, SourceLocation rp) :
967    Expr(StmtExprClass, T), SubStmt(substmt),  LParenLoc(lp), RParenLoc(rp) { }
968
969  CompoundStmt *getSubStmt() { return SubStmt; }
970  const CompoundStmt *getSubStmt() const { return SubStmt; }
971
972  virtual SourceRange getSourceRange() const {
973    return SourceRange(LParenLoc, RParenLoc);
974  }
975
976  static bool classof(const Stmt *T) {
977    return T->getStmtClass() == StmtExprClass;
978  }
979  static bool classof(const StmtExpr *) { return true; }
980
981  // Iterators
982  virtual child_iterator child_begin();
983  virtual child_iterator child_end();
984
985  virtual void EmitImpl(llvm::Serializer& S) const;
986  static StmtExpr* CreateImpl(llvm::Deserializer& D);
987};
988
989/// TypesCompatibleExpr - GNU builtin-in function __builtin_type_compatible_p.
990/// This AST node represents a function that returns 1 if two *types* (not
991/// expressions) are compatible. The result of this built-in function can be
992/// used in integer constant expressions.
993class TypesCompatibleExpr : public Expr {
994  QualType Type1;
995  QualType Type2;
996  SourceLocation BuiltinLoc, RParenLoc;
997public:
998  TypesCompatibleExpr(QualType ReturnType, SourceLocation BLoc,
999                      QualType t1, QualType t2, SourceLocation RP) :
1000    Expr(TypesCompatibleExprClass, ReturnType), Type1(t1), Type2(t2),
1001    BuiltinLoc(BLoc), RParenLoc(RP) {}
1002
1003  QualType getArgType1() const { return Type1; }
1004  QualType getArgType2() const { return Type2; }
1005
1006  virtual SourceRange getSourceRange() const {
1007    return SourceRange(BuiltinLoc, RParenLoc);
1008  }
1009  static bool classof(const Stmt *T) {
1010    return T->getStmtClass() == TypesCompatibleExprClass;
1011  }
1012  static bool classof(const TypesCompatibleExpr *) { return true; }
1013
1014  // Iterators
1015  virtual child_iterator child_begin();
1016  virtual child_iterator child_end();
1017};
1018
1019/// ChooseExpr - GNU builtin-in function __builtin_choose_expr.
1020/// This AST node is similar to the conditional operator (?:) in C, with
1021/// the following exceptions:
1022/// - the test expression much be a constant expression.
1023/// - the expression returned has it's type unaltered by promotion rules.
1024/// - does not evaluate the expression that was not chosen.
1025class ChooseExpr : public Expr {
1026  enum { COND, LHS, RHS, END_EXPR };
1027  Expr* SubExprs[END_EXPR]; // Left/Middle/Right hand sides.
1028  SourceLocation BuiltinLoc, RParenLoc;
1029public:
1030  ChooseExpr(SourceLocation BLoc, Expr *cond, Expr *lhs, Expr *rhs, QualType t,
1031             SourceLocation RP)
1032    : Expr(ChooseExprClass, t),
1033      BuiltinLoc(BLoc), RParenLoc(RP) {
1034      SubExprs[COND] = cond;
1035      SubExprs[LHS] = lhs;
1036      SubExprs[RHS] = rhs;
1037    }
1038
1039  /// isConditionTrue - Return true if the condition is true.  This is always
1040  /// statically knowable for a well-formed choosexpr.
1041  bool isConditionTrue(ASTContext &C) const;
1042
1043  Expr *getCond() const { return SubExprs[COND]; }
1044  Expr *getLHS() const { return SubExprs[LHS]; }
1045  Expr *getRHS() const { return SubExprs[RHS]; }
1046
1047  virtual SourceRange getSourceRange() const {
1048    return SourceRange(BuiltinLoc, RParenLoc);
1049  }
1050  static bool classof(const Stmt *T) {
1051    return T->getStmtClass() == ChooseExprClass;
1052  }
1053  static bool classof(const ChooseExpr *) { return true; }
1054
1055  // Iterators
1056  virtual child_iterator child_begin();
1057  virtual child_iterator child_end();
1058};
1059
1060/// VAArgExpr, used for the builtin function __builtin_va_start.
1061class VAArgExpr : public Expr {
1062  Expr *Val;
1063  SourceLocation BuiltinLoc, RParenLoc;
1064public:
1065  VAArgExpr(SourceLocation BLoc, Expr* e, QualType t, SourceLocation RPLoc)
1066    : Expr(VAArgExprClass, t),
1067      Val(e),
1068      BuiltinLoc(BLoc),
1069      RParenLoc(RPLoc) { }
1070
1071  const Expr *getSubExpr() const { return Val; }
1072  Expr *getSubExpr() { return Val; }
1073  virtual SourceRange getSourceRange() const {
1074    return SourceRange(BuiltinLoc, RParenLoc);
1075  }
1076  static bool classof(const Stmt *T) {
1077    return T->getStmtClass() == VAArgExprClass;
1078  }
1079  static bool classof(const VAArgExpr *) { return true; }
1080
1081  // Iterators
1082  virtual child_iterator child_begin();
1083  virtual child_iterator child_end();
1084};
1085
1086/// InitListExpr, used for struct and array initializers.
1087class InitListExpr : public Expr {
1088  Expr **InitExprs;
1089  unsigned NumInits;
1090  SourceLocation LBraceLoc, RBraceLoc;
1091public:
1092  InitListExpr(SourceLocation lbraceloc, Expr **initexprs, unsigned numinits,
1093               SourceLocation rbraceloc);
1094  ~InitListExpr() {
1095    delete [] InitExprs;
1096  }
1097
1098  unsigned getNumInits() const { return NumInits; }
1099
1100  const Expr* getInit(unsigned Init) const {
1101    assert(Init < NumInits && "Initializer access out of range!");
1102    return InitExprs[Init];
1103  }
1104
1105  Expr* getInit(unsigned Init) {
1106    assert(Init < NumInits && "Initializer access out of range!");
1107    return InitExprs[Init];
1108  }
1109
1110  void setInit(unsigned Init, Expr *expr) {
1111    assert(Init < NumInits && "Initializer access out of range!");
1112    InitExprs[Init] = expr;
1113  }
1114
1115  virtual SourceRange getSourceRange() const {
1116    return SourceRange(LBraceLoc, RBraceLoc);
1117  }
1118  static bool classof(const Stmt *T) {
1119    return T->getStmtClass() == InitListExprClass;
1120  }
1121  static bool classof(const InitListExpr *) { return true; }
1122
1123  // Iterators
1124  virtual child_iterator child_begin();
1125  virtual child_iterator child_end();
1126};
1127
1128/// ObjCStringLiteral, used for Objective-C string literals
1129/// i.e. @"foo".
1130class ObjCStringLiteral : public Expr {
1131  StringLiteral *String;
1132  SourceLocation AtLoc;
1133public:
1134  ObjCStringLiteral(StringLiteral *SL, QualType T, SourceLocation L)
1135    : Expr(ObjCStringLiteralClass, T), String(SL), AtLoc(L) {}
1136
1137  StringLiteral* getString() { return String; }
1138
1139  const StringLiteral* getString() const { return String; }
1140
1141  virtual SourceRange getSourceRange() const {
1142    return SourceRange(AtLoc, String->getLocEnd());
1143  }
1144
1145  static bool classof(const Stmt *T) {
1146    return T->getStmtClass() == ObjCStringLiteralClass;
1147  }
1148  static bool classof(const ObjCStringLiteral *) { return true; }
1149
1150  // Iterators
1151  virtual child_iterator child_begin();
1152  virtual child_iterator child_end();
1153};
1154
1155/// ObjCEncodeExpr, used for @encode in Objective-C.
1156class ObjCEncodeExpr : public Expr {
1157  QualType EncType;
1158  SourceLocation AtLoc, RParenLoc;
1159public:
1160  ObjCEncodeExpr(QualType T, QualType ET,
1161                 SourceLocation at, SourceLocation rp)
1162    : Expr(ObjCEncodeExprClass, T), EncType(ET), AtLoc(at), RParenLoc(rp) {}
1163
1164  SourceLocation getAtLoc() const { return AtLoc; }
1165  SourceLocation getRParenLoc() const { return RParenLoc; }
1166
1167  SourceRange getSourceRange() const { return SourceRange(AtLoc, RParenLoc); }
1168
1169  QualType getEncodedType() const { return EncType; }
1170
1171  static bool classof(const Stmt *T) {
1172    return T->getStmtClass() == ObjCEncodeExprClass;
1173  }
1174  static bool classof(const ObjCEncodeExpr *) { return true; }
1175
1176  // Iterators
1177  virtual child_iterator child_begin();
1178  virtual child_iterator child_end();
1179};
1180
1181/// ObjCSelectorExpr used for @selector in Objective-C.
1182class ObjCSelectorExpr : public Expr {
1183
1184  Selector SelName;
1185
1186  SourceLocation AtLoc, RParenLoc;
1187public:
1188  ObjCSelectorExpr(QualType T, Selector selInfo,
1189                   SourceLocation at, SourceLocation rp)
1190  : Expr(ObjCSelectorExprClass, T), SelName(selInfo),
1191  AtLoc(at), RParenLoc(rp) {}
1192
1193  const Selector &getSelector() const { return SelName; }
1194  Selector &getSelector() { return SelName; }
1195
1196  SourceLocation getAtLoc() const { return AtLoc; }
1197  SourceLocation getRParenLoc() const { return RParenLoc; }
1198  SourceRange getSourceRange() const { return SourceRange(AtLoc, RParenLoc); }
1199
1200  /// getNumArgs - Return the number of actual arguments to this call.
1201  unsigned getNumArgs() const { return SelName.getNumArgs(); }
1202
1203  static bool classof(const Stmt *T) {
1204    return T->getStmtClass() == ObjCSelectorExprClass;
1205  }
1206  static bool classof(const ObjCSelectorExpr *) { return true; }
1207
1208  // Iterators
1209  virtual child_iterator child_begin();
1210  virtual child_iterator child_end();
1211
1212};
1213
1214/// ObjCProtocolExpr used for protocol in Objective-C.
1215class ObjCProtocolExpr : public Expr {
1216
1217  ObjcProtocolDecl *Protocol;
1218
1219  SourceLocation AtLoc, RParenLoc;
1220  public:
1221  ObjCProtocolExpr(QualType T, ObjcProtocolDecl *protocol,
1222                   SourceLocation at, SourceLocation rp)
1223  : Expr(ObjCProtocolExprClass, T), Protocol(protocol),
1224  AtLoc(at), RParenLoc(rp) {}
1225
1226  ObjcProtocolDecl *getProtocol() const { return Protocol; }
1227
1228  SourceLocation getAtLoc() const { return AtLoc; }
1229  SourceLocation getRParenLoc() const { return RParenLoc; }
1230  SourceRange getSourceRange() const { return SourceRange(AtLoc, RParenLoc); }
1231
1232  static bool classof(const Stmt *T) {
1233    return T->getStmtClass() == ObjCProtocolExprClass;
1234  }
1235  static bool classof(const ObjCProtocolExpr *) { return true; }
1236
1237  // Iterators
1238  virtual child_iterator child_begin();
1239  virtual child_iterator child_end();
1240
1241};
1242
1243/// ObjCIvarRefExpr - A reference to an ObjC instance variable.
1244class ObjCIvarRefExpr : public Expr {
1245  class ObjcIvarDecl *D;
1246  SourceLocation Loc;
1247  Expr *Base;
1248  bool IsArrow;      // True if this is "X->F", false if this is "X.F".
1249
1250public:
1251  ObjCIvarRefExpr(ObjcIvarDecl *d, QualType t, SourceLocation l, Expr *base=0,
1252                  bool arrow = false) :
1253    Expr(ObjCIvarRefExprClass, t), D(d), Loc(l), Base(base), IsArrow(arrow)  {}
1254
1255  ObjcIvarDecl *getDecl() { return D; }
1256  const ObjcIvarDecl *getDecl() const { return D; }
1257  virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
1258  Expr *const getBase() const { return Base; }
1259  const bool isArrow() const { return IsArrow; }
1260
1261  static bool classof(const Stmt *T) {
1262    return T->getStmtClass() == ObjCIvarRefExprClass;
1263  }
1264  static bool classof(const ObjCIvarRefExpr *) { return true; }
1265
1266  // Iterators
1267  virtual child_iterator child_begin();
1268  virtual child_iterator child_end();
1269
1270  virtual void EmitImpl(llvm::Serializer& S) const;
1271  static ObjCIvarRefExpr* CreateImpl(llvm::Deserializer& D);
1272};
1273
1274class ObjCMessageExpr : public Expr {
1275  enum { RECEIVER=0, ARGS_START=1 };
1276
1277  Expr **SubExprs;
1278
1279  // A unigue name for this message.
1280  Selector SelName;
1281
1282  // A method prototype for this message (optional).
1283  // FIXME: Since method decls contain the selector, and most messages have a
1284  // prototype, consider devising a scheme for unifying SelName/MethodProto.
1285  ObjcMethodDecl *MethodProto;
1286
1287  IdentifierInfo *ClassName; // optional - 0 for instance messages.
1288
1289  SourceLocation LBracloc, RBracloc;
1290public:
1291  // constructor for class messages.
1292  // FIXME: clsName should be typed to ObjCInterfaceType
1293  ObjCMessageExpr(IdentifierInfo *clsName, Selector selInfo,
1294                  QualType retType, ObjcMethodDecl *methDecl,
1295                  SourceLocation LBrac, SourceLocation RBrac,
1296                  Expr **ArgExprs);
1297  // constructor for instance messages.
1298  ObjCMessageExpr(Expr *receiver, Selector selInfo,
1299                  QualType retType, ObjcMethodDecl *methDecl,
1300                  SourceLocation LBrac, SourceLocation RBrac,
1301                  Expr **ArgExprs);
1302  ~ObjCMessageExpr() {
1303    delete [] SubExprs;
1304  }
1305
1306  const Expr *getReceiver() const { return SubExprs[RECEIVER]; }
1307  Expr *getReceiver() { return SubExprs[RECEIVER]; }
1308
1309  const Selector &getSelector() const { return SelName; }
1310  Selector &getSelector() { return SelName; }
1311
1312  const ObjcMethodDecl *getMethodDecl() const { return MethodProto; }
1313  ObjcMethodDecl *getMethodDecl() { return MethodProto; }
1314
1315  const IdentifierInfo *getClassName() const { return ClassName; }
1316  IdentifierInfo *getClassName() { return ClassName; }
1317
1318  /// getNumArgs - Return the number of actual arguments to this call.
1319  unsigned getNumArgs() const { return SelName.getNumArgs(); }
1320
1321/// getArg - Return the specified argument.
1322  Expr *getArg(unsigned Arg) {
1323    assert(Arg < SelName.getNumArgs() && "Arg access out of range!");
1324    return SubExprs[Arg+ARGS_START];
1325  }
1326  const Expr *getArg(unsigned Arg) const {
1327    assert(Arg < SelName.getNumArgs() && "Arg access out of range!");
1328    return SubExprs[Arg+ARGS_START];
1329  }
1330  /// setArg - Set the specified argument.
1331  void setArg(unsigned Arg, Expr *ArgExpr) {
1332    assert(Arg < SelName.getNumArgs() && "Arg access out of range!");
1333    SubExprs[Arg+ARGS_START] = ArgExpr;
1334  }
1335  SourceRange getSourceRange() const { return SourceRange(LBracloc, RBracloc); }
1336
1337  static bool classof(const Stmt *T) {
1338    return T->getStmtClass() == ObjCMessageExprClass;
1339  }
1340  static bool classof(const ObjCMessageExpr *) { return true; }
1341
1342  // Iterators
1343  virtual child_iterator child_begin();
1344  virtual child_iterator child_end();
1345};
1346
1347}  // end namespace clang
1348
1349#endif
1350