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