clang 23.0.0git
ExprObjC.h
Go to the documentation of this file.
1//===- ExprObjC.h - Classes for representing ObjC expressions ---*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file defines the ExprObjC interface and subclasses.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_CLANG_AST_EXPROBJC_H
14#define LLVM_CLANG_AST_EXPROBJC_H
15
16#include "clang/AST/Attr.h"
18#include "clang/AST/Decl.h"
19#include "clang/AST/DeclObjC.h"
21#include "clang/AST/Expr.h"
24#include "clang/AST/Stmt.h"
25#include "clang/AST/Type.h"
27#include "clang/Basic/LLVM.h"
30#include "llvm/ADT/ArrayRef.h"
31#include "llvm/ADT/PointerIntPair.h"
32#include "llvm/ADT/PointerUnion.h"
33#include "llvm/ADT/StringRef.h"
34#include "llvm/ADT/iterator_range.h"
35#include "llvm/Support/Casting.h"
36#include "llvm/Support/Compiler.h"
37#include "llvm/Support/TrailingObjects.h"
38#include "llvm/Support/VersionTuple.h"
39#include "llvm/Support/type_traits.h"
40#include <cassert>
41#include <cstddef>
42#include <cstdint>
43#include <optional>
44
45namespace clang {
46
47class ASTContext;
49
50/// Base class for Objective-C object literals (@"...", @42, @[], @{}).
51class ObjCObjectLiteral : public Expr {
52protected:
54 bool ExpressibleAsConstantInitializer, ExprValueKind VK,
56 : Expr(SC, T, VK, OK) {
57 setDependence(ExprDependence::None);
58 ObjCObjectLiteralBits.IsExpressibleAsConstantInitializer =
59 ExpressibleAsConstantInitializer;
60 }
63
64public:
69 return ObjCObjectLiteralBits.IsExpressibleAsConstantInitializer;
70 }
71 void
72 setExpressibleAsConstantInitializer(bool ExpressibleAsConstantInitializer) {
73 ObjCObjectLiteralBits.IsExpressibleAsConstantInitializer =
74 ExpressibleAsConstantInitializer;
75 }
76 static bool classof(const Stmt *T) {
77 return T->getStmtClass() >= firstObjCObjectLiteralConstant &&
78 T->getStmtClass() <= lastObjCObjectLiteralConstant;
79 }
80};
81
82/// ObjCStringLiteral, used for Objective-C string literals
83/// i.e. @"foo".
85 Stmt *String;
86 SourceLocation AtLoc;
87
88public:
90 : ObjCObjectLiteral(ObjCStringLiteralClass, T, true, VK_PRValue,
92 String(SL), AtLoc(L) {}
94 : ObjCObjectLiteral(ObjCStringLiteralClass, Empty) {}
95
97 const StringLiteral *getString() const { return cast<StringLiteral>(String); }
98 void setString(StringLiteral *S) { String = S; }
99
100 SourceLocation getAtLoc() const { return AtLoc; }
101 void setAtLoc(SourceLocation L) { AtLoc = L; }
102
103 SourceLocation getBeginLoc() const LLVM_READONLY { return AtLoc; }
104 SourceLocation getEndLoc() const LLVM_READONLY { return String->getEndLoc(); }
105
106 // Iterators
107 child_range children() { return child_range(&String, &String+1); }
108
110 return const_child_range(&String, &String + 1);
111 }
112
113 static bool classof(const Stmt *T) {
114 return T->getStmtClass() == ObjCStringLiteralClass;
115 }
116};
117
118/// ObjCBoolLiteralExpr - Objective-C Boolean Literal.
119class ObjCBoolLiteralExpr : public Expr {
120 bool Value;
121 SourceLocation Loc;
122
123public:
125 : Expr(ObjCBoolLiteralExprClass, Ty, VK_PRValue, OK_Ordinary), Value(val),
126 Loc(l) {
127 setDependence(ExprDependence::None);
128 }
130 : Expr(ObjCBoolLiteralExprClass, Empty) {}
131
132 bool getValue() const { return Value; }
133 void setValue(bool V) { Value = V; }
134
135 SourceLocation getBeginLoc() const LLVM_READONLY { return Loc; }
136 SourceLocation getEndLoc() const LLVM_READONLY { return Loc; }
137
138 SourceLocation getLocation() const { return Loc; }
139 void setLocation(SourceLocation L) { Loc = L; }
140
141 // Iterators
145
149
150 static bool classof(const Stmt *T) {
151 return T->getStmtClass() == ObjCBoolLiteralExprClass;
152 }
153};
154
155/// ObjCBoxedExpr - used for generalized expression boxing.
156/// as in: @(strdup("hello world")), @(random()) or @(view.frame)
157/// Also used for boxing non-parenthesized numeric literals;
158/// as in: @42 or \@true (c++/objc++) or \@__objc_yes (c/objc).
159class ObjCBoxedExpr final : public ObjCObjectLiteral {
160 Stmt *SubExpr;
161 ObjCMethodDecl *BoxingMethod;
162 SourceRange Range;
163
164public:
165 friend class ASTStmtReader;
166
168 bool ExpressibleAsConstantInitializer, SourceRange R)
169 : ObjCObjectLiteral(ObjCBoxedExprClass, T,
170 ExpressibleAsConstantInitializer, VK_PRValue,
172 SubExpr(E), BoxingMethod(Method), Range(R) {
174 }
176 : ObjCObjectLiteral(ObjCBoxedExprClass, Empty) {}
177
178 Expr *getSubExpr() { return cast<Expr>(SubExpr); }
179 const Expr *getSubExpr() const { return cast<Expr>(SubExpr); }
180
182 return BoxingMethod;
183 }
184
185 SourceLocation getAtLoc() const { return Range.getBegin(); }
186
187 SourceLocation getBeginLoc() const LLVM_READONLY { return Range.getBegin(); }
188 SourceLocation getEndLoc() const LLVM_READONLY { return Range.getEnd(); }
189
190 SourceRange getSourceRange() const LLVM_READONLY {
191 return Range;
192 }
193
194 // Iterators
195 child_range children() { return child_range(&SubExpr, &SubExpr+1); }
196
198 return const_child_range(&SubExpr, &SubExpr + 1);
199 }
200
202
204 return reinterpret_cast<Stmt const * const*>(&SubExpr);
205 }
206
208 return reinterpret_cast<Stmt const * const*>(&SubExpr + 1);
209 }
210
211 static bool classof(const Stmt *T) {
212 return T->getStmtClass() == ObjCBoxedExprClass;
213 }
214};
215
216/// ObjCArrayLiteral - used for objective-c array containers; as in:
217/// @[@"Hello", NSApp, [NSNumber numberWithInt:42]];
218class ObjCArrayLiteral final
219 : public ObjCObjectLiteral,
220 private llvm::TrailingObjects<ObjCArrayLiteral, Expr *> {
221 unsigned NumElements;
222 SourceRange Range;
223 ObjCMethodDecl *ArrayWithObjectsMethod;
224
225 ObjCArrayLiteral(ArrayRef<Expr *> Elements, QualType T,
227 bool ExpressibleAsConstantInitializer, SourceRange SR);
228
229 explicit ObjCArrayLiteral(EmptyShell Empty, unsigned NumElements)
230 : ObjCObjectLiteral(ObjCArrayLiteralClass, Empty),
231 NumElements(NumElements) {}
232
233public:
234 friend class ASTStmtReader;
236
237 static ObjCArrayLiteral *Create(const ASTContext &C,
238 ArrayRef<Expr *> Elements, QualType T,
240 bool ExpressibleAsConstantInitializer,
241 SourceRange SR);
242
243 static ObjCArrayLiteral *CreateEmpty(const ASTContext &C,
244 unsigned NumElements);
245
246 SourceLocation getBeginLoc() const LLVM_READONLY { return Range.getBegin(); }
247 SourceLocation getEndLoc() const LLVM_READONLY { return Range.getEnd(); }
248 SourceRange getSourceRange() const LLVM_READONLY { return Range; }
249
250 /// Retrieve elements of array of literals.
251 Expr **getElements() { return getTrailingObjects(); }
252
253 /// Retrieve elements of array of literals.
254 const Expr *const *getElements() const { return getTrailingObjects(); }
255
256 /// getNumElements - Return number of elements of objective-c array literal.
257 unsigned getNumElements() const { return NumElements; }
258
259 /// elements - Return the elements of the array literal.
261 return {getElements(), NumElements};
262 }
263
264 /// getElement - Return the Element at the specified index.
265 Expr *getElement(unsigned Index) {
266 assert((Index < NumElements) && "Arg access out of range!");
267 return getElements()[Index];
268 }
269 const Expr *getElement(unsigned Index) const {
270 assert((Index < NumElements) && "Arg access out of range!");
271 return getElements()[Index];
272 }
273
275 return ArrayWithObjectsMethod;
276 }
277
278 // Iterators
280 return child_range(reinterpret_cast<Stmt **>(getElements()),
281 reinterpret_cast<Stmt **>(getElements()) + NumElements);
282 }
283
285 return const_cast<ObjCArrayLiteral *>(this)->children();
286 }
287
288 static bool classof(const Stmt *T) {
289 return T->getStmtClass() == ObjCArrayLiteralClass;
290 }
291};
292
293/// An element in an Objective-C dictionary literal.
294///
296 /// The key for the dictionary element.
298
299 /// The value of the dictionary element.
301
302 /// The location of the ellipsis, if this is a pack expansion.
304
305 /// The number of elements this pack expansion will expand to, if
306 /// this is a pack expansion and is known.
308
309 /// Determines whether this dictionary element is a pack expansion.
310 bool isPackExpansion() const { return EllipsisLoc.isValid(); }
311};
312
313} // namespace clang
314
315namespace clang {
316
317/// Internal struct for storing Key/value pair.
322
323/// Internal struct to describes an element that is a pack
324/// expansion, used if any of the elements in the dictionary literal
325/// are pack expansions.
327 /// The location of the ellipsis, if this element is a pack
328 /// expansion.
330
331 /// If non-zero, the number of elements that this pack
332 /// expansion will expand to (+1).
334};
335
336/// ObjCDictionaryLiteral - AST node to represent objective-c dictionary
337/// literals; as in: @{@"name" : NSUserName(), @"date" : [NSDate date] };
338class ObjCDictionaryLiteral final
339 : public ObjCObjectLiteral,
340 private llvm::TrailingObjects<ObjCDictionaryLiteral,
341 ObjCDictionaryLiteral_KeyValuePair,
342 ObjCDictionaryLiteral_ExpansionData> {
343 /// The number of elements in this dictionary literal.
344 unsigned NumElements : 31;
345
346 /// Determine whether this dictionary literal has any pack expansions.
347 ///
348 /// If the dictionary literal has pack expansions, then there will
349 /// be an array of pack expansion data following the array of
350 /// key/value pairs, which provide the locations of the ellipses (if
351 /// any) and number of elements in the expansion (if known). If
352 /// there are no pack expansions, we optimize away this storage.
353 LLVM_PREFERRED_TYPE(bool)
354 unsigned HasPackExpansions : 1;
355
356 SourceRange Range;
357 ObjCMethodDecl *DictWithObjectsMethod;
358
359 using KeyValuePair = ObjCDictionaryLiteral_KeyValuePair;
360 using ExpansionData = ObjCDictionaryLiteral_ExpansionData;
361
362 ObjCDictionaryLiteral(ArrayRef<ObjCDictionaryElement> VK,
363 bool HasPackExpansions, QualType T,
365 bool ExpressibleAsConstantInitializer, SourceRange SR);
366
367 explicit ObjCDictionaryLiteral(EmptyShell Empty, unsigned NumElements,
368 bool HasPackExpansions)
369 : ObjCObjectLiteral(ObjCDictionaryLiteralClass, Empty),
370 NumElements(NumElements), HasPackExpansions(HasPackExpansions) {}
371
372 size_t numTrailingObjects(OverloadToken<KeyValuePair>) const {
373 return NumElements;
374 }
375
376public:
377 friend class ASTStmtReader;
378 friend class ASTStmtWriter;
380
381 static ObjCDictionaryLiteral *
383 bool HasPackExpansions, QualType T, ObjCMethodDecl *Method,
384 bool ExpressibleAsConstantInitializer, SourceRange SR);
385
386 static ObjCDictionaryLiteral *CreateEmpty(const ASTContext &C,
387 unsigned NumElements,
388 bool HasPackExpansions);
389
390 /// getNumElements - Return number of elements of objective-c dictionary
391 /// literal.
392 unsigned getNumElements() const { return NumElements; }
393
395 assert((Index < NumElements) && "Arg access out of range!");
396 const KeyValuePair &KV = getTrailingObjects<KeyValuePair>()[Index];
398 std::nullopt};
399 if (HasPackExpansions) {
400 const ExpansionData &Expansion =
401 getTrailingObjects<ExpansionData>()[Index];
402 Result.EllipsisLoc = Expansion.EllipsisLoc;
403 if (Expansion.NumExpansionsPlusOne > 0)
404 Result.NumExpansions = Expansion.NumExpansionsPlusOne - 1;
405 }
406 return Result;
407 }
408
410 return DictWithObjectsMethod;
411 }
412
413 SourceLocation getBeginLoc() const LLVM_READONLY { return Range.getBegin(); }
414 SourceLocation getEndLoc() const LLVM_READONLY { return Range.getEnd(); }
415 SourceRange getSourceRange() const LLVM_READONLY { return Range; }
416
417 // Iterators
419 // Note: we're taking advantage of the layout of the KeyValuePair struct
420 // here. If that struct changes, this code will need to change as well.
421 static_assert(sizeof(KeyValuePair) == sizeof(Stmt *) * 2,
422 "KeyValuePair is expected size");
423 return child_range(
424 reinterpret_cast<Stmt **>(getTrailingObjects<KeyValuePair>()),
425 reinterpret_cast<Stmt **>(getTrailingObjects<KeyValuePair>()) +
426 NumElements * 2);
427 }
428
430 return const_cast<ObjCDictionaryLiteral *>(this)->children();
431 }
432
433 static bool classof(const Stmt *T) {
434 return T->getStmtClass() == ObjCDictionaryLiteralClass;
435 }
436};
437
438/// ObjCEncodeExpr, used for \@encode in Objective-C. \@encode has the same
439/// type and behavior as StringLiteral except that the string initializer is
440/// obtained from ASTContext with the encoding type as an argument.
441class ObjCEncodeExpr : public Expr {
442 TypeSourceInfo *EncodedType;
443 SourceLocation AtLoc, RParenLoc;
444
445public:
448 : Expr(ObjCEncodeExprClass, T, VK_LValue, OK_Ordinary),
449 EncodedType(EncodedType), AtLoc(at), RParenLoc(rp) {
451 }
452
453 explicit ObjCEncodeExpr(EmptyShell Empty) : Expr(ObjCEncodeExprClass, Empty){}
454
455 SourceLocation getAtLoc() const { return AtLoc; }
456 void setAtLoc(SourceLocation L) { AtLoc = L; }
457 SourceLocation getRParenLoc() const { return RParenLoc; }
458 void setRParenLoc(SourceLocation L) { RParenLoc = L; }
459
460 QualType getEncodedType() const { return EncodedType->getType(); }
461
462 TypeSourceInfo *getEncodedTypeSourceInfo() const { return EncodedType; }
463
465 EncodedType = EncType;
466 }
467
468 SourceLocation getBeginLoc() const LLVM_READONLY { return AtLoc; }
469 SourceLocation getEndLoc() const LLVM_READONLY { return RParenLoc; }
470
471 // Iterators
475
479
480 static bool classof(const Stmt *T) {
481 return T->getStmtClass() == ObjCEncodeExprClass;
482 }
483};
484
485/// ObjCSelectorExpr used for \@selector in Objective-C.
486class ObjCSelectorExpr : public Expr {
487 Selector SelName;
488 SourceLocation AtLoc, RParenLoc;
489
490public:
493 : Expr(ObjCSelectorExprClass, T, VK_PRValue, OK_Ordinary),
494 SelName(selInfo), AtLoc(at), RParenLoc(rp) {
495 setDependence(ExprDependence::None);
496 }
498 : Expr(ObjCSelectorExprClass, Empty) {}
499
500 Selector getSelector() const { return SelName; }
501 void setSelector(Selector S) { SelName = S; }
502
503 SourceLocation getAtLoc() const { return AtLoc; }
504 SourceLocation getRParenLoc() const { return RParenLoc; }
505 void setAtLoc(SourceLocation L) { AtLoc = L; }
506 void setRParenLoc(SourceLocation L) { RParenLoc = L; }
507
508 SourceLocation getBeginLoc() const LLVM_READONLY { return AtLoc; }
509 SourceLocation getEndLoc() const LLVM_READONLY { return RParenLoc; }
510
511 /// getNumArgs - Return the number of actual arguments to this call.
512 unsigned getNumArgs() const { return SelName.getNumArgs(); }
513
514 // Iterators
518
522
523 static bool classof(const Stmt *T) {
524 return T->getStmtClass() == ObjCSelectorExprClass;
525 }
526};
527
528/// ObjCProtocolExpr used for protocol expression in Objective-C.
529///
530/// This is used as: \@protocol(foo), as in:
531/// \code
532/// [obj conformsToProtocol:@protocol(foo)]
533/// \endcode
534///
535/// The return type is "Protocol*".
536class ObjCProtocolExpr : public Expr {
537 ObjCProtocolDecl *TheProtocol;
538 SourceLocation AtLoc, ProtoLoc, RParenLoc;
539
540public:
541 friend class ASTStmtReader;
542 friend class ASTStmtWriter;
543
545 SourceLocation protoLoc, SourceLocation rp)
546 : Expr(ObjCProtocolExprClass, T, VK_PRValue, OK_Ordinary),
547 TheProtocol(protocol), AtLoc(at), ProtoLoc(protoLoc), RParenLoc(rp) {
548 setDependence(ExprDependence::None);
549 }
551 : Expr(ObjCProtocolExprClass, Empty) {}
552
553 ObjCProtocolDecl *getProtocol() const { return TheProtocol; }
554 void setProtocol(ObjCProtocolDecl *P) { TheProtocol = P; }
555
556 SourceLocation getProtocolIdLoc() const { return ProtoLoc; }
557 SourceLocation getAtLoc() const { return AtLoc; }
558 SourceLocation getRParenLoc() const { return RParenLoc; }
559 void setAtLoc(SourceLocation L) { AtLoc = L; }
560 void setRParenLoc(SourceLocation L) { RParenLoc = L; }
561
562 SourceLocation getBeginLoc() const LLVM_READONLY { return AtLoc; }
563 SourceLocation getEndLoc() const LLVM_READONLY { return RParenLoc; }
564
565 // Iterators
569
573
574 static bool classof(const Stmt *T) {
575 return T->getStmtClass() == ObjCProtocolExprClass;
576 }
577};
578
579/// ObjCIvarRefExpr - A reference to an ObjC instance variable.
580class ObjCIvarRefExpr : public Expr {
581 ObjCIvarDecl *D;
582 Stmt *Base;
583 SourceLocation Loc;
584
585 /// OpLoc - This is the location of '.' or '->'
586 SourceLocation OpLoc;
587
588 // True if this is "X->F", false if this is "X.F".
589 LLVM_PREFERRED_TYPE(bool)
590 bool IsArrow : 1;
591
592 // True if ivar reference has no base (self assumed).
593 LLVM_PREFERRED_TYPE(bool)
594 bool IsFreeIvar : 1;
595
596public:
598 SourceLocation oploc, Expr *base, bool arrow = false,
599 bool freeIvar = false)
600 : Expr(ObjCIvarRefExprClass, t, VK_LValue,
601 d->isBitField() ? OK_BitField : OK_Ordinary),
602 D(d), Base(base), Loc(l), OpLoc(oploc), IsArrow(arrow),
603 IsFreeIvar(freeIvar) {
605 }
606
608 : Expr(ObjCIvarRefExprClass, Empty) {}
609
610 ObjCIvarDecl *getDecl() { return D; }
611 const ObjCIvarDecl *getDecl() const { return D; }
612 void setDecl(ObjCIvarDecl *d) { D = d; }
613
614 const Expr *getBase() const { return cast<Expr>(Base); }
615 Expr *getBase() { return cast<Expr>(Base); }
616 void setBase(Expr * base) { Base = base; }
617
618 bool isArrow() const { return IsArrow; }
619 bool isFreeIvar() const { return IsFreeIvar; }
620 void setIsArrow(bool A) { IsArrow = A; }
621 void setIsFreeIvar(bool A) { IsFreeIvar = A; }
622
623 SourceLocation getLocation() const { return Loc; }
624 void setLocation(SourceLocation L) { Loc = L; }
625
626 SourceLocation getBeginLoc() const LLVM_READONLY {
627 return isFreeIvar() ? Loc : getBase()->getBeginLoc();
628 }
629 SourceLocation getEndLoc() const LLVM_READONLY { return Loc; }
630
631 SourceLocation getOpLoc() const { return OpLoc; }
632 void setOpLoc(SourceLocation L) { OpLoc = L; }
633
634 // Iterators
635 child_range children() { return child_range(&Base, &Base+1); }
636
638 return const_child_range(&Base, &Base + 1);
639 }
640
641 static bool classof(const Stmt *T) {
642 return T->getStmtClass() == ObjCIvarRefExprClass;
643 }
644};
645
646/// ObjCPropertyRefExpr - A dot-syntax expression to access an ObjC
647/// property.
648class ObjCPropertyRefExpr : public Expr {
649private:
650 /// If the bool is true, this is an implicit property reference; the
651 /// pointer is an (optional) ObjCMethodDecl and Setter may be set.
652 /// if the bool is false, this is an explicit property reference;
653 /// the pointer is an ObjCPropertyDecl and Setter is always null.
654 llvm::PointerIntPair<NamedDecl *, 1, bool> PropertyOrGetter;
655
656 /// Indicates whether the property reference will result in a message
657 /// to the getter, the setter, or both.
658 /// This applies to both implicit and explicit property references.
659 enum MethodRefFlags {
660 MethodRef_None = 0,
661 MethodRef_Getter = 0x1,
662 MethodRef_Setter = 0x2
663 };
664
665 /// Contains the Setter method pointer and MethodRefFlags bit flags.
666 llvm::PointerIntPair<ObjCMethodDecl *, 2, unsigned> SetterAndMethodRefFlags;
667
668 // FIXME: Maybe we should store the property identifier here,
669 // because it's not rederivable from the other data when there's an
670 // implicit property with no getter (because the 'foo' -> 'setFoo:'
671 // transformation is lossy on the first character).
672
673 SourceLocation IdLoc;
674
675 /// When the receiver in property access is 'super', this is
676 /// the location of the 'super' keyword. When it's an interface,
677 /// this is that interface.
678 SourceLocation ReceiverLoc;
679 llvm::PointerUnion<Stmt *, const Type *, ObjCInterfaceDecl *> Receiver;
680
681public:
684 : Expr(ObjCPropertyRefExprClass, t, VK, OK), PropertyOrGetter(PD, false),
685 IdLoc(l), Receiver(base) {
686 assert(t->isSpecificPlaceholderType(BuiltinType::PseudoObject));
688 }
689
692 QualType st)
693 : Expr(ObjCPropertyRefExprClass, t, VK, OK), PropertyOrGetter(PD, false),
694 IdLoc(l), ReceiverLoc(sl), Receiver(st.getTypePtr()) {
695 assert(t->isSpecificPlaceholderType(BuiltinType::PseudoObject));
697 }
698
701 SourceLocation IdLoc, Expr *Base)
702 : Expr(ObjCPropertyRefExprClass, T, VK, OK),
703 PropertyOrGetter(Getter, true), SetterAndMethodRefFlags(Setter, 0),
704 IdLoc(IdLoc), Receiver(Base) {
705 assert(T->isSpecificPlaceholderType(BuiltinType::PseudoObject));
707 }
708
711 SourceLocation IdLoc, SourceLocation SuperLoc,
712 QualType SuperTy)
713 : Expr(ObjCPropertyRefExprClass, T, VK, OK),
714 PropertyOrGetter(Getter, true), SetterAndMethodRefFlags(Setter, 0),
715 IdLoc(IdLoc), ReceiverLoc(SuperLoc), Receiver(SuperTy.getTypePtr()) {
716 assert(T->isSpecificPlaceholderType(BuiltinType::PseudoObject));
718 }
719
722 SourceLocation IdLoc, SourceLocation ReceiverLoc,
723 ObjCInterfaceDecl *Receiver)
724 : Expr(ObjCPropertyRefExprClass, T, VK, OK),
725 PropertyOrGetter(Getter, true), SetterAndMethodRefFlags(Setter, 0),
726 IdLoc(IdLoc), ReceiverLoc(ReceiverLoc), Receiver(Receiver) {
727 assert(T->isSpecificPlaceholderType(BuiltinType::PseudoObject));
729 }
730
732 : Expr(ObjCPropertyRefExprClass, Empty) {}
733
734 bool isImplicitProperty() const { return PropertyOrGetter.getInt(); }
735 bool isExplicitProperty() const { return !PropertyOrGetter.getInt(); }
736
738 assert(!isImplicitProperty());
739 return cast<ObjCPropertyDecl>(PropertyOrGetter.getPointer());
740 }
741
743 assert(isImplicitProperty());
744 return cast_or_null<ObjCMethodDecl>(PropertyOrGetter.getPointer());
745 }
746
748 assert(isImplicitProperty());
749 return SetterAndMethodRefFlags.getPointer();
750 }
751
757
763
764 /// True if the property reference will result in a message to the
765 /// getter.
766 /// This applies to both implicit and explicit property references.
767 bool isMessagingGetter() const {
768 return SetterAndMethodRefFlags.getInt() & MethodRef_Getter;
769 }
770
771 /// True if the property reference will result in a message to the
772 /// setter.
773 /// This applies to both implicit and explicit property references.
774 bool isMessagingSetter() const {
775 return SetterAndMethodRefFlags.getInt() & MethodRef_Setter;
776 }
777
778 void setIsMessagingGetter(bool val = true) {
779 setMethodRefFlag(MethodRef_Getter, val);
780 }
781
782 void setIsMessagingSetter(bool val = true) {
783 setMethodRefFlag(MethodRef_Setter, val);
784 }
785
786 const Expr *getBase() const { return cast<Expr>(cast<Stmt *>(Receiver)); }
787 Expr *getBase() { return cast<Expr>(cast<Stmt *>(Receiver)); }
788
789 SourceLocation getLocation() const { return IdLoc; }
790
791 SourceLocation getReceiverLocation() const { return ReceiverLoc; }
792
794 return QualType(cast<const Type *>(Receiver), 0);
795 }
796
798 return cast<ObjCInterfaceDecl *>(Receiver);
799 }
800
801 bool isObjectReceiver() const { return isa<Stmt *>(Receiver); }
802 bool isSuperReceiver() const { return isa<const Type *>(Receiver); }
803 bool isClassReceiver() const { return isa<ObjCInterfaceDecl *>(Receiver); }
804
805 /// Determine the type of the base, regardless of the kind of receiver.
806 QualType getReceiverType(const ASTContext &ctx) const;
807
808 SourceLocation getBeginLoc() const LLVM_READONLY {
809 return isObjectReceiver() ? getBase()->getBeginLoc()
811 }
812
813 SourceLocation getEndLoc() const LLVM_READONLY { return IdLoc; }
814
815 // Iterators
817 if (isa<Stmt *>(Receiver)) {
818 Stmt **begin = reinterpret_cast<Stmt**>(&Receiver); // hack!
819 return child_range(begin, begin+1);
820 }
822 }
823
825 return const_cast<ObjCPropertyRefExpr *>(this)->children();
826 }
827
828 static bool classof(const Stmt *T) {
829 return T->getStmtClass() == ObjCPropertyRefExprClass;
830 }
831
832private:
833 friend class ASTStmtReader;
834 friend class ASTStmtWriter;
835
836 void setExplicitProperty(ObjCPropertyDecl *D, unsigned methRefFlags) {
837 PropertyOrGetter.setPointer(D);
838 PropertyOrGetter.setInt(false);
839 SetterAndMethodRefFlags.setPointer(nullptr);
840 SetterAndMethodRefFlags.setInt(methRefFlags);
841 }
842
843 void setImplicitProperty(ObjCMethodDecl *Getter, ObjCMethodDecl *Setter,
844 unsigned methRefFlags) {
845 PropertyOrGetter.setPointer(Getter);
846 PropertyOrGetter.setInt(true);
847 SetterAndMethodRefFlags.setPointer(Setter);
848 SetterAndMethodRefFlags.setInt(methRefFlags);
849 }
850
851 void setBase(Expr *Base) { Receiver = Base; }
852 void setSuperReceiver(QualType T) { Receiver = T.getTypePtr(); }
853 void setClassReceiver(ObjCInterfaceDecl *D) { Receiver = D; }
854
855 void setLocation(SourceLocation L) { IdLoc = L; }
856 void setReceiverLocation(SourceLocation Loc) { ReceiverLoc = Loc; }
857
858 void setMethodRefFlag(MethodRefFlags flag, bool val) {
859 unsigned f = SetterAndMethodRefFlags.getInt();
860 if (val)
861 f |= flag;
862 else
863 f &= ~flag;
864 SetterAndMethodRefFlags.setInt(f);
865 }
866};
867
868/// ObjCSubscriptRefExpr - used for array and dictionary subscripting.
869/// array[4] = array[3]; dictionary[key] = dictionary[alt_key];
871 // Location of ']' in an indexing expression.
872 SourceLocation RBracket;
873
874 // array/dictionary base expression.
875 // for arrays, this is a numeric expression. For dictionaries, this is
876 // an objective-c object pointer expression.
877 enum { BASE, KEY, END_EXPR };
878 Stmt* SubExprs[END_EXPR];
879
880 ObjCMethodDecl *GetAtIndexMethodDecl;
881
882 // For immutable objects this is null. When ObjCSubscriptRefExpr is to read
883 // an indexed object this is null too.
884 ObjCMethodDecl *SetAtIndexMethodDecl;
885
886public:
888 ExprObjectKind OK, ObjCMethodDecl *getMethod,
889 ObjCMethodDecl *setMethod, SourceLocation RB)
890 : Expr(ObjCSubscriptRefExprClass, T, VK, OK), RBracket(RB),
891 GetAtIndexMethodDecl(getMethod), SetAtIndexMethodDecl(setMethod) {
892 SubExprs[BASE] = base;
893 SubExprs[KEY] = key;
895 }
896
898 : Expr(ObjCSubscriptRefExprClass, Empty) {}
899
900 SourceLocation getRBracket() const { return RBracket; }
901 void setRBracket(SourceLocation RB) { RBracket = RB; }
902
903 SourceLocation getBeginLoc() const LLVM_READONLY {
904 return SubExprs[BASE]->getBeginLoc();
905 }
906
907 SourceLocation getEndLoc() const LLVM_READONLY { return RBracket; }
908
909 Expr *getBaseExpr() const { return cast<Expr>(SubExprs[BASE]); }
910 void setBaseExpr(Stmt *S) { SubExprs[BASE] = S; }
911
912 Expr *getKeyExpr() const { return cast<Expr>(SubExprs[KEY]); }
913 void setKeyExpr(Stmt *S) { SubExprs[KEY] = S; }
914
916 return GetAtIndexMethodDecl;
917 }
918
920 return SetAtIndexMethodDecl;
921 }
922
926
928 return child_range(SubExprs, SubExprs+END_EXPR);
929 }
930
932 return const_child_range(SubExprs, SubExprs + END_EXPR);
933 }
934
935 static bool classof(const Stmt *T) {
936 return T->getStmtClass() == ObjCSubscriptRefExprClass;
937 }
938
939private:
940 friend class ASTStmtReader;
941};
942
943/// An expression that sends a message to the given Objective-C
944/// object or class.
945///
946/// The following contains two message send expressions:
947///
948/// \code
949/// [[NSString alloc] initWithString:@"Hello"]
950/// \endcode
951///
952/// The innermost message send invokes the "alloc" class method on the
953/// NSString class, while the outermost message send invokes the
954/// "initWithString" instance method on the object returned from
955/// NSString's "alloc". In all, an Objective-C message send can take
956/// on four different (although related) forms:
957///
958/// 1. Send to an object instance.
959/// 2. Send to a class.
960/// 3. Send to the superclass instance of the current class.
961/// 4. Send to the superclass of the current class.
962///
963/// All four kinds of message sends are modeled by the ObjCMessageExpr
964/// class, and can be distinguished via \c getReceiverKind(). Example:
965///
966/// The "void *" trailing objects are actually ONE void * (the
967/// receiver pointer), and NumArgs Expr *. But due to the
968/// implementation of children(), these must be together contiguously.
969class ObjCMessageExpr final
970 : public Expr,
971 private llvm::TrailingObjects<ObjCMessageExpr, void *, SourceLocation> {
972public:
973 /// The kind of receiver this message is sending to.
975 /// The receiver is a class.
976 Class = 0,
977
978 /// The receiver is an object instance.
980
981 /// The receiver is a superclass.
983
984 /// The receiver is the instance of the superclass object.
986 };
987
988private:
989 /// Stores either the selector that this message is sending
990 /// to (when \c HasMethod is zero) or an \c ObjCMethodDecl pointer
991 /// referring to the method that we type-checked against.
992 uintptr_t SelectorOrMethod = 0;
993
994 enum { NumArgsBitWidth = 16 };
995
996 /// The number of arguments in the message send, not
997 /// including the receiver.
998 unsigned NumArgs : NumArgsBitWidth;
999
1000 /// The kind of message send this is, which is one of the
1001 /// ReceiverKind values.
1002 ///
1003 /// We pad this out to a byte to avoid excessive masking and shifting.
1004 LLVM_PREFERRED_TYPE(ReceiverKind)
1005 unsigned Kind : 8;
1006
1007 /// Whether we have an actual method prototype in \c
1008 /// SelectorOrMethod.
1009 ///
1010 /// When non-zero, we have a method declaration; otherwise, we just
1011 /// have a selector.
1012 LLVM_PREFERRED_TYPE(bool)
1013 unsigned HasMethod : 1;
1014
1015 /// Whether this message send is a "delegate init call",
1016 /// i.e. a call of an init method on self from within an init method.
1017 LLVM_PREFERRED_TYPE(bool)
1018 unsigned IsDelegateInitCall : 1;
1019
1020 /// Whether this message send was implicitly generated by
1021 /// the implementation rather than explicitly written by the user.
1022 LLVM_PREFERRED_TYPE(bool)
1023 unsigned IsImplicit : 1;
1024
1025 /// Whether the locations of the selector identifiers are in a
1026 /// "standard" position, a enum SelectorLocationsKind.
1027 LLVM_PREFERRED_TYPE(SelectorLocationsKind)
1028 unsigned SelLocsKind : 2;
1029
1030 /// When the message expression is a send to 'super', this is
1031 /// the location of the 'super' keyword.
1032 SourceLocation SuperLoc;
1033
1034 /// The source locations of the open and close square
1035 /// brackets ('[' and ']', respectively).
1036 SourceLocation LBracLoc, RBracLoc;
1037
1038 ObjCMessageExpr(EmptyShell Empty, unsigned NumArgs)
1039 : Expr(ObjCMessageExprClass, Empty), Kind(0), HasMethod(false),
1040 IsDelegateInitCall(false), IsImplicit(false), SelLocsKind(0) {
1041 setNumArgs(NumArgs);
1042 }
1043
1044 ObjCMessageExpr(QualType T, ExprValueKind VK,
1045 SourceLocation LBracLoc,
1046 SourceLocation SuperLoc,
1047 bool IsInstanceSuper,
1048 QualType SuperType,
1049 Selector Sel,
1050 ArrayRef<SourceLocation> SelLocs,
1051 SelectorLocationsKind SelLocsK,
1052 ObjCMethodDecl *Method,
1053 ArrayRef<Expr *> Args,
1054 SourceLocation RBracLoc,
1055 bool isImplicit);
1056 ObjCMessageExpr(QualType T, ExprValueKind VK,
1057 SourceLocation LBracLoc,
1058 TypeSourceInfo *Receiver,
1059 Selector Sel,
1060 ArrayRef<SourceLocation> SelLocs,
1061 SelectorLocationsKind SelLocsK,
1062 ObjCMethodDecl *Method,
1063 ArrayRef<Expr *> Args,
1064 SourceLocation RBracLoc,
1065 bool isImplicit);
1066 ObjCMessageExpr(QualType T, ExprValueKind VK,
1067 SourceLocation LBracLoc,
1068 Expr *Receiver,
1069 Selector Sel,
1070 ArrayRef<SourceLocation> SelLocs,
1071 SelectorLocationsKind SelLocsK,
1072 ObjCMethodDecl *Method,
1073 ArrayRef<Expr *> Args,
1074 SourceLocation RBracLoc,
1075 bool isImplicit);
1076
1077 size_t numTrailingObjects(OverloadToken<void *>) const { return NumArgs + 1; }
1078
1079 void setNumArgs(unsigned Num) {
1080 assert((Num >> NumArgsBitWidth) == 0 && "Num of args is out of range!");
1081 NumArgs = Num;
1082 }
1083
1084 void initArgsAndSelLocs(ArrayRef<Expr *> Args,
1085 ArrayRef<SourceLocation> SelLocs,
1086 SelectorLocationsKind SelLocsK);
1087
1088 /// Retrieve the pointer value of the message receiver.
1089 void *getReceiverPointer() const { return *getTrailingObjects<void *>(); }
1090
1091 /// Set the pointer value of the message receiver.
1092 void setReceiverPointer(void *Value) {
1093 *getTrailingObjects<void *>() = Value;
1094 }
1095
1096 SelectorLocationsKind getSelLocsKind() const {
1097 return (SelectorLocationsKind)SelLocsKind;
1098 }
1099
1100 bool hasStandardSelLocs() const {
1101 return getSelLocsKind() != SelLoc_NonStandard;
1102 }
1103
1104 /// Get a pointer to the stored selector identifiers locations array.
1105 /// No locations will be stored if HasStandardSelLocs is true.
1106 SourceLocation *getStoredSelLocs() {
1107 return getTrailingObjects<SourceLocation>();
1108 }
1109 const SourceLocation *getStoredSelLocs() const {
1110 return getTrailingObjects<SourceLocation>();
1111 }
1112
1113 /// Get the number of stored selector identifiers locations.
1114 /// No locations will be stored if HasStandardSelLocs is true.
1115 unsigned getNumStoredSelLocs() const {
1116 if (hasStandardSelLocs())
1117 return 0;
1118 return getNumSelectorLocs();
1119 }
1120
1121 static ObjCMessageExpr *alloc(const ASTContext &C,
1122 ArrayRef<Expr *> Args,
1123 SourceLocation RBraceLoc,
1124 ArrayRef<SourceLocation> SelLocs,
1125 Selector Sel,
1126 SelectorLocationsKind &SelLocsK);
1127 static ObjCMessageExpr *alloc(const ASTContext &C,
1128 unsigned NumArgs,
1129 unsigned NumStoredSelLocs);
1130
1131public:
1132 friend class ASTStmtReader;
1133 friend class ASTStmtWriter;
1135
1136 /// Create a message send to super.
1137 ///
1138 /// \param Context The ASTContext in which this expression will be created.
1139 ///
1140 /// \param T The result type of this message.
1141 ///
1142 /// \param VK The value kind of this message. A message returning
1143 /// a l-value or r-value reference will be an l-value or x-value,
1144 /// respectively.
1145 ///
1146 /// \param LBracLoc The location of the open square bracket '['.
1147 ///
1148 /// \param SuperLoc The location of the "super" keyword.
1149 ///
1150 /// \param IsInstanceSuper Whether this is an instance "super"
1151 /// message (otherwise, it's a class "super" message).
1152 ///
1153 /// \param Sel The selector used to determine which method gets called.
1154 ///
1155 /// \param Method The Objective-C method against which this message
1156 /// send was type-checked. May be nullptr.
1157 ///
1158 /// \param Args The message send arguments.
1159 ///
1160 /// \param RBracLoc The location of the closing square bracket ']'.
1161 static ObjCMessageExpr *Create(const ASTContext &Context, QualType T,
1163 SourceLocation LBracLoc,
1164 SourceLocation SuperLoc,
1165 bool IsInstanceSuper,
1166 QualType SuperType,
1167 Selector Sel,
1170 ArrayRef<Expr *> Args,
1171 SourceLocation RBracLoc,
1172 bool isImplicit);
1173
1174 /// Create a class message send.
1175 ///
1176 /// \param Context The ASTContext in which this expression will be created.
1177 ///
1178 /// \param T The result type of this message.
1179 ///
1180 /// \param VK The value kind of this message. A message returning
1181 /// a l-value or r-value reference will be an l-value or x-value,
1182 /// respectively.
1183 ///
1184 /// \param LBracLoc The location of the open square bracket '['.
1185 ///
1186 /// \param Receiver The type of the receiver, including
1187 /// source-location information.
1188 ///
1189 /// \param Sel The selector used to determine which method gets called.
1190 ///
1191 /// \param Method The Objective-C method against which this message
1192 /// send was type-checked. May be nullptr.
1193 ///
1194 /// \param Args The message send arguments.
1195 ///
1196 /// \param RBracLoc The location of the closing square bracket ']'.
1197 static ObjCMessageExpr *Create(const ASTContext &Context, QualType T,
1199 SourceLocation LBracLoc,
1200 TypeSourceInfo *Receiver,
1201 Selector Sel,
1204 ArrayRef<Expr *> Args,
1205 SourceLocation RBracLoc,
1206 bool isImplicit);
1207
1208 /// Create an instance message send.
1209 ///
1210 /// \param Context The ASTContext in which this expression will be created.
1211 ///
1212 /// \param T The result type of this message.
1213 ///
1214 /// \param VK The value kind of this message. A message returning
1215 /// a l-value or r-value reference will be an l-value or x-value,
1216 /// respectively.
1217 ///
1218 /// \param LBracLoc The location of the open square bracket '['.
1219 ///
1220 /// \param Receiver The expression used to produce the object that
1221 /// will receive this message.
1222 ///
1223 /// \param Sel The selector used to determine which method gets called.
1224 ///
1225 /// \param Method The Objective-C method against which this message
1226 /// send was type-checked. May be nullptr.
1227 ///
1228 /// \param Args The message send arguments.
1229 ///
1230 /// \param RBracLoc The location of the closing square bracket ']'.
1231 static ObjCMessageExpr *Create(const ASTContext &Context, QualType T,
1233 SourceLocation LBracLoc,
1234 Expr *Receiver,
1235 Selector Sel,
1238 ArrayRef<Expr *> Args,
1239 SourceLocation RBracLoc,
1240 bool isImplicit);
1241
1242 /// Create an empty Objective-C message expression, to be
1243 /// filled in by subsequent calls.
1244 ///
1245 /// \param Context The context in which the message send will be created.
1246 ///
1247 /// \param NumArgs The number of message arguments, not including
1248 /// the receiver.
1249 static ObjCMessageExpr *CreateEmpty(const ASTContext &Context,
1250 unsigned NumArgs,
1251 unsigned NumStoredSelLocs);
1252
1253 /// Indicates whether the message send was implicitly
1254 /// generated by the implementation. If false, it was written explicitly
1255 /// in the source code.
1256 bool isImplicit() const { return IsImplicit; }
1257
1258 /// Determine the kind of receiver that this message is being
1259 /// sent to.
1261
1262 /// \return the return type of the message being sent.
1263 /// This is not always the type of the message expression itself because
1264 /// of references (the expression would not have a reference type).
1265 /// It is also not always the declared return type of the method because
1266 /// of `instancetype` (in that case it's an expression type).
1268
1269 /// Returns the WarnUnusedResultAttr that is declared on the callee
1270 /// or its return type declaration, together with a NamedDecl that
1271 /// refers to the declaration the attribute is attached to.
1272 std::pair<const NamedDecl *, const WarnUnusedResultAttr *>
1276
1277 /// Returns true if this message send should warn on unused results.
1279 return getUnusedResultAttr(Ctx).second != nullptr;
1280 }
1281
1282 /// Source range of the receiver.
1284
1285 /// Determine whether this is an instance message to either a
1286 /// computed object or to super.
1287 bool isInstanceMessage() const {
1289 }
1290
1291 /// Determine whether this is an class message to either a
1292 /// specified class or to super.
1293 bool isClassMessage() const {
1294 return getReceiverKind() == Class || getReceiverKind() == SuperClass;
1295 }
1296
1297 /// Returns the object expression (receiver) for an instance message,
1298 /// or null for a message that is not an instance message.
1300 if (getReceiverKind() == Instance)
1301 return static_cast<Expr *>(getReceiverPointer());
1302
1303 return nullptr;
1304 }
1305 const Expr *getInstanceReceiver() const {
1306 return const_cast<ObjCMessageExpr*>(this)->getInstanceReceiver();
1307 }
1308
1309 /// Turn this message send into an instance message that
1310 /// computes the receiver object with the given expression.
1312 Kind = Instance;
1313 setReceiverPointer(rec);
1314 }
1315
1316 /// Returns the type of a class message send, or NULL if the
1317 /// message is not a class message.
1320 return TSInfo->getType();
1321
1322 return {};
1323 }
1324
1325 /// Returns a type-source information of a class message
1326 /// send, or nullptr if the message is not a class message.
1328 if (getReceiverKind() == Class)
1329 return reinterpret_cast<TypeSourceInfo *>(getReceiverPointer());
1330 return nullptr;
1331 }
1332
1334 Kind = Class;
1335 setReceiverPointer(TSInfo);
1336 }
1337
1338 /// Retrieve the location of the 'super' keyword for a class
1339 /// or instance message to 'super', otherwise an invalid source location.
1342 return SuperLoc;
1343
1344 return SourceLocation();
1345 }
1346
1347 /// Retrieve the receiver type to which this message is being directed.
1348 ///
1349 /// This routine cross-cuts all of the different kinds of message
1350 /// sends to determine what the underlying (statically known) type
1351 /// of the receiver will be; use \c getReceiverKind() to determine
1352 /// whether the message is a class or an instance method, whether it
1353 /// is a send to super or not, etc.
1354 ///
1355 /// \returns The type of the receiver.
1356 QualType getReceiverType() const;
1357
1358 /// Retrieve the Objective-C interface to which this message
1359 /// is being directed, if known.
1360 ///
1361 /// This routine cross-cuts all of the different kinds of message
1362 /// sends to determine what the underlying (statically known) type
1363 /// of the receiver will be; use \c getReceiverKind() to determine
1364 /// whether the message is a class or an instance method, whether it
1365 /// is a send to super or not, etc.
1366 ///
1367 /// \returns The Objective-C interface if known, otherwise nullptr.
1369
1370 /// Retrieve the type referred to by 'super'.
1371 ///
1372 /// The returned type will either be an ObjCInterfaceType (for an
1373 /// class message to super) or an ObjCObjectPointerType that refers
1374 /// to a class (for an instance message to super);
1377 return QualType::getFromOpaquePtr(getReceiverPointer());
1378
1379 return QualType();
1380 }
1381
1382 void setSuper(SourceLocation Loc, QualType T, bool IsInstanceSuper) {
1383 Kind = IsInstanceSuper? SuperInstance : SuperClass;
1384 SuperLoc = Loc;
1385 setReceiverPointer(T.getAsOpaquePtr());
1386 }
1387
1388 Selector getSelector() const;
1389
1391 HasMethod = false;
1392 SelectorOrMethod = reinterpret_cast<uintptr_t>(S.getAsOpaquePtr());
1393 }
1394
1396 if (HasMethod)
1397 return reinterpret_cast<const ObjCMethodDecl *>(SelectorOrMethod);
1398
1399 return nullptr;
1400 }
1401
1403 if (HasMethod)
1404 return reinterpret_cast<ObjCMethodDecl *>(SelectorOrMethod);
1405
1406 return nullptr;
1407 }
1408
1410 HasMethod = true;
1411 SelectorOrMethod = reinterpret_cast<uintptr_t>(MD);
1412 }
1413
1415 if (HasMethod) return getMethodDecl()->getMethodFamily();
1416 return getSelector().getMethodFamily();
1417 }
1418
1419 /// Return the number of actual arguments in this message,
1420 /// not counting the receiver.
1421 unsigned getNumArgs() const { return NumArgs; }
1422
1423 /// Retrieve the arguments to this message, not including the
1424 /// receiver.
1426 return reinterpret_cast<Expr **>(getTrailingObjects<void *>() + 1);
1427 }
1428 const Expr * const *getArgs() const {
1429 return reinterpret_cast<const Expr *const *>(getTrailingObjects<void *>() +
1430 1);
1431 }
1432
1433 /// getArg - Return the specified argument.
1434 Expr *getArg(unsigned Arg) {
1435 assert(Arg < NumArgs && "Arg access out of range!");
1436 return getArgs()[Arg];
1437 }
1438 const Expr *getArg(unsigned Arg) const {
1439 assert(Arg < NumArgs && "Arg access out of range!");
1440 return getArgs()[Arg];
1441 }
1442
1443 /// setArg - Set the specified argument.
1444 void setArg(unsigned Arg, Expr *ArgExpr) {
1445 assert(Arg < NumArgs && "Arg access out of range!");
1446 getArgs()[Arg] = ArgExpr;
1447 }
1448
1449 /// isDelegateInitCall - Answers whether this message send has been
1450 /// tagged as a "delegate init call", i.e. a call to a method in the
1451 /// -init family on self from within an -init method implementation.
1452 bool isDelegateInitCall() const { return IsDelegateInitCall; }
1453 void setDelegateInitCall(bool isDelegate) { IsDelegateInitCall = isDelegate; }
1454
1455 SourceLocation getLeftLoc() const { return LBracLoc; }
1456 SourceLocation getRightLoc() const { return RBracLoc; }
1457
1459 if (isImplicit())
1460 return getBeginLoc();
1461 return getSelectorLoc(0);
1462 }
1463
1464 SourceLocation getSelectorLoc(unsigned Index) const {
1465 assert(Index < getNumSelectorLocs() && "Index out of range!");
1466 if (hasStandardSelLocs())
1468 Index, getSelector(), getSelLocsKind() == SelLoc_StandardWithSpace,
1469 ArrayRef(const_cast<Expr **>(getArgs()), getNumArgs()), RBracLoc);
1470 return getStoredSelLocs()[Index];
1471 }
1472
1474
1475 unsigned getNumSelectorLocs() const {
1476 if (isImplicit())
1477 return 0;
1478 Selector Sel = getSelector();
1479 if (Sel.isUnarySelector())
1480 return 1;
1481 return Sel.getNumArgs();
1482 }
1483
1485 LBracLoc = R.getBegin();
1486 RBracLoc = R.getEnd();
1487 }
1488
1489 SourceLocation getBeginLoc() const LLVM_READONLY { return LBracLoc; }
1490 SourceLocation getEndLoc() const LLVM_READONLY { return RBracLoc; }
1491
1492 // Iterators
1494
1496
1499
1500 llvm::iterator_range<arg_iterator> arguments() {
1501 return llvm::make_range(arg_begin(), arg_end());
1502 }
1503
1504 llvm::iterator_range<const_arg_iterator> arguments() const {
1505 return llvm::make_range(arg_begin(), arg_end());
1506 }
1507
1508 arg_iterator arg_begin() { return reinterpret_cast<Stmt **>(getArgs()); }
1509
1511 return reinterpret_cast<Stmt **>(getArgs() + NumArgs);
1512 }
1513
1515 return reinterpret_cast<Stmt const * const*>(getArgs());
1516 }
1517
1519 return reinterpret_cast<Stmt const * const*>(getArgs() + NumArgs);
1520 }
1521
1522 static bool classof(const Stmt *T) {
1523 return T->getStmtClass() == ObjCMessageExprClass;
1524 }
1525};
1526
1527/// ObjCIsaExpr - Represent X->isa and X.isa when X is an ObjC 'id' type.
1528/// (similar in spirit to MemberExpr).
1529class ObjCIsaExpr : public Expr {
1530 /// Base - the expression for the base object pointer.
1531 Stmt *Base;
1532
1533 /// IsaMemberLoc - This is the location of the 'isa'.
1534 SourceLocation IsaMemberLoc;
1535
1536 /// OpLoc - This is the location of '.' or '->'
1537 SourceLocation OpLoc;
1538
1539 /// IsArrow - True if this is "X->F", false if this is "X.F".
1540 bool IsArrow;
1541
1542public:
1543 ObjCIsaExpr(Expr *base, bool isarrow, SourceLocation l, SourceLocation oploc,
1544 QualType ty)
1545 : Expr(ObjCIsaExprClass, ty, VK_LValue, OK_Ordinary), Base(base),
1546 IsaMemberLoc(l), OpLoc(oploc), IsArrow(isarrow) {
1548 }
1549
1550 /// Build an empty expression.
1551 explicit ObjCIsaExpr(EmptyShell Empty) : Expr(ObjCIsaExprClass, Empty) {}
1552
1553 void setBase(Expr *E) { Base = E; }
1554 Expr *getBase() const { return cast<Expr>(Base); }
1555
1556 bool isArrow() const { return IsArrow; }
1557 void setArrow(bool A) { IsArrow = A; }
1558
1559 /// getMemberLoc - Return the location of the "member", in X->F, it is the
1560 /// location of 'F'.
1561 SourceLocation getIsaMemberLoc() const { return IsaMemberLoc; }
1562 void setIsaMemberLoc(SourceLocation L) { IsaMemberLoc = L; }
1563
1564 SourceLocation getOpLoc() const { return OpLoc; }
1565 void setOpLoc(SourceLocation L) { OpLoc = L; }
1566
1567 SourceLocation getBeginLoc() const LLVM_READONLY {
1568 return getBase()->getBeginLoc();
1569 }
1570
1571 SourceLocation getBaseLocEnd() const LLVM_READONLY {
1572 return getBase()->getEndLoc();
1573 }
1574
1575 SourceLocation getEndLoc() const LLVM_READONLY { return IsaMemberLoc; }
1576
1577 SourceLocation getExprLoc() const LLVM_READONLY { return IsaMemberLoc; }
1578
1579 // Iterators
1580 child_range children() { return child_range(&Base, &Base+1); }
1581
1583 return const_child_range(&Base, &Base + 1);
1584 }
1585
1586 static bool classof(const Stmt *T) {
1587 return T->getStmtClass() == ObjCIsaExprClass;
1588 }
1589};
1590
1591/// ObjCIndirectCopyRestoreExpr - Represents the passing of a function
1592/// argument by indirect copy-restore in ARC. This is used to support
1593/// passing indirect arguments with the wrong lifetime, e.g. when
1594/// passing the address of a __strong local variable to an 'out'
1595/// parameter. This expression kind is only valid in an "argument"
1596/// position to some sort of call expression.
1597///
1598/// The parameter must have type 'pointer to T', and the argument must
1599/// have type 'pointer to U', where T and U agree except possibly in
1600/// qualification. If the argument value is null, then a null pointer
1601/// is passed; otherwise it points to an object A, and:
1602/// 1. A temporary object B of type T is initialized, either by
1603/// zero-initialization (used when initializing an 'out' parameter)
1604/// or copy-initialization (used when initializing an 'inout'
1605/// parameter).
1606/// 2. The address of the temporary is passed to the function.
1607/// 3. If the call completes normally, A is move-assigned from B.
1608/// 4. Finally, A is destroyed immediately.
1609///
1610/// Currently 'T' must be a retainable object lifetime and must be
1611/// __autoreleasing; this qualifier is ignored when initializing
1612/// the value.
1613class ObjCIndirectCopyRestoreExpr : public Expr {
1614 friend class ASTReader;
1615 friend class ASTStmtReader;
1616
1617 Stmt *Operand;
1618
1619 // unsigned ObjCIndirectCopyRestoreBits.ShouldCopy : 1;
1620
1621 explicit ObjCIndirectCopyRestoreExpr(EmptyShell Empty)
1622 : Expr(ObjCIndirectCopyRestoreExprClass, Empty) {}
1623
1624 void setShouldCopy(bool shouldCopy) {
1626 }
1627
1628public:
1630 : Expr(ObjCIndirectCopyRestoreExprClass, type, VK_LValue, OK_Ordinary),
1631 Operand(operand) {
1632 setShouldCopy(shouldCopy);
1634 }
1635
1636 Expr *getSubExpr() { return cast<Expr>(Operand); }
1637 const Expr *getSubExpr() const { return cast<Expr>(Operand); }
1638
1639 /// shouldCopy - True if we should do the 'copy' part of the
1640 /// copy-restore. If false, the temporary will be zero-initialized.
1641 bool shouldCopy() const { return ObjCIndirectCopyRestoreExprBits.ShouldCopy; }
1642
1643 child_range children() { return child_range(&Operand, &Operand+1); }
1644
1646 return const_child_range(&Operand, &Operand + 1);
1647 }
1648
1649 // Source locations are determined by the subexpression.
1650 SourceLocation getBeginLoc() const LLVM_READONLY {
1651 return Operand->getBeginLoc();
1652 }
1653 SourceLocation getEndLoc() const LLVM_READONLY {
1654 return Operand->getEndLoc();
1655 }
1656
1657 SourceLocation getExprLoc() const LLVM_READONLY {
1658 return getSubExpr()->getExprLoc();
1659 }
1660
1661 static bool classof(const Stmt *s) {
1662 return s->getStmtClass() == ObjCIndirectCopyRestoreExprClass;
1663 }
1664};
1665
1666/// An Objective-C "bridged" cast expression, which casts between
1667/// Objective-C pointers and C pointers, transferring ownership in the process.
1668///
1669/// \code
1670/// NSString *str = (__bridge_transfer NSString *)CFCreateString();
1671/// \endcode
1673 : public ExplicitCastExpr,
1674 private llvm::TrailingObjects<ObjCBridgedCastExpr, CXXBaseSpecifier *> {
1675 friend class ASTStmtReader;
1676 friend class ASTStmtWriter;
1677 friend class CastExpr;
1678 friend TrailingObjects;
1679
1680 SourceLocation LParenLoc;
1681 SourceLocation BridgeKeywordLoc;
1682 LLVM_PREFERRED_TYPE(ObjCBridgeCastKind)
1683 unsigned Kind : 2;
1684
1685public:
1687 CastKind CK, SourceLocation BridgeKeywordLoc,
1688 TypeSourceInfo *TSInfo, Expr *Operand)
1689 : ExplicitCastExpr(ObjCBridgedCastExprClass, TSInfo->getType(),
1690 VK_PRValue, CK, Operand, 0, false, TSInfo),
1691 LParenLoc(LParenLoc), BridgeKeywordLoc(BridgeKeywordLoc), Kind(Kind) {}
1692
1693 /// Construct an empty Objective-C bridged cast.
1695 : ExplicitCastExpr(ObjCBridgedCastExprClass, Shell, 0, false) {}
1696
1697 SourceLocation getLParenLoc() const { return LParenLoc; }
1698
1699 /// Determine which kind of bridge is being performed via this cast.
1701 return static_cast<ObjCBridgeCastKind>(Kind);
1702 }
1703
1704 /// Retrieve the kind of bridge being performed as a string.
1705 StringRef getBridgeKindName() const;
1706
1707 /// The location of the bridge keyword.
1708 SourceLocation getBridgeKeywordLoc() const { return BridgeKeywordLoc; }
1709
1710 SourceLocation getBeginLoc() const LLVM_READONLY { return LParenLoc; }
1711
1712 SourceLocation getEndLoc() const LLVM_READONLY {
1713 return getSubExpr()->getEndLoc();
1714 }
1715
1716 static bool classof(const Stmt *T) {
1717 return T->getStmtClass() == ObjCBridgedCastExprClass;
1718 }
1719};
1720
1721/// A runtime availability query.
1722///
1723/// There are 2 ways to spell this node:
1724/// \code
1725/// @available(macos 10.10, ios 8, *); // Objective-C
1726/// __builtin_available(macos 10.10, ios 8, *); // C, C++, and Objective-C
1727/// \endcode
1728///
1729/// Note that we only need to keep track of one \c VersionTuple here, which is
1730/// the one that corresponds to the current deployment target. This is meant to
1731/// be used in the condition of an \c if, but it is also usable as top level
1732/// expressions.
1733///
1735 friend class ASTStmtReader;
1736
1737 VersionTuple VersionToCheck;
1738 SourceLocation AtLoc, RParen;
1739
1740public:
1741 ObjCAvailabilityCheckExpr(VersionTuple VersionToCheck, SourceLocation AtLoc,
1742 SourceLocation RParen, QualType Ty)
1743 : Expr(ObjCAvailabilityCheckExprClass, Ty, VK_PRValue, OK_Ordinary),
1744 VersionToCheck(VersionToCheck), AtLoc(AtLoc), RParen(RParen) {
1745 setDependence(ExprDependence::None);
1746 }
1747
1749 : Expr(ObjCAvailabilityCheckExprClass, Shell) {}
1750
1751 SourceLocation getBeginLoc() const { return AtLoc; }
1752 SourceLocation getEndLoc() const { return RParen; }
1753 SourceRange getSourceRange() const { return {AtLoc, RParen}; }
1754
1755 /// This may be '*', in which case this should fold to true.
1756 bool hasVersion() const { return !VersionToCheck.empty(); }
1757 VersionTuple getVersion() const { return VersionToCheck; }
1758
1762
1766
1767 static bool classof(const Stmt *T) {
1768 return T->getStmtClass() == ObjCAvailabilityCheckExprClass;
1769 }
1770};
1771
1772} // namespace clang
1773
1774#endif // LLVM_CLANG_AST_EXPROBJC_H
#define V(N, I)
Defines the clang::IdentifierInfo, clang::IdentifierTable, and clang::Selector interfaces.
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified.
Defines the clang::SourceLocation class and associated facilities.
Defines various enumerations that describe declaration and type specifiers.
C Language Family Type Representation.
__device__ __2f16 float __ockl_bool s
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition ASTContext.h:226
Represents a base class of a C++ class.
Definition DeclCXX.h:146
Expr * getSubExpr()
Definition Expr.h:3729
ExplicitCastExpr(StmtClass SC, QualType exprTy, ExprValueKind VK, CastKind kind, Expr *op, unsigned PathSize, bool HasFPFeatures, TypeSourceInfo *writtenTy)
Definition Expr.h:3937
This represents one expression.
Definition Expr.h:112
static std::pair< const NamedDecl *, const WarnUnusedResultAttr * > getUnusedResultAttrImpl(const Decl *Callee, QualType ReturnType)
Returns the WarnUnusedResultAttr that is declared on the callee or its return type declaration,...
Definition Expr.cpp:1634
Expr()=delete
SourceLocation getExprLoc() const LLVM_READONLY
getExprLoc - Return the preferred location for the arrow when diagnosing a problem with a generic exp...
Definition Expr.cpp:277
QualType getType() const
Definition Expr.h:144
void setDependence(ExprDependence Deps)
Each concrete expr subclass is expected to compute its dependence and call this in the constructor.
Definition Expr.h:137
Expr * getElement(unsigned Index)
getElement - Return the Element at the specified index.
Definition ExprObjC.h:265
const Expr *const * getElements() const
Retrieve elements of array of literals.
Definition ExprObjC.h:254
child_range children()
Definition ExprObjC.h:279
static ObjCArrayLiteral * CreateEmpty(const ASTContext &C, unsigned NumElements)
Definition ExprObjC.cpp:51
ArrayRef< const Expr * > elements() const
elements - Return the elements of the array literal.
Definition ExprObjC.h:260
const_child_range children() const
Definition ExprObjC.h:284
SourceLocation getBeginLoc() const LLVM_READONLY
Definition ExprObjC.h:246
Expr ** getElements()
Retrieve elements of array of literals.
Definition ExprObjC.h:251
unsigned getNumElements() const
getNumElements - Return number of elements of objective-c array literal.
Definition ExprObjC.h:257
const Expr * getElement(unsigned Index) const
Definition ExprObjC.h:269
SourceRange getSourceRange() const LLVM_READONLY
Definition ExprObjC.h:248
ObjCMethodDecl * getArrayWithObjectsMethod() const
Definition ExprObjC.h:274
SourceLocation getEndLoc() const LLVM_READONLY
Definition ExprObjC.h:247
friend class ASTStmtReader
Definition ExprObjC.h:234
static bool classof(const Stmt *T)
Definition ExprObjC.h:288
bool hasVersion() const
This may be '*', in which case this should fold to true.
Definition ExprObjC.h:1756
const_child_range children() const
Definition ExprObjC.h:1763
static bool classof(const Stmt *T)
Definition ExprObjC.h:1767
ObjCAvailabilityCheckExpr(EmptyShell Shell)
Definition ExprObjC.h:1748
SourceRange getSourceRange() const
Definition ExprObjC.h:1753
SourceLocation getBeginLoc() const
Definition ExprObjC.h:1751
SourceLocation getEndLoc() const
Definition ExprObjC.h:1752
VersionTuple getVersion() const
Definition ExprObjC.h:1757
ObjCAvailabilityCheckExpr(VersionTuple VersionToCheck, SourceLocation AtLoc, SourceLocation RParen, QualType Ty)
Definition ExprObjC.h:1741
SourceLocation getEndLoc() const LLVM_READONLY
Definition ExprObjC.h:136
void setLocation(SourceLocation L)
Definition ExprObjC.h:139
SourceLocation getBeginLoc() const LLVM_READONLY
Definition ExprObjC.h:135
SourceLocation getLocation() const
Definition ExprObjC.h:138
const_child_range children() const
Definition ExprObjC.h:146
ObjCBoolLiteralExpr(bool val, QualType Ty, SourceLocation l)
Definition ExprObjC.h:124
static bool classof(const Stmt *T)
Definition ExprObjC.h:150
ObjCBoolLiteralExpr(EmptyShell Empty)
Definition ExprObjC.h:129
const_arg_iterator arg_begin() const
Definition ExprObjC.h:203
const Expr * getSubExpr() const
Definition ExprObjC.h:179
ConstExprIterator const_arg_iterator
Definition ExprObjC.h:201
SourceLocation getAtLoc() const
Definition ExprObjC.h:185
SourceRange getSourceRange() const LLVM_READONLY
Definition ExprObjC.h:190
static bool classof(const Stmt *T)
Definition ExprObjC.h:211
ObjCBoxedExpr(EmptyShell Empty)
Definition ExprObjC.h:175
ObjCBoxedExpr(Expr *E, QualType T, ObjCMethodDecl *Method, bool ExpressibleAsConstantInitializer, SourceRange R)
Definition ExprObjC.h:167
const_child_range children() const
Definition ExprObjC.h:197
ObjCMethodDecl * getBoxingMethod() const
Definition ExprObjC.h:181
SourceLocation getBeginLoc() const LLVM_READONLY
Definition ExprObjC.h:187
const_arg_iterator arg_end() const
Definition ExprObjC.h:207
friend class ASTStmtReader
Definition ExprObjC.h:165
child_range children()
Definition ExprObjC.h:195
SourceLocation getEndLoc() const LLVM_READONLY
Definition ExprObjC.h:188
SourceLocation getEndLoc() const LLVM_READONLY
Definition ExprObjC.h:1712
ObjCBridgedCastExpr(EmptyShell Shell)
Construct an empty Objective-C bridged cast.
Definition ExprObjC.h:1694
StringRef getBridgeKindName() const
Retrieve the kind of bridge being performed as a string.
Definition ExprObjC.cpp:348
SourceLocation getLParenLoc() const
Definition ExprObjC.h:1697
static bool classof(const Stmt *T)
Definition ExprObjC.h:1716
SourceLocation getBridgeKeywordLoc() const
The location of the bridge keyword.
Definition ExprObjC.h:1708
ObjCBridgeCastKind getBridgeKind() const
Determine which kind of bridge is being performed via this cast.
Definition ExprObjC.h:1700
ObjCBridgedCastExpr(SourceLocation LParenLoc, ObjCBridgeCastKind Kind, CastKind CK, SourceLocation BridgeKeywordLoc, TypeSourceInfo *TSInfo, Expr *Operand)
Definition ExprObjC.h:1686
SourceLocation getBeginLoc() const LLVM_READONLY
Definition ExprObjC.h:1710
static ObjCDictionaryLiteral * CreateEmpty(const ASTContext &C, unsigned NumElements, bool HasPackExpansions)
Definition ExprObjC.cpp:96
const_child_range children() const
Definition ExprObjC.h:429
unsigned getNumElements() const
getNumElements - Return number of elements of objective-c dictionary literal.
Definition ExprObjC.h:392
ObjCMethodDecl * getDictWithObjectsMethod() const
Definition ExprObjC.h:409
ObjCDictionaryElement getKeyValueElement(unsigned Index) const
Definition ExprObjC.h:394
SourceLocation getBeginLoc() const LLVM_READONLY
Definition ExprObjC.h:413
SourceLocation getEndLoc() const LLVM_READONLY
Definition ExprObjC.h:414
SourceRange getSourceRange() const LLVM_READONLY
Definition ExprObjC.h:415
static bool classof(const Stmt *T)
Definition ExprObjC.h:433
void setEncodedTypeSourceInfo(TypeSourceInfo *EncType)
Definition ExprObjC.h:464
TypeSourceInfo * getEncodedTypeSourceInfo() const
Definition ExprObjC.h:462
const_child_range children() const
Definition ExprObjC.h:476
SourceLocation getBeginLoc() const LLVM_READONLY
Definition ExprObjC.h:468
SourceLocation getRParenLoc() const
Definition ExprObjC.h:457
void setRParenLoc(SourceLocation L)
Definition ExprObjC.h:458
static bool classof(const Stmt *T)
Definition ExprObjC.h:480
QualType getEncodedType() const
Definition ExprObjC.h:460
SourceLocation getEndLoc() const LLVM_READONLY
Definition ExprObjC.h:469
void setAtLoc(SourceLocation L)
Definition ExprObjC.h:456
ObjCEncodeExpr(QualType T, TypeSourceInfo *EncodedType, SourceLocation at, SourceLocation rp)
Definition ExprObjC.h:446
SourceLocation getAtLoc() const
Definition ExprObjC.h:455
child_range children()
Definition ExprObjC.h:472
ObjCEncodeExpr(EmptyShell Empty)
Definition ExprObjC.h:453
const Expr * getSubExpr() const
Definition ExprObjC.h:1637
SourceLocation getEndLoc() const LLVM_READONLY
Definition ExprObjC.h:1653
static bool classof(const Stmt *s)
Definition ExprObjC.h:1661
bool shouldCopy() const
shouldCopy - True if we should do the 'copy' part of the copy-restore.
Definition ExprObjC.h:1641
SourceLocation getExprLoc() const LLVM_READONLY
Definition ExprObjC.h:1657
ObjCIndirectCopyRestoreExpr(Expr *operand, QualType type, bool shouldCopy)
Definition ExprObjC.h:1629
const_child_range children() const
Definition ExprObjC.h:1645
SourceLocation getBeginLoc() const LLVM_READONLY
Definition ExprObjC.h:1650
Represents an ObjC class declaration.
Definition DeclObjC.h:1154
SourceLocation getIsaMemberLoc() const
getMemberLoc - Return the location of the "member", in X->F, it is the location of 'F'.
Definition ExprObjC.h:1561
ObjCIsaExpr(EmptyShell Empty)
Build an empty expression.
Definition ExprObjC.h:1551
SourceLocation getOpLoc() const
Definition ExprObjC.h:1564
void setIsaMemberLoc(SourceLocation L)
Definition ExprObjC.h:1562
Expr * getBase() const
Definition ExprObjC.h:1554
static bool classof(const Stmt *T)
Definition ExprObjC.h:1586
SourceLocation getBaseLocEnd() const LLVM_READONLY
Definition ExprObjC.h:1571
bool isArrow() const
Definition ExprObjC.h:1556
child_range children()
Definition ExprObjC.h:1580
void setBase(Expr *E)
Definition ExprObjC.h:1553
void setArrow(bool A)
Definition ExprObjC.h:1557
void setOpLoc(SourceLocation L)
Definition ExprObjC.h:1565
SourceLocation getExprLoc() const LLVM_READONLY
Definition ExprObjC.h:1577
SourceLocation getEndLoc() const LLVM_READONLY
Definition ExprObjC.h:1575
const_child_range children() const
Definition ExprObjC.h:1582
SourceLocation getBeginLoc() const LLVM_READONLY
Definition ExprObjC.h:1567
ObjCIsaExpr(Expr *base, bool isarrow, SourceLocation l, SourceLocation oploc, QualType ty)
Definition ExprObjC.h:1543
ObjCIvarDecl - Represents an ObjC instance variable.
Definition DeclObjC.h:1952
SourceLocation getBeginLoc() const LLVM_READONLY
Definition ExprObjC.h:626
void setIsArrow(bool A)
Definition ExprObjC.h:620
void setBase(Expr *base)
Definition ExprObjC.h:616
SourceLocation getLocation() const
Definition ExprObjC.h:623
SourceLocation getOpLoc() const
Definition ExprObjC.h:631
void setDecl(ObjCIvarDecl *d)
Definition ExprObjC.h:612
ObjCIvarDecl * getDecl()
Definition ExprObjC.h:610
ObjCIvarRefExpr(EmptyShell Empty)
Definition ExprObjC.h:607
bool isArrow() const
Definition ExprObjC.h:618
bool isFreeIvar() const
Definition ExprObjC.h:619
void setIsFreeIvar(bool A)
Definition ExprObjC.h:621
void setOpLoc(SourceLocation L)
Definition ExprObjC.h:632
SourceLocation getEndLoc() const LLVM_READONLY
Definition ExprObjC.h:629
const_child_range children() const
Definition ExprObjC.h:637
const ObjCIvarDecl * getDecl() const
Definition ExprObjC.h:611
const Expr * getBase() const
Definition ExprObjC.h:614
child_range children()
Definition ExprObjC.h:635
void setLocation(SourceLocation L)
Definition ExprObjC.h:624
static bool classof(const Stmt *T)
Definition ExprObjC.h:641
ObjCIvarRefExpr(ObjCIvarDecl *d, QualType t, SourceLocation l, SourceLocation oploc, Expr *base, bool arrow=false, bool freeIvar=false)
Definition ExprObjC.h:597
const Expr * getArg(unsigned Arg) const
Definition ExprObjC.h:1438
Expr * getArg(unsigned Arg)
getArg - Return the specified argument.
Definition ExprObjC.h:1434
void getSelectorLocs(SmallVectorImpl< SourceLocation > &SelLocs) const
Definition ExprObjC.cpp:266
bool isImplicit() const
Indicates whether the message send was implicitly generated by the implementation.
Definition ExprObjC.h:1256
llvm::iterator_range< const_arg_iterator > arguments() const
Definition ExprObjC.h:1504
static ObjCMessageExpr * CreateEmpty(const ASTContext &Context, unsigned NumArgs, unsigned NumStoredSelLocs)
Create an empty Objective-C message expression, to be filled in by subsequent calls.
Definition ExprObjC.cpp:240
void setMethodDecl(ObjCMethodDecl *MD)
Definition ExprObjC.h:1409
Expr ** getArgs()
Retrieve the arguments to this message, not including the receiver.
Definition ExprObjC.h:1425
bool isDelegateInitCall() const
isDelegateInitCall - Answers whether this message send has been tagged as a "delegate init call",...
Definition ExprObjC.h:1452
ObjCMethodDecl * getMethodDecl()
Definition ExprObjC.h:1402
void setClassReceiver(TypeSourceInfo *TSInfo)
Definition ExprObjC.h:1333
void setInstanceReceiver(Expr *rec)
Turn this message send into an instance message that computes the receiver object with the given expr...
Definition ExprObjC.h:1311
const_arg_iterator arg_end() const
Definition ExprObjC.h:1518
SourceLocation getBeginLoc() const LLVM_READONLY
Definition ExprObjC.h:1489
void setSuper(SourceLocation Loc, QualType T, bool IsInstanceSuper)
Definition ExprObjC.h:1382
SourceLocation getLeftLoc() const
Definition ExprObjC.h:1455
Expr * getInstanceReceiver()
Returns the object expression (receiver) for an instance message, or null for a message that is not a...
Definition ExprObjC.h:1299
QualType getCallReturnType(ASTContext &Ctx) const
Definition ExprObjC.cpp:273
SourceLocation getSuperLoc() const
Retrieve the location of the 'super' keyword for a class or instance message to 'super',...
Definition ExprObjC.h:1340
ObjCMethodFamily getMethodFamily() const
Definition ExprObjC.h:1414
Selector getSelector() const
Definition ExprObjC.cpp:301
ReceiverKind
The kind of receiver this message is sending to.
Definition ExprObjC.h:974
@ SuperInstance
The receiver is the instance of the superclass object.
Definition ExprObjC.h:985
@ Instance
The receiver is an object instance.
Definition ExprObjC.h:979
@ SuperClass
The receiver is a superclass.
Definition ExprObjC.h:982
@ Class
The receiver is a class.
Definition ExprObjC.h:976
ConstExprIterator const_arg_iterator
Definition ExprObjC.h:1498
TypeSourceInfo * getClassReceiverTypeInfo() const
Returns a type-source information of a class message send, or nullptr if the message is not a class m...
Definition ExprObjC.h:1327
QualType getClassReceiver() const
Returns the type of a class message send, or NULL if the message is not a class message.
Definition ExprObjC.h:1318
void setDelegateInitCall(bool isDelegate)
Definition ExprObjC.h:1453
bool isInstanceMessage() const
Determine whether this is an instance message to either a computed object or to super.
Definition ExprObjC.h:1287
llvm::iterator_range< arg_iterator > arguments()
Definition ExprObjC.h:1500
ObjCInterfaceDecl * getReceiverInterface() const
Retrieve the Objective-C interface to which this message is being directed, if known.
Definition ExprObjC.cpp:322
QualType getSuperType() const
Retrieve the type referred to by 'super'.
Definition ExprObjC.h:1375
const ObjCMethodDecl * getMethodDecl() const
Definition ExprObjC.h:1395
SourceRange getReceiverRange() const
Source range of the receiver.
Definition ExprObjC.cpp:285
bool isClassMessage() const
Determine whether this is an class message to either a specified class or to super.
Definition ExprObjC.h:1293
const Expr * getInstanceReceiver() const
Definition ExprObjC.h:1305
unsigned getNumSelectorLocs() const
Definition ExprObjC.h:1475
const Expr *const * getArgs() const
Definition ExprObjC.h:1428
ReceiverKind getReceiverKind() const
Determine the kind of receiver that this message is being sent to.
Definition ExprObjC.h:1260
SourceLocation getEndLoc() const LLVM_READONLY
Definition ExprObjC.h:1490
child_range children()
Definition ExprObjC.cpp:334
QualType getReceiverType() const
Retrieve the receiver type to which this message is being directed.
Definition ExprObjC.cpp:308
SourceLocation getSelectorLoc(unsigned Index) const
Definition ExprObjC.h:1464
ExprIterator arg_iterator
Definition ExprObjC.h:1497
SourceLocation getSelectorStartLoc() const
Definition ExprObjC.h:1458
friend class ASTStmtWriter
Definition ExprObjC.h:1133
arg_iterator arg_begin()
Definition ExprObjC.h:1508
static bool classof(const Stmt *T)
Definition ExprObjC.h:1522
void setSourceRange(SourceRange R)
Definition ExprObjC.h:1484
SourceLocation getRightLoc() const
Definition ExprObjC.h:1456
unsigned getNumArgs() const
Return the number of actual arguments in this message, not counting the receiver.
Definition ExprObjC.h:1421
friend class ASTStmtReader
Definition ExprObjC.h:1132
std::pair< const NamedDecl *, const WarnUnusedResultAttr * > getUnusedResultAttr(ASTContext &Ctx) const
Returns the WarnUnusedResultAttr that is declared on the callee or its return type declaration,...
Definition ExprObjC.h:1273
void setSelector(Selector S)
Definition ExprObjC.h:1390
bool hasUnusedResultAttr(ASTContext &Ctx) const
Returns true if this message send should warn on unused results.
Definition ExprObjC.h:1278
void setArg(unsigned Arg, Expr *ArgExpr)
setArg - Set the specified argument.
Definition ExprObjC.h:1444
arg_iterator arg_end()
Definition ExprObjC.h:1510
const_arg_iterator arg_begin() const
Definition ExprObjC.h:1514
ObjCMethodDecl - Represents an instance or class method declaration.
Definition DeclObjC.h:140
Selector getSelector() const
Definition DeclObjC.h:327
ObjCMethodFamily getMethodFamily() const
Determines the family of this method.
void setExpressibleAsConstantInitializer(bool ExpressibleAsConstantInitializer)
Definition ExprObjC.h:72
ObjCObjectLiteral(StmtClass SC, QualType T, bool ExpressibleAsConstantInitializer, ExprValueKind VK, ExprObjectKind OK)
Definition ExprObjC.h:53
bool isGlobalAllocation() const
Definition ExprObjC.h:65
ObjCObjectLiteral(StmtClass SC, EmptyShell Empty)
Definition ExprObjC.h:61
bool isExpressibleAsConstantInitializer() const
Definition ExprObjC.h:68
static bool classof(const Stmt *T)
Definition ExprObjC.h:76
Represents one property declaration in an Objective-C interface.
Definition DeclObjC.h:731
Selector getSetterName() const
Definition DeclObjC.h:893
Selector getGetterName() const
Definition DeclObjC.h:885
bool isMessagingGetter() const
True if the property reference will result in a message to the getter.
Definition ExprObjC.h:767
ObjCPropertyDecl * getExplicitProperty() const
Definition ExprObjC.h:737
Selector getSetterSelector() const
Definition ExprObjC.h:758
bool isMessagingSetter() const
True if the property reference will result in a message to the setter.
Definition ExprObjC.h:774
ObjCMethodDecl * getImplicitPropertyGetter() const
Definition ExprObjC.h:742
ObjCPropertyRefExpr(ObjCMethodDecl *Getter, ObjCMethodDecl *Setter, QualType T, ExprValueKind VK, ExprObjectKind OK, SourceLocation IdLoc, SourceLocation ReceiverLoc, ObjCInterfaceDecl *Receiver)
Definition ExprObjC.h:720
ObjCPropertyRefExpr(ObjCMethodDecl *Getter, ObjCMethodDecl *Setter, QualType T, ExprValueKind VK, ExprObjectKind OK, SourceLocation IdLoc, Expr *Base)
Definition ExprObjC.h:699
void setIsMessagingSetter(bool val=true)
Definition ExprObjC.h:782
SourceLocation getReceiverLocation() const
Definition ExprObjC.h:791
const Expr * getBase() const
Definition ExprObjC.h:786
const_child_range children() const
Definition ExprObjC.h:824
static bool classof(const Stmt *T)
Definition ExprObjC.h:828
bool isObjectReceiver() const
Definition ExprObjC.h:801
bool isExplicitProperty() const
Definition ExprObjC.h:735
SourceLocation getBeginLoc() const LLVM_READONLY
Definition ExprObjC.h:808
void setIsMessagingGetter(bool val=true)
Definition ExprObjC.h:778
QualType getSuperReceiverType() const
Definition ExprObjC.h:793
bool isImplicitProperty() const
Definition ExprObjC.h:734
SourceLocation getEndLoc() const LLVM_READONLY
Definition ExprObjC.h:813
ObjCMethodDecl * getImplicitPropertySetter() const
Definition ExprObjC.h:747
ObjCInterfaceDecl * getClassReceiver() const
Definition ExprObjC.h:797
SourceLocation getLocation() const
Definition ExprObjC.h:789
ObjCPropertyRefExpr(ObjCPropertyDecl *PD, QualType t, ExprValueKind VK, ExprObjectKind OK, SourceLocation l, Expr *base)
Definition ExprObjC.h:682
friend class ASTStmtWriter
Definition ExprObjC.h:834
ObjCPropertyRefExpr(ObjCMethodDecl *Getter, ObjCMethodDecl *Setter, QualType T, ExprValueKind VK, ExprObjectKind OK, SourceLocation IdLoc, SourceLocation SuperLoc, QualType SuperTy)
Definition ExprObjC.h:709
Selector getGetterSelector() const
Definition ExprObjC.h:752
friend class ASTStmtReader
Definition ExprObjC.h:833
ObjCPropertyRefExpr(EmptyShell Empty)
Definition ExprObjC.h:731
QualType getReceiverType(const ASTContext &ctx) const
Determine the type of the base, regardless of the kind of receiver.
Definition ExprObjC.cpp:106
ObjCPropertyRefExpr(ObjCPropertyDecl *PD, QualType t, ExprValueKind VK, ExprObjectKind OK, SourceLocation l, SourceLocation sl, QualType st)
Definition ExprObjC.h:690
bool isClassReceiver() const
Definition ExprObjC.h:803
bool isSuperReceiver() const
Definition ExprObjC.h:802
Represents an Objective-C protocol declaration.
Definition DeclObjC.h:2084
SourceLocation getBeginLoc() const LLVM_READONLY
Definition ExprObjC.h:562
ObjCProtocolDecl * getProtocol() const
Definition ExprObjC.h:553
ObjCProtocolExpr(QualType T, ObjCProtocolDecl *protocol, SourceLocation at, SourceLocation protoLoc, SourceLocation rp)
Definition ExprObjC.h:544
SourceLocation getProtocolIdLoc() const
Definition ExprObjC.h:556
const_child_range children() const
Definition ExprObjC.h:570
void setProtocol(ObjCProtocolDecl *P)
Definition ExprObjC.h:554
void setRParenLoc(SourceLocation L)
Definition ExprObjC.h:560
void setAtLoc(SourceLocation L)
Definition ExprObjC.h:559
SourceLocation getRParenLoc() const
Definition ExprObjC.h:558
static bool classof(const Stmt *T)
Definition ExprObjC.h:574
SourceLocation getAtLoc() const
Definition ExprObjC.h:557
friend class ASTStmtWriter
Definition ExprObjC.h:542
child_range children()
Definition ExprObjC.h:566
ObjCProtocolExpr(EmptyShell Empty)
Definition ExprObjC.h:550
friend class ASTStmtReader
Definition ExprObjC.h:541
SourceLocation getEndLoc() const LLVM_READONLY
Definition ExprObjC.h:563
static bool classof(const Stmt *T)
Definition ExprObjC.h:523
SourceLocation getBeginLoc() const LLVM_READONLY
Definition ExprObjC.h:508
void setSelector(Selector S)
Definition ExprObjC.h:501
unsigned getNumArgs() const
getNumArgs - Return the number of actual arguments to this call.
Definition ExprObjC.h:512
ObjCSelectorExpr(EmptyShell Empty)
Definition ExprObjC.h:497
ObjCSelectorExpr(QualType T, Selector selInfo, SourceLocation at, SourceLocation rp)
Definition ExprObjC.h:491
child_range children()
Definition ExprObjC.h:515
void setAtLoc(SourceLocation L)
Definition ExprObjC.h:505
SourceLocation getRParenLoc() const
Definition ExprObjC.h:504
const_child_range children() const
Definition ExprObjC.h:519
Selector getSelector() const
Definition ExprObjC.h:500
SourceLocation getEndLoc() const LLVM_READONLY
Definition ExprObjC.h:509
void setRParenLoc(SourceLocation L)
Definition ExprObjC.h:506
SourceLocation getAtLoc() const
Definition ExprObjC.h:503
child_range children()
Definition ExprObjC.h:107
SourceLocation getEndLoc() const LLVM_READONLY
Definition ExprObjC.h:104
const StringLiteral * getString() const
Definition ExprObjC.h:97
SourceLocation getAtLoc() const
Definition ExprObjC.h:100
void setAtLoc(SourceLocation L)
Definition ExprObjC.h:101
void setString(StringLiteral *S)
Definition ExprObjC.h:98
const_child_range children() const
Definition ExprObjC.h:109
ObjCStringLiteral(EmptyShell Empty)
Definition ExprObjC.h:93
static bool classof(const Stmt *T)
Definition ExprObjC.h:113
StringLiteral * getString()
Definition ExprObjC.h:96
SourceLocation getBeginLoc() const LLVM_READONLY
Definition ExprObjC.h:103
ObjCStringLiteral(StringLiteral *SL, QualType T, SourceLocation L)
Definition ExprObjC.h:89
SourceLocation getBeginLoc() const LLVM_READONLY
Definition ExprObjC.h:903
Expr * getKeyExpr() const
Definition ExprObjC.h:912
SourceLocation getEndLoc() const LLVM_READONLY
Definition ExprObjC.h:907
void setRBracket(SourceLocation RB)
Definition ExprObjC.h:901
bool isArraySubscriptRefExpr() const
Definition ExprObjC.h:923
ObjCSubscriptRefExpr(EmptyShell Empty)
Definition ExprObjC.h:897
ObjCSubscriptRefExpr(Expr *base, Expr *key, QualType T, ExprValueKind VK, ExprObjectKind OK, ObjCMethodDecl *getMethod, ObjCMethodDecl *setMethod, SourceLocation RB)
Definition ExprObjC.h:887
static bool classof(const Stmt *T)
Definition ExprObjC.h:935
void setBaseExpr(Stmt *S)
Definition ExprObjC.h:910
Expr * getBaseExpr() const
Definition ExprObjC.h:909
const_child_range children() const
Definition ExprObjC.h:931
ObjCMethodDecl * getAtIndexMethodDecl() const
Definition ExprObjC.h:915
SourceLocation getRBracket() const
Definition ExprObjC.h:900
ObjCMethodDecl * setAtIndexMethodDecl() const
Definition ExprObjC.h:919
A (possibly-)qualified type.
Definition TypeBase.h:937
static QualType getFromOpaquePtr(const void *Ptr)
Definition TypeBase.h:986
Smart pointer class that efficiently represents Objective-C method names.
void * getAsOpaquePtr() const
ObjCMethodFamily getMethodFamily() const
Derive the conventional family of this method.
bool isUnarySelector() const
unsigned getNumArgs() const
Encodes a location in the source.
A trivial tuple used to represent a source range.
Stmt - This represents one statement.
Definition Stmt.h:86
SourceLocation getEndLoc() const LLVM_READONLY
Definition Stmt.cpp:367
ObjCObjectLiteralBitfields ObjCObjectLiteralBits
Definition Stmt.h:1404
StmtIterator child_iterator
Child Iterators: All subclasses must implement 'children' to permit easy iteration over the substatem...
Definition Stmt.h:1580
ConstCastIterator< Expr > ConstExprIterator
Definition Stmt.h:1468
llvm::iterator_range< child_iterator > child_range
Definition Stmt.h:1583
ConstStmtIterator const_child_iterator
Definition Stmt.h:1581
ObjCIndirectCopyRestoreExprBitfields ObjCIndirectCopyRestoreExprBits
Definition Stmt.h:1405
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Stmt.cpp:355
llvm::iterator_range< const_child_iterator > const_child_range
Definition Stmt.h:1584
CastIterator< Expr > ExprIterator
Definition Stmt.h:1467
StringLiteral - This represents a string literal expression, e.g.
Definition Expr.h:1802
A container of type source information.
Definition TypeBase.h:8402
bool isSpecificPlaceholderType(unsigned K) const
Test for a specific placeholder type.
Definition TypeBase.h:9023
bool isIntegralOrEnumerationType() const
Determine whether this type is an integral or enumeration type.
Definition TypeBase.h:9156
Definition SPIR.cpp:47
const internal::VariadicAllOfMatcher< Type > type
Matches Types in the clang AST.
The JSON file list parser is used to communicate input to InstallAPI.
bool isa(CodeGen::Address addr)
Definition Address.h:330
SelectorLocationsKind
Whether all locations of the selector identifiers are in a "standard" position.
@ SelLoc_StandardWithSpace
For nullary selectors, immediately before the end: "[foo release]" / "-(void)release;" Or with a spac...
@ SelLoc_NonStandard
Non-standard.
ExprObjectKind
A further classification of the kind of object referenced by an l-value or x-value.
Definition Specifiers.h:149
@ OK_Ordinary
An ordinary object is located at an address in memory.
Definition Specifiers.h:151
@ OK_BitField
A bitfield object is a bitfield on a C or C++ record.
Definition Specifiers.h:154
ExprDependence computeDependence(FullExpr *E)
@ Create
'create' clause, allowed on Compute and Combined constructs, plus 'data', 'enter data',...
ObjCMethodFamily
A family of Objective-C methods.
@ Result
The result type of a method or function.
Definition TypeBase.h:905
ObjCBridgeCastKind
The kind of bridging performed by the Objective-C bridge cast.
CastKind
CastKind - The kind of operation required for a conversion.
SourceLocation getStandardSelectorLoc(unsigned Index, Selector Sel, bool WithArgSpace, ArrayRef< Expr * > Args, SourceLocation EndLoc)
Get the "standard" location of a selector identifier, e.g: For nullary selectors, immediately before ...
ExprValueKind
The categorization of expression values, currently following the C++11 scheme.
Definition Specifiers.h:132
@ VK_PRValue
A pr-value expression (in the C++11 taxonomy) produces a temporary value.
Definition Specifiers.h:135
@ VK_LValue
An l-value expression is a reference to an object with independent storage.
Definition Specifiers.h:139
U cast(CodeGen::Address addr)
Definition Address.h:327
__UINTPTR_TYPE__ uintptr_t
An unsigned integer type with the property that any valid pointer to void can be converted to this ty...
#define false
Definition stdbool.h:26
#define true
Definition stdbool.h:25
An element in an Objective-C dictionary literal.
Definition ExprObjC.h:295
Expr * Value
The value of the dictionary element.
Definition ExprObjC.h:300
bool isPackExpansion() const
Determines whether this dictionary element is a pack expansion.
Definition ExprObjC.h:310
SourceLocation EllipsisLoc
The location of the ellipsis, if this is a pack expansion.
Definition ExprObjC.h:303
UnsignedOrNone NumExpansions
The number of elements this pack expansion will expand to, if this is a pack expansion and is known.
Definition ExprObjC.h:307
Expr * Key
The key for the dictionary element.
Definition ExprObjC.h:297
Internal struct to describes an element that is a pack expansion, used if any of the elements in the ...
Definition ExprObjC.h:326
SourceLocation EllipsisLoc
The location of the ellipsis, if this element is a pack expansion.
Definition ExprObjC.h:329
unsigned NumExpansionsPlusOne
If non-zero, the number of elements that this pack expansion will expand to (+1).
Definition ExprObjC.h:333
Internal struct for storing Key/value pair.
Definition ExprObjC.h:318
A placeholder type used to construct an empty shell of a type, that will be filled in later (e....
Definition Stmt.h:1434