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