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