clang 19.0.0git
SemaPseudoObject.cpp
Go to the documentation of this file.
1//===--- SemaPseudoObject.cpp - Semantic Analysis for Pseudo-Objects ------===//
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 implements semantic analysis for expressions involving
10// pseudo-object references. Pseudo-objects are conceptual objects
11// whose storage is entirely abstract and all accesses to which are
12// translated through some sort of abstraction barrier.
13//
14// For example, Objective-C objects can have "properties", either
15// declared or undeclared. A property may be accessed by writing
16// expr.prop
17// where 'expr' is an r-value of Objective-C pointer type and 'prop'
18// is the name of the property. If this expression is used in a context
19// needing an r-value, it is treated as if it were a message-send
20// of the associated 'getter' selector, typically:
21// [expr prop]
22// If it is used as the LHS of a simple assignment, it is treated
23// as a message-send of the associated 'setter' selector, typically:
24// [expr setProp: RHS]
25// If it is used as the LHS of a compound assignment, or the operand
26// of a unary increment or decrement, both are required; for example,
27// 'expr.prop *= 100' would be translated to:
28// [expr setProp: [expr prop] * 100]
29//
30//===----------------------------------------------------------------------===//
31
32#include "clang/AST/ExprCXX.h"
33#include "clang/AST/ExprObjC.h"
39#include "clang/Sema/SemaObjC.h"
40#include "llvm/ADT/SmallString.h"
41
42using namespace clang;
43using namespace sema;
44
45namespace {
46 // Basically just a very focused copy of TreeTransform.
47 struct Rebuilder {
48 Sema &S;
49 unsigned MSPropertySubscriptCount;
50 typedef llvm::function_ref<Expr *(Expr *, unsigned)> SpecificRebuilderRefTy;
51 const SpecificRebuilderRefTy &SpecificCallback;
52 Rebuilder(Sema &S, const SpecificRebuilderRefTy &SpecificCallback)
53 : S(S), MSPropertySubscriptCount(0),
54 SpecificCallback(SpecificCallback) {}
55
56 Expr *rebuildObjCPropertyRefExpr(ObjCPropertyRefExpr *refExpr) {
57 // Fortunately, the constraint that we're rebuilding something
58 // with a base limits the number of cases here.
59 if (refExpr->isClassReceiver() || refExpr->isSuperReceiver())
60 return refExpr;
61
62 if (refExpr->isExplicitProperty()) {
63 return new (S.Context) ObjCPropertyRefExpr(
64 refExpr->getExplicitProperty(), refExpr->getType(),
65 refExpr->getValueKind(), refExpr->getObjectKind(),
66 refExpr->getLocation(), SpecificCallback(refExpr->getBase(), 0));
67 }
68 return new (S.Context) ObjCPropertyRefExpr(
70 refExpr->getImplicitPropertySetter(), refExpr->getType(),
71 refExpr->getValueKind(), refExpr->getObjectKind(),
72 refExpr->getLocation(), SpecificCallback(refExpr->getBase(), 0));
73 }
74 Expr *rebuildObjCSubscriptRefExpr(ObjCSubscriptRefExpr *refExpr) {
75 assert(refExpr->getBaseExpr());
76 assert(refExpr->getKeyExpr());
77
78 return new (S.Context) ObjCSubscriptRefExpr(
79 SpecificCallback(refExpr->getBaseExpr(), 0),
80 SpecificCallback(refExpr->getKeyExpr(), 1), refExpr->getType(),
81 refExpr->getValueKind(), refExpr->getObjectKind(),
82 refExpr->getAtIndexMethodDecl(), refExpr->setAtIndexMethodDecl(),
83 refExpr->getRBracket());
84 }
85 Expr *rebuildMSPropertyRefExpr(MSPropertyRefExpr *refExpr) {
86 assert(refExpr->getBaseExpr());
87
88 return new (S.Context) MSPropertyRefExpr(
89 SpecificCallback(refExpr->getBaseExpr(), 0),
90 refExpr->getPropertyDecl(), refExpr->isArrow(), refExpr->getType(),
91 refExpr->getValueKind(), refExpr->getQualifierLoc(),
92 refExpr->getMemberLoc());
93 }
94 Expr *rebuildMSPropertySubscriptExpr(MSPropertySubscriptExpr *refExpr) {
95 assert(refExpr->getBase());
96 assert(refExpr->getIdx());
97
98 auto *NewBase = rebuild(refExpr->getBase());
99 ++MSPropertySubscriptCount;
100 return new (S.Context) MSPropertySubscriptExpr(
101 NewBase,
102 SpecificCallback(refExpr->getIdx(), MSPropertySubscriptCount),
103 refExpr->getType(), refExpr->getValueKind(), refExpr->getObjectKind(),
104 refExpr->getRBracketLoc());
105 }
106
107 Expr *rebuild(Expr *e) {
108 // Fast path: nothing to look through.
109 if (auto *PRE = dyn_cast<ObjCPropertyRefExpr>(e))
110 return rebuildObjCPropertyRefExpr(PRE);
111 if (auto *SRE = dyn_cast<ObjCSubscriptRefExpr>(e))
112 return rebuildObjCSubscriptRefExpr(SRE);
113 if (auto *MSPRE = dyn_cast<MSPropertyRefExpr>(e))
114 return rebuildMSPropertyRefExpr(MSPRE);
115 if (auto *MSPSE = dyn_cast<MSPropertySubscriptExpr>(e))
116 return rebuildMSPropertySubscriptExpr(MSPSE);
117
118 // Otherwise, we should look through and rebuild anything that
119 // IgnoreParens would.
120
121 if (ParenExpr *parens = dyn_cast<ParenExpr>(e)) {
122 e = rebuild(parens->getSubExpr());
123 return new (S.Context) ParenExpr(parens->getLParen(),
124 parens->getRParen(),
125 e);
126 }
127
128 if (UnaryOperator *uop = dyn_cast<UnaryOperator>(e)) {
129 assert(uop->getOpcode() == UO_Extension);
130 e = rebuild(uop->getSubExpr());
132 S.Context, e, uop->getOpcode(), uop->getType(), uop->getValueKind(),
133 uop->getObjectKind(), uop->getOperatorLoc(), uop->canOverflow(),
135 }
136
137 if (GenericSelectionExpr *gse = dyn_cast<GenericSelectionExpr>(e)) {
138 assert(!gse->isResultDependent());
139 unsigned resultIndex = gse->getResultIndex();
140 unsigned numAssocs = gse->getNumAssocs();
141
142 SmallVector<Expr *, 8> assocExprs;
144 assocExprs.reserve(numAssocs);
145 assocTypes.reserve(numAssocs);
146
147 for (const GenericSelectionExpr::Association assoc :
148 gse->associations()) {
149 Expr *assocExpr = assoc.getAssociationExpr();
150 if (assoc.isSelected())
151 assocExpr = rebuild(assocExpr);
152 assocExprs.push_back(assocExpr);
153 assocTypes.push_back(assoc.getTypeSourceInfo());
154 }
155
156 if (gse->isExprPredicate())
158 S.Context, gse->getGenericLoc(), gse->getControllingExpr(),
159 assocTypes, assocExprs, gse->getDefaultLoc(), gse->getRParenLoc(),
160 gse->containsUnexpandedParameterPack(), resultIndex);
162 S.Context, gse->getGenericLoc(), gse->getControllingType(),
163 assocTypes, assocExprs, gse->getDefaultLoc(), gse->getRParenLoc(),
164 gse->containsUnexpandedParameterPack(), resultIndex);
165 }
166
167 if (ChooseExpr *ce = dyn_cast<ChooseExpr>(e)) {
168 assert(!ce->isConditionDependent());
169
170 Expr *LHS = ce->getLHS(), *RHS = ce->getRHS();
171 Expr *&rebuiltExpr = ce->isConditionTrue() ? LHS : RHS;
172 rebuiltExpr = rebuild(rebuiltExpr);
173
174 return new (S.Context)
175 ChooseExpr(ce->getBuiltinLoc(), ce->getCond(), LHS, RHS,
176 rebuiltExpr->getType(), rebuiltExpr->getValueKind(),
177 rebuiltExpr->getObjectKind(), ce->getRParenLoc(),
178 ce->isConditionTrue());
179 }
180
181 llvm_unreachable("bad expression to rebuild!");
182 }
183 };
184
185 class PseudoOpBuilder {
186 public:
187 Sema &S;
188 unsigned ResultIndex;
189 SourceLocation GenericLoc;
190 bool IsUnique;
191 SmallVector<Expr *, 4> Semantics;
192
193 PseudoOpBuilder(Sema &S, SourceLocation genericLoc, bool IsUnique)
194 : S(S), ResultIndex(PseudoObjectExpr::NoResult),
195 GenericLoc(genericLoc), IsUnique(IsUnique) {}
196
197 virtual ~PseudoOpBuilder() {}
198
199 /// Add a normal semantic expression.
200 void addSemanticExpr(Expr *semantic) {
201 Semantics.push_back(semantic);
202 }
203
204 /// Add the 'result' semantic expression.
205 void addResultSemanticExpr(Expr *resultExpr) {
206 assert(ResultIndex == PseudoObjectExpr::NoResult);
207 ResultIndex = Semantics.size();
208 Semantics.push_back(resultExpr);
209 // An OVE is not unique if it is used as the result expression.
210 if (auto *OVE = dyn_cast<OpaqueValueExpr>(Semantics.back()))
211 OVE->setIsUnique(false);
212 }
213
214 ExprResult buildRValueOperation(Expr *op);
215 ExprResult buildAssignmentOperation(Scope *Sc,
216 SourceLocation opLoc,
217 BinaryOperatorKind opcode,
218 Expr *LHS, Expr *RHS);
219 ExprResult buildIncDecOperation(Scope *Sc, SourceLocation opLoc,
220 UnaryOperatorKind opcode,
221 Expr *op);
222
223 virtual ExprResult complete(Expr *syntacticForm);
224
225 OpaqueValueExpr *capture(Expr *op);
226 OpaqueValueExpr *captureValueAsResult(Expr *op);
227
228 void setResultToLastSemantic() {
229 assert(ResultIndex == PseudoObjectExpr::NoResult);
230 ResultIndex = Semantics.size() - 1;
231 // An OVE is not unique if it is used as the result expression.
232 if (auto *OVE = dyn_cast<OpaqueValueExpr>(Semantics.back()))
233 OVE->setIsUnique(false);
234 }
235
236 /// Return true if assignments have a non-void result.
237 static bool CanCaptureValue(Expr *exp) {
238 if (exp->isGLValue())
239 return true;
240 QualType ty = exp->getType();
241 assert(!ty->isIncompleteType());
242 assert(!ty->isDependentType());
243
244 if (const CXXRecordDecl *ClassDecl = ty->getAsCXXRecordDecl())
245 return ClassDecl->isTriviallyCopyable();
246 return true;
247 }
248
249 virtual Expr *rebuildAndCaptureObject(Expr *) = 0;
250 virtual ExprResult buildGet() = 0;
251 virtual ExprResult buildSet(Expr *, SourceLocation,
252 bool captureSetValueAsResult) = 0;
253 /// Should the result of an assignment be the formal result of the
254 /// setter call or the value that was passed to the setter?
255 ///
256 /// Different pseudo-object language features use different language rules
257 /// for this.
258 /// The default is to use the set value. Currently, this affects the
259 /// behavior of simple assignments, compound assignments, and prefix
260 /// increment and decrement.
261 /// Postfix increment and decrement always use the getter result as the
262 /// expression result.
263 ///
264 /// If this method returns true, and the set value isn't capturable for
265 /// some reason, the result of the expression will be void.
266 virtual bool captureSetValueAsResult() const { return true; }
267 };
268
269 /// A PseudoOpBuilder for Objective-C \@properties.
270 class ObjCPropertyOpBuilder : public PseudoOpBuilder {
271 ObjCPropertyRefExpr *RefExpr;
272 ObjCPropertyRefExpr *SyntacticRefExpr;
273 OpaqueValueExpr *InstanceReceiver;
274 ObjCMethodDecl *Getter;
275
276 ObjCMethodDecl *Setter;
277 Selector SetterSelector;
278 Selector GetterSelector;
279
280 public:
281 ObjCPropertyOpBuilder(Sema &S, ObjCPropertyRefExpr *refExpr, bool IsUnique)
282 : PseudoOpBuilder(S, refExpr->getLocation(), IsUnique),
283 RefExpr(refExpr), SyntacticRefExpr(nullptr),
284 InstanceReceiver(nullptr), Getter(nullptr), Setter(nullptr) {
285 }
286
287 ExprResult buildRValueOperation(Expr *op);
288 ExprResult buildAssignmentOperation(Scope *Sc,
289 SourceLocation opLoc,
290 BinaryOperatorKind opcode,
291 Expr *LHS, Expr *RHS);
292 ExprResult buildIncDecOperation(Scope *Sc, SourceLocation opLoc,
293 UnaryOperatorKind opcode,
294 Expr *op);
295
296 bool tryBuildGetOfReference(Expr *op, ExprResult &result);
297 bool findSetter(bool warn=true);
298 bool findGetter();
299 void DiagnoseUnsupportedPropertyUse();
300
301 Expr *rebuildAndCaptureObject(Expr *syntacticBase) override;
302 ExprResult buildGet() override;
303 ExprResult buildSet(Expr *op, SourceLocation, bool) override;
304 ExprResult complete(Expr *SyntacticForm) override;
305
306 bool isWeakProperty() const;
307 };
308
309 /// A PseudoOpBuilder for Objective-C array/dictionary indexing.
310 class ObjCSubscriptOpBuilder : public PseudoOpBuilder {
311 ObjCSubscriptRefExpr *RefExpr;
312 OpaqueValueExpr *InstanceBase;
313 OpaqueValueExpr *InstanceKey;
314 ObjCMethodDecl *AtIndexGetter;
315 Selector AtIndexGetterSelector;
316
317 ObjCMethodDecl *AtIndexSetter;
318 Selector AtIndexSetterSelector;
319
320 public:
321 ObjCSubscriptOpBuilder(Sema &S, ObjCSubscriptRefExpr *refExpr, bool IsUnique)
322 : PseudoOpBuilder(S, refExpr->getSourceRange().getBegin(), IsUnique),
323 RefExpr(refExpr), InstanceBase(nullptr), InstanceKey(nullptr),
324 AtIndexGetter(nullptr), AtIndexSetter(nullptr) {}
325
326 ExprResult buildRValueOperation(Expr *op);
327 ExprResult buildAssignmentOperation(Scope *Sc,
328 SourceLocation opLoc,
329 BinaryOperatorKind opcode,
330 Expr *LHS, Expr *RHS);
331 Expr *rebuildAndCaptureObject(Expr *syntacticBase) override;
332
333 bool findAtIndexGetter();
334 bool findAtIndexSetter();
335
336 ExprResult buildGet() override;
337 ExprResult buildSet(Expr *op, SourceLocation, bool) override;
338 };
339
340 class MSPropertyOpBuilder : public PseudoOpBuilder {
341 MSPropertyRefExpr *RefExpr;
342 OpaqueValueExpr *InstanceBase;
343 SmallVector<Expr *, 4> CallArgs;
344
345 MSPropertyRefExpr *getBaseMSProperty(MSPropertySubscriptExpr *E);
346
347 public:
348 MSPropertyOpBuilder(Sema &S, MSPropertyRefExpr *refExpr, bool IsUnique)
349 : PseudoOpBuilder(S, refExpr->getSourceRange().getBegin(), IsUnique),
350 RefExpr(refExpr), InstanceBase(nullptr) {}
351 MSPropertyOpBuilder(Sema &S, MSPropertySubscriptExpr *refExpr, bool IsUnique)
352 : PseudoOpBuilder(S, refExpr->getSourceRange().getBegin(), IsUnique),
353 InstanceBase(nullptr) {
354 RefExpr = getBaseMSProperty(refExpr);
355 }
356
357 Expr *rebuildAndCaptureObject(Expr *) override;
358 ExprResult buildGet() override;
359 ExprResult buildSet(Expr *op, SourceLocation, bool) override;
360 bool captureSetValueAsResult() const override { return false; }
361 };
362}
363
364/// Capture the given expression in an OpaqueValueExpr.
365OpaqueValueExpr *PseudoOpBuilder::capture(Expr *e) {
366 // Make a new OVE whose source is the given expression.
367 OpaqueValueExpr *captured =
368 new (S.Context) OpaqueValueExpr(GenericLoc, e->getType(),
369 e->getValueKind(), e->getObjectKind(),
370 e);
371 if (IsUnique)
372 captured->setIsUnique(true);
373
374 // Make sure we bind that in the semantics.
375 addSemanticExpr(captured);
376 return captured;
377}
378
379/// Capture the given expression as the result of this pseudo-object
380/// operation. This routine is safe against expressions which may
381/// already be captured.
382///
383/// \returns the captured expression, which will be the
384/// same as the input if the input was already captured
385OpaqueValueExpr *PseudoOpBuilder::captureValueAsResult(Expr *e) {
386 assert(ResultIndex == PseudoObjectExpr::NoResult);
387
388 // If the expression hasn't already been captured, just capture it
389 // and set the new semantic
390 if (!isa<OpaqueValueExpr>(e)) {
391 OpaqueValueExpr *cap = capture(e);
392 setResultToLastSemantic();
393 return cap;
394 }
395
396 // Otherwise, it must already be one of our semantic expressions;
397 // set ResultIndex to its index.
398 unsigned index = 0;
399 for (;; ++index) {
400 assert(index < Semantics.size() &&
401 "captured expression not found in semantics!");
402 if (e == Semantics[index]) break;
403 }
404 ResultIndex = index;
405 // An OVE is not unique if it is used as the result expression.
406 cast<OpaqueValueExpr>(e)->setIsUnique(false);
407 return cast<OpaqueValueExpr>(e);
408}
409
410/// The routine which creates the final PseudoObjectExpr.
411ExprResult PseudoOpBuilder::complete(Expr *syntactic) {
412 return PseudoObjectExpr::Create(S.Context, syntactic,
413 Semantics, ResultIndex);
414}
415
416/// The main skeleton for building an r-value operation.
417ExprResult PseudoOpBuilder::buildRValueOperation(Expr *op) {
418 Expr *syntacticBase = rebuildAndCaptureObject(op);
419
420 ExprResult getExpr = buildGet();
421 if (getExpr.isInvalid()) return ExprError();
422 addResultSemanticExpr(getExpr.get());
423
424 return complete(syntacticBase);
425}
426
427/// The basic skeleton for building a simple or compound
428/// assignment operation.
430PseudoOpBuilder::buildAssignmentOperation(Scope *Sc, SourceLocation opcLoc,
431 BinaryOperatorKind opcode,
432 Expr *LHS, Expr *RHS) {
433 assert(BinaryOperator::isAssignmentOp(opcode));
434
435 Expr *syntacticLHS = rebuildAndCaptureObject(LHS);
436 OpaqueValueExpr *capturedRHS = capture(RHS);
437
438 // In some very specific cases, semantic analysis of the RHS as an
439 // expression may require it to be rewritten. In these cases, we
440 // cannot safely keep the OVE around. Fortunately, we don't really
441 // need to: we don't use this particular OVE in multiple places, and
442 // no clients rely that closely on matching up expressions in the
443 // semantic expression with expressions from the syntactic form.
444 Expr *semanticRHS = capturedRHS;
445 if (RHS->hasPlaceholderType() || isa<InitListExpr>(RHS)) {
446 semanticRHS = RHS;
447 Semantics.pop_back();
448 }
449
450 Expr *syntactic;
451
452 ExprResult result;
453 if (opcode == BO_Assign) {
454 result = semanticRHS;
455 syntactic = BinaryOperator::Create(S.Context, syntacticLHS, capturedRHS,
456 opcode, capturedRHS->getType(),
457 capturedRHS->getValueKind(), OK_Ordinary,
458 opcLoc, S.CurFPFeatureOverrides());
459
460 } else {
461 ExprResult opLHS = buildGet();
462 if (opLHS.isInvalid()) return ExprError();
463
464 // Build an ordinary, non-compound operation.
465 BinaryOperatorKind nonCompound =
467 result = S.BuildBinOp(Sc, opcLoc, nonCompound, opLHS.get(), semanticRHS);
468 if (result.isInvalid()) return ExprError();
469
471 S.Context, syntacticLHS, capturedRHS, opcode, result.get()->getType(),
472 result.get()->getValueKind(), OK_Ordinary, opcLoc,
473 S.CurFPFeatureOverrides(), opLHS.get()->getType(),
474 result.get()->getType());
475 }
476
477 // The result of the assignment, if not void, is the value set into
478 // the l-value.
479 result = buildSet(result.get(), opcLoc, captureSetValueAsResult());
480 if (result.isInvalid()) return ExprError();
481 addSemanticExpr(result.get());
482 if (!captureSetValueAsResult() && !result.get()->getType()->isVoidType() &&
483 (result.get()->isTypeDependent() || CanCaptureValue(result.get())))
484 setResultToLastSemantic();
485
486 return complete(syntactic);
487}
488
489/// The basic skeleton for building an increment or decrement
490/// operation.
492PseudoOpBuilder::buildIncDecOperation(Scope *Sc, SourceLocation opcLoc,
493 UnaryOperatorKind opcode,
494 Expr *op) {
496
497 Expr *syntacticOp = rebuildAndCaptureObject(op);
498
499 // Load the value.
500 ExprResult result = buildGet();
501 if (result.isInvalid()) return ExprError();
502
503 QualType resultType = result.get()->getType();
504
505 // That's the postfix result.
506 if (UnaryOperator::isPostfix(opcode) &&
507 (result.get()->isTypeDependent() || CanCaptureValue(result.get()))) {
508 result = capture(result.get());
509 setResultToLastSemantic();
510 }
511
512 // Add or subtract a literal 1.
513 llvm::APInt oneV(S.Context.getTypeSize(S.Context.IntTy), 1);
515 GenericLoc);
516
517 if (UnaryOperator::isIncrementOp(opcode)) {
518 result = S.BuildBinOp(Sc, opcLoc, BO_Add, result.get(), one);
519 } else {
520 result = S.BuildBinOp(Sc, opcLoc, BO_Sub, result.get(), one);
521 }
522 if (result.isInvalid()) return ExprError();
523
524 // Store that back into the result. The value stored is the result
525 // of a prefix operation.
526 result = buildSet(result.get(), opcLoc, UnaryOperator::isPrefix(opcode) &&
527 captureSetValueAsResult());
528 if (result.isInvalid()) return ExprError();
529 addSemanticExpr(result.get());
530 if (UnaryOperator::isPrefix(opcode) && !captureSetValueAsResult() &&
531 !result.get()->getType()->isVoidType() &&
532 (result.get()->isTypeDependent() || CanCaptureValue(result.get())))
533 setResultToLastSemantic();
534
535 UnaryOperator *syntactic =
536 UnaryOperator::Create(S.Context, syntacticOp, opcode, resultType,
537 VK_LValue, OK_Ordinary, opcLoc,
538 !resultType->isDependentType()
539 ? S.Context.getTypeSize(resultType) >=
541 : false,
543 return complete(syntactic);
544}
545
546
547//===----------------------------------------------------------------------===//
548// Objective-C @property and implicit property references
549//===----------------------------------------------------------------------===//
550
551/// Look up a method in the receiver type of an Objective-C property
552/// reference.
554 const ObjCPropertyRefExpr *PRE) {
555 if (PRE->isObjectReceiver()) {
556 const ObjCObjectPointerType *PT =
558
559 // Special case for 'self' in class method implementations.
560 if (PT->isObjCClassType() &&
561 S.ObjC().isSelfExpr(const_cast<Expr *>(PRE->getBase()))) {
562 // This cast is safe because isSelfExpr is only true within
563 // methods.
564 ObjCMethodDecl *method =
565 cast<ObjCMethodDecl>(S.CurContext->getNonClosureAncestor());
568 /*instance*/ false);
569 }
570
571 return S.ObjC().LookupMethodInObjectType(sel, PT->getPointeeType(), true);
572 }
573
574 if (PRE->isSuperReceiver()) {
575 if (const ObjCObjectPointerType *PT =
577 return S.ObjC().LookupMethodInObjectType(sel, PT->getPointeeType(), true);
578
580 false);
581 }
582
583 assert(PRE->isClassReceiver() && "Invalid expression");
585 return S.ObjC().LookupMethodInObjectType(sel, IT, false);
586}
587
588bool ObjCPropertyOpBuilder::isWeakProperty() const {
589 QualType T;
590 if (RefExpr->isExplicitProperty()) {
591 const ObjCPropertyDecl *Prop = RefExpr->getExplicitProperty();
593 return true;
594
595 T = Prop->getType();
596 } else if (Getter) {
597 T = Getter->getReturnType();
598 } else {
599 return false;
600 }
601
602 return T.getObjCLifetime() == Qualifiers::OCL_Weak;
603}
604
605bool ObjCPropertyOpBuilder::findGetter() {
606 if (Getter) return true;
607
608 // For implicit properties, just trust the lookup we already did.
609 if (RefExpr->isImplicitProperty()) {
610 if ((Getter = RefExpr->getImplicitPropertyGetter())) {
611 GetterSelector = Getter->getSelector();
612 return true;
613 }
614 else {
615 // Must build the getter selector the hard way.
616 ObjCMethodDecl *setter = RefExpr->getImplicitPropertySetter();
617 assert(setter && "both setter and getter are null - cannot happen");
618 const IdentifierInfo *setterName =
620 const IdentifierInfo *getterName =
621 &S.Context.Idents.get(setterName->getName().substr(3));
622 GetterSelector =
623 S.PP.getSelectorTable().getNullarySelector(getterName);
624 return false;
625 }
626 }
627
628 ObjCPropertyDecl *prop = RefExpr->getExplicitProperty();
629 Getter = LookupMethodInReceiverType(S, prop->getGetterName(), RefExpr);
630 return (Getter != nullptr);
631}
632
633/// Try to find the most accurate setter declaration for the property
634/// reference.
635///
636/// \return true if a setter was found, in which case Setter
637bool ObjCPropertyOpBuilder::findSetter(bool warn) {
638 // For implicit properties, just trust the lookup we already did.
639 if (RefExpr->isImplicitProperty()) {
640 if (ObjCMethodDecl *setter = RefExpr->getImplicitPropertySetter()) {
641 Setter = setter;
642 SetterSelector = setter->getSelector();
643 return true;
644 } else {
645 const IdentifierInfo *getterName = RefExpr->getImplicitPropertyGetter()
646 ->getSelector()
647 .getIdentifierInfoForSlot(0);
648 SetterSelector =
651 getterName);
652 return false;
653 }
654 }
655
656 // For explicit properties, this is more involved.
657 ObjCPropertyDecl *prop = RefExpr->getExplicitProperty();
658 SetterSelector = prop->getSetterName();
659
660 // Do a normal method lookup first.
661 if (ObjCMethodDecl *setter =
662 LookupMethodInReceiverType(S, SetterSelector, RefExpr)) {
663 if (setter->isPropertyAccessor() && warn)
664 if (const ObjCInterfaceDecl *IFace =
665 dyn_cast<ObjCInterfaceDecl>(setter->getDeclContext())) {
666 StringRef thisPropertyName = prop->getName();
667 // Try flipping the case of the first character.
668 char front = thisPropertyName.front();
669 front = isLowercase(front) ? toUppercase(front) : toLowercase(front);
670 SmallString<100> PropertyName = thisPropertyName;
671 PropertyName[0] = front;
672 const IdentifierInfo *AltMember =
673 &S.PP.getIdentifierTable().get(PropertyName);
674 if (ObjCPropertyDecl *prop1 = IFace->FindPropertyDeclaration(
675 AltMember, prop->getQueryKind()))
676 if (prop != prop1 && (prop1->getSetterMethodDecl() == setter)) {
677 S.Diag(RefExpr->getExprLoc(), diag::err_property_setter_ambiguous_use)
678 << prop << prop1 << setter->getSelector();
679 S.Diag(prop->getLocation(), diag::note_property_declare);
680 S.Diag(prop1->getLocation(), diag::note_property_declare);
681 }
682 }
683 Setter = setter;
684 return true;
685 }
686
687 // That can fail in the somewhat crazy situation that we're
688 // type-checking a message send within the @interface declaration
689 // that declared the @property. But it's not clear that that's
690 // valuable to support.
691
692 return false;
693}
694
695void ObjCPropertyOpBuilder::DiagnoseUnsupportedPropertyUse() {
697 S.getCurLexicalContext()->getDeclKind() != Decl::ObjCCategoryImpl &&
698 S.getCurLexicalContext()->getDeclKind() != Decl::ObjCImplementation) {
699 if (ObjCPropertyDecl *prop = RefExpr->getExplicitProperty()) {
700 S.Diag(RefExpr->getLocation(),
701 diag::err_property_function_in_objc_container);
702 S.Diag(prop->getLocation(), diag::note_property_declare);
703 }
704 }
705}
706
707/// Capture the base object of an Objective-C property expression.
708Expr *ObjCPropertyOpBuilder::rebuildAndCaptureObject(Expr *syntacticBase) {
709 assert(InstanceReceiver == nullptr);
710
711 // If we have a base, capture it in an OVE and rebuild the syntactic
712 // form to use the OVE as its base.
713 if (RefExpr->isObjectReceiver()) {
714 InstanceReceiver = capture(RefExpr->getBase());
715 syntacticBase = Rebuilder(S, [=](Expr *, unsigned) -> Expr * {
716 return InstanceReceiver;
717 }).rebuild(syntacticBase);
718 }
719
721 refE = dyn_cast<ObjCPropertyRefExpr>(syntacticBase->IgnoreParens()))
722 SyntacticRefExpr = refE;
723
724 return syntacticBase;
725}
726
727/// Load from an Objective-C property reference.
728ExprResult ObjCPropertyOpBuilder::buildGet() {
729 findGetter();
730 if (!Getter) {
731 DiagnoseUnsupportedPropertyUse();
732 return ExprError();
733 }
734
735 if (SyntacticRefExpr)
736 SyntacticRefExpr->setIsMessagingGetter();
737
738 QualType receiverType = RefExpr->getReceiverType(S.Context);
739 if (!Getter->isImplicit())
740 S.DiagnoseUseOfDecl(Getter, GenericLoc, nullptr, true);
741 // Build a message-send.
742 ExprResult msg;
743 if ((Getter->isInstanceMethod() && !RefExpr->isClassReceiver()) ||
744 RefExpr->isObjectReceiver()) {
745 assert(InstanceReceiver || RefExpr->isSuperReceiver());
747 InstanceReceiver, receiverType, GenericLoc, Getter->getSelector(),
748 Getter, std::nullopt);
749 } else {
751 receiverType, RefExpr->isSuperReceiver(), GenericLoc,
752 Getter->getSelector(), Getter, std::nullopt);
753 }
754 return msg;
755}
756
757/// Store to an Objective-C property reference.
758///
759/// \param captureSetValueAsResult If true, capture the actual
760/// value being set as the value of the property operation.
761ExprResult ObjCPropertyOpBuilder::buildSet(Expr *op, SourceLocation opcLoc,
762 bool captureSetValueAsResult) {
763 if (!findSetter(false)) {
764 DiagnoseUnsupportedPropertyUse();
765 return ExprError();
766 }
767
768 if (SyntacticRefExpr)
769 SyntacticRefExpr->setIsMessagingSetter();
770
771 QualType receiverType = RefExpr->getReceiverType(S.Context);
772
773 // Use assignment constraints when possible; they give us better
774 // diagnostics. "When possible" basically means anything except a
775 // C++ class type.
776 if (!S.getLangOpts().CPlusPlus || !op->getType()->isRecordType()) {
777 QualType paramType = (*Setter->param_begin())->getType()
779 receiverType,
780 Setter->getDeclContext(),
781 ObjCSubstitutionContext::Parameter);
782 if (!S.getLangOpts().CPlusPlus || !paramType->isRecordType()) {
783 ExprResult opResult = op;
784 Sema::AssignConvertType assignResult
785 = S.CheckSingleAssignmentConstraints(paramType, opResult);
786 if (opResult.isInvalid() ||
787 S.DiagnoseAssignmentResult(assignResult, opcLoc, paramType,
788 op->getType(), opResult.get(),
790 return ExprError();
791
792 op = opResult.get();
793 assert(op && "successful assignment left argument invalid?");
794 }
795 }
796
797 // Arguments.
798 Expr *args[] = { op };
799
800 // Build a message-send.
801 ExprResult msg;
802 if (!Setter->isImplicit())
803 S.DiagnoseUseOfDecl(Setter, GenericLoc, nullptr, true);
804 if ((Setter->isInstanceMethod() && !RefExpr->isClassReceiver()) ||
805 RefExpr->isObjectReceiver()) {
806 msg = S.ObjC().BuildInstanceMessageImplicit(InstanceReceiver, receiverType,
807 GenericLoc, SetterSelector,
808 Setter, MultiExprArg(args, 1));
809 } else {
811 receiverType, RefExpr->isSuperReceiver(), GenericLoc, SetterSelector,
812 Setter, MultiExprArg(args, 1));
813 }
814
815 if (!msg.isInvalid() && captureSetValueAsResult) {
816 ObjCMessageExpr *msgExpr =
817 cast<ObjCMessageExpr>(msg.get()->IgnoreImplicit());
818 Expr *arg = msgExpr->getArg(0);
819 if (CanCaptureValue(arg))
820 msgExpr->setArg(0, captureValueAsResult(arg));
821 }
822
823 return msg;
824}
825
826/// @property-specific behavior for doing lvalue-to-rvalue conversion.
827ExprResult ObjCPropertyOpBuilder::buildRValueOperation(Expr *op) {
828 // Explicit properties always have getters, but implicit ones don't.
829 // Check that before proceeding.
830 if (RefExpr->isImplicitProperty() && !RefExpr->getImplicitPropertyGetter()) {
831 S.Diag(RefExpr->getLocation(), diag::err_getter_not_found)
832 << RefExpr->getSourceRange();
833 return ExprError();
834 }
835
836 ExprResult result = PseudoOpBuilder::buildRValueOperation(op);
837 if (result.isInvalid()) return ExprError();
838
839 if (RefExpr->isExplicitProperty() && !Getter->hasRelatedResultType())
840 S.ObjC().DiagnosePropertyAccessorMismatch(RefExpr->getExplicitProperty(),
841 Getter, RefExpr->getLocation());
842
843 // As a special case, if the method returns 'id', try to get
844 // a better type from the property.
845 if (RefExpr->isExplicitProperty() && result.get()->isPRValue()) {
846 QualType receiverType = RefExpr->getReceiverType(S.Context);
847 QualType propType = RefExpr->getExplicitProperty()
848 ->getUsageType(receiverType);
849 if (result.get()->getType()->isObjCIdType()) {
850 if (const ObjCObjectPointerType *ptr
851 = propType->getAs<ObjCObjectPointerType>()) {
852 if (!ptr->isObjCIdType())
853 result = S.ImpCastExprToType(result.get(), propType, CK_BitCast);
854 }
855 }
856 if (propType.getObjCLifetime() == Qualifiers::OCL_Weak &&
857 !S.Diags.isIgnored(diag::warn_arc_repeated_use_of_weak,
858 RefExpr->getLocation()))
859 S.getCurFunction()->markSafeWeakUse(RefExpr);
860 }
861
862 return result;
863}
864
865/// Try to build this as a call to a getter that returns a reference.
866///
867/// \return true if it was possible, whether or not it actually
868/// succeeded
869bool ObjCPropertyOpBuilder::tryBuildGetOfReference(Expr *op,
870 ExprResult &result) {
871 if (!S.getLangOpts().CPlusPlus) return false;
872
873 findGetter();
874 if (!Getter) {
875 // The property has no setter and no getter! This can happen if the type is
876 // invalid. Error have already been reported.
877 result = ExprError();
878 return true;
879 }
880
881 // Only do this if the getter returns an l-value reference type.
882 QualType resultType = Getter->getReturnType();
883 if (!resultType->isLValueReferenceType()) return false;
884
885 result = buildRValueOperation(op);
886 return true;
887}
888
889/// @property-specific behavior for doing assignments.
891ObjCPropertyOpBuilder::buildAssignmentOperation(Scope *Sc,
892 SourceLocation opcLoc,
893 BinaryOperatorKind opcode,
894 Expr *LHS, Expr *RHS) {
895 assert(BinaryOperator::isAssignmentOp(opcode));
896
897 // If there's no setter, we have no choice but to try to assign to
898 // the result of the getter.
899 if (!findSetter()) {
900 ExprResult result;
901 if (tryBuildGetOfReference(LHS, result)) {
902 if (result.isInvalid()) return ExprError();
903 return S.BuildBinOp(Sc, opcLoc, opcode, result.get(), RHS);
904 }
905
906 // Otherwise, it's an error.
907 S.Diag(opcLoc, diag::err_nosetter_property_assignment)
908 << unsigned(RefExpr->isImplicitProperty())
909 << SetterSelector
910 << LHS->getSourceRange() << RHS->getSourceRange();
911 return ExprError();
912 }
913
914 // If there is a setter, we definitely want to use it.
915
916 // Verify that we can do a compound assignment.
917 if (opcode != BO_Assign && !findGetter()) {
918 S.Diag(opcLoc, diag::err_nogetter_property_compound_assignment)
919 << LHS->getSourceRange() << RHS->getSourceRange();
920 return ExprError();
921 }
922
923 ExprResult result =
924 PseudoOpBuilder::buildAssignmentOperation(Sc, opcLoc, opcode, LHS, RHS);
925 if (result.isInvalid()) return ExprError();
926
927 // Various warnings about property assignments in ARC.
928 if (S.getLangOpts().ObjCAutoRefCount && InstanceReceiver) {
929 S.ObjC().checkRetainCycles(InstanceReceiver->getSourceExpr(), RHS);
930 S.checkUnsafeExprAssigns(opcLoc, LHS, RHS);
931 }
932
933 return result;
934}
935
936/// @property-specific behavior for doing increments and decrements.
938ObjCPropertyOpBuilder::buildIncDecOperation(Scope *Sc, SourceLocation opcLoc,
939 UnaryOperatorKind opcode,
940 Expr *op) {
941 // If there's no setter, we have no choice but to try to assign to
942 // the result of the getter.
943 if (!findSetter()) {
944 ExprResult result;
945 if (tryBuildGetOfReference(op, result)) {
946 if (result.isInvalid()) return ExprError();
947 return S.BuildUnaryOp(Sc, opcLoc, opcode, result.get());
948 }
949
950 // Otherwise, it's an error.
951 S.Diag(opcLoc, diag::err_nosetter_property_incdec)
952 << unsigned(RefExpr->isImplicitProperty())
954 << SetterSelector
955 << op->getSourceRange();
956 return ExprError();
957 }
958
959 // If there is a setter, we definitely want to use it.
960
961 // We also need a getter.
962 if (!findGetter()) {
963 assert(RefExpr->isImplicitProperty());
964 S.Diag(opcLoc, diag::err_nogetter_property_incdec)
966 << GetterSelector
967 << op->getSourceRange();
968 return ExprError();
969 }
970
971 return PseudoOpBuilder::buildIncDecOperation(Sc, opcLoc, opcode, op);
972}
973
974ExprResult ObjCPropertyOpBuilder::complete(Expr *SyntacticForm) {
975 if (isWeakProperty() && !S.isUnevaluatedContext() &&
976 !S.Diags.isIgnored(diag::warn_arc_repeated_use_of_weak,
977 SyntacticForm->getBeginLoc()))
978 S.getCurFunction()->recordUseOfWeak(SyntacticRefExpr,
979 SyntacticRefExpr->isMessagingGetter());
980
981 return PseudoOpBuilder::complete(SyntacticForm);
982}
983
984// ObjCSubscript build stuff.
985//
986
987/// objective-c subscripting-specific behavior for doing lvalue-to-rvalue
988/// conversion.
989/// FIXME. Remove this routine if it is proven that no additional
990/// specifity is needed.
991ExprResult ObjCSubscriptOpBuilder::buildRValueOperation(Expr *op) {
992 ExprResult result = PseudoOpBuilder::buildRValueOperation(op);
993 if (result.isInvalid()) return ExprError();
994 return result;
995}
996
997/// objective-c subscripting-specific behavior for doing assignments.
999ObjCSubscriptOpBuilder::buildAssignmentOperation(Scope *Sc,
1000 SourceLocation opcLoc,
1001 BinaryOperatorKind opcode,
1002 Expr *LHS, Expr *RHS) {
1003 assert(BinaryOperator::isAssignmentOp(opcode));
1004 // There must be a method to do the Index'ed assignment.
1005 if (!findAtIndexSetter())
1006 return ExprError();
1007
1008 // Verify that we can do a compound assignment.
1009 if (opcode != BO_Assign && !findAtIndexGetter())
1010 return ExprError();
1011
1012 ExprResult result =
1013 PseudoOpBuilder::buildAssignmentOperation(Sc, opcLoc, opcode, LHS, RHS);
1014 if (result.isInvalid()) return ExprError();
1015
1016 // Various warnings about objc Index'ed assignments in ARC.
1017 if (S.getLangOpts().ObjCAutoRefCount && InstanceBase) {
1018 S.ObjC().checkRetainCycles(InstanceBase->getSourceExpr(), RHS);
1019 S.checkUnsafeExprAssigns(opcLoc, LHS, RHS);
1020 }
1021
1022 return result;
1023}
1024
1025/// Capture the base object of an Objective-C Index'ed expression.
1026Expr *ObjCSubscriptOpBuilder::rebuildAndCaptureObject(Expr *syntacticBase) {
1027 assert(InstanceBase == nullptr);
1028
1029 // Capture base expression in an OVE and rebuild the syntactic
1030 // form to use the OVE as its base expression.
1031 InstanceBase = capture(RefExpr->getBaseExpr());
1032 InstanceKey = capture(RefExpr->getKeyExpr());
1033
1034 syntacticBase =
1035 Rebuilder(S, [=](Expr *, unsigned Idx) -> Expr * {
1036 switch (Idx) {
1037 case 0:
1038 return InstanceBase;
1039 case 1:
1040 return InstanceKey;
1041 default:
1042 llvm_unreachable("Unexpected index for ObjCSubscriptExpr");
1043 }
1044 }).rebuild(syntacticBase);
1045
1046 return syntacticBase;
1047}
1048
1049/// CheckKeyForObjCARCConversion - This routine suggests bridge casting of CF
1050/// objects used as dictionary subscript key objects.
1051static void CheckKeyForObjCARCConversion(Sema &S, QualType ContainerT,
1052 Expr *Key) {
1053 if (ContainerT.isNull())
1054 return;
1055 // dictionary subscripting.
1056 // - (id)objectForKeyedSubscript:(id)key;
1057 const IdentifierInfo *KeyIdents[] = {
1058 &S.Context.Idents.get("objectForKeyedSubscript")};
1059 Selector GetterSelector = S.Context.Selectors.getSelector(1, KeyIdents);
1061 GetterSelector, ContainerT, true /*instance*/);
1062 if (!Getter)
1063 return;
1064 QualType T = Getter->parameters()[0]->getType();
1065 S.ObjC().CheckObjCConversion(Key->getSourceRange(), T, Key,
1066 CheckedConversionKind::Implicit);
1067}
1068
1069bool ObjCSubscriptOpBuilder::findAtIndexGetter() {
1070 if (AtIndexGetter)
1071 return true;
1072
1073 Expr *BaseExpr = RefExpr->getBaseExpr();
1074 QualType BaseT = BaseExpr->getType();
1075
1076 QualType ResultType;
1077 if (const ObjCObjectPointerType *PTy =
1078 BaseT->getAs<ObjCObjectPointerType>()) {
1079 ResultType = PTy->getPointeeType();
1080 }
1082 S.ObjC().CheckSubscriptingKind(RefExpr->getKeyExpr());
1083 if (Res == SemaObjC::OS_Error) {
1084 if (S.getLangOpts().ObjCAutoRefCount)
1085 CheckKeyForObjCARCConversion(S, ResultType,
1086 RefExpr->getKeyExpr());
1087 return false;
1088 }
1089 bool arrayRef = (Res == SemaObjC::OS_Array);
1090
1091 if (ResultType.isNull()) {
1092 S.Diag(BaseExpr->getExprLoc(), diag::err_objc_subscript_base_type)
1093 << BaseExpr->getType() << arrayRef;
1094 return false;
1095 }
1096 if (!arrayRef) {
1097 // dictionary subscripting.
1098 // - (id)objectForKeyedSubscript:(id)key;
1099 const IdentifierInfo *KeyIdents[] = {
1100 &S.Context.Idents.get("objectForKeyedSubscript")};
1101 AtIndexGetterSelector = S.Context.Selectors.getSelector(1, KeyIdents);
1102 }
1103 else {
1104 // - (id)objectAtIndexedSubscript:(size_t)index;
1105 const IdentifierInfo *KeyIdents[] = {
1106 &S.Context.Idents.get("objectAtIndexedSubscript")};
1107
1108 AtIndexGetterSelector = S.Context.Selectors.getSelector(1, KeyIdents);
1109 }
1110
1111 AtIndexGetter = S.ObjC().LookupMethodInObjectType(
1112 AtIndexGetterSelector, ResultType, true /*instance*/);
1113
1114 if (!AtIndexGetter && S.getLangOpts().DebuggerObjCLiteral) {
1115 AtIndexGetter = ObjCMethodDecl::Create(
1116 S.Context, SourceLocation(), SourceLocation(), AtIndexGetterSelector,
1117 S.Context.getObjCIdType() /*ReturnType*/, nullptr /*TypeSourceInfo */,
1118 S.Context.getTranslationUnitDecl(), true /*Instance*/,
1119 false /*isVariadic*/,
1120 /*isPropertyAccessor=*/false,
1121 /*isSynthesizedAccessorStub=*/false,
1122 /*isImplicitlyDeclared=*/true, /*isDefined=*/false,
1123 ObjCImplementationControl::Required, false);
1124 ParmVarDecl *Argument = ParmVarDecl::Create(S.Context, AtIndexGetter,
1126 arrayRef ? &S.Context.Idents.get("index")
1127 : &S.Context.Idents.get("key"),
1128 arrayRef ? S.Context.UnsignedLongTy
1129 : S.Context.getObjCIdType(),
1130 /*TInfo=*/nullptr,
1131 SC_None,
1132 nullptr);
1133 AtIndexGetter->setMethodParams(S.Context, Argument, std::nullopt);
1134 }
1135
1136 if (!AtIndexGetter) {
1137 if (!BaseT->isObjCIdType()) {
1138 S.Diag(BaseExpr->getExprLoc(), diag::err_objc_subscript_method_not_found)
1139 << BaseExpr->getType() << 0 << arrayRef;
1140 return false;
1141 }
1142 AtIndexGetter = S.ObjC().LookupInstanceMethodInGlobalPool(
1143 AtIndexGetterSelector, RefExpr->getSourceRange(), true);
1144 }
1145
1146 if (AtIndexGetter) {
1147 QualType T = AtIndexGetter->parameters()[0]->getType();
1148 if ((arrayRef && !T->isIntegralOrEnumerationType()) ||
1149 (!arrayRef && !T->isObjCObjectPointerType())) {
1150 S.Diag(RefExpr->getKeyExpr()->getExprLoc(),
1151 arrayRef ? diag::err_objc_subscript_index_type
1152 : diag::err_objc_subscript_key_type) << T;
1153 S.Diag(AtIndexGetter->parameters()[0]->getLocation(),
1154 diag::note_parameter_type) << T;
1155 return false;
1156 }
1157 QualType R = AtIndexGetter->getReturnType();
1158 if (!R->isObjCObjectPointerType()) {
1159 S.Diag(RefExpr->getKeyExpr()->getExprLoc(),
1160 diag::err_objc_indexing_method_result_type) << R << arrayRef;
1161 S.Diag(AtIndexGetter->getLocation(), diag::note_method_declared_at) <<
1162 AtIndexGetter->getDeclName();
1163 }
1164 }
1165 return true;
1166}
1167
1168bool ObjCSubscriptOpBuilder::findAtIndexSetter() {
1169 if (AtIndexSetter)
1170 return true;
1171
1172 Expr *BaseExpr = RefExpr->getBaseExpr();
1173 QualType BaseT = BaseExpr->getType();
1174
1175 QualType ResultType;
1176 if (const ObjCObjectPointerType *PTy =
1177 BaseT->getAs<ObjCObjectPointerType>()) {
1178 ResultType = PTy->getPointeeType();
1179 }
1180
1182 S.ObjC().CheckSubscriptingKind(RefExpr->getKeyExpr());
1183 if (Res == SemaObjC::OS_Error) {
1184 if (S.getLangOpts().ObjCAutoRefCount)
1185 CheckKeyForObjCARCConversion(S, ResultType,
1186 RefExpr->getKeyExpr());
1187 return false;
1188 }
1189 bool arrayRef = (Res == SemaObjC::OS_Array);
1190
1191 if (ResultType.isNull()) {
1192 S.Diag(BaseExpr->getExprLoc(), diag::err_objc_subscript_base_type)
1193 << BaseExpr->getType() << arrayRef;
1194 return false;
1195 }
1196
1197 if (!arrayRef) {
1198 // dictionary subscripting.
1199 // - (void)setObject:(id)object forKeyedSubscript:(id)key;
1200 const IdentifierInfo *KeyIdents[] = {
1201 &S.Context.Idents.get("setObject"),
1202 &S.Context.Idents.get("forKeyedSubscript")};
1203 AtIndexSetterSelector = S.Context.Selectors.getSelector(2, KeyIdents);
1204 }
1205 else {
1206 // - (void)setObject:(id)object atIndexedSubscript:(NSInteger)index;
1207 const IdentifierInfo *KeyIdents[] = {
1208 &S.Context.Idents.get("setObject"),
1209 &S.Context.Idents.get("atIndexedSubscript")};
1210 AtIndexSetterSelector = S.Context.Selectors.getSelector(2, KeyIdents);
1211 }
1212 AtIndexSetter = S.ObjC().LookupMethodInObjectType(
1213 AtIndexSetterSelector, ResultType, true /*instance*/);
1214
1215 if (!AtIndexSetter && S.getLangOpts().DebuggerObjCLiteral) {
1216 TypeSourceInfo *ReturnTInfo = nullptr;
1217 QualType ReturnType = S.Context.VoidTy;
1218 AtIndexSetter = ObjCMethodDecl::Create(
1219 S.Context, SourceLocation(), SourceLocation(), AtIndexSetterSelector,
1220 ReturnType, ReturnTInfo, S.Context.getTranslationUnitDecl(),
1221 true /*Instance*/, false /*isVariadic*/,
1222 /*isPropertyAccessor=*/false,
1223 /*isSynthesizedAccessorStub=*/false,
1224 /*isImplicitlyDeclared=*/true, /*isDefined=*/false,
1225 ObjCImplementationControl::Required, false);
1227 ParmVarDecl *object = ParmVarDecl::Create(S.Context, AtIndexSetter,
1229 &S.Context.Idents.get("object"),
1231 /*TInfo=*/nullptr,
1232 SC_None,
1233 nullptr);
1234 Params.push_back(object);
1235 ParmVarDecl *key = ParmVarDecl::Create(S.Context, AtIndexSetter,
1237 arrayRef ? &S.Context.Idents.get("index")
1238 : &S.Context.Idents.get("key"),
1239 arrayRef ? S.Context.UnsignedLongTy
1240 : S.Context.getObjCIdType(),
1241 /*TInfo=*/nullptr,
1242 SC_None,
1243 nullptr);
1244 Params.push_back(key);
1245 AtIndexSetter->setMethodParams(S.Context, Params, std::nullopt);
1246 }
1247
1248 if (!AtIndexSetter) {
1249 if (!BaseT->isObjCIdType()) {
1250 S.Diag(BaseExpr->getExprLoc(),
1251 diag::err_objc_subscript_method_not_found)
1252 << BaseExpr->getType() << 1 << arrayRef;
1253 return false;
1254 }
1255 AtIndexSetter = S.ObjC().LookupInstanceMethodInGlobalPool(
1256 AtIndexSetterSelector, RefExpr->getSourceRange(), true);
1257 }
1258
1259 bool err = false;
1260 if (AtIndexSetter && arrayRef) {
1261 QualType T = AtIndexSetter->parameters()[1]->getType();
1263 S.Diag(RefExpr->getKeyExpr()->getExprLoc(),
1264 diag::err_objc_subscript_index_type) << T;
1265 S.Diag(AtIndexSetter->parameters()[1]->getLocation(),
1266 diag::note_parameter_type) << T;
1267 err = true;
1268 }
1269 T = AtIndexSetter->parameters()[0]->getType();
1270 if (!T->isObjCObjectPointerType()) {
1271 S.Diag(RefExpr->getBaseExpr()->getExprLoc(),
1272 diag::err_objc_subscript_object_type) << T << arrayRef;
1273 S.Diag(AtIndexSetter->parameters()[0]->getLocation(),
1274 diag::note_parameter_type) << T;
1275 err = true;
1276 }
1277 }
1278 else if (AtIndexSetter && !arrayRef)
1279 for (unsigned i=0; i <2; i++) {
1280 QualType T = AtIndexSetter->parameters()[i]->getType();
1281 if (!T->isObjCObjectPointerType()) {
1282 if (i == 1)
1283 S.Diag(RefExpr->getKeyExpr()->getExprLoc(),
1284 diag::err_objc_subscript_key_type) << T;
1285 else
1286 S.Diag(RefExpr->getBaseExpr()->getExprLoc(),
1287 diag::err_objc_subscript_dic_object_type) << T;
1288 S.Diag(AtIndexSetter->parameters()[i]->getLocation(),
1289 diag::note_parameter_type) << T;
1290 err = true;
1291 }
1292 }
1293
1294 return !err;
1295}
1296
1297// Get the object at "Index" position in the container.
1298// [BaseExpr objectAtIndexedSubscript : IndexExpr];
1299ExprResult ObjCSubscriptOpBuilder::buildGet() {
1300 if (!findAtIndexGetter())
1301 return ExprError();
1302
1303 QualType receiverType = InstanceBase->getType();
1304
1305 // Build a message-send.
1306 ExprResult msg;
1307 Expr *Index = InstanceKey;
1308
1309 // Arguments.
1310 Expr *args[] = { Index };
1311 assert(InstanceBase);
1312 if (AtIndexGetter)
1313 S.DiagnoseUseOfDecl(AtIndexGetter, GenericLoc);
1315 InstanceBase, receiverType, GenericLoc, AtIndexGetterSelector,
1316 AtIndexGetter, MultiExprArg(args, 1));
1317 return msg;
1318}
1319
1320/// Store into the container the "op" object at "Index"'ed location
1321/// by building this messaging expression:
1322/// - (void)setObject:(id)object atIndexedSubscript:(NSInteger)index;
1323/// \param captureSetValueAsResult If true, capture the actual
1324/// value being set as the value of the property operation.
1325ExprResult ObjCSubscriptOpBuilder::buildSet(Expr *op, SourceLocation opcLoc,
1326 bool captureSetValueAsResult) {
1327 if (!findAtIndexSetter())
1328 return ExprError();
1329 if (AtIndexSetter)
1330 S.DiagnoseUseOfDecl(AtIndexSetter, GenericLoc);
1331 QualType receiverType = InstanceBase->getType();
1332 Expr *Index = InstanceKey;
1333
1334 // Arguments.
1335 Expr *args[] = { op, Index };
1336
1337 // Build a message-send.
1339 InstanceBase, receiverType, GenericLoc, AtIndexSetterSelector,
1340 AtIndexSetter, MultiExprArg(args, 2));
1341
1342 if (!msg.isInvalid() && captureSetValueAsResult) {
1343 ObjCMessageExpr *msgExpr =
1344 cast<ObjCMessageExpr>(msg.get()->IgnoreImplicit());
1345 Expr *arg = msgExpr->getArg(0);
1346 if (CanCaptureValue(arg))
1347 msgExpr->setArg(0, captureValueAsResult(arg));
1348 }
1349
1350 return msg;
1351}
1352
1353//===----------------------------------------------------------------------===//
1354// MSVC __declspec(property) references
1355//===----------------------------------------------------------------------===//
1356
1358MSPropertyOpBuilder::getBaseMSProperty(MSPropertySubscriptExpr *E) {
1359 CallArgs.insert(CallArgs.begin(), E->getIdx());
1360 Expr *Base = E->getBase()->IgnoreParens();
1361 while (auto *MSPropSubscript = dyn_cast<MSPropertySubscriptExpr>(Base)) {
1362 CallArgs.insert(CallArgs.begin(), MSPropSubscript->getIdx());
1363 Base = MSPropSubscript->getBase()->IgnoreParens();
1364 }
1365 return cast<MSPropertyRefExpr>(Base);
1366}
1367
1368Expr *MSPropertyOpBuilder::rebuildAndCaptureObject(Expr *syntacticBase) {
1369 InstanceBase = capture(RefExpr->getBaseExpr());
1370 for (Expr *&Arg : CallArgs)
1371 Arg = capture(Arg);
1372 syntacticBase = Rebuilder(S, [=](Expr *, unsigned Idx) -> Expr * {
1373 switch (Idx) {
1374 case 0:
1375 return InstanceBase;
1376 default:
1377 assert(Idx <= CallArgs.size());
1378 return CallArgs[Idx - 1];
1379 }
1380 }).rebuild(syntacticBase);
1381
1382 return syntacticBase;
1383}
1384
1385ExprResult MSPropertyOpBuilder::buildGet() {
1386 if (!RefExpr->getPropertyDecl()->hasGetter()) {
1387 S.Diag(RefExpr->getMemberLoc(), diag::err_no_accessor_for_property)
1388 << 0 /* getter */ << RefExpr->getPropertyDecl();
1389 return ExprError();
1390 }
1391
1392 UnqualifiedId GetterName;
1393 const IdentifierInfo *II = RefExpr->getPropertyDecl()->getGetterId();
1394 GetterName.setIdentifier(II, RefExpr->getMemberLoc());
1395 CXXScopeSpec SS;
1396 SS.Adopt(RefExpr->getQualifierLoc());
1397 ExprResult GetterExpr =
1398 S.ActOnMemberAccessExpr(S.getCurScope(), InstanceBase, SourceLocation(),
1399 RefExpr->isArrow() ? tok::arrow : tok::period, SS,
1400 SourceLocation(), GetterName, nullptr);
1401 if (GetterExpr.isInvalid()) {
1402 S.Diag(RefExpr->getMemberLoc(),
1403 diag::err_cannot_find_suitable_accessor) << 0 /* getter */
1404 << RefExpr->getPropertyDecl();
1405 return ExprError();
1406 }
1407
1408 return S.BuildCallExpr(S.getCurScope(), GetterExpr.get(),
1409 RefExpr->getSourceRange().getBegin(), CallArgs,
1410 RefExpr->getSourceRange().getEnd());
1411}
1412
1413ExprResult MSPropertyOpBuilder::buildSet(Expr *op, SourceLocation sl,
1414 bool captureSetValueAsResult) {
1415 if (!RefExpr->getPropertyDecl()->hasSetter()) {
1416 S.Diag(RefExpr->getMemberLoc(), diag::err_no_accessor_for_property)
1417 << 1 /* setter */ << RefExpr->getPropertyDecl();
1418 return ExprError();
1419 }
1420
1421 UnqualifiedId SetterName;
1422 const IdentifierInfo *II = RefExpr->getPropertyDecl()->getSetterId();
1423 SetterName.setIdentifier(II, RefExpr->getMemberLoc());
1424 CXXScopeSpec SS;
1425 SS.Adopt(RefExpr->getQualifierLoc());
1426 ExprResult SetterExpr =
1427 S.ActOnMemberAccessExpr(S.getCurScope(), InstanceBase, SourceLocation(),
1428 RefExpr->isArrow() ? tok::arrow : tok::period, SS,
1429 SourceLocation(), SetterName, nullptr);
1430 if (SetterExpr.isInvalid()) {
1431 S.Diag(RefExpr->getMemberLoc(),
1432 diag::err_cannot_find_suitable_accessor) << 1 /* setter */
1433 << RefExpr->getPropertyDecl();
1434 return ExprError();
1435 }
1436
1437 SmallVector<Expr*, 4> ArgExprs;
1438 ArgExprs.append(CallArgs.begin(), CallArgs.end());
1439 ArgExprs.push_back(op);
1440 return S.BuildCallExpr(S.getCurScope(), SetterExpr.get(),
1441 RefExpr->getSourceRange().getBegin(), ArgExprs,
1442 op->getSourceRange().getEnd());
1443}
1444
1445//===----------------------------------------------------------------------===//
1446// General Sema routines.
1447//===----------------------------------------------------------------------===//
1448
1450 Expr *opaqueRef = E->IgnoreParens();
1451 if (ObjCPropertyRefExpr *refExpr
1452 = dyn_cast<ObjCPropertyRefExpr>(opaqueRef)) {
1453 ObjCPropertyOpBuilder builder(*this, refExpr, true);
1454 return builder.buildRValueOperation(E);
1455 }
1456 else if (ObjCSubscriptRefExpr *refExpr
1457 = dyn_cast<ObjCSubscriptRefExpr>(opaqueRef)) {
1458 ObjCSubscriptOpBuilder builder(*this, refExpr, true);
1459 return builder.buildRValueOperation(E);
1460 } else if (MSPropertyRefExpr *refExpr
1461 = dyn_cast<MSPropertyRefExpr>(opaqueRef)) {
1462 MSPropertyOpBuilder builder(*this, refExpr, true);
1463 return builder.buildRValueOperation(E);
1464 } else if (MSPropertySubscriptExpr *RefExpr =
1465 dyn_cast<MSPropertySubscriptExpr>(opaqueRef)) {
1466 MSPropertyOpBuilder Builder(*this, RefExpr, true);
1467 return Builder.buildRValueOperation(E);
1468 } else {
1469 llvm_unreachable("unknown pseudo-object kind!");
1470 }
1471}
1472
1473/// Check an increment or decrement of a pseudo-object expression.
1475 UnaryOperatorKind opcode, Expr *op) {
1476 // Do nothing if the operand is dependent.
1477 if (op->isTypeDependent())
1479 VK_PRValue, OK_Ordinary, opcLoc, false,
1481
1483 Expr *opaqueRef = op->IgnoreParens();
1484 if (ObjCPropertyRefExpr *refExpr
1485 = dyn_cast<ObjCPropertyRefExpr>(opaqueRef)) {
1486 ObjCPropertyOpBuilder builder(*this, refExpr, false);
1487 return builder.buildIncDecOperation(Sc, opcLoc, opcode, op);
1488 } else if (isa<ObjCSubscriptRefExpr>(opaqueRef)) {
1489 Diag(opcLoc, diag::err_illegal_container_subscripting_op);
1490 return ExprError();
1491 } else if (MSPropertyRefExpr *refExpr
1492 = dyn_cast<MSPropertyRefExpr>(opaqueRef)) {
1493 MSPropertyOpBuilder builder(*this, refExpr, false);
1494 return builder.buildIncDecOperation(Sc, opcLoc, opcode, op);
1495 } else if (MSPropertySubscriptExpr *RefExpr
1496 = dyn_cast<MSPropertySubscriptExpr>(opaqueRef)) {
1497 MSPropertyOpBuilder Builder(*this, RefExpr, false);
1498 return Builder.buildIncDecOperation(Sc, opcLoc, opcode, op);
1499 } else {
1500 llvm_unreachable("unknown pseudo-object kind!");
1501 }
1502}
1503
1505 BinaryOperatorKind opcode,
1506 Expr *LHS, Expr *RHS) {
1507 // Do nothing if either argument is dependent.
1508 if (LHS->isTypeDependent() || RHS->isTypeDependent())
1509 return BinaryOperator::Create(Context, LHS, RHS, opcode,
1511 opcLoc, CurFPFeatureOverrides());
1512
1513 // Filter out non-overload placeholder types in the RHS.
1514 if (RHS->getType()->isNonOverloadPlaceholderType()) {
1515 ExprResult result = CheckPlaceholderExpr(RHS);
1516 if (result.isInvalid()) return ExprError();
1517 RHS = result.get();
1518 }
1519
1520 bool IsSimpleAssign = opcode == BO_Assign;
1521 Expr *opaqueRef = LHS->IgnoreParens();
1522 if (ObjCPropertyRefExpr *refExpr
1523 = dyn_cast<ObjCPropertyRefExpr>(opaqueRef)) {
1524 ObjCPropertyOpBuilder builder(*this, refExpr, IsSimpleAssign);
1525 return builder.buildAssignmentOperation(S, opcLoc, opcode, LHS, RHS);
1526 } else if (ObjCSubscriptRefExpr *refExpr
1527 = dyn_cast<ObjCSubscriptRefExpr>(opaqueRef)) {
1528 ObjCSubscriptOpBuilder builder(*this, refExpr, IsSimpleAssign);
1529 return builder.buildAssignmentOperation(S, opcLoc, opcode, LHS, RHS);
1530 } else if (MSPropertyRefExpr *refExpr
1531 = dyn_cast<MSPropertyRefExpr>(opaqueRef)) {
1532 MSPropertyOpBuilder builder(*this, refExpr, IsSimpleAssign);
1533 return builder.buildAssignmentOperation(S, opcLoc, opcode, LHS, RHS);
1534 } else if (MSPropertySubscriptExpr *RefExpr
1535 = dyn_cast<MSPropertySubscriptExpr>(opaqueRef)) {
1536 MSPropertyOpBuilder Builder(*this, RefExpr, IsSimpleAssign);
1537 return Builder.buildAssignmentOperation(S, opcLoc, opcode, LHS, RHS);
1538 } else {
1539 llvm_unreachable("unknown pseudo-object kind!");
1540 }
1541}
1542
1543/// Given a pseudo-object reference, rebuild it without the opaque
1544/// values. Basically, undo the behavior of rebuildAndCaptureObject.
1545/// This should never operate in-place.
1547 return Rebuilder(S,
1548 [=](Expr *E, unsigned) -> Expr * {
1549 return cast<OpaqueValueExpr>(E)->getSourceExpr();
1550 })
1551 .rebuild(E);
1552}
1553
1554/// Given a pseudo-object expression, recreate what it looks like
1555/// syntactically without the attendant OpaqueValueExprs.
1556///
1557/// This is a hack which should be removed when TreeTransform is
1558/// capable of rebuilding a tree without stripping implicit
1559/// operations.
1561 Expr *syntax = E->getSyntacticForm();
1562 if (UnaryOperator *uop = dyn_cast<UnaryOperator>(syntax)) {
1563 Expr *op = stripOpaqueValuesFromPseudoObjectRef(*this, uop->getSubExpr());
1564 return UnaryOperator::Create(Context, op, uop->getOpcode(), uop->getType(),
1565 uop->getValueKind(), uop->getObjectKind(),
1566 uop->getOperatorLoc(), uop->canOverflow(),
1568 } else if (CompoundAssignOperator *cop
1569 = dyn_cast<CompoundAssignOperator>(syntax)) {
1570 Expr *lhs = stripOpaqueValuesFromPseudoObjectRef(*this, cop->getLHS());
1571 Expr *rhs = cast<OpaqueValueExpr>(cop->getRHS())->getSourceExpr();
1573 Context, lhs, rhs, cop->getOpcode(), cop->getType(),
1574 cop->getValueKind(), cop->getObjectKind(), cop->getOperatorLoc(),
1575 CurFPFeatureOverrides(), cop->getComputationLHSType(),
1576 cop->getComputationResultType());
1577
1578 } else if (BinaryOperator *bop = dyn_cast<BinaryOperator>(syntax)) {
1579 Expr *lhs = stripOpaqueValuesFromPseudoObjectRef(*this, bop->getLHS());
1580 Expr *rhs = cast<OpaqueValueExpr>(bop->getRHS())->getSourceExpr();
1581 return BinaryOperator::Create(Context, lhs, rhs, bop->getOpcode(),
1582 bop->getType(), bop->getValueKind(),
1583 bop->getObjectKind(), bop->getOperatorLoc(),
1585
1586 } else if (isa<CallExpr>(syntax)) {
1587 return syntax;
1588 } else {
1589 assert(syntax->hasPlaceholderType(BuiltinType::PseudoObject));
1590 return stripOpaqueValuesFromPseudoObjectRef(*this, syntax);
1591 }
1592}
Defines the clang::Expr interface and subclasses for C++ expressions.
Defines the clang::Preprocessor interface.
This file declares semantic analysis for Objective-C.
static ObjCMethodDecl * LookupMethodInReceiverType(Sema &S, Selector sel, const ObjCPropertyRefExpr *PRE)
Look up a method in the receiver type of an Objective-C property reference.
static Expr * stripOpaqueValuesFromPseudoObjectRef(Sema &S, Expr *E)
Given a pseudo-object reference, rebuild it without the opaque values.
static void CheckKeyForObjCARCConversion(Sema &S, QualType ContainerT, Expr *Key)
CheckKeyForObjCARCConversion - This routine suggests bridge casting of CF objects used as dictionary ...
TranslationUnitDecl * getTranslationUnitDecl() const
Definition: ASTContext.h:1073
QualType getObjCInterfaceType(const ObjCInterfaceDecl *Decl, ObjCInterfaceDecl *PrevDecl=nullptr) const
getObjCInterfaceType - Return the unique reference to the type for the specified ObjC interface decl.
CanQualType DependentTy
Definition: ASTContext.h:1119
IdentifierTable & Idents
Definition: ASTContext.h:644
SelectorTable & Selectors
Definition: ASTContext.h:645
CanQualType UnsignedLongTy
Definition: ASTContext.h:1101
CanQualType IntTy
Definition: ASTContext.h:1100
QualType getObjCIdType() const
Represents the Objective-CC id type.
Definition: ASTContext.h:2064
uint64_t getTypeSize(QualType T) const
Return the size of the specified (complete) type T, in bits.
Definition: ASTContext.h:2341
CanQualType VoidTy
Definition: ASTContext.h:1091
PtrTy get() const
Definition: Ownership.h:170
bool isInvalid() const
Definition: Ownership.h:166
A builtin binary operation expression such as "x + y" or "x <= y".
Definition: Expr.h:3840
static Opcode getOpForCompoundAssignment(Opcode Opc)
Definition: Expr.h:3986
static BinaryOperator * Create(const ASTContext &C, Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy, ExprValueKind VK, ExprObjectKind OK, SourceLocation opLoc, FPOptionsOverride FPFeatures)
Definition: Expr.cpp:4786
bool isAssignmentOp() const
Definition: Expr.h:3978
Represents a C++ struct/union/class.
Definition: DeclCXX.h:258
Represents a C++ nested-name-specifier or a global scope specifier.
Definition: DeclSpec.h:74
void Adopt(NestedNameSpecifierLoc Other)
Adopt an existing nested-name-specifier (with source-range information).
Definition: DeclSpec.cpp:132
ChooseExpr - GNU builtin-in function __builtin_choose_expr.
Definition: Expr.h:4558
CompoundAssignOperator - For compound assignments (e.g.
Definition: Expr.h:4088
static CompoundAssignOperator * Create(const ASTContext &C, Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy, ExprValueKind VK, ExprObjectKind OK, SourceLocation opLoc, FPOptionsOverride FPFeatures, QualType CompLHSType=QualType(), QualType CompResultType=QualType())
Definition: Expr.cpp:4808
Decl * getNonClosureAncestor()
Find the nearest non-closure ancestor of this context, i.e.
Definition: DeclBase.cpp:1195
bool isObjCContainer() const
Definition: DeclBase.h:2105
Decl::Kind getDeclKind() const
Definition: DeclBase.h:2059
SourceLocation getLocation() const
Definition: DeclBase.h:445
DeclContext * getDeclContext()
Definition: DeclBase.h:454
bool isIgnored(unsigned DiagID, SourceLocation Loc) const
Determine whether the diagnostic is known to be ignored.
Definition: Diagnostic.h:916
This represents one expression.
Definition: Expr.h:110
ExprValueKind getValueKind() const
getValueKind - The value kind that this expression produces.
Definition: Expr.h:437
bool isTypeDependent() const
Determines whether the type of this expression depends on.
Definition: Expr.h:192
Expr * IgnoreImplicit() LLVM_READONLY
Skip past any implicit AST nodes which might surround this expression until reaching a fixed point.
Definition: Expr.cpp:3047
Expr * IgnoreParens() LLVM_READONLY
Skip past any parentheses which might surround this expression until reaching a fixed point.
Definition: Expr.cpp:3055
bool isPRValue() const
Definition: Expr.h:278
ExprObjectKind getObjectKind() const
getObjectKind - The object kind that this expression produces.
Definition: Expr.h:444
SourceLocation getExprLoc() const LLVM_READONLY
getExprLoc - Return the preferred location for the arrow when diagnosing a problem with a generic exp...
Definition: Expr.cpp:277
QualType getType() const
Definition: Expr.h:142
bool hasPlaceholderType() const
Returns whether this expression has a placeholder type.
Definition: Expr.h:516
QualType getReturnType() const
Definition: Type.h:4573
Represents a C11 generic selection.
Definition: Expr.h:5725
AssociationTy< false > Association
Definition: Expr.h:5956
static GenericSelectionExpr * Create(const ASTContext &Context, SourceLocation GenericLoc, Expr *ControllingExpr, ArrayRef< TypeSourceInfo * > AssocTypes, ArrayRef< Expr * > AssocExprs, SourceLocation DefaultLoc, SourceLocation RParenLoc, bool ContainsUnexpandedParameterPack, unsigned ResultIndex)
Create a non-result-dependent generic selection expression accepting an expression predicate.
Definition: Expr.cpp:4475
One of these records is kept for each identifier that is lexed.
StringRef getName() const
Return the actual identifier string.
IdentifierInfo & get(StringRef Name)
Return the identifier token info for the specified named identifier.
static IntegerLiteral * Create(const ASTContext &C, const llvm::APInt &V, QualType type, SourceLocation l)
Returns a new integer literal with value 'V' and type 'type'.
Definition: Expr.cpp:977
A member reference to an MSPropertyDecl.
Definition: ExprCXX.h:929
NestedNameSpecifierLoc getQualifierLoc() const
Definition: ExprCXX.h:986
bool isArrow() const
Definition: ExprCXX.h:984
MSPropertyDecl * getPropertyDecl() const
Definition: ExprCXX.h:983
Expr * getBaseExpr() const
Definition: ExprCXX.h:982
SourceLocation getMemberLoc() const
Definition: ExprCXX.h:985
MS property subscript expression.
Definition: ExprCXX.h:1000
SourceLocation getRBracketLoc() const
Definition: ExprCXX.h:1037
StringRef getName() const
Get the name of identifier for this declaration as a StringRef.
Definition: Decl.h:276
Represents an ObjC class declaration.
Definition: DeclObjC.h:1153
An expression that sends a message to the given Objective-C object or class.
Definition: ExprObjC.h:945
Expr * getArg(unsigned Arg)
getArg - Return the specified argument.
Definition: ExprObjC.h:1395
void setArg(unsigned Arg, Expr *ArgExpr)
setArg - Set the specified argument.
Definition: ExprObjC.h:1405
ObjCMethodDecl - Represents an instance or class method declaration.
Definition: DeclObjC.h:140
ArrayRef< ParmVarDecl * > parameters() const
Definition: DeclObjC.h:373
bool isPropertyAccessor() const
Definition: DeclObjC.h:436
static ObjCMethodDecl * Create(ASTContext &C, SourceLocation beginLoc, SourceLocation endLoc, Selector SelInfo, QualType T, TypeSourceInfo *ReturnTInfo, DeclContext *contextDecl, bool isInstance=true, bool isVariadic=false, bool isPropertyAccessor=false, bool isSynthesizedAccessorStub=false, bool isImplicitlyDeclared=false, bool isDefined=false, ObjCImplementationControl impControl=ObjCImplementationControl::None, bool HasRelatedResultType=false)
Definition: DeclObjC.cpp:852
Selector getSelector() const
Definition: DeclObjC.h:327
ObjCInterfaceDecl * getClassInterface()
Definition: DeclObjC.cpp:1211
Represents a pointer to an Objective C object.
Definition: Type.h:7008
QualType getPointeeType() const
Gets the type pointed to by this ObjC pointer.
Definition: Type.h:7020
bool isObjCClassType() const
True if this is equivalent to the 'Class' type, i.e.
Definition: Type.h:7072
Represents one property declaration in an Objective-C interface.
Definition: DeclObjC.h:730
ObjCPropertyQueryKind getQueryKind() const
Definition: DeclObjC.h:859
Selector getSetterName() const
Definition: DeclObjC.h:892
QualType getType() const
Definition: DeclObjC.h:803
Selector getGetterName() const
Definition: DeclObjC.h:884
ObjCPropertyAttribute::Kind getPropertyAttributes() const
Definition: DeclObjC.h:814
ObjCPropertyRefExpr - A dot-syntax expression to access an ObjC property.
Definition: ExprObjC.h:617
ObjCPropertyDecl * getExplicitProperty() const
Definition: ExprObjC.h:706
ObjCMethodDecl * getImplicitPropertyGetter() const
Definition: ExprObjC.h:711
const Expr * getBase() const
Definition: ExprObjC.h:755
bool isObjectReceiver() const
Definition: ExprObjC.h:774
bool isExplicitProperty() const
Definition: ExprObjC.h:704
QualType getSuperReceiverType() const
Definition: ExprObjC.h:766
ObjCMethodDecl * getImplicitPropertySetter() const
Definition: ExprObjC.h:716
ObjCInterfaceDecl * getClassReceiver() const
Definition: ExprObjC.h:770
SourceLocation getLocation() const
Definition: ExprObjC.h:762
bool isClassReceiver() const
Definition: ExprObjC.h:776
bool isSuperReceiver() const
Definition: ExprObjC.h:775
ObjCSubscriptRefExpr - used for array and dictionary subscripting.
Definition: ExprObjC.h:844
Expr * getKeyExpr() const
Definition: ExprObjC.h:886
Expr * getBaseExpr() const
Definition: ExprObjC.h:883
ObjCMethodDecl * getAtIndexMethodDecl() const
Definition: ExprObjC.h:889
SourceLocation getRBracket() const
Definition: ExprObjC.h:874
ObjCMethodDecl * setAtIndexMethodDecl() const
Definition: ExprObjC.h:893
OpaqueValueExpr - An expression referring to an opaque object of a fixed type and value class.
Definition: Expr.h:1168
void setIsUnique(bool V)
Definition: Expr.h:1220
ParenExpr - This represents a parethesized expression, e.g.
Definition: Expr.h:2130
Represents a parameter to a function.
Definition: Decl.h:1761
static ParmVarDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, const IdentifierInfo *Id, QualType T, TypeSourceInfo *TInfo, StorageClass S, Expr *DefArg)
Definition: Decl.cpp:2915
IdentifierTable & getIdentifierTable()
SelectorTable & getSelectorTable()
PseudoObjectExpr - An expression which accesses a pseudo-object l-value.
Definition: Expr.h:6305
static PseudoObjectExpr * Create(const ASTContext &Context, Expr *syntactic, ArrayRef< Expr * > semantic, unsigned resultIndex)
Definition: Expr.cpp:4880
Expr * getSyntacticForm()
Return the syntactic form of this expression, i.e.
Definition: Expr.h:6347
A (possibly-)qualified type.
Definition: Type.h:940
bool isNull() const
Return true if this QualType doesn't point to a type yet.
Definition: Type.h:1007
Qualifiers::ObjCLifetime getObjCLifetime() const
Returns lifetime attribute of this type.
Definition: Type.h:1432
QualType substObjCMemberType(QualType objectType, const DeclContext *dc, ObjCSubstitutionContext context) const
Substitute type arguments from an object type for the Objective-C type parameters used in the subject...
Definition: Type.cpp:1603
@ OCL_Weak
Reading or writing from this object requires a barrier call.
Definition: Type.h:350
Scope - A scope is a transient data structure that is used while parsing the program.
Definition: Scope.h:41
static Selector constructSetterSelector(IdentifierTable &Idents, SelectorTable &SelTable, const IdentifierInfo *Name)
Return the default setter selector for the given identifier.
Selector getNullarySelector(const IdentifierInfo *ID)
Selector getSelector(unsigned NumArgs, const IdentifierInfo **IIV)
Can create any sort of selector.
Smart pointer class that efficiently represents Objective-C method names.
const IdentifierInfo * getIdentifierInfoForSlot(unsigned argIndex) const
Retrieve the identifier at a given position in the selector.
SemaDiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID, bool DeferHint=false)
Emit a diagnostic.
Definition: SemaBase.cpp:56
bool DiagnosePropertyAccessorMismatch(ObjCPropertyDecl *PD, ObjCMethodDecl *Getter, SourceLocation Loc)
ARCConversionResult CheckObjCConversion(SourceRange castRange, QualType castType, Expr *&op, CheckedConversionKind CCK, bool Diagnose=true, bool DiagnoseCFAudited=false, BinaryOperatorKind Opc=BO_PtrMemD)
Checks for invalid conversions and casts between retainable pointers and other pointer kinds for ARC ...
ObjCSubscriptKind CheckSubscriptingKind(Expr *FromE)
CheckSubscriptingKind - This routine decide what type of indexing represented by "FromE" is being don...
Definition: SemaObjC.cpp:1375
ObjCMethodDecl * LookupInstanceMethodInGlobalPool(Selector Sel, SourceRange R, bool receiverIdOrClass=false)
LookupInstanceMethodInGlobalPool - Returns the method and warns if there are multiple signatures.
Definition: SemaObjC.h:841
ObjCMethodDecl * LookupMethodInObjectType(Selector Sel, QualType Ty, bool IsInstance)
LookupMethodInType - Look up a method in an ObjCObjectType.
ExprResult BuildClassMessageImplicit(QualType ReceiverType, bool isSuperReceiver, SourceLocation Loc, Selector Sel, ObjCMethodDecl *Method, MultiExprArg Args)
ExprResult BuildInstanceMessageImplicit(Expr *Receiver, QualType ReceiverType, SourceLocation Loc, Selector Sel, ObjCMethodDecl *Method, MultiExprArg Args)
void checkRetainCycles(ObjCMessageExpr *msg)
checkRetainCycles - Check whether an Objective-C message send might create an obvious retain cycle.
Definition: SemaObjC.cpp:1157
bool isSelfExpr(Expr *RExpr)
Private Helper predicate to check for 'self'.
Sema - This implements semantic analysis and AST building for C.
Definition: Sema.h:451
Scope * getCurScope() const
Retrieve the parser's current scope.
Definition: Sema.h:688
FPOptionsOverride CurFPFeatureOverrides()
Definition: Sema.h:1422
ASTContext & Context
Definition: Sema.h:848
ExprResult checkPseudoObjectAssignment(Scope *S, SourceLocation OpLoc, BinaryOperatorKind Opcode, Expr *LHS, Expr *RHS)
SemaObjC & ObjC()
Definition: Sema.h:1003
ExprResult BuildUnaryOp(Scope *S, SourceLocation OpLoc, UnaryOperatorKind Opc, Expr *Input, bool IsAfterAmp=false)
Definition: SemaExpr.cpp:15710
ExprResult ImpCastExprToType(Expr *E, QualType Type, CastKind CK, ExprValueKind VK=VK_PRValue, const CXXCastPath *BasePath=nullptr, CheckedConversionKind CCK=CheckedConversionKind::Implicit)
ImpCastExprToType - If Expr is not of type 'Type', insert an implicit cast.
Definition: Sema.cpp:645
Expr * recreateSyntacticForm(PseudoObjectExpr *E)
Given a pseudo-object expression, recreate what it looks like syntactically without the attendant Opa...
const LangOptions & getLangOpts() const
Definition: Sema.h:510
Preprocessor & PP
Definition: Sema.h:847
ExprResult BuildCallExpr(Scope *S, Expr *Fn, SourceLocation LParenLoc, MultiExprArg ArgExprs, SourceLocation RParenLoc, Expr *ExecConfig=nullptr, bool IsExecConfig=false, bool AllowRecovery=false)
BuildCallExpr - Handle a call to Fn with the specified array of arguments.
Definition: SemaExpr.cpp:6507
ExprResult checkPseudoObjectIncDec(Scope *S, SourceLocation OpLoc, UnaryOperatorKind Opcode, Expr *Op)
Check an increment or decrement of a pseudo-object expression.
DeclContext * getCurLexicalContext() const
Definition: Sema.h:692
sema::FunctionScopeInfo * getCurFunction() const
Definition: Sema.h:882
void checkUnsafeExprAssigns(SourceLocation Loc, Expr *LHS, Expr *RHS)
checkUnsafeExprAssigns - Check whether +1 expr is being assigned to weak/__unsafe_unretained expressi...
AssignConvertType CheckSingleAssignmentConstraints(QualType LHSType, ExprResult &RHS, bool Diagnose=true, bool DiagnoseCFAudited=false, bool ConvertRHS=true)
Check assignment constraints for an assignment of RHS to LHSType.
Definition: SemaExpr.cpp:9725
ExprResult ActOnMemberAccessExpr(Scope *S, Expr *Base, SourceLocation OpLoc, tok::TokenKind OpKind, CXXScopeSpec &SS, SourceLocation TemplateKWLoc, UnqualifiedId &Member, Decl *ObjCImpDecl)
The main callback when the parser finds something like expression .
DeclContext * CurContext
CurContext - This is the current declaration context of parsing.
Definition: Sema.h:986
bool isUnevaluatedContext() const
Determines whether we are currently in a context that is not evaluated as per C++ [expr] p5.
Definition: Sema.h:6213
AssignConvertType
AssignConvertType - All of the 'assignment' semantic checks return this enum to indicate whether the ...
Definition: Sema.h:6020
ExprResult CheckPlaceholderExpr(Expr *E)
Check for operands with placeholder types and complain if found.
Definition: SemaExpr.cpp:20849
@ AA_Assigning
Definition: Sema.h:5158
ExprResult checkPseudoObjectRValue(Expr *E)
bool DiagnoseUseOfDecl(NamedDecl *D, ArrayRef< SourceLocation > Locs, const ObjCInterfaceDecl *UnknownObjCClass=nullptr, bool ObjCPropertyAccess=false, bool AvoidPartialAvailabilityChecks=false, ObjCInterfaceDecl *ClassReciever=nullptr, bool SkipTrailingRequiresClause=false)
Determine whether the use of this declaration is valid, and emit any corresponding diagnostics.
Definition: SemaExpr.cpp:228
DiagnosticsEngine & Diags
Definition: Sema.h:850
bool DiagnoseAssignmentResult(AssignConvertType ConvTy, SourceLocation Loc, QualType DstType, QualType SrcType, Expr *SrcExpr, AssignmentAction Action, bool *Complained=nullptr)
DiagnoseAssignmentResult - Emit a diagnostic, if required, for the assignment conversion type specifi...
Definition: SemaExpr.cpp:16748
ExprResult BuildBinOp(Scope *S, SourceLocation OpLoc, BinaryOperatorKind Opc, Expr *LHSExpr, Expr *RHSExpr)
Definition: SemaExpr.cpp:15275
Encodes a location in the source.
SourceLocation getEnd() const
SourceLocation getBegin() const
SourceRange getSourceRange() const LLVM_READONLY
SourceLocation tokens are not useful in isolation - they are low level value objects created/interpre...
Definition: Stmt.cpp:326
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Stmt.cpp:338
A container of type source information.
Definition: Type.h:7330
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
Definition: Type.cpp:1871
bool isVoidType() const
Definition: Type.h:7905
const T * castAs() const
Member-template castAs<specific type>.
Definition: Type.h:8193
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee.
Definition: Type.cpp:695
bool isIntegralOrEnumerationType() const
Determine whether this type is an integral or enumeration type.
Definition: Type.h:8020
bool isNonOverloadPlaceholderType() const
Test for a placeholder type other than Overload; see BuiltinType::isNonOverloadPlaceholderType.
Definition: Type.h:7899
bool isLValueReferenceType() const
Definition: Type.h:7628
bool isDependentType() const
Whether this type is a dependent type, meaning that its definition somehow depends on a template para...
Definition: Type.h:2653
bool isObjCIdType() const
Definition: Type.h:7777
bool isIncompleteType(NamedDecl **Def=nullptr) const
Types are partitioned into 3 broad categories (C99 6.2.5p1): object types, function types,...
Definition: Type.cpp:2351
bool isObjCObjectPointerType() const
Definition: Type.h:7744
const T * getAs() const
Member-template getAs<specific type>'.
Definition: Type.h:8126
bool isRecordType() const
Definition: Type.h:7706
UnaryOperator - This represents the unary-expression's (except sizeof and alignof),...
Definition: Expr.h:2183
bool isDecrementOp() const
Definition: Expr.h:2279
bool isPostfix() const
Definition: Expr.h:2267
bool isPrefix() const
Definition: Expr.h:2266
static UnaryOperator * Create(const ASTContext &C, Expr *input, Opcode opc, QualType type, ExprValueKind VK, ExprObjectKind OK, SourceLocation l, bool CanOverflow, FPOptionsOverride FPFeatures)
Definition: Expr.cpp:4843
bool isIncrementDecrementOp() const
Definition: Expr.h:2284
bool isIncrementOp() const
Definition: Expr.h:2272
Represents a C++ unqualified-id that has been parsed.
Definition: DeclSpec.h:1025
void setIdentifier(const IdentifierInfo *Id, SourceLocation IdLoc)
Specify that this unqualified-id was parsed as an identifier.
Definition: DeclSpec.h:1113
void recordUseOfWeak(const ExprT *E, bool IsRead=true)
Record that a weak object was accessed.
Definition: ScopeInfo.h:1087
void markSafeWeakUse(const Expr *E)
Record that a given expression is a "safe" access of a weak object (e.g.
Definition: ScopeInfo.cpp:160
CharSourceRange getSourceRange(const SourceRange &Range)
Returns the token CharSourceRange corresponding to Range.
Definition: FixIt.h:32
The JSON file list parser is used to communicate input to InstallAPI.
LLVM_READONLY char toLowercase(char c)
Converts the given ASCII character to its lowercase equivalent.
Definition: CharInfo.h:224
@ OK_Ordinary
An ordinary object is located at an address in memory.
Definition: Specifiers.h:148
BinaryOperatorKind
@ SC_None
Definition: Specifiers.h:247
UnaryOperatorKind
LLVM_READONLY bool isLowercase(unsigned char c)
Return true if this character is a lowercase ASCII letter: [a-z].
Definition: CharInfo.h:121
LLVM_READONLY char toUppercase(char c)
Converts the given ASCII character to its uppercase equivalent.
Definition: CharInfo.h:233
ExprResult ExprError()
Definition: Ownership.h:264
@ VK_PRValue
A pr-value expression (in the C++11 taxonomy) produces a temporary value.
Definition: Specifiers.h:132
@ VK_LValue
An l-value expression is a reference to an object with independent storage.
Definition: Specifiers.h:136
const FunctionProtoType * T
MutableArrayRef< Expr * > MultiExprArg
Definition: Ownership.h:258
__DEVICE__ _Tp arg(const std::complex< _Tp > &__c)
Definition: complex_cmath.h:40
#define exp(__x)
Definition: tgmath.h:431