1 //===--- ExprObjC.h - Classes for representing ObjC expressions -*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines the ExprObjC interface and subclasses.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_CLANG_AST_EXPROBJC_H
15 #define LLVM_CLANG_AST_EXPROBJC_H
17 #include "clang/AST/Expr.h"
18 #include "clang/Basic/IdentifierTable.h"
24 class ObjCPropertyDecl;
26 /// ObjCStringLiteral, used for Objective-C string literals
28 class ObjCStringLiteral : public Expr {
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) {}
37 StringLiteral *getString() { return cast<StringLiteral>(String); }
38 const StringLiteral *getString() const { return cast<StringLiteral>(String); }
39 void setString(StringLiteral *S) { String = S; }
41 SourceLocation getAtLoc() const { return AtLoc; }
42 void setAtLoc(SourceLocation L) { AtLoc = L; }
44 virtual SourceRange getSourceRange() const {
45 return SourceRange(AtLoc, String->getLocEnd());
48 static bool classof(const Stmt *T) {
49 return T->getStmtClass() == ObjCStringLiteralClass;
51 static bool classof(const ObjCStringLiteral *) { return true; }
54 virtual child_iterator child_begin();
55 virtual child_iterator child_end();
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;
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) {}
71 explicit ObjCEncodeExpr(EmptyShell Empty) : Expr(ObjCEncodeExprClass, Empty){}
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; }
79 QualType getEncodedType() const { return EncodedType->getType(); }
81 TypeSourceInfo *getEncodedTypeSourceInfo() const { return EncodedType; }
82 void setEncodedTypeSourceInfo(TypeSourceInfo *EncType) {
83 EncodedType = EncType;
86 virtual SourceRange getSourceRange() const {
87 return SourceRange(AtLoc, RParenLoc);
90 static bool classof(const Stmt *T) {
91 return T->getStmtClass() == ObjCEncodeExprClass;
93 static bool classof(const ObjCEncodeExpr *) { return true; }
96 virtual child_iterator child_begin();
97 virtual child_iterator child_end();
100 /// ObjCSelectorExpr used for @selector in Objective-C.
101 class ObjCSelectorExpr : public Expr {
103 SourceLocation AtLoc, RParenLoc;
105 ObjCSelectorExpr(QualType T, Selector selInfo,
106 SourceLocation at, SourceLocation rp)
107 : Expr(ObjCSelectorExprClass, T, false, false), SelName(selInfo), AtLoc(at),
109 explicit ObjCSelectorExpr(EmptyShell Empty)
110 : Expr(ObjCSelectorExprClass, Empty) {}
112 Selector getSelector() const { return SelName; }
113 void setSelector(Selector S) { SelName = S; }
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; }
120 virtual SourceRange getSourceRange() const {
121 return SourceRange(AtLoc, RParenLoc);
124 /// getNumArgs - Return the number of actual arguments to this call.
125 unsigned getNumArgs() const { return SelName.getNumArgs(); }
127 static bool classof(const Stmt *T) {
128 return T->getStmtClass() == ObjCSelectorExprClass;
130 static bool classof(const ObjCSelectorExpr *) { return true; }
133 virtual child_iterator child_begin();
134 virtual child_iterator child_end();
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;
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) {}
152 ObjCProtocolDecl *getProtocol() const { return TheProtocol; }
153 void setProtocol(ObjCProtocolDecl *P) { TheProtocol = P; }
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; }
160 virtual SourceRange getSourceRange() const {
161 return SourceRange(AtLoc, RParenLoc);
164 static bool classof(const Stmt *T) {
165 return T->getStmtClass() == ObjCProtocolExprClass;
167 static bool classof(const ObjCProtocolExpr *) { return true; }
170 virtual child_iterator child_begin();
171 virtual child_iterator child_end();
174 /// ObjCIvarRefExpr - A reference to an ObjC instance variable.
175 class ObjCIvarRefExpr : public Expr {
176 class ObjCIvarDecl *D;
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).
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) {}
191 explicit ObjCIvarRefExpr(EmptyShell Empty)
192 : Expr(ObjCIvarRefExprClass, Empty) {}
194 ObjCIvarDecl *getDecl() { return D; }
195 const ObjCIvarDecl *getDecl() const { return D; }
196 void setDecl(ObjCIvarDecl *d) { D = d; }
198 const Expr *getBase() const { return cast<Expr>(Base); }
199 Expr *getBase() { return cast<Expr>(Base); }
200 void setBase(Expr * base) { Base = base; }
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; }
207 SourceLocation getLocation() const { return Loc; }
208 void setLocation(SourceLocation L) { Loc = L; }
210 virtual SourceRange getSourceRange() const {
211 return isFreeIvar() ? SourceRange(Loc)
212 : SourceRange(getBase()->getLocStart(), Loc);
215 static bool classof(const Stmt *T) {
216 return T->getStmtClass() == ObjCIvarRefExprClass;
218 static bool classof(const ObjCIvarRefExpr *) { return true; }
221 virtual child_iterator child_begin();
222 virtual child_iterator child_end();
225 /// ObjCPropertyRefExpr - A dot-syntax expression to access an ObjC
228 class ObjCPropertyRefExpr : public Expr {
230 ObjCPropertyDecl *AsProperty;
231 SourceLocation IdLoc;
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) {
241 explicit ObjCPropertyRefExpr(EmptyShell Empty)
242 : Expr(ObjCPropertyRefExprClass, Empty) {}
244 ObjCPropertyDecl *getProperty() const { return AsProperty; }
245 void setProperty(ObjCPropertyDecl *D) { AsProperty = D; }
247 const Expr *getBase() const { return cast<Expr>(Base); }
248 Expr *getBase() { return cast<Expr>(Base); }
249 void setBase(Expr *base) { Base = base; }
251 SourceLocation getLocation() const { return IdLoc; }
252 void setLocation(SourceLocation L) { IdLoc = L; }
254 virtual SourceRange getSourceRange() const {
255 return SourceRange(getBase()->getLocStart(), IdLoc);
258 static bool classof(const Stmt *T) {
259 return T->getStmtClass() == ObjCPropertyRefExprClass;
261 static bool classof(const ObjCPropertyRefExpr *) { return true; }
264 virtual child_iterator child_begin();
265 virtual child_iterator child_end();
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:
273 /// @interface Test { }
275 /// - (void)setCrash: (Test*)value;
277 /// void foo(Test *p1, Test *p2)
279 /// p2.crash = p1.crash; // Uses ObjCImplicitSetterGetterRefExpr AST
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.
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;
298 ObjCImplicitSetterGetterRefExpr(ObjCMethodDecl *getter,
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()) {
307 ObjCImplicitSetterGetterRefExpr(ObjCMethodDecl *getter,
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),
315 explicit ObjCImplicitSetterGetterRefExpr(EmptyShell Empty)
316 : Expr(ObjCImplicitSetterGetterRefExprClass, Empty){}
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; }
325 virtual SourceRange getSourceRange() const {
327 return SourceRange(getBase()->getLocStart(), MemberLoc);
328 return SourceRange(ClassLoc, MemberLoc);
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; }
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; }
339 static bool classof(const Stmt *T) {
340 return T->getStmtClass() == ObjCImplicitSetterGetterRefExprClass;
342 static bool classof(const ObjCImplicitSetterGetterRefExpr *) { return true; }
345 virtual child_iterator child_begin();
346 virtual child_iterator child_end();
349 /// \brief An expression that sends a message to the given Objective-C
352 /// The following contains two message send expressions:
355 /// [[NSString alloc] initWithString:@"Hello"]
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:
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.
369 /// All four kinds of message sends are modeled by the ObjCMessageExpr
370 /// class, and can be distinguished via \c getReceiverKind(). Example:
372 class ObjCMessageExpr : public Expr {
373 /// \brief The number of arguments in the message send, not
374 /// including the receiver.
375 unsigned NumArgs : 16;
377 /// \brief The kind of message send this is, which is one of the
378 /// ReceiverKind values.
380 /// We pad this out to a byte to avoid excessive masking and shifting.
383 /// \brief Whether we have an actual method prototype in \c
384 /// SelectorOrMethod.
386 /// When non-zero, we have a method declaration; otherwise, we just
388 unsigned HasMethod : 8;
390 /// \brief When the message expression is a send to 'super', this is
391 /// the location of the 'super' keyword.
392 SourceLocation SuperLoc;
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;
399 /// \brief The source locations of the open and close square
400 /// brackets ('[' and ']', respectively).
401 SourceLocation LBracLoc, RBracLoc;
403 ObjCMessageExpr(EmptyShell Empty, unsigned NumArgs)
404 : Expr(ObjCMessageExprClass, Empty), NumArgs(NumArgs), Kind(0),
405 HasMethod(0), SelectorOrMethod(0) { }
407 ObjCMessageExpr(QualType T,
408 SourceLocation LBracLoc,
409 SourceLocation SuperLoc,
410 bool IsInstanceSuper,
413 ObjCMethodDecl *Method,
414 Expr **Args, unsigned NumArgs,
415 SourceLocation RBracLoc);
416 ObjCMessageExpr(QualType T,
417 SourceLocation LBracLoc,
418 TypeSourceInfo *Receiver,
420 ObjCMethodDecl *Method,
421 Expr **Args, unsigned NumArgs,
422 SourceLocation RBracLoc);
423 ObjCMessageExpr(QualType T,
424 SourceLocation LBracLoc,
427 ObjCMethodDecl *Method,
428 Expr **Args, unsigned NumArgs,
429 SourceLocation RBracLoc);
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));
437 /// \brief Set the pointer value of the message receiver.
438 void setReceiverPointer(void *Value) {
439 *reinterpret_cast<void **>(this + 1) = Value;
443 /// \brief The kind of receiver this message is sending to.
445 /// \brief The receiver is a class.
447 /// \brief The receiver is an object instance.
449 /// \brief The receiver is a superclass.
451 /// \brief The receiver is the instance of the superclass object.
455 /// \brief Create a message send to super.
457 /// \param Context The ASTContext in which this expression will be created.
459 /// \param T The result type of this message.
461 /// \param LBrac The location of the open square bracket '['.
463 /// \param SuperLoc The location of the "super" keyword.
465 /// \param IsInstanceSuper Whether this is an instance "super"
466 /// message (otherwise, it's a class "super" message).
468 /// \param Sel The selector used to determine which method gets called.
470 /// \param Method The Objective-C method against which this message
471 /// send was type-checked. May be NULL.
473 /// \param Args The message send arguments.
475 /// \param NumArgs The number of arguments.
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,
484 ObjCMethodDecl *Method,
485 Expr **Args, unsigned NumArgs,
486 SourceLocation RBracLoc);
488 /// \brief Create a class message send.
490 /// \param Context The ASTContext in which this expression will be created.
492 /// \param T The result type of this message.
494 /// \param LBrac The location of the open square bracket '['.
496 /// \param Receiver The type of the receiver, including
497 /// source-location information.
499 /// \param Sel The selector used to determine which method gets called.
501 /// \param Method The Objective-C method against which this message
502 /// send was type-checked. May be NULL.
504 /// \param Args The message send arguments.
506 /// \param NumArgs The number of arguments.
508 /// \param RBracLoc The location of the closing square bracket ']'.
509 static ObjCMessageExpr *Create(ASTContext &Context, QualType T,
510 SourceLocation LBracLoc,
511 TypeSourceInfo *Receiver,
513 ObjCMethodDecl *Method,
514 Expr **Args, unsigned NumArgs,
515 SourceLocation RBracLoc);
517 /// \brief Create an instance message send.
519 /// \param Context The ASTContext in which this expression will be created.
521 /// \param T The result type of this message.
523 /// \param LBrac The location of the open square bracket '['.
525 /// \param Receiver The expression used to produce the object that
526 /// will receive this message.
528 /// \param Sel The selector used to determine which method gets called.
530 /// \param Method The Objective-C method against which this message
531 /// send was type-checked. May be NULL.
533 /// \param Args The message send arguments.
535 /// \param NumArgs The number of arguments.
537 /// \param RBracLoc The location of the closing square bracket ']'.
538 static ObjCMessageExpr *Create(ASTContext &Context, QualType T,
539 SourceLocation LBracLoc,
542 ObjCMethodDecl *Method,
543 Expr **Args, unsigned NumArgs,
544 SourceLocation RBracLoc);
546 /// \brief Create an empty Objective-C message expression, to be
547 /// filled in by subsequent calls.
549 /// \param Context The context in which the message send will be created.
551 /// \param NumArgs The number of message arguments, not including
553 static ObjCMessageExpr *CreateEmpty(ASTContext &Context, unsigned NumArgs);
555 /// \brief Determine the kind of receiver that this message is being
557 ReceiverKind getReceiverKind() const { return (ReceiverKind)Kind; }
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;
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;
571 /// \brief Returns the receiver of an instance message.
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());
581 const Expr *getInstanceReceiver() const {
582 return const_cast<ObjCMessageExpr*>(this)->getInstanceReceiver();
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) {
589 setReceiverPointer(rec);
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();
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());
609 void setClassReceiver(TypeSourceInfo *TSInfo) {
611 setReceiverPointer(TSInfo);
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)
620 return SourceLocation();
623 /// \brief Retrieve the Objective-C interface to which this message
624 /// is being directed, if known.
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.
632 /// \returns The Objective-C interface if known, otherwise NULL.
633 ObjCInterfaceDecl *getReceiverInterface() const;
635 /// \brief Retrieve the type referred to by 'super'.
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());
647 void setSuper(SourceLocation Loc, QualType T, bool IsInstanceSuper) {
648 Kind = IsInstanceSuper? SuperInstance : SuperClass;
650 setReceiverPointer(T.getAsOpaquePtr());
653 Selector getSelector() const;
655 void setSelector(Selector S) {
657 SelectorOrMethod = reinterpret_cast<uintptr_t>(S.getAsOpaquePtr());
660 const ObjCMethodDecl *getMethodDecl() const {
662 return reinterpret_cast<const ObjCMethodDecl *>(SelectorOrMethod);
667 ObjCMethodDecl *getMethodDecl() {
669 return reinterpret_cast<ObjCMethodDecl *>(SelectorOrMethod);
674 void setMethodDecl(ObjCMethodDecl *MD) {
676 SelectorOrMethod = reinterpret_cast<uintptr_t>(MD);
679 /// \brief Return the number of actual arguments in this message,
680 /// not counting the receiver.
681 unsigned getNumArgs() const { return NumArgs; }
683 /// \brief Retrieve the arguments to this message, not including the
686 return reinterpret_cast<Stmt **>(this + 1) + 1;
688 const Stmt * const *getArgs() const {
689 return reinterpret_cast<const Stmt * const *>(this + 1) + 1;
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]);
697 const Expr *getArg(unsigned Arg) const {
698 assert(Arg < NumArgs && "Arg access out of range!");
699 return cast<Expr>(getArgs()[Arg]);
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;
707 SourceLocation getLeftLoc() const { return LBracLoc; }
708 SourceLocation getRightLoc() const { return RBracLoc; }
710 void setLeftLoc(SourceLocation L) { LBracLoc = L; }
711 void setRightLoc(SourceLocation L) { RBracLoc = L; }
713 void setSourceRange(SourceRange R) {
714 LBracLoc = R.getBegin();
715 RBracLoc = R.getEnd();
717 virtual SourceRange getSourceRange() const {
718 return SourceRange(LBracLoc, RBracLoc);
721 static bool classof(const Stmt *T) {
722 return T->getStmtClass() == ObjCMessageExprClass;
724 static bool classof(const ObjCMessageExpr *) { return true; }
727 virtual child_iterator child_begin();
728 virtual child_iterator child_end();
730 typedef ExprIterator arg_iterator;
731 typedef ConstExprIterator const_arg_iterator;
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; }
739 /// ObjCSuperExpr - Represents the "super" expression in Objective-C,
740 /// which refers to the object on which the current method is executing.
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 {
747 ObjCSuperExpr(SourceLocation L, QualType Type)
748 : Expr(ObjCSuperExprClass, Type, false, false), Loc(L) { }
749 explicit ObjCSuperExpr(EmptyShell Empty) : Expr(ObjCSuperExprClass, Empty) {}
751 SourceLocation getLoc() const { return Loc; }
752 void setLoc(SourceLocation L) { Loc = L; }
754 virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
756 static bool classof(const Stmt *T) {
757 return T->getStmtClass() == ObjCSuperExprClass;
759 static bool classof(const ObjCSuperExpr *) { return true; }
762 virtual child_iterator child_begin();
763 virtual child_iterator child_end();
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.
772 /// IsaMemberLoc - This is the location of the 'isa'.
773 SourceLocation IsaMemberLoc;
775 /// IsArrow - True if this is "X->F", false if this is "X.F".
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) {}
783 /// \brief Build an empty expression.
784 explicit ObjCIsaExpr(EmptyShell Empty) : Expr(ObjCIsaExprClass, Empty) { }
786 void setBase(Expr *E) { Base = E; }
787 Expr *getBase() const { return cast<Expr>(Base); }
789 bool isArrow() const { return IsArrow; }
790 void setArrow(bool A) { IsArrow = A; }
792 /// getMemberLoc - Return the location of the "member", in X->F, it is the
794 SourceLocation getIsaMemberLoc() const { return IsaMemberLoc; }
795 void setIsaMemberLoc(SourceLocation L) { IsaMemberLoc = L; }
797 virtual SourceRange getSourceRange() const {
798 return SourceRange(getBase()->getLocStart(), IsaMemberLoc);
801 virtual SourceLocation getExprLoc() const { return IsaMemberLoc; }
803 static bool classof(const Stmt *T) {
804 return T->getStmtClass() == ObjCIsaExprClass;
806 static bool classof(const ObjCIsaExpr *) { return true; }
809 virtual child_iterator child_begin();
810 virtual child_iterator child_end();
813 } // end namespace clang