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