]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/clang/include/clang/AST/ExprObjC.h
Merge libpcap-1.1.1.
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / clang / include / clang / AST / ExprObjC.h
1 //===--- ExprObjC.h - Classes for representing ObjC expressions -*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 //  This file defines the ExprObjC interface and subclasses.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef LLVM_CLANG_AST_EXPROBJC_H
15 #define LLVM_CLANG_AST_EXPROBJC_H
16
17 #include "clang/AST/Expr.h"
18 #include "clang/Basic/IdentifierTable.h"
19
20 namespace clang {
21   class IdentifierInfo;
22   class ASTContext;
23   class ObjCMethodDecl;
24   class ObjCPropertyDecl;
25
26 /// ObjCStringLiteral, used for Objective-C string literals
27 /// i.e. @"foo".
28 class ObjCStringLiteral : public Expr {
29   Stmt *String;
30   SourceLocation AtLoc;
31 public:
32   ObjCStringLiteral(StringLiteral *SL, QualType T, SourceLocation L)
33     : Expr(ObjCStringLiteralClass, T, false, false), String(SL), AtLoc(L) {}
34   explicit ObjCStringLiteral(EmptyShell Empty)
35     : Expr(ObjCStringLiteralClass, Empty) {}
36
37   StringLiteral *getString() { return cast<StringLiteral>(String); }
38   const StringLiteral *getString() const { return cast<StringLiteral>(String); }
39   void setString(StringLiteral *S) { String = S; }
40
41   SourceLocation getAtLoc() const { return AtLoc; }
42   void setAtLoc(SourceLocation L) { AtLoc = L; }
43
44   virtual SourceRange getSourceRange() const {
45     return SourceRange(AtLoc, String->getLocEnd());
46   }
47
48   static bool classof(const Stmt *T) {
49     return T->getStmtClass() == ObjCStringLiteralClass;
50   }
51   static bool classof(const ObjCStringLiteral *) { return true; }
52
53   // Iterators
54   virtual child_iterator child_begin();
55   virtual child_iterator child_end();
56 };
57
58 /// ObjCEncodeExpr, used for @encode in Objective-C.  @encode has the same type
59 /// and behavior as StringLiteral except that the string initializer is obtained
60 /// from ASTContext with the encoding type as an argument.
61 class ObjCEncodeExpr : public Expr {
62   TypeSourceInfo *EncodedType;
63   SourceLocation AtLoc, RParenLoc;
64 public:
65   ObjCEncodeExpr(QualType T, TypeSourceInfo *EncodedType,
66                  SourceLocation at, SourceLocation rp)
67     : Expr(ObjCEncodeExprClass, T, EncodedType->getType()->isDependentType(),
68            EncodedType->getType()->isDependentType()), 
69       EncodedType(EncodedType), AtLoc(at), RParenLoc(rp) {}
70
71   explicit ObjCEncodeExpr(EmptyShell Empty) : Expr(ObjCEncodeExprClass, Empty){}
72
73
74   SourceLocation getAtLoc() const { return AtLoc; }
75   void setAtLoc(SourceLocation L) { AtLoc = L; }
76   SourceLocation getRParenLoc() const { return RParenLoc; }
77   void setRParenLoc(SourceLocation L) { RParenLoc = L; }
78
79   QualType getEncodedType() const { return EncodedType->getType(); }
80
81   TypeSourceInfo *getEncodedTypeSourceInfo() const { return EncodedType; }
82   void setEncodedTypeSourceInfo(TypeSourceInfo *EncType) { 
83     EncodedType = EncType; 
84   }
85
86   virtual SourceRange getSourceRange() const {
87     return SourceRange(AtLoc, RParenLoc);
88   }
89
90   static bool classof(const Stmt *T) {
91     return T->getStmtClass() == ObjCEncodeExprClass;
92   }
93   static bool classof(const ObjCEncodeExpr *) { return true; }
94
95   // Iterators
96   virtual child_iterator child_begin();
97   virtual child_iterator child_end();
98 };
99
100 /// ObjCSelectorExpr used for @selector in Objective-C.
101 class ObjCSelectorExpr : public Expr {
102   Selector SelName;
103   SourceLocation AtLoc, RParenLoc;
104 public:
105   ObjCSelectorExpr(QualType T, Selector selInfo,
106                    SourceLocation at, SourceLocation rp)
107   : Expr(ObjCSelectorExprClass, T, false, false), SelName(selInfo), AtLoc(at),
108     RParenLoc(rp){}
109   explicit ObjCSelectorExpr(EmptyShell Empty)
110    : Expr(ObjCSelectorExprClass, Empty) {}
111
112   Selector getSelector() const { return SelName; }
113   void setSelector(Selector S) { SelName = S; }
114
115   SourceLocation getAtLoc() const { return AtLoc; }
116   SourceLocation getRParenLoc() const { return RParenLoc; }
117   void setAtLoc(SourceLocation L) { AtLoc = L; }
118   void setRParenLoc(SourceLocation L) { RParenLoc = L; }
119
120   virtual SourceRange getSourceRange() const {
121     return SourceRange(AtLoc, RParenLoc);
122   }
123
124   /// getNumArgs - Return the number of actual arguments to this call.
125   unsigned getNumArgs() const { return SelName.getNumArgs(); }
126
127   static bool classof(const Stmt *T) {
128     return T->getStmtClass() == ObjCSelectorExprClass;
129   }
130   static bool classof(const ObjCSelectorExpr *) { return true; }
131
132   // Iterators
133   virtual child_iterator child_begin();
134   virtual child_iterator child_end();
135 };
136
137 /// ObjCProtocolExpr used for protocol expression in Objective-C.  This is used
138 /// as: @protocol(foo), as in:
139 ///   obj conformsToProtocol:@protocol(foo)]
140 /// The return type is "Protocol*".
141 class ObjCProtocolExpr : public Expr {
142   ObjCProtocolDecl *TheProtocol;
143   SourceLocation AtLoc, RParenLoc;
144 public:
145   ObjCProtocolExpr(QualType T, ObjCProtocolDecl *protocol,
146                    SourceLocation at, SourceLocation rp)
147   : Expr(ObjCProtocolExprClass, T, false, false), TheProtocol(protocol),
148     AtLoc(at), RParenLoc(rp) {}
149   explicit ObjCProtocolExpr(EmptyShell Empty)
150     : Expr(ObjCProtocolExprClass, Empty) {}
151
152   ObjCProtocolDecl *getProtocol() const { return TheProtocol; }
153   void setProtocol(ObjCProtocolDecl *P) { TheProtocol = P; }
154
155   SourceLocation getAtLoc() const { return AtLoc; }
156   SourceLocation getRParenLoc() const { return RParenLoc; }
157   void setAtLoc(SourceLocation L) { AtLoc = L; }
158   void setRParenLoc(SourceLocation L) { RParenLoc = L; }
159
160   virtual SourceRange getSourceRange() const {
161     return SourceRange(AtLoc, RParenLoc);
162   }
163
164   static bool classof(const Stmt *T) {
165     return T->getStmtClass() == ObjCProtocolExprClass;
166   }
167   static bool classof(const ObjCProtocolExpr *) { return true; }
168
169   // Iterators
170   virtual child_iterator child_begin();
171   virtual child_iterator child_end();
172 };
173
174 /// ObjCIvarRefExpr - A reference to an ObjC instance variable.
175 class ObjCIvarRefExpr : public Expr {
176   class ObjCIvarDecl *D;
177   SourceLocation Loc;
178   Stmt *Base;
179   bool IsArrow:1;      // True if this is "X->F", false if this is "X.F".
180   bool IsFreeIvar:1;   // True if ivar reference has no base (self assumed).
181
182 public:
183   ObjCIvarRefExpr(ObjCIvarDecl *d,
184                   QualType t, SourceLocation l, Expr *base,
185                   bool arrow = false, bool freeIvar = false) :
186     Expr(ObjCIvarRefExprClass, t, /*TypeDependent=*/false,
187          base->isValueDependent()), D(d),
188          Loc(l), Base(base), IsArrow(arrow),
189          IsFreeIvar(freeIvar) {}
190
191   explicit ObjCIvarRefExpr(EmptyShell Empty)
192     : Expr(ObjCIvarRefExprClass, Empty) {}
193
194   ObjCIvarDecl *getDecl() { return D; }
195   const ObjCIvarDecl *getDecl() const { return D; }
196   void setDecl(ObjCIvarDecl *d) { D = d; }
197
198   const Expr *getBase() const { return cast<Expr>(Base); }
199   Expr *getBase() { return cast<Expr>(Base); }
200   void setBase(Expr * base) { Base = base; }
201
202   bool isArrow() const { return IsArrow; }
203   bool isFreeIvar() const { return IsFreeIvar; }
204   void setIsArrow(bool A) { IsArrow = A; }
205   void setIsFreeIvar(bool A) { IsFreeIvar = A; }
206
207   SourceLocation getLocation() const { return Loc; }
208   void setLocation(SourceLocation L) { Loc = L; }
209
210   virtual SourceRange getSourceRange() const {
211     return isFreeIvar() ? SourceRange(Loc)
212     : SourceRange(getBase()->getLocStart(), Loc);
213   }
214
215   static bool classof(const Stmt *T) {
216     return T->getStmtClass() == ObjCIvarRefExprClass;
217   }
218   static bool classof(const ObjCIvarRefExpr *) { return true; }
219
220   // Iterators
221   virtual child_iterator child_begin();
222   virtual child_iterator child_end();
223 };
224
225 /// ObjCPropertyRefExpr - A dot-syntax expression to access an ObjC
226 /// property.
227 ///
228 class ObjCPropertyRefExpr : public Expr {
229 private:
230   ObjCPropertyDecl *AsProperty;
231   SourceLocation IdLoc;
232   Stmt *Base;
233 public:
234   ObjCPropertyRefExpr(ObjCPropertyDecl *PD, QualType t,
235                       SourceLocation l, Expr *base)
236     : Expr(ObjCPropertyRefExprClass, t, /*TypeDependent=*/false, 
237            base->isValueDependent()), 
238       AsProperty(PD), IdLoc(l), Base(base) {
239   }
240
241   explicit ObjCPropertyRefExpr(EmptyShell Empty)
242     : Expr(ObjCPropertyRefExprClass, Empty) {}
243
244   ObjCPropertyDecl *getProperty() const { return AsProperty; }
245   void setProperty(ObjCPropertyDecl *D) { AsProperty = D; }
246
247   const Expr *getBase() const { return cast<Expr>(Base); }
248   Expr *getBase() { return cast<Expr>(Base); }
249   void setBase(Expr *base) { Base = base; }
250
251   SourceLocation getLocation() const { return IdLoc; }
252   void setLocation(SourceLocation L) { IdLoc = L; }
253
254   virtual SourceRange getSourceRange() const {
255     return SourceRange(getBase()->getLocStart(), IdLoc);
256   }
257
258   static bool classof(const Stmt *T) {
259     return T->getStmtClass() == ObjCPropertyRefExprClass;
260   }
261   static bool classof(const ObjCPropertyRefExpr *) { return true; }
262
263   // Iterators
264   virtual child_iterator child_begin();
265   virtual child_iterator child_end();
266 };
267
268 /// ObjCImplicitSetterGetterRefExpr - A dot-syntax expression to access two
269 /// methods; one to set a value to an 'ivar' (Setter) and the other to access
270 /// an 'ivar' (Setter).
271 /// An example for use of this AST is:
272 /// @code
273 ///  @interface Test { }
274 ///  - (Test *)crash;
275 ///  - (void)setCrash: (Test*)value;
276 /// @end
277 /// void  foo(Test *p1, Test *p2)
278 /// {
279 ///    p2.crash  = p1.crash; // Uses ObjCImplicitSetterGetterRefExpr AST
280 /// }
281 /// @endcode
282 class ObjCImplicitSetterGetterRefExpr : public Expr {
283   /// Setter - Setter method user declared for setting its 'ivar' to a value
284   ObjCMethodDecl *Setter;
285   /// Getter - Getter method user declared for accessing 'ivar' it controls.
286   ObjCMethodDecl *Getter;
287   /// Location of the member in the dot syntax notation. This is location
288   /// of the getter method.
289   SourceLocation MemberLoc;
290   // FIXME: Swizzle these into a single pointer.
291   Stmt *Base;
292   ObjCInterfaceDecl *InterfaceDecl;
293   /// Location of the receiver class in the dot syntax notation
294   /// used to call a class method setter/getter.
295   SourceLocation ClassLoc;
296
297 public:
298   ObjCImplicitSetterGetterRefExpr(ObjCMethodDecl *getter,
299                  QualType t,
300                  ObjCMethodDecl *setter,
301                  SourceLocation l, Expr *base)
302     : Expr(ObjCImplicitSetterGetterRefExprClass, t, /*TypeDependent=*/false, 
303            base->isValueDependent()),
304       Setter(setter), Getter(getter), MemberLoc(l), Base(base),
305       InterfaceDecl(0), ClassLoc(SourceLocation()) {
306     }
307   ObjCImplicitSetterGetterRefExpr(ObjCMethodDecl *getter,
308                  QualType t,
309                  ObjCMethodDecl *setter,
310                  SourceLocation l, ObjCInterfaceDecl *C, SourceLocation CL)
311     : Expr(ObjCImplicitSetterGetterRefExprClass, t, false, false),
312       Setter(setter), Getter(getter), MemberLoc(l), Base(0), InterfaceDecl(C),
313       ClassLoc(CL) {
314     }
315   explicit ObjCImplicitSetterGetterRefExpr(EmptyShell Empty)
316            : Expr(ObjCImplicitSetterGetterRefExprClass, Empty){}
317
318   ObjCMethodDecl *getGetterMethod() const { return Getter; }
319   ObjCMethodDecl *getSetterMethod() const { return Setter; }
320   ObjCInterfaceDecl *getInterfaceDecl() const { return InterfaceDecl; }
321   void setGetterMethod(ObjCMethodDecl *D) { Getter = D; }
322   void setSetterMethod(ObjCMethodDecl *D) { Setter = D; }
323   void setInterfaceDecl(ObjCInterfaceDecl *D) { InterfaceDecl = D; }
324
325   virtual SourceRange getSourceRange() const {
326     if (Base)
327       return SourceRange(getBase()->getLocStart(), MemberLoc);
328     return SourceRange(ClassLoc, MemberLoc);
329   }
330   const Expr *getBase() const { return cast_or_null<Expr>(Base); }
331   Expr *getBase() { return cast_or_null<Expr>(Base); }
332   void setBase(Expr *base) { Base = base; }
333
334   SourceLocation getLocation() const { return MemberLoc; }
335   void setLocation(SourceLocation L) { MemberLoc = L; }
336   SourceLocation getClassLoc() const { return ClassLoc; }
337   void setClassLoc(SourceLocation L) { ClassLoc = L; }
338
339   static bool classof(const Stmt *T) {
340     return T->getStmtClass() == ObjCImplicitSetterGetterRefExprClass;
341   }
342   static bool classof(const ObjCImplicitSetterGetterRefExpr *) { return true; }
343
344   // Iterators
345   virtual child_iterator child_begin();
346   virtual child_iterator child_end();
347 };
348
349 /// \brief An expression that sends a message to the given Objective-C
350 /// object or class.
351 ///
352 /// The following contains two message send expressions:
353 ///
354 /// \code
355 ///   [[NSString alloc] initWithString:@"Hello"]
356 /// \endcode
357 ///
358 /// The innermost message send invokes the "alloc" class method on the
359 /// NSString class, while the outermost message send invokes the
360 /// "initWithString" instance method on the object returned from
361 /// NSString's "alloc". In all, an Objective-C message send can take
362 /// on four different (although related) forms:
363 ///
364 ///   1. Send to an object instance.
365 ///   2. Send to a class.
366 ///   3. Send to the superclass instance of the current class.
367 ///   4. Send to the superclass of the current class.
368 ///
369 /// All four kinds of message sends are modeled by the ObjCMessageExpr
370 /// class, and can be distinguished via \c getReceiverKind(). Example:
371 ///
372 class ObjCMessageExpr : public Expr {
373   /// \brief The number of arguments in the message send, not
374   /// including the receiver.
375   unsigned NumArgs : 16;
376
377   /// \brief The kind of message send this is, which is one of the
378   /// ReceiverKind values.
379   ///
380   /// We pad this out to a byte to avoid excessive masking and shifting.
381   unsigned Kind : 8;
382
383   /// \brief Whether we have an actual method prototype in \c
384   /// SelectorOrMethod.
385   ///
386   /// When non-zero, we have a method declaration; otherwise, we just
387   /// have a selector.
388   unsigned HasMethod : 8;
389
390   /// \brief When the message expression is a send to 'super', this is
391   /// the location of the 'super' keyword.
392   SourceLocation SuperLoc;
393
394   /// \brief Stores either the selector that this message is sending
395   /// to (when \c HasMethod is zero) or an \c ObjCMethodDecl pointer
396   /// referring to the method that we type-checked against.
397   uintptr_t SelectorOrMethod;
398
399   /// \brief The source locations of the open and close square
400   /// brackets ('[' and ']', respectively).
401   SourceLocation LBracLoc, RBracLoc;
402
403   ObjCMessageExpr(EmptyShell Empty, unsigned NumArgs)
404     : Expr(ObjCMessageExprClass, Empty), NumArgs(NumArgs), Kind(0), 
405       HasMethod(0), SelectorOrMethod(0) { }
406
407   ObjCMessageExpr(QualType T,
408                   SourceLocation LBracLoc,
409                   SourceLocation SuperLoc,
410                   bool IsInstanceSuper,
411                   QualType SuperType,
412                   Selector Sel, 
413                   ObjCMethodDecl *Method,
414                   Expr **Args, unsigned NumArgs,
415                   SourceLocation RBracLoc);
416   ObjCMessageExpr(QualType T,
417                   SourceLocation LBracLoc,
418                   TypeSourceInfo *Receiver,
419                   Selector Sel, 
420                   ObjCMethodDecl *Method,
421                   Expr **Args, unsigned NumArgs,
422                   SourceLocation RBracLoc);
423   ObjCMessageExpr(QualType T,
424                   SourceLocation LBracLoc,
425                   Expr *Receiver,
426                   Selector Sel, 
427                   ObjCMethodDecl *Method,
428                   Expr **Args, unsigned NumArgs,
429                   SourceLocation RBracLoc);
430
431   /// \brief Retrieve the pointer value of the message receiver.
432   void *getReceiverPointer() const {
433     return *const_cast<void **>(
434                              reinterpret_cast<const void * const*>(this + 1));
435   }
436
437   /// \brief Set the pointer value of the message receiver.
438   void setReceiverPointer(void *Value) {
439     *reinterpret_cast<void **>(this + 1) = Value;
440   }
441
442 public:
443   /// \brief The kind of receiver this message is sending to.
444   enum ReceiverKind {
445     /// \brief The receiver is a class.
446     Class = 0,
447     /// \brief The receiver is an object instance.
448     Instance,
449     /// \brief The receiver is a superclass.
450     SuperClass,
451     /// \brief The receiver is the instance of the superclass object.
452     SuperInstance
453   };
454
455   /// \brief Create a message send to super.
456   ///
457   /// \param Context The ASTContext in which this expression will be created.
458   ///
459   /// \param T The result type of this message.
460   ///
461   /// \param LBrac The location of the open square bracket '['.
462   ///
463   /// \param SuperLoc The location of the "super" keyword.
464   ///
465   /// \param IsInstanceSuper Whether this is an instance "super"
466   /// message (otherwise, it's a class "super" message).
467   ///
468   /// \param Sel The selector used to determine which method gets called.
469   ///
470   /// \param Method The Objective-C method against which this message
471   /// send was type-checked. May be NULL.
472   ///
473   /// \param Args The message send arguments.
474   ///
475   /// \param NumArgs The number of arguments.
476   ///
477   /// \param RBracLoc The location of the closing square bracket ']'.
478   static ObjCMessageExpr *Create(ASTContext &Context, QualType T,
479                                  SourceLocation LBracLoc,
480                                  SourceLocation SuperLoc,
481                                  bool IsInstanceSuper,
482                                  QualType SuperType,
483                                  Selector Sel, 
484                                  ObjCMethodDecl *Method,
485                                  Expr **Args, unsigned NumArgs,
486                                  SourceLocation RBracLoc);
487
488   /// \brief Create a class message send.
489   ///
490   /// \param Context The ASTContext in which this expression will be created.
491   ///
492   /// \param T The result type of this message.
493   ///
494   /// \param LBrac The location of the open square bracket '['.
495   ///
496   /// \param Receiver The type of the receiver, including
497   /// source-location information.
498   ///
499   /// \param Sel The selector used to determine which method gets called.
500   ///
501   /// \param Method The Objective-C method against which this message
502   /// send was type-checked. May be NULL.
503   ///
504   /// \param Args The message send arguments.
505   ///
506   /// \param NumArgs The number of arguments.
507   ///
508   /// \param RBracLoc The location of the closing square bracket ']'.
509   static ObjCMessageExpr *Create(ASTContext &Context, QualType T,
510                                  SourceLocation LBracLoc,
511                                  TypeSourceInfo *Receiver,
512                                  Selector Sel, 
513                                  ObjCMethodDecl *Method,
514                                  Expr **Args, unsigned NumArgs,
515                                  SourceLocation RBracLoc);
516
517   /// \brief Create an instance message send.
518   ///
519   /// \param Context The ASTContext in which this expression will be created.
520   ///
521   /// \param T The result type of this message.
522   ///
523   /// \param LBrac The location of the open square bracket '['.
524   ///
525   /// \param Receiver The expression used to produce the object that
526   /// will receive this message.
527   ///
528   /// \param Sel The selector used to determine which method gets called.
529   ///
530   /// \param Method The Objective-C method against which this message
531   /// send was type-checked. May be NULL.
532   ///
533   /// \param Args The message send arguments.
534   ///
535   /// \param NumArgs The number of arguments.
536   ///
537   /// \param RBracLoc The location of the closing square bracket ']'.
538   static ObjCMessageExpr *Create(ASTContext &Context, QualType T,
539                                  SourceLocation LBracLoc,
540                                  Expr *Receiver,
541                                  Selector Sel, 
542                                  ObjCMethodDecl *Method,
543                                  Expr **Args, unsigned NumArgs,
544                                  SourceLocation RBracLoc);
545
546   /// \brief Create an empty Objective-C message expression, to be
547   /// filled in by subsequent calls.
548   ///
549   /// \param Context The context in which the message send will be created.
550   ///
551   /// \param NumArgs The number of message arguments, not including
552   /// the receiver.
553   static ObjCMessageExpr *CreateEmpty(ASTContext &Context, unsigned NumArgs);
554
555   /// \brief Determine the kind of receiver that this message is being
556   /// sent to.
557   ReceiverKind getReceiverKind() const { return (ReceiverKind)Kind; }
558
559   /// \brief Determine whether this is an instance message to either a
560   /// computed object or to super.
561   bool isInstanceMessage() const {
562     return getReceiverKind() == Instance || getReceiverKind() == SuperInstance;
563   }
564
565   /// \brief Determine whether this is an class message to either a
566   /// specified class or to super.
567   bool isClassMessage() const {
568     return getReceiverKind() == Class || getReceiverKind() == SuperClass;
569   }
570
571   /// \brief Returns the receiver of an instance message.
572   ///
573   /// \brief Returns the object expression for an instance message, or
574   /// NULL for a message that is not an instance message.
575   Expr *getInstanceReceiver() {
576     if (getReceiverKind() == Instance)
577       return static_cast<Expr *>(getReceiverPointer());
578
579     return 0;
580   }
581   const Expr *getInstanceReceiver() const {
582     return const_cast<ObjCMessageExpr*>(this)->getInstanceReceiver();
583   }
584
585   /// \brief Turn this message send into an instance message that
586   /// computes the receiver object with the given expression.
587   void setInstanceReceiver(Expr *rec) { 
588     Kind = Instance;
589     setReceiverPointer(rec);
590   }
591   
592   /// \brief Returns the type of a class message send, or NULL if the
593   /// message is not a class message.
594   QualType getClassReceiver() const { 
595     if (TypeSourceInfo *TSInfo = getClassReceiverTypeInfo())
596       return TSInfo->getType();
597
598     return QualType();
599   }
600
601   /// \brief Returns a type-source information of a class message
602   /// send, or NULL if the message is not a class message.
603   TypeSourceInfo *getClassReceiverTypeInfo() const {
604     if (getReceiverKind() == Class)
605       return reinterpret_cast<TypeSourceInfo *>(getReceiverPointer());
606     return 0;
607   }
608
609   void setClassReceiver(TypeSourceInfo *TSInfo) {
610     Kind = Class;
611     setReceiverPointer(TSInfo);
612   }
613
614   /// \brief Retrieve the location of the 'super' keyword for a class
615   /// or instance message to 'super', otherwise an invalid source location.
616   SourceLocation getSuperLoc() const { 
617     if (getReceiverKind() == SuperInstance || getReceiverKind() == SuperClass)
618       return SuperLoc;
619
620     return SourceLocation();
621   }
622
623   /// \brief Retrieve the Objective-C interface to which this message
624   /// is being directed, if known.
625   ///
626   /// This routine cross-cuts all of the different kinds of message
627   /// sends to determine what the underlying (statically known) type
628   /// of the receiver will be; use \c getReceiverKind() to determine
629   /// whether the message is a class or an instance method, whether it
630   /// is a send to super or not, etc.
631   ///
632   /// \returns The Objective-C interface if known, otherwise NULL.
633   ObjCInterfaceDecl *getReceiverInterface() const;
634
635   /// \brief Retrieve the type referred to by 'super'. 
636   ///
637   /// The returned type will either be an ObjCInterfaceType (for an
638   /// class message to super) or an ObjCObjectPointerType that refers
639   /// to a class (for an instance message to super);
640   QualType getSuperType() const {
641     if (getReceiverKind() == SuperInstance || getReceiverKind() == SuperClass)
642       return QualType::getFromOpaquePtr(getReceiverPointer());
643
644     return QualType();
645   }
646
647   void setSuper(SourceLocation Loc, QualType T, bool IsInstanceSuper) {
648     Kind = IsInstanceSuper? SuperInstance : SuperClass;
649     SuperLoc = Loc;
650     setReceiverPointer(T.getAsOpaquePtr());
651   }
652
653   Selector getSelector() const;
654
655   void setSelector(Selector S) { 
656     HasMethod = false;
657     SelectorOrMethod = reinterpret_cast<uintptr_t>(S.getAsOpaquePtr());
658   }
659
660   const ObjCMethodDecl *getMethodDecl() const { 
661     if (HasMethod)
662       return reinterpret_cast<const ObjCMethodDecl *>(SelectorOrMethod);
663
664     return 0;
665   }
666
667   ObjCMethodDecl *getMethodDecl() { 
668     if (HasMethod)
669       return reinterpret_cast<ObjCMethodDecl *>(SelectorOrMethod);
670
671     return 0;
672   }
673
674   void setMethodDecl(ObjCMethodDecl *MD) { 
675     HasMethod = true;
676     SelectorOrMethod = reinterpret_cast<uintptr_t>(MD);
677   }
678
679   /// \brief Return the number of actual arguments in this message,
680   /// not counting the receiver.
681   unsigned getNumArgs() const { return NumArgs; }
682
683   /// \brief Retrieve the arguments to this message, not including the
684   /// receiver.
685   Stmt **getArgs() {
686     return reinterpret_cast<Stmt **>(this + 1) + 1;
687   }
688   const Stmt * const *getArgs() const {
689     return reinterpret_cast<const Stmt * const *>(this + 1) + 1;
690   }
691
692   /// getArg - Return the specified argument.
693   Expr *getArg(unsigned Arg) {
694     assert(Arg < NumArgs && "Arg access out of range!");
695     return cast<Expr>(getArgs()[Arg]);
696   }
697   const Expr *getArg(unsigned Arg) const {
698     assert(Arg < NumArgs && "Arg access out of range!");
699     return cast<Expr>(getArgs()[Arg]);
700   }
701   /// setArg - Set the specified argument.
702   void setArg(unsigned Arg, Expr *ArgExpr) {
703     assert(Arg < NumArgs && "Arg access out of range!");
704     getArgs()[Arg] = ArgExpr;
705   }
706
707   SourceLocation getLeftLoc() const { return LBracLoc; }
708   SourceLocation getRightLoc() const { return RBracLoc; }
709
710   void setLeftLoc(SourceLocation L) { LBracLoc = L; }
711   void setRightLoc(SourceLocation L) { RBracLoc = L; }
712
713   void setSourceRange(SourceRange R) {
714     LBracLoc = R.getBegin();
715     RBracLoc = R.getEnd();
716   }
717   virtual SourceRange getSourceRange() const {
718     return SourceRange(LBracLoc, RBracLoc);
719   }
720
721   static bool classof(const Stmt *T) {
722     return T->getStmtClass() == ObjCMessageExprClass;
723   }
724   static bool classof(const ObjCMessageExpr *) { return true; }
725
726   // Iterators
727   virtual child_iterator child_begin();
728   virtual child_iterator child_end();
729
730   typedef ExprIterator arg_iterator;
731   typedef ConstExprIterator const_arg_iterator;
732
733   arg_iterator arg_begin() { return getArgs(); }
734   arg_iterator arg_end()   { return getArgs() + NumArgs; }
735   const_arg_iterator arg_begin() const { return getArgs(); }
736   const_arg_iterator arg_end() const { return getArgs() + NumArgs; }
737 };
738
739 /// ObjCSuperExpr - Represents the "super" expression in Objective-C,
740 /// which refers to the object on which the current method is executing.
741 ///
742 /// FIXME: This class is intended for removal, once its remaining
743 /// clients have been altered to represent "super" internally.
744 class ObjCSuperExpr : public Expr {
745   SourceLocation Loc;
746 public:
747   ObjCSuperExpr(SourceLocation L, QualType Type)
748     : Expr(ObjCSuperExprClass, Type, false, false), Loc(L) { }
749   explicit ObjCSuperExpr(EmptyShell Empty) : Expr(ObjCSuperExprClass, Empty) {}
750
751   SourceLocation getLoc() const { return Loc; }
752   void setLoc(SourceLocation L) { Loc = L; }
753
754   virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
755
756   static bool classof(const Stmt *T) {
757     return T->getStmtClass() == ObjCSuperExprClass;
758   }
759   static bool classof(const ObjCSuperExpr *) { return true; }
760
761   // Iterators
762   virtual child_iterator child_begin();
763   virtual child_iterator child_end();
764 };
765
766 /// ObjCIsaExpr - Represent X->isa and X.isa when X is an ObjC 'id' type.
767 /// (similiar in spirit to MemberExpr).
768 class ObjCIsaExpr : public Expr {
769   /// Base - the expression for the base object pointer.
770   Stmt *Base;
771
772   /// IsaMemberLoc - This is the location of the 'isa'.
773   SourceLocation IsaMemberLoc;
774
775   /// IsArrow - True if this is "X->F", false if this is "X.F".
776   bool IsArrow;
777 public:
778   ObjCIsaExpr(Expr *base, bool isarrow, SourceLocation l, QualType ty)
779     : Expr(ObjCIsaExprClass, ty, /*TypeDependent=*/false, 
780            base->isValueDependent()),
781       Base(base), IsaMemberLoc(l), IsArrow(isarrow) {}
782
783   /// \brief Build an empty expression.
784   explicit ObjCIsaExpr(EmptyShell Empty) : Expr(ObjCIsaExprClass, Empty) { }
785
786   void setBase(Expr *E) { Base = E; }
787   Expr *getBase() const { return cast<Expr>(Base); }
788
789   bool isArrow() const { return IsArrow; }
790   void setArrow(bool A) { IsArrow = A; }
791
792   /// getMemberLoc - Return the location of the "member", in X->F, it is the
793   /// location of 'F'.
794   SourceLocation getIsaMemberLoc() const { return IsaMemberLoc; }
795   void setIsaMemberLoc(SourceLocation L) { IsaMemberLoc = L; }
796
797   virtual SourceRange getSourceRange() const {
798     return SourceRange(getBase()->getLocStart(), IsaMemberLoc);
799   }
800
801   virtual SourceLocation getExprLoc() const { return IsaMemberLoc; }
802
803   static bool classof(const Stmt *T) {
804     return T->getStmtClass() == ObjCIsaExprClass;
805   }
806   static bool classof(const ObjCIsaExpr *) { return true; }
807
808   // Iterators
809   virtual child_iterator child_begin();
810   virtual child_iterator child_end();
811 };
812
813 }  // end namespace clang
814
815 #endif