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