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