ExprObjC.h revision f9b9eab747e911ded499924b2616d8712d65efce
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 20namespace 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". 28class ObjCStringLiteral : public Expr { 29 Stmt *String; 30 SourceLocation AtLoc; 31public: 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. 61class ObjCEncodeExpr : public Expr { 62 TypeSourceInfo *EncodedType; 63 SourceLocation AtLoc, RParenLoc; 64public: 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. 101class ObjCSelectorExpr : public Expr { 102 Selector SelName; 103 SourceLocation AtLoc, RParenLoc; 104public: 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*". 141class ObjCProtocolExpr : public Expr { 142 ObjCProtocolDecl *TheProtocol; 143 SourceLocation AtLoc, RParenLoc; 144public: 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. 175class 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 182public: 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/// 228class ObjCPropertyRefExpr : public Expr { 229private: 230 ObjCPropertyDecl *AsProperty; 231 SourceLocation IdLoc; 232 Stmt *Base; 233public: 234 ObjCPropertyRefExpr(ObjCPropertyDecl *PD, QualType t, 235 SourceLocation l, Expr *base) 236 : Expr(ObjCPropertyRefExprClass, t, false, false), AsProperty(PD), 237 IdLoc(l), Base(base) { 238 } 239 240 explicit ObjCPropertyRefExpr(EmptyShell Empty) 241 : Expr(ObjCPropertyRefExprClass, Empty) {} 242 243 ObjCPropertyDecl *getProperty() const { return AsProperty; } 244 void setProperty(ObjCPropertyDecl *D) { AsProperty = D; } 245 246 const Expr *getBase() const { return cast<Expr>(Base); } 247 Expr *getBase() { return cast<Expr>(Base); } 248 void setBase(Expr *base) { Base = base; } 249 250 SourceLocation getLocation() const { return IdLoc; } 251 void setLocation(SourceLocation L) { IdLoc = L; } 252 253 virtual SourceRange getSourceRange() const { 254 return SourceRange(getBase()->getLocStart(), IdLoc); 255 } 256 257 static bool classof(const Stmt *T) { 258 return T->getStmtClass() == ObjCPropertyRefExprClass; 259 } 260 static bool classof(const ObjCPropertyRefExpr *) { return true; } 261 262 // Iterators 263 virtual child_iterator child_begin(); 264 virtual child_iterator child_end(); 265}; 266 267/// ObjCImplicitSetterGetterRefExpr - A dot-syntax expression to access two 268/// methods; one to set a value to an 'ivar' (Setter) and the other to access 269/// an 'ivar' (Setter). 270/// An example for use of this AST is: 271/// @code 272/// @interface Test { } 273/// - (Test *)crash; 274/// - (void)setCrash: (Test*)value; 275/// @end 276/// void foo(Test *p1, Test *p2) 277/// { 278/// p2.crash = p1.crash; // Uses ObjCImplicitSetterGetterRefExpr AST 279/// } 280/// @endcode 281class ObjCImplicitSetterGetterRefExpr : public Expr { 282 /// Setter - Setter method user declared for setting its 'ivar' to a value 283 ObjCMethodDecl *Setter; 284 /// Getter - Getter method user declared for accessing 'ivar' it controls. 285 ObjCMethodDecl *Getter; 286 /// Location of the member in the dot syntax notation. This is location 287 /// of the getter method. 288 SourceLocation MemberLoc; 289 // FIXME: Swizzle these into a single pointer. 290 Stmt *Base; 291 ObjCInterfaceDecl *InterfaceDecl; 292 /// Location of the receiver class in the dot syntax notation 293 /// used to call a class method setter/getter. 294 SourceLocation ClassLoc; 295 296public: 297 ObjCImplicitSetterGetterRefExpr(ObjCMethodDecl *getter, 298 QualType t, 299 ObjCMethodDecl *setter, 300 SourceLocation l, Expr *base) 301 : Expr(ObjCImplicitSetterGetterRefExprClass, t, false, false), 302 Setter(setter), Getter(getter), MemberLoc(l), Base(base), 303 InterfaceDecl(0), ClassLoc(SourceLocation()) { 304 } 305 ObjCImplicitSetterGetterRefExpr(ObjCMethodDecl *getter, 306 QualType t, 307 ObjCMethodDecl *setter, 308 SourceLocation l, ObjCInterfaceDecl *C, SourceLocation CL) 309 : Expr(ObjCImplicitSetterGetterRefExprClass, t, false, false), 310 Setter(setter), Getter(getter), MemberLoc(l), Base(0), InterfaceDecl(C), 311 ClassLoc(CL) { 312 } 313 explicit ObjCImplicitSetterGetterRefExpr(EmptyShell Empty) 314 : Expr(ObjCImplicitSetterGetterRefExprClass, Empty){} 315 316 ObjCMethodDecl *getGetterMethod() const { return Getter; } 317 ObjCMethodDecl *getSetterMethod() const { return Setter; } 318 ObjCInterfaceDecl *getInterfaceDecl() const { return InterfaceDecl; } 319 void setGetterMethod(ObjCMethodDecl *D) { Getter = D; } 320 void setSetterMethod(ObjCMethodDecl *D) { Setter = D; } 321 void setInterfaceDecl(ObjCInterfaceDecl *D) { InterfaceDecl = D; } 322 323 virtual SourceRange getSourceRange() const { 324 if (Base) 325 return SourceRange(getBase()->getLocStart(), MemberLoc); 326 return SourceRange(ClassLoc, MemberLoc); 327 } 328 const Expr *getBase() const { return cast_or_null<Expr>(Base); } 329 Expr *getBase() { return cast_or_null<Expr>(Base); } 330 void setBase(Expr *base) { Base = base; } 331 332 SourceLocation getLocation() const { return MemberLoc; } 333 void setLocation(SourceLocation L) { MemberLoc = L; } 334 SourceLocation getClassLoc() const { return ClassLoc; } 335 void setClassLoc(SourceLocation L) { ClassLoc = L; } 336 337 static bool classof(const Stmt *T) { 338 return T->getStmtClass() == ObjCImplicitSetterGetterRefExprClass; 339 } 340 static bool classof(const ObjCImplicitSetterGetterRefExpr *) { return true; } 341 342 // Iterators 343 virtual child_iterator child_begin(); 344 virtual child_iterator child_end(); 345}; 346 347/// \brief An expression that sends a message to the given Objective-C 348/// object or class. 349/// 350/// The following contains two message send expressions: 351/// 352/// \code 353/// [[NSString alloc] initWithString:@"Hello"] 354/// \endcode 355/// 356/// The innermost message send invokes the "alloc" class method on the 357/// NSString class, while the outermost message send invokes the 358/// "initWithString" instance method on the object returned from 359/// NSString's "alloc". In all, an Objective-C message send can take 360/// on four different (although related) forms: 361/// 362/// 1. Send to an object instance. 363/// 2. Send to a class. 364/// 3. Send to the superclass instance of the current class. 365/// 4. Send to the superclass of the current class. 366/// 367/// All four kinds of message sends are modeled by the ObjCMessageExpr 368/// class, and can be distinguished via \c getReceiverKind(). Example: 369/// 370class ObjCMessageExpr : public Expr { 371 /// \brief The number of arguments in the message send, not 372 /// including the receiver. 373 unsigned NumArgs : 16; 374 375 /// \brief The kind of message send this is, which is one of the 376 /// ReceiverKind values. 377 /// 378 /// We pad this out to a byte to avoid excessive masking and shifting. 379 unsigned Kind : 8; 380 381 /// \brief Whether we have an actual method prototype in \c 382 /// SelectorOrMethod. 383 /// 384 /// When non-zero, we have a method declaration; otherwise, we just 385 /// have a selector. 386 unsigned HasMethod : 8; 387 388 /// \brief When the message expression is a send to 'super', this is 389 /// the location of the 'super' keyword. 390 SourceLocation SuperLoc; 391 392 /// \brief Stores either the selector that this message is sending 393 /// to (when \c HasMethod is zero) or an \c ObjCMethodDecl pointer 394 /// referring to the method that we type-checked against. 395 uintptr_t SelectorOrMethod; 396 397 /// \brief The source locations of the open and close square 398 /// brackets ('[' and ']', respectively). 399 SourceLocation LBracLoc, RBracLoc; 400 401 ObjCMessageExpr(EmptyShell Empty, unsigned NumArgs) 402 : Expr(ObjCMessageExprClass, Empty), NumArgs(NumArgs), Kind(0), 403 HasMethod(0), SelectorOrMethod(0) { } 404 405 ObjCMessageExpr(QualType T, 406 SourceLocation LBracLoc, 407 SourceLocation SuperLoc, 408 bool IsInstanceSuper, 409 QualType SuperType, 410 Selector Sel, 411 ObjCMethodDecl *Method, 412 Expr **Args, unsigned NumArgs, 413 SourceLocation RBracLoc); 414 ObjCMessageExpr(QualType T, 415 SourceLocation LBracLoc, 416 TypeSourceInfo *Receiver, 417 Selector Sel, 418 ObjCMethodDecl *Method, 419 Expr **Args, unsigned NumArgs, 420 SourceLocation RBracLoc); 421 ObjCMessageExpr(QualType T, 422 SourceLocation LBracLoc, 423 Expr *Receiver, 424 Selector Sel, 425 ObjCMethodDecl *Method, 426 Expr **Args, unsigned NumArgs, 427 SourceLocation RBracLoc); 428 429 /// \brief Retrieve the pointer value of the message receiver. 430 void *getReceiverPointer() const { 431 return *const_cast<void **>( 432 reinterpret_cast<const void * const*>(this + 1)); 433 } 434 435 /// \brief Set the pointer value of the message receiver. 436 void setReceiverPointer(void *Value) { 437 *reinterpret_cast<void **>(this + 1) = Value; 438 } 439 440public: 441 /// \brief The kind of receiver this message is sending to. 442 enum ReceiverKind { 443 /// \brief The receiver is a class. 444 Class = 0, 445 /// \brief The receiver is an object instance. 446 Instance, 447 /// \brief The receiver is a superclass. 448 SuperClass, 449 /// \brief The receiver is the instance of the superclass object. 450 SuperInstance 451 }; 452 453 /// \brief Create a message send to super. 454 /// 455 /// \param Context The ASTContext in which this expression will be created. 456 /// 457 /// \param T The result type of this message. 458 /// 459 /// \param LBrac The location of the open square bracket '['. 460 /// 461 /// \param SuperLoc The location of the "super" keyword. 462 /// 463 /// \param IsInstanceSuper Whether this is an instance "super" 464 /// message (otherwise, it's a class "super" message). 465 /// 466 /// \param Sel The selector used to determine which method gets called. 467 /// 468 /// \param Method The Objective-C method against which this message 469 /// send was type-checked. May be NULL. 470 /// 471 /// \param Args The message send arguments. 472 /// 473 /// \param NumArgs The number of arguments. 474 /// 475 /// \param RBracLoc The location of the closing square bracket ']'. 476 static ObjCMessageExpr *Create(ASTContext &Context, QualType T, 477 SourceLocation LBracLoc, 478 SourceLocation SuperLoc, 479 bool IsInstanceSuper, 480 QualType SuperType, 481 Selector Sel, 482 ObjCMethodDecl *Method, 483 Expr **Args, unsigned NumArgs, 484 SourceLocation RBracLoc); 485 486 /// \brief Create a class message send. 487 /// 488 /// \param Context The ASTContext in which this expression will be created. 489 /// 490 /// \param T The result type of this message. 491 /// 492 /// \param LBrac The location of the open square bracket '['. 493 /// 494 /// \param Receiver The type of the receiver, including 495 /// source-location information. 496 /// 497 /// \param Sel The selector used to determine which method gets called. 498 /// 499 /// \param Method The Objective-C method against which this message 500 /// send was type-checked. May be NULL. 501 /// 502 /// \param Args The message send arguments. 503 /// 504 /// \param NumArgs The number of arguments. 505 /// 506 /// \param RBracLoc The location of the closing square bracket ']'. 507 static ObjCMessageExpr *Create(ASTContext &Context, QualType T, 508 SourceLocation LBracLoc, 509 TypeSourceInfo *Receiver, 510 Selector Sel, 511 ObjCMethodDecl *Method, 512 Expr **Args, unsigned NumArgs, 513 SourceLocation RBracLoc); 514 515 /// \brief Create an instance message send. 516 /// 517 /// \param Context The ASTContext in which this expression will be created. 518 /// 519 /// \param T The result type of this message. 520 /// 521 /// \param LBrac The location of the open square bracket '['. 522 /// 523 /// \param Receiver The expression used to produce the object that 524 /// will receive this message. 525 /// 526 /// \param Sel The selector used to determine which method gets called. 527 /// 528 /// \param Method The Objective-C method against which this message 529 /// send was type-checked. May be NULL. 530 /// 531 /// \param Args The message send arguments. 532 /// 533 /// \param NumArgs The number of arguments. 534 /// 535 /// \param RBracLoc The location of the closing square bracket ']'. 536 static ObjCMessageExpr *Create(ASTContext &Context, QualType T, 537 SourceLocation LBracLoc, 538 Expr *Receiver, 539 Selector Sel, 540 ObjCMethodDecl *Method, 541 Expr **Args, unsigned NumArgs, 542 SourceLocation RBracLoc); 543 544 /// \brief Create an empty Objective-C message expression, to be 545 /// filled in by subsequent calls. 546 /// 547 /// \param Context The context in which the message send will be created. 548 /// 549 /// \param NumArgs The number of message arguments, not including 550 /// the receiver. 551 static ObjCMessageExpr *CreateEmpty(ASTContext &Context, unsigned NumArgs); 552 553 /// \brief Determine the kind of receiver that this message is being 554 /// sent to. 555 ReceiverKind getReceiverKind() const { return (ReceiverKind)Kind; } 556 557 /// \brief Determine whether this is an instance message to either a 558 /// computed object or to super. 559 bool isInstanceMessage() const { 560 return getReceiverKind() == Instance || getReceiverKind() == SuperInstance; 561 } 562 563 /// \brief Determine whether this is an class message to either a 564 /// specified class or to super. 565 bool isClassMessage() const { 566 return getReceiverKind() == Class || getReceiverKind() == SuperClass; 567 } 568 569 /// \brief Returns the receiver of an instance message. 570 /// 571 /// \brief Returns the object expression for an instance message, or 572 /// NULL for a message that is not an instance message. 573 Expr *getInstanceReceiver() { 574 if (getReceiverKind() == Instance) 575 return static_cast<Expr *>(getReceiverPointer()); 576 577 return 0; 578 } 579 const Expr *getInstanceReceiver() const { 580 return const_cast<ObjCMessageExpr*>(this)->getInstanceReceiver(); 581 } 582 583 /// \brief Turn this message send into an instance message that 584 /// computes the receiver object with the given expression. 585 void setInstanceReceiver(Expr *rec) { 586 Kind = Instance; 587 setReceiverPointer(rec); 588 } 589 590 /// \brief Returns the type of a class message send, or NULL if the 591 /// message is not a class message. 592 QualType getClassReceiver() const { 593 if (TypeSourceInfo *TSInfo = getClassReceiverTypeInfo()) 594 return TSInfo->getType(); 595 596 return QualType(); 597 } 598 599 /// \brief Returns a type-source information of a class message 600 /// send, or NULL if the message is not a class message. 601 TypeSourceInfo *getClassReceiverTypeInfo() const { 602 if (getReceiverKind() == Class) 603 return reinterpret_cast<TypeSourceInfo *>(getReceiverPointer()); 604 return 0; 605 } 606 607 void setClassReceiver(TypeSourceInfo *TSInfo) { 608 Kind = Class; 609 setReceiverPointer(TSInfo); 610 } 611 612 /// \brief Retrieve the location of the 'super' keyword for a class 613 /// or instance message to 'super', otherwise an invalid source location. 614 SourceLocation getSuperLoc() const { 615 if (getReceiverKind() == SuperInstance || getReceiverKind() == SuperClass) 616 return SuperLoc; 617 618 return SourceLocation(); 619 } 620 621 /// \brief Retrieve the Objective-C interface to which this message 622 /// is being directed, if known. 623 /// 624 /// This routine cross-cuts all of the different kinds of message 625 /// sends to determine what the underlying (statically known) type 626 /// of the receiver will be; use \c getReceiverKind() to determine 627 /// whether the message is a class or an instance method, whether it 628 /// is a send to super or not, etc. 629 /// 630 /// \returns The Objective-C interface if known, otherwise NULL. 631 ObjCInterfaceDecl *getReceiverInterface() const; 632 633 /// \brief Retrieve the type referred to by 'super'. 634 /// 635 /// The returned type will either be an ObjCInterfaceType (for an 636 /// class message to super) or an ObjCObjectPointerType that refers 637 /// to a class (for an instance message to super); 638 QualType getSuperType() const { 639 if (getReceiverKind() == SuperInstance || getReceiverKind() == SuperClass) 640 return QualType::getFromOpaquePtr(getReceiverPointer()); 641 642 return QualType(); 643 } 644 645 void setSuper(SourceLocation Loc, QualType T, bool IsInstanceSuper) { 646 Kind = IsInstanceSuper? SuperInstance : SuperClass; 647 SuperLoc = Loc; 648 setReceiverPointer(T.getAsOpaquePtr()); 649 } 650 651 Selector getSelector() const; 652 653 void setSelector(Selector S) { 654 HasMethod = false; 655 SelectorOrMethod = reinterpret_cast<uintptr_t>(S.getAsOpaquePtr()); 656 } 657 658 const ObjCMethodDecl *getMethodDecl() const { 659 if (HasMethod) 660 return reinterpret_cast<const ObjCMethodDecl *>(SelectorOrMethod); 661 662 return 0; 663 } 664 665 ObjCMethodDecl *getMethodDecl() { 666 if (HasMethod) 667 return reinterpret_cast<ObjCMethodDecl *>(SelectorOrMethod); 668 669 return 0; 670 } 671 672 void setMethodDecl(ObjCMethodDecl *MD) { 673 HasMethod = true; 674 SelectorOrMethod = reinterpret_cast<uintptr_t>(MD); 675 } 676 677 /// \brief Return the number of actual arguments in this message, 678 /// not counting the receiver. 679 unsigned getNumArgs() const { return NumArgs; } 680 681 /// \brief Retrieve the arguments to this message, not including the 682 /// receiver. 683 Stmt **getArgs() { 684 return reinterpret_cast<Stmt **>(this + 1) + 1; 685 } 686 const Stmt * const *getArgs() const { 687 return reinterpret_cast<const Stmt * const *>(this + 1) + 1; 688 } 689 690 /// getArg - Return the specified argument. 691 Expr *getArg(unsigned Arg) { 692 assert(Arg < NumArgs && "Arg access out of range!"); 693 return cast<Expr>(getArgs()[Arg]); 694 } 695 const Expr *getArg(unsigned Arg) const { 696 assert(Arg < NumArgs && "Arg access out of range!"); 697 return cast<Expr>(getArgs()[Arg]); 698 } 699 /// setArg - Set the specified argument. 700 void setArg(unsigned Arg, Expr *ArgExpr) { 701 assert(Arg < NumArgs && "Arg access out of range!"); 702 getArgs()[Arg] = ArgExpr; 703 } 704 705 SourceLocation getLeftLoc() const { return LBracLoc; } 706 SourceLocation getRightLoc() const { return RBracLoc; } 707 708 void setLeftLoc(SourceLocation L) { LBracLoc = L; } 709 void setRightLoc(SourceLocation L) { RBracLoc = L; } 710 711 void setSourceRange(SourceRange R) { 712 LBracLoc = R.getBegin(); 713 RBracLoc = R.getEnd(); 714 } 715 virtual SourceRange getSourceRange() const { 716 return SourceRange(LBracLoc, RBracLoc); 717 } 718 719 static bool classof(const Stmt *T) { 720 return T->getStmtClass() == ObjCMessageExprClass; 721 } 722 static bool classof(const ObjCMessageExpr *) { return true; } 723 724 // Iterators 725 virtual child_iterator child_begin(); 726 virtual child_iterator child_end(); 727 728 typedef ExprIterator arg_iterator; 729 typedef ConstExprIterator const_arg_iterator; 730 731 arg_iterator arg_begin() { return getArgs(); } 732 arg_iterator arg_end() { return getArgs() + NumArgs; } 733 const_arg_iterator arg_begin() const { return getArgs(); } 734 const_arg_iterator arg_end() const { return getArgs() + NumArgs; } 735}; 736 737/// ObjCSuperExpr - Represents the "super" expression in Objective-C, 738/// which refers to the object on which the current method is executing. 739/// 740/// FIXME: This class is intended for removal, once its remaining 741/// clients have been altered to represent "super" internally. 742class ObjCSuperExpr : public Expr { 743 SourceLocation Loc; 744public: 745 ObjCSuperExpr(SourceLocation L, QualType Type) 746 : Expr(ObjCSuperExprClass, Type, false, false), Loc(L) { } 747 explicit ObjCSuperExpr(EmptyShell Empty) : Expr(ObjCSuperExprClass, Empty) {} 748 749 SourceLocation getLoc() const { return Loc; } 750 void setLoc(SourceLocation L) { Loc = L; } 751 752 virtual SourceRange getSourceRange() const { return SourceRange(Loc); } 753 754 static bool classof(const Stmt *T) { 755 return T->getStmtClass() == ObjCSuperExprClass; 756 } 757 static bool classof(const ObjCSuperExpr *) { return true; } 758 759 // Iterators 760 virtual child_iterator child_begin(); 761 virtual child_iterator child_end(); 762}; 763 764/// ObjCIsaExpr - Represent X->isa and X.isa when X is an ObjC 'id' type. 765/// (similiar in spirit to MemberExpr). 766class ObjCIsaExpr : public Expr { 767 /// Base - the expression for the base object pointer. 768 Stmt *Base; 769 770 /// IsaMemberLoc - This is the location of the 'isa'. 771 SourceLocation IsaMemberLoc; 772 773 /// IsArrow - True if this is "X->F", false if this is "X.F". 774 bool IsArrow; 775public: 776 ObjCIsaExpr(Expr *base, bool isarrow, SourceLocation l, QualType ty) 777 : Expr(ObjCIsaExprClass, ty, /*TypeDependent=*/false, 778 base->isValueDependent()), 779 Base(base), IsaMemberLoc(l), IsArrow(isarrow) {} 780 781 /// \brief Build an empty expression. 782 explicit ObjCIsaExpr(EmptyShell Empty) : Expr(ObjCIsaExprClass, Empty) { } 783 784 void setBase(Expr *E) { Base = E; } 785 Expr *getBase() const { return cast<Expr>(Base); } 786 787 bool isArrow() const { return IsArrow; } 788 void setArrow(bool A) { IsArrow = A; } 789 790 /// getMemberLoc - Return the location of the "member", in X->F, it is the 791 /// location of 'F'. 792 SourceLocation getIsaMemberLoc() const { return IsaMemberLoc; } 793 void setIsaMemberLoc(SourceLocation L) { IsaMemberLoc = L; } 794 795 virtual SourceRange getSourceRange() const { 796 return SourceRange(getBase()->getLocStart(), IsaMemberLoc); 797 } 798 799 virtual SourceLocation getExprLoc() const { return IsaMemberLoc; } 800 801 static bool classof(const Stmt *T) { 802 return T->getStmtClass() == ObjCIsaExprClass; 803 } 804 static bool classof(const ObjCIsaExpr *) { return true; } 805 806 // Iterators 807 virtual child_iterator child_begin(); 808 virtual child_iterator child_end(); 809}; 810 811} // end namespace clang 812 813#endif 814