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