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