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