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