blob: b740540dcaf17525b48ab703a3712ba9d5e97df9 [file] [log] [blame]
John McCall526ab472011-10-25 17:37:35 +00001//===--- SemaPseudoObject.cpp - Semantic Analysis for Pseudo-Objects ------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file implements semantic analysis for expressions involving
11// pseudo-object references. Pseudo-objects are conceptual objects
12// whose storage is entirely abstract and all accesses to which are
13// translated through some sort of abstraction barrier.
14//
15// For example, Objective-C objects can have "properties", either
16// declared or undeclared. A property may be accessed by writing
17// expr.prop
18// where 'expr' is an r-value of Objective-C pointer type and 'prop'
19// is the name of the property. If this expression is used in a context
20// needing an r-value, it is treated as if it were a message-send
21// of the associated 'getter' selector, typically:
22// [expr prop]
23// If it is used as the LHS of a simple assignment, it is treated
24// as a message-send of the associated 'setter' selector, typically:
25// [expr setProp: RHS]
26// If it is used as the LHS of a compound assignment, or the operand
27// of a unary increment or decrement, both are required; for example,
28// 'expr.prop *= 100' would be translated to:
29// [expr setProp: [expr prop] * 100]
30//
31//===----------------------------------------------------------------------===//
32
33#include "clang/Sema/SemaInternal.h"
Benjamin Kramerf3ca26982014-05-10 16:31:55 +000034#include "clang/AST/ExprCXX.h"
John McCall526ab472011-10-25 17:37:35 +000035#include "clang/AST/ExprObjC.h"
Jordan Rosea7d03842013-02-08 22:30:41 +000036#include "clang/Basic/CharInfo.h"
John McCall526ab472011-10-25 17:37:35 +000037#include "clang/Lex/Preprocessor.h"
Chandler Carruth3a022472012-12-04 09:13:33 +000038#include "clang/Sema/Initialization.h"
39#include "clang/Sema/ScopeInfo.h"
Fariborz Jahanian3f88afa2012-05-24 22:48:38 +000040#include "llvm/ADT/SmallString.h"
John McCall526ab472011-10-25 17:37:35 +000041
42using namespace clang;
43using namespace sema;
44
John McCallfe96e0b2011-11-06 09:01:30 +000045namespace {
46 // Basically just a very focused copy of TreeTransform.
Alexey Bataevf7630272015-11-25 12:01:00 +000047 struct Rebuilder {
John McCallfe96e0b2011-11-06 09:01:30 +000048 Sema &S;
Alexey Bataevf7630272015-11-25 12:01:00 +000049 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) {}
John McCallfe96e0b2011-11-06 09:01:30 +000055
Alexey Bataevf7630272015-11-25 12:01:00 +000056 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(
69 refExpr->getImplicitPropertyGetter(),
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 }
John McCallfe96e0b2011-11-06 09:01:30 +0000106
107 Expr *rebuild(Expr *e) {
108 // Fast path: nothing to look through.
Alexey Bataevf7630272015-11-25 12:01:00 +0000109 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);
John McCallfe96e0b2011-11-06 09:01:30 +0000117
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());
131 return new (S.Context) UnaryOperator(e, uop->getOpcode(),
132 uop->getType(),
133 uop->getValueKind(),
134 uop->getObjectKind(),
135 uop->getOperatorLoc());
136 }
137
138 if (GenericSelectionExpr *gse = dyn_cast<GenericSelectionExpr>(e)) {
139 assert(!gse->isResultDependent());
140 unsigned resultIndex = gse->getResultIndex();
141 unsigned numAssocs = gse->getNumAssocs();
142
143 SmallVector<Expr*, 8> assocs(numAssocs);
144 SmallVector<TypeSourceInfo*, 8> assocTypes(numAssocs);
145
146 for (unsigned i = 0; i != numAssocs; ++i) {
147 Expr *assoc = gse->getAssocExpr(i);
148 if (i == resultIndex) assoc = rebuild(assoc);
149 assocs[i] = assoc;
150 assocTypes[i] = gse->getAssocTypeSourceInfo(i);
151 }
152
153 return new (S.Context) GenericSelectionExpr(S.Context,
154 gse->getGenericLoc(),
155 gse->getControllingExpr(),
Benjamin Kramerc215e762012-08-24 11:54:20 +0000156 assocTypes,
157 assocs,
John McCallfe96e0b2011-11-06 09:01:30 +0000158 gse->getDefaultLoc(),
159 gse->getRParenLoc(),
160 gse->containsUnexpandedParameterPack(),
161 resultIndex);
162 }
163
Eli Friedman75807f22013-07-20 00:40:58 +0000164 if (ChooseExpr *ce = dyn_cast<ChooseExpr>(e)) {
165 assert(!ce->isConditionDependent());
166
167 Expr *LHS = ce->getLHS(), *RHS = ce->getRHS();
168 Expr *&rebuiltExpr = ce->isConditionTrue() ? LHS : RHS;
169 rebuiltExpr = rebuild(rebuiltExpr);
170
171 return new (S.Context) ChooseExpr(ce->getBuiltinLoc(),
172 ce->getCond(),
173 LHS, RHS,
174 rebuiltExpr->getType(),
175 rebuiltExpr->getValueKind(),
176 rebuiltExpr->getObjectKind(),
177 ce->getRParenLoc(),
178 ce->isConditionTrue(),
179 rebuiltExpr->isTypeDependent(),
180 rebuiltExpr->isValueDependent());
181 }
182
John McCallfe96e0b2011-11-06 09:01:30 +0000183 llvm_unreachable("bad expression to rebuild!");
184 }
185 };
186
John McCallfe96e0b2011-11-06 09:01:30 +0000187 class PseudoOpBuilder {
188 public:
189 Sema &S;
190 unsigned ResultIndex;
191 SourceLocation GenericLoc;
192 SmallVector<Expr *, 4> Semantics;
193
194 PseudoOpBuilder(Sema &S, SourceLocation genericLoc)
195 : S(S), ResultIndex(PseudoObjectExpr::NoResult),
196 GenericLoc(genericLoc) {}
197
Angel Garcia Gomez637d1e62015-10-20 13:23:58 +0000198 virtual ~PseudoOpBuilder() {}
Matt Beaumont-Gayfb3cb9a2011-11-08 01:53:17 +0000199
John McCallfe96e0b2011-11-06 09:01:30 +0000200 /// Add a normal semantic expression.
201 void addSemanticExpr(Expr *semantic) {
202 Semantics.push_back(semantic);
203 }
204
205 /// Add the 'result' semantic expression.
206 void addResultSemanticExpr(Expr *resultExpr) {
207 assert(ResultIndex == PseudoObjectExpr::NoResult);
208 ResultIndex = Semantics.size();
209 Semantics.push_back(resultExpr);
210 }
211
212 ExprResult buildRValueOperation(Expr *op);
213 ExprResult buildAssignmentOperation(Scope *Sc,
214 SourceLocation opLoc,
215 BinaryOperatorKind opcode,
216 Expr *LHS, Expr *RHS);
217 ExprResult buildIncDecOperation(Scope *Sc, SourceLocation opLoc,
218 UnaryOperatorKind opcode,
219 Expr *op);
220
Jordan Rosed3934582012-09-28 22:21:30 +0000221 virtual ExprResult complete(Expr *syntacticForm);
John McCallfe96e0b2011-11-06 09:01:30 +0000222
223 OpaqueValueExpr *capture(Expr *op);
224 OpaqueValueExpr *captureValueAsResult(Expr *op);
225
226 void setResultToLastSemantic() {
227 assert(ResultIndex == PseudoObjectExpr::NoResult);
228 ResultIndex = Semantics.size() - 1;
229 }
230
231 /// Return true if assignments have a non-void result.
Alexey Bataev60520e22015-12-10 04:38:18 +0000232 static bool CanCaptureValue(Expr *exp) {
Fariborz Jahanian15dde892014-03-06 00:34:05 +0000233 if (exp->isGLValue())
234 return true;
235 QualType ty = exp->getType();
Eli Friedman00fa4292012-11-13 23:16:33 +0000236 assert(!ty->isIncompleteType());
237 assert(!ty->isDependentType());
238
239 if (const CXXRecordDecl *ClassDecl = ty->getAsCXXRecordDecl())
240 return ClassDecl->isTriviallyCopyable();
241 return true;
242 }
John McCallfe96e0b2011-11-06 09:01:30 +0000243
244 virtual Expr *rebuildAndCaptureObject(Expr *) = 0;
245 virtual ExprResult buildGet() = 0;
246 virtual ExprResult buildSet(Expr *, SourceLocation,
247 bool captureSetValueAsResult) = 0;
Alexey Bataev60520e22015-12-10 04:38:18 +0000248 /// \brief Should the result of an assignment be the formal result of the
249 /// setter call or the value that was passed to the setter?
250 ///
251 /// Different pseudo-object language features use different language rules
252 /// for this.
253 /// The default is to use the set value. Currently, this affects the
254 /// behavior of simple assignments, compound assignments, and prefix
255 /// increment and decrement.
256 /// Postfix increment and decrement always use the getter result as the
257 /// expression result.
258 ///
259 /// If this method returns true, and the set value isn't capturable for
260 /// some reason, the result of the expression will be void.
261 virtual bool captureSetValueAsResult() const { return true; }
John McCallfe96e0b2011-11-06 09:01:30 +0000262 };
263
Dmitri Gribenko00bcdd32012-09-12 17:01:48 +0000264 /// A PseudoOpBuilder for Objective-C \@properties.
John McCallfe96e0b2011-11-06 09:01:30 +0000265 class ObjCPropertyOpBuilder : public PseudoOpBuilder {
266 ObjCPropertyRefExpr *RefExpr;
Argyrios Kyrtzidisab468b02012-03-30 00:19:18 +0000267 ObjCPropertyRefExpr *SyntacticRefExpr;
John McCallfe96e0b2011-11-06 09:01:30 +0000268 OpaqueValueExpr *InstanceReceiver;
269 ObjCMethodDecl *Getter;
270
271 ObjCMethodDecl *Setter;
272 Selector SetterSelector;
Fariborz Jahanianb525b522012-04-18 19:13:23 +0000273 Selector GetterSelector;
John McCallfe96e0b2011-11-06 09:01:30 +0000274
275 public:
276 ObjCPropertyOpBuilder(Sema &S, ObjCPropertyRefExpr *refExpr) :
277 PseudoOpBuilder(S, refExpr->getLocation()), RefExpr(refExpr),
Craig Topperc3ec1492014-05-26 06:22:03 +0000278 SyntacticRefExpr(nullptr), InstanceReceiver(nullptr), Getter(nullptr),
279 Setter(nullptr) {
John McCallfe96e0b2011-11-06 09:01:30 +0000280 }
281
282 ExprResult buildRValueOperation(Expr *op);
283 ExprResult buildAssignmentOperation(Scope *Sc,
284 SourceLocation opLoc,
285 BinaryOperatorKind opcode,
286 Expr *LHS, Expr *RHS);
287 ExprResult buildIncDecOperation(Scope *Sc, SourceLocation opLoc,
288 UnaryOperatorKind opcode,
289 Expr *op);
290
291 bool tryBuildGetOfReference(Expr *op, ExprResult &result);
Fariborz Jahanian3f88afa2012-05-24 22:48:38 +0000292 bool findSetter(bool warn=true);
John McCallfe96e0b2011-11-06 09:01:30 +0000293 bool findGetter();
Olivier Goffartf6fabcc2014-08-04 17:28:11 +0000294 void DiagnoseUnsupportedPropertyUse();
John McCallfe96e0b2011-11-06 09:01:30 +0000295
Craig Toppere14c0f82014-03-12 04:55:44 +0000296 Expr *rebuildAndCaptureObject(Expr *syntacticBase) override;
297 ExprResult buildGet() override;
298 ExprResult buildSet(Expr *op, SourceLocation, bool) override;
299 ExprResult complete(Expr *SyntacticForm) override;
Jordan Rosed3934582012-09-28 22:21:30 +0000300
301 bool isWeakProperty() const;
John McCallfe96e0b2011-11-06 09:01:30 +0000302 };
Ted Kremeneke65b0862012-03-06 20:05:56 +0000303
304 /// A PseudoOpBuilder for Objective-C array/dictionary indexing.
305 class ObjCSubscriptOpBuilder : public PseudoOpBuilder {
306 ObjCSubscriptRefExpr *RefExpr;
307 OpaqueValueExpr *InstanceBase;
308 OpaqueValueExpr *InstanceKey;
309 ObjCMethodDecl *AtIndexGetter;
310 Selector AtIndexGetterSelector;
311
312 ObjCMethodDecl *AtIndexSetter;
313 Selector AtIndexSetterSelector;
314
315 public:
316 ObjCSubscriptOpBuilder(Sema &S, ObjCSubscriptRefExpr *refExpr) :
317 PseudoOpBuilder(S, refExpr->getSourceRange().getBegin()),
318 RefExpr(refExpr),
Craig Topperc3ec1492014-05-26 06:22:03 +0000319 InstanceBase(nullptr), InstanceKey(nullptr),
320 AtIndexGetter(nullptr), AtIndexSetter(nullptr) {}
321
Ted Kremeneke65b0862012-03-06 20:05:56 +0000322 ExprResult buildRValueOperation(Expr *op);
323 ExprResult buildAssignmentOperation(Scope *Sc,
324 SourceLocation opLoc,
325 BinaryOperatorKind opcode,
326 Expr *LHS, Expr *RHS);
Craig Toppere14c0f82014-03-12 04:55:44 +0000327 Expr *rebuildAndCaptureObject(Expr *syntacticBase) override;
328
Ted Kremeneke65b0862012-03-06 20:05:56 +0000329 bool findAtIndexGetter();
330 bool findAtIndexSetter();
Craig Toppere14c0f82014-03-12 04:55:44 +0000331
332 ExprResult buildGet() override;
333 ExprResult buildSet(Expr *op, SourceLocation, bool) override;
Ted Kremeneke65b0862012-03-06 20:05:56 +0000334 };
335
John McCall5e77d762013-04-16 07:28:30 +0000336 class MSPropertyOpBuilder : public PseudoOpBuilder {
337 MSPropertyRefExpr *RefExpr;
Alexey Bataev69103472015-10-14 04:05:42 +0000338 OpaqueValueExpr *InstanceBase;
Alexey Bataevf7630272015-11-25 12:01:00 +0000339 SmallVector<Expr *, 4> CallArgs;
340
341 MSPropertyRefExpr *getBaseMSProperty(MSPropertySubscriptExpr *E);
John McCall5e77d762013-04-16 07:28:30 +0000342
343 public:
344 MSPropertyOpBuilder(Sema &S, MSPropertyRefExpr *refExpr) :
345 PseudoOpBuilder(S, refExpr->getSourceRange().getBegin()),
Alexey Bataev69103472015-10-14 04:05:42 +0000346 RefExpr(refExpr), InstanceBase(nullptr) {}
Alexey Bataevf7630272015-11-25 12:01:00 +0000347 MSPropertyOpBuilder(Sema &S, MSPropertySubscriptExpr *refExpr)
348 : PseudoOpBuilder(S, refExpr->getSourceRange().getBegin()),
349 InstanceBase(nullptr) {
350 RefExpr = getBaseMSProperty(refExpr);
351 }
John McCall5e77d762013-04-16 07:28:30 +0000352
Craig Toppere14c0f82014-03-12 04:55:44 +0000353 Expr *rebuildAndCaptureObject(Expr *) override;
354 ExprResult buildGet() override;
355 ExprResult buildSet(Expr *op, SourceLocation, bool) override;
Alexey Bataev60520e22015-12-10 04:38:18 +0000356 bool captureSetValueAsResult() const override { return false; }
John McCall5e77d762013-04-16 07:28:30 +0000357 };
Alexander Kornienkoab9db512015-06-22 23:07:51 +0000358}
John McCallfe96e0b2011-11-06 09:01:30 +0000359
360/// Capture the given expression in an OpaqueValueExpr.
361OpaqueValueExpr *PseudoOpBuilder::capture(Expr *e) {
362 // Make a new OVE whose source is the given expression.
363 OpaqueValueExpr *captured =
364 new (S.Context) OpaqueValueExpr(GenericLoc, e->getType(),
Douglas Gregor2d5aea02012-02-23 22:17:26 +0000365 e->getValueKind(), e->getObjectKind(),
366 e);
John McCallfe96e0b2011-11-06 09:01:30 +0000367
368 // Make sure we bind that in the semantics.
369 addSemanticExpr(captured);
370 return captured;
371}
372
373/// Capture the given expression as the result of this pseudo-object
374/// operation. This routine is safe against expressions which may
375/// already be captured.
376///
Dmitri Gribenkoadba9be2012-08-23 17:58:28 +0000377/// \returns the captured expression, which will be the
John McCallfe96e0b2011-11-06 09:01:30 +0000378/// same as the input if the input was already captured
379OpaqueValueExpr *PseudoOpBuilder::captureValueAsResult(Expr *e) {
380 assert(ResultIndex == PseudoObjectExpr::NoResult);
381
382 // If the expression hasn't already been captured, just capture it
383 // and set the new semantic
384 if (!isa<OpaqueValueExpr>(e)) {
385 OpaqueValueExpr *cap = capture(e);
386 setResultToLastSemantic();
387 return cap;
388 }
389
390 // Otherwise, it must already be one of our semantic expressions;
391 // set ResultIndex to its index.
392 unsigned index = 0;
393 for (;; ++index) {
394 assert(index < Semantics.size() &&
395 "captured expression not found in semantics!");
396 if (e == Semantics[index]) break;
397 }
398 ResultIndex = index;
399 return cast<OpaqueValueExpr>(e);
400}
401
402/// The routine which creates the final PseudoObjectExpr.
403ExprResult PseudoOpBuilder::complete(Expr *syntactic) {
404 return PseudoObjectExpr::Create(S.Context, syntactic,
405 Semantics, ResultIndex);
406}
407
408/// The main skeleton for building an r-value operation.
409ExprResult PseudoOpBuilder::buildRValueOperation(Expr *op) {
410 Expr *syntacticBase = rebuildAndCaptureObject(op);
411
412 ExprResult getExpr = buildGet();
413 if (getExpr.isInvalid()) return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +0000414 addResultSemanticExpr(getExpr.get());
John McCallfe96e0b2011-11-06 09:01:30 +0000415
416 return complete(syntacticBase);
417}
418
419/// The basic skeleton for building a simple or compound
420/// assignment operation.
421ExprResult
422PseudoOpBuilder::buildAssignmentOperation(Scope *Sc, SourceLocation opcLoc,
423 BinaryOperatorKind opcode,
424 Expr *LHS, Expr *RHS) {
425 assert(BinaryOperator::isAssignmentOp(opcode));
426
427 Expr *syntacticLHS = rebuildAndCaptureObject(LHS);
428 OpaqueValueExpr *capturedRHS = capture(RHS);
429
John McCallee04aeb2015-08-22 00:35:27 +0000430 // In some very specific cases, semantic analysis of the RHS as an
431 // expression may require it to be rewritten. In these cases, we
432 // cannot safely keep the OVE around. Fortunately, we don't really
433 // need to: we don't use this particular OVE in multiple places, and
434 // no clients rely that closely on matching up expressions in the
435 // semantic expression with expressions from the syntactic form.
436 Expr *semanticRHS = capturedRHS;
437 if (RHS->hasPlaceholderType() || isa<InitListExpr>(RHS)) {
438 semanticRHS = RHS;
439 Semantics.pop_back();
440 }
441
John McCallfe96e0b2011-11-06 09:01:30 +0000442 Expr *syntactic;
443
444 ExprResult result;
445 if (opcode == BO_Assign) {
John McCallee04aeb2015-08-22 00:35:27 +0000446 result = semanticRHS;
John McCallfe96e0b2011-11-06 09:01:30 +0000447 syntactic = new (S.Context) BinaryOperator(syntacticLHS, capturedRHS,
448 opcode, capturedRHS->getType(),
449 capturedRHS->getValueKind(),
Adam Nemet484aa452017-03-27 19:17:25 +0000450 OK_Ordinary, opcLoc,
451 FPOptions());
John McCallfe96e0b2011-11-06 09:01:30 +0000452 } else {
453 ExprResult opLHS = buildGet();
454 if (opLHS.isInvalid()) return ExprError();
455
456 // Build an ordinary, non-compound operation.
457 BinaryOperatorKind nonCompound =
458 BinaryOperator::getOpForCompoundAssignment(opcode);
John McCallee04aeb2015-08-22 00:35:27 +0000459 result = S.BuildBinOp(Sc, opcLoc, nonCompound, opLHS.get(), semanticRHS);
John McCallfe96e0b2011-11-06 09:01:30 +0000460 if (result.isInvalid()) return ExprError();
461
462 syntactic =
463 new (S.Context) CompoundAssignOperator(syntacticLHS, capturedRHS, opcode,
464 result.get()->getType(),
465 result.get()->getValueKind(),
466 OK_Ordinary,
467 opLHS.get()->getType(),
468 result.get()->getType(),
Adam Nemet484aa452017-03-27 19:17:25 +0000469 opcLoc, FPOptions());
John McCallfe96e0b2011-11-06 09:01:30 +0000470 }
471
472 // The result of the assignment, if not void, is the value set into
473 // the l-value.
Alexey Bataev60520e22015-12-10 04:38:18 +0000474 result = buildSet(result.get(), opcLoc, captureSetValueAsResult());
John McCallfe96e0b2011-11-06 09:01:30 +0000475 if (result.isInvalid()) return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +0000476 addSemanticExpr(result.get());
Alexey Bataev60520e22015-12-10 04:38:18 +0000477 if (!captureSetValueAsResult() && !result.get()->getType()->isVoidType() &&
478 (result.get()->isTypeDependent() || CanCaptureValue(result.get())))
479 setResultToLastSemantic();
John McCallfe96e0b2011-11-06 09:01:30 +0000480
481 return complete(syntactic);
482}
483
484/// The basic skeleton for building an increment or decrement
485/// operation.
486ExprResult
487PseudoOpBuilder::buildIncDecOperation(Scope *Sc, SourceLocation opcLoc,
488 UnaryOperatorKind opcode,
489 Expr *op) {
490 assert(UnaryOperator::isIncrementDecrementOp(opcode));
491
492 Expr *syntacticOp = rebuildAndCaptureObject(op);
493
494 // Load the value.
495 ExprResult result = buildGet();
496 if (result.isInvalid()) return ExprError();
497
498 QualType resultType = result.get()->getType();
499
500 // That's the postfix result.
John McCall0d9dd732013-04-16 22:32:04 +0000501 if (UnaryOperator::isPostfix(opcode) &&
Fariborz Jahanian15dde892014-03-06 00:34:05 +0000502 (result.get()->isTypeDependent() || CanCaptureValue(result.get()))) {
Nikola Smiljanic01a75982014-05-29 10:55:11 +0000503 result = capture(result.get());
John McCallfe96e0b2011-11-06 09:01:30 +0000504 setResultToLastSemantic();
505 }
506
507 // Add or subtract a literal 1.
508 llvm::APInt oneV(S.Context.getTypeSize(S.Context.IntTy), 1);
509 Expr *one = IntegerLiteral::Create(S.Context, oneV, S.Context.IntTy,
510 GenericLoc);
511
512 if (UnaryOperator::isIncrementOp(opcode)) {
Nikola Smiljanic01a75982014-05-29 10:55:11 +0000513 result = S.BuildBinOp(Sc, opcLoc, BO_Add, result.get(), one);
John McCallfe96e0b2011-11-06 09:01:30 +0000514 } else {
Nikola Smiljanic01a75982014-05-29 10:55:11 +0000515 result = S.BuildBinOp(Sc, opcLoc, BO_Sub, result.get(), one);
John McCallfe96e0b2011-11-06 09:01:30 +0000516 }
517 if (result.isInvalid()) return ExprError();
518
519 // Store that back into the result. The value stored is the result
520 // of a prefix operation.
Alexey Bataev60520e22015-12-10 04:38:18 +0000521 result = buildSet(result.get(), opcLoc, UnaryOperator::isPrefix(opcode) &&
522 captureSetValueAsResult());
John McCallfe96e0b2011-11-06 09:01:30 +0000523 if (result.isInvalid()) return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +0000524 addSemanticExpr(result.get());
Alexey Bataev60520e22015-12-10 04:38:18 +0000525 if (UnaryOperator::isPrefix(opcode) && !captureSetValueAsResult() &&
526 !result.get()->getType()->isVoidType() &&
527 (result.get()->isTypeDependent() || CanCaptureValue(result.get())))
528 setResultToLastSemantic();
John McCallfe96e0b2011-11-06 09:01:30 +0000529
530 UnaryOperator *syntactic =
531 new (S.Context) UnaryOperator(syntacticOp, opcode, resultType,
532 VK_LValue, OK_Ordinary, opcLoc);
533 return complete(syntactic);
534}
535
536
537//===----------------------------------------------------------------------===//
538// Objective-C @property and implicit property references
539//===----------------------------------------------------------------------===//
540
541/// Look up a method in the receiver type of an Objective-C property
542/// reference.
John McCall526ab472011-10-25 17:37:35 +0000543static ObjCMethodDecl *LookupMethodInReceiverType(Sema &S, Selector sel,
544 const ObjCPropertyRefExpr *PRE) {
John McCall526ab472011-10-25 17:37:35 +0000545 if (PRE->isObjectReceiver()) {
Benjamin Kramer8dc57602011-10-28 13:21:18 +0000546 const ObjCObjectPointerType *PT =
547 PRE->getBase()->getType()->castAs<ObjCObjectPointerType>();
John McCallfe96e0b2011-11-06 09:01:30 +0000548
549 // Special case for 'self' in class method implementations.
550 if (PT->isObjCClassType() &&
551 S.isSelfExpr(const_cast<Expr*>(PRE->getBase()))) {
552 // This cast is safe because isSelfExpr is only true within
553 // methods.
554 ObjCMethodDecl *method =
555 cast<ObjCMethodDecl>(S.CurContext->getNonClosureAncestor());
556 return S.LookupMethodInObjectType(sel,
557 S.Context.getObjCInterfaceType(method->getClassInterface()),
558 /*instance*/ false);
559 }
560
Benjamin Kramer8dc57602011-10-28 13:21:18 +0000561 return S.LookupMethodInObjectType(sel, PT->getPointeeType(), true);
John McCall526ab472011-10-25 17:37:35 +0000562 }
563
Benjamin Kramer8dc57602011-10-28 13:21:18 +0000564 if (PRE->isSuperReceiver()) {
565 if (const ObjCObjectPointerType *PT =
566 PRE->getSuperReceiverType()->getAs<ObjCObjectPointerType>())
567 return S.LookupMethodInObjectType(sel, PT->getPointeeType(), true);
568
569 return S.LookupMethodInObjectType(sel, PRE->getSuperReceiverType(), false);
570 }
571
572 assert(PRE->isClassReceiver() && "Invalid expression");
573 QualType IT = S.Context.getObjCInterfaceType(PRE->getClassReceiver());
574 return S.LookupMethodInObjectType(sel, IT, false);
John McCall526ab472011-10-25 17:37:35 +0000575}
576
Jordan Rosed3934582012-09-28 22:21:30 +0000577bool ObjCPropertyOpBuilder::isWeakProperty() const {
578 QualType T;
579 if (RefExpr->isExplicitProperty()) {
580 const ObjCPropertyDecl *Prop = RefExpr->getExplicitProperty();
581 if (Prop->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_weak)
Bob Wilsonf4f54e32016-05-25 05:41:57 +0000582 return true;
Jordan Rosed3934582012-09-28 22:21:30 +0000583
584 T = Prop->getType();
585 } else if (Getter) {
Alp Toker314cc812014-01-25 16:55:45 +0000586 T = Getter->getReturnType();
Jordan Rosed3934582012-09-28 22:21:30 +0000587 } else {
588 return false;
589 }
590
591 return T.getObjCLifetime() == Qualifiers::OCL_Weak;
592}
593
John McCallfe96e0b2011-11-06 09:01:30 +0000594bool ObjCPropertyOpBuilder::findGetter() {
595 if (Getter) return true;
John McCall526ab472011-10-25 17:37:35 +0000596
John McCallcfef5462011-11-07 22:49:50 +0000597 // For implicit properties, just trust the lookup we already did.
598 if (RefExpr->isImplicitProperty()) {
Fariborz Jahanianb525b522012-04-18 19:13:23 +0000599 if ((Getter = RefExpr->getImplicitPropertyGetter())) {
600 GetterSelector = Getter->getSelector();
601 return true;
602 }
603 else {
604 // Must build the getter selector the hard way.
605 ObjCMethodDecl *setter = RefExpr->getImplicitPropertySetter();
606 assert(setter && "both setter and getter are null - cannot happen");
607 IdentifierInfo *setterName =
608 setter->getSelector().getIdentifierInfoForSlot(0);
Alp Toker541d5072014-06-07 23:30:53 +0000609 IdentifierInfo *getterName =
610 &S.Context.Idents.get(setterName->getName().substr(3));
Fariborz Jahanianb525b522012-04-18 19:13:23 +0000611 GetterSelector =
612 S.PP.getSelectorTable().getNullarySelector(getterName);
613 return false;
Fariborz Jahanianb525b522012-04-18 19:13:23 +0000614 }
John McCallcfef5462011-11-07 22:49:50 +0000615 }
616
617 ObjCPropertyDecl *prop = RefExpr->getExplicitProperty();
618 Getter = LookupMethodInReceiverType(S, prop->getGetterName(), RefExpr);
Craig Topperc3ec1492014-05-26 06:22:03 +0000619 return (Getter != nullptr);
John McCallfe96e0b2011-11-06 09:01:30 +0000620}
621
622/// Try to find the most accurate setter declaration for the property
623/// reference.
624///
625/// \return true if a setter was found, in which case Setter
Fariborz Jahanian3f88afa2012-05-24 22:48:38 +0000626bool ObjCPropertyOpBuilder::findSetter(bool warn) {
John McCallfe96e0b2011-11-06 09:01:30 +0000627 // For implicit properties, just trust the lookup we already did.
628 if (RefExpr->isImplicitProperty()) {
629 if (ObjCMethodDecl *setter = RefExpr->getImplicitPropertySetter()) {
630 Setter = setter;
631 SetterSelector = setter->getSelector();
632 return true;
John McCall526ab472011-10-25 17:37:35 +0000633 } else {
John McCallfe96e0b2011-11-06 09:01:30 +0000634 IdentifierInfo *getterName =
635 RefExpr->getImplicitPropertyGetter()->getSelector()
636 .getIdentifierInfoForSlot(0);
637 SetterSelector =
Adrian Prantla4ce9062013-06-07 22:29:12 +0000638 SelectorTable::constructSetterSelector(S.PP.getIdentifierTable(),
639 S.PP.getSelectorTable(),
640 getterName);
John McCallfe96e0b2011-11-06 09:01:30 +0000641 return false;
John McCall526ab472011-10-25 17:37:35 +0000642 }
John McCallfe96e0b2011-11-06 09:01:30 +0000643 }
644
645 // For explicit properties, this is more involved.
646 ObjCPropertyDecl *prop = RefExpr->getExplicitProperty();
647 SetterSelector = prop->getSetterName();
648
649 // Do a normal method lookup first.
650 if (ObjCMethodDecl *setter =
651 LookupMethodInReceiverType(S, SetterSelector, RefExpr)) {
Jordan Rosed01e83a2012-10-10 16:42:25 +0000652 if (setter->isPropertyAccessor() && warn)
Fariborz Jahanian3f88afa2012-05-24 22:48:38 +0000653 if (const ObjCInterfaceDecl *IFace =
654 dyn_cast<ObjCInterfaceDecl>(setter->getDeclContext())) {
Craig Topperbf3e3272014-08-30 16:55:52 +0000655 StringRef thisPropertyName = prop->getName();
Jordan Rosea7d03842013-02-08 22:30:41 +0000656 // Try flipping the case of the first character.
Fariborz Jahanian3f88afa2012-05-24 22:48:38 +0000657 char front = thisPropertyName.front();
Jordan Rosea7d03842013-02-08 22:30:41 +0000658 front = isLowercase(front) ? toUppercase(front) : toLowercase(front);
Fariborz Jahanian3f88afa2012-05-24 22:48:38 +0000659 SmallString<100> PropertyName = thisPropertyName;
660 PropertyName[0] = front;
661 IdentifierInfo *AltMember = &S.PP.getIdentifierTable().get(PropertyName);
Manman Ren5b786402016-01-28 18:49:28 +0000662 if (ObjCPropertyDecl *prop1 = IFace->FindPropertyDeclaration(
663 AltMember, prop->getQueryKind()))
Fariborz Jahanian3f88afa2012-05-24 22:48:38 +0000664 if (prop != prop1 && (prop1->getSetterMethodDecl() == setter)) {
Richard Smithf8812672016-12-02 22:38:31 +0000665 S.Diag(RefExpr->getExprLoc(), diag::err_property_setter_ambiguous_use)
Aaron Ballman1fb39552014-01-03 14:23:03 +0000666 << prop << prop1 << setter->getSelector();
Fariborz Jahanian3f88afa2012-05-24 22:48:38 +0000667 S.Diag(prop->getLocation(), diag::note_property_declare);
668 S.Diag(prop1->getLocation(), diag::note_property_declare);
669 }
670 }
John McCallfe96e0b2011-11-06 09:01:30 +0000671 Setter = setter;
672 return true;
673 }
674
675 // That can fail in the somewhat crazy situation that we're
676 // type-checking a message send within the @interface declaration
677 // that declared the @property. But it's not clear that that's
678 // valuable to support.
679
680 return false;
681}
682
Olivier Goffartf6fabcc2014-08-04 17:28:11 +0000683void ObjCPropertyOpBuilder::DiagnoseUnsupportedPropertyUse() {
Fariborz Jahanian55513282014-05-28 18:12:10 +0000684 if (S.getCurLexicalContext()->isObjCContainer() &&
685 S.getCurLexicalContext()->getDeclKind() != Decl::ObjCCategoryImpl &&
686 S.getCurLexicalContext()->getDeclKind() != Decl::ObjCImplementation) {
687 if (ObjCPropertyDecl *prop = RefExpr->getExplicitProperty()) {
688 S.Diag(RefExpr->getLocation(),
689 diag::err_property_function_in_objc_container);
690 S.Diag(prop->getLocation(), diag::note_property_declare);
Fariborz Jahanian55513282014-05-28 18:12:10 +0000691 }
692 }
Fariborz Jahanian55513282014-05-28 18:12:10 +0000693}
694
John McCallfe96e0b2011-11-06 09:01:30 +0000695/// Capture the base object of an Objective-C property expression.
696Expr *ObjCPropertyOpBuilder::rebuildAndCaptureObject(Expr *syntacticBase) {
Craig Topperc3ec1492014-05-26 06:22:03 +0000697 assert(InstanceReceiver == nullptr);
John McCallfe96e0b2011-11-06 09:01:30 +0000698
699 // If we have a base, capture it in an OVE and rebuild the syntactic
700 // form to use the OVE as its base.
701 if (RefExpr->isObjectReceiver()) {
702 InstanceReceiver = capture(RefExpr->getBase());
Alexey Bataevf7630272015-11-25 12:01:00 +0000703 syntacticBase = Rebuilder(S, [=](Expr *, unsigned) -> Expr * {
704 return InstanceReceiver;
705 }).rebuild(syntacticBase);
John McCallfe96e0b2011-11-06 09:01:30 +0000706 }
707
Argyrios Kyrtzidisab468b02012-03-30 00:19:18 +0000708 if (ObjCPropertyRefExpr *
709 refE = dyn_cast<ObjCPropertyRefExpr>(syntacticBase->IgnoreParens()))
710 SyntacticRefExpr = refE;
711
John McCallfe96e0b2011-11-06 09:01:30 +0000712 return syntacticBase;
713}
714
715/// Load from an Objective-C property reference.
716ExprResult ObjCPropertyOpBuilder::buildGet() {
717 findGetter();
Olivier Goffartf6fabcc2014-08-04 17:28:11 +0000718 if (!Getter) {
719 DiagnoseUnsupportedPropertyUse();
720 return ExprError();
721 }
Argyrios Kyrtzidisab468b02012-03-30 00:19:18 +0000722
723 if (SyntacticRefExpr)
724 SyntacticRefExpr->setIsMessagingGetter();
725
Douglas Gregore83b9562015-07-07 03:57:53 +0000726 QualType receiverType = RefExpr->getReceiverType(S.Context);
Fariborz Jahanian89ea9612014-06-16 17:25:41 +0000727 if (!Getter->isImplicit())
728 S.DiagnoseUseOfDecl(Getter, GenericLoc, nullptr, true);
John McCallfe96e0b2011-11-06 09:01:30 +0000729 // Build a message-send.
730 ExprResult msg;
Fariborz Jahanian29cdbc62014-04-21 20:22:17 +0000731 if ((Getter->isInstanceMethod() && !RefExpr->isClassReceiver()) ||
732 RefExpr->isObjectReceiver()) {
John McCallfe96e0b2011-11-06 09:01:30 +0000733 assert(InstanceReceiver || RefExpr->isSuperReceiver());
Argyrios Kyrtzidisa80f1bf2012-01-12 02:34:39 +0000734 msg = S.BuildInstanceMessageImplicit(InstanceReceiver, receiverType,
735 GenericLoc, Getter->getSelector(),
Dmitri Gribenko78852e92013-05-05 20:40:26 +0000736 Getter, None);
John McCallfe96e0b2011-11-06 09:01:30 +0000737 } else {
Argyrios Kyrtzidisa80f1bf2012-01-12 02:34:39 +0000738 msg = S.BuildClassMessageImplicit(receiverType, RefExpr->isSuperReceiver(),
Dmitri Gribenko78852e92013-05-05 20:40:26 +0000739 GenericLoc, Getter->getSelector(),
740 Getter, None);
John McCallfe96e0b2011-11-06 09:01:30 +0000741 }
742 return msg;
743}
John McCall526ab472011-10-25 17:37:35 +0000744
John McCallfe96e0b2011-11-06 09:01:30 +0000745/// Store to an Objective-C property reference.
746///
Dmitri Gribenkoadba9be2012-08-23 17:58:28 +0000747/// \param captureSetValueAsResult If true, capture the actual
John McCallfe96e0b2011-11-06 09:01:30 +0000748/// value being set as the value of the property operation.
749ExprResult ObjCPropertyOpBuilder::buildSet(Expr *op, SourceLocation opcLoc,
750 bool captureSetValueAsResult) {
Olivier Goffartf6fabcc2014-08-04 17:28:11 +0000751 if (!findSetter(false)) {
752 DiagnoseUnsupportedPropertyUse();
753 return ExprError();
754 }
John McCallfe96e0b2011-11-06 09:01:30 +0000755
Argyrios Kyrtzidisab468b02012-03-30 00:19:18 +0000756 if (SyntacticRefExpr)
757 SyntacticRefExpr->setIsMessagingSetter();
758
Douglas Gregore83b9562015-07-07 03:57:53 +0000759 QualType receiverType = RefExpr->getReceiverType(S.Context);
John McCallfe96e0b2011-11-06 09:01:30 +0000760
761 // Use assignment constraints when possible; they give us better
762 // diagnostics. "When possible" basically means anything except a
763 // C++ class type.
David Blaikiebbafb8a2012-03-11 07:00:24 +0000764 if (!S.getLangOpts().CPlusPlus || !op->getType()->isRecordType()) {
Douglas Gregore83b9562015-07-07 03:57:53 +0000765 QualType paramType = (*Setter->param_begin())->getType()
766 .substObjCMemberType(
767 receiverType,
768 Setter->getDeclContext(),
769 ObjCSubstitutionContext::Parameter);
David Blaikiebbafb8a2012-03-11 07:00:24 +0000770 if (!S.getLangOpts().CPlusPlus || !paramType->isRecordType()) {
John McCallfe96e0b2011-11-06 09:01:30 +0000771 ExprResult opResult = op;
772 Sema::AssignConvertType assignResult
773 = S.CheckSingleAssignmentConstraints(paramType, opResult);
Richard Smithe15a3702016-10-06 23:12:58 +0000774 if (opResult.isInvalid() ||
775 S.DiagnoseAssignmentResult(assignResult, opcLoc, paramType,
John McCallfe96e0b2011-11-06 09:01:30 +0000776 op->getType(), opResult.get(),
777 Sema::AA_Assigning))
778 return ExprError();
779
Nikola Smiljanic01a75982014-05-29 10:55:11 +0000780 op = opResult.get();
John McCallfe96e0b2011-11-06 09:01:30 +0000781 assert(op && "successful assignment left argument invalid?");
John McCall526ab472011-10-25 17:37:35 +0000782 }
783 }
784
John McCallfe96e0b2011-11-06 09:01:30 +0000785 // Arguments.
786 Expr *args[] = { op };
John McCall526ab472011-10-25 17:37:35 +0000787
John McCallfe96e0b2011-11-06 09:01:30 +0000788 // Build a message-send.
789 ExprResult msg;
Fariborz Jahanian89ea9612014-06-16 17:25:41 +0000790 if (!Setter->isImplicit())
791 S.DiagnoseUseOfDecl(Setter, GenericLoc, nullptr, true);
Fariborz Jahanian29cdbc62014-04-21 20:22:17 +0000792 if ((Setter->isInstanceMethod() && !RefExpr->isClassReceiver()) ||
793 RefExpr->isObjectReceiver()) {
Argyrios Kyrtzidisa80f1bf2012-01-12 02:34:39 +0000794 msg = S.BuildInstanceMessageImplicit(InstanceReceiver, receiverType,
795 GenericLoc, SetterSelector, Setter,
796 MultiExprArg(args, 1));
John McCallfe96e0b2011-11-06 09:01:30 +0000797 } else {
Argyrios Kyrtzidisa80f1bf2012-01-12 02:34:39 +0000798 msg = S.BuildClassMessageImplicit(receiverType, RefExpr->isSuperReceiver(),
799 GenericLoc,
800 SetterSelector, Setter,
801 MultiExprArg(args, 1));
John McCallfe96e0b2011-11-06 09:01:30 +0000802 }
803
804 if (!msg.isInvalid() && captureSetValueAsResult) {
805 ObjCMessageExpr *msgExpr =
806 cast<ObjCMessageExpr>(msg.get()->IgnoreImplicit());
807 Expr *arg = msgExpr->getArg(0);
Fariborz Jahanian15dde892014-03-06 00:34:05 +0000808 if (CanCaptureValue(arg))
Eli Friedman00fa4292012-11-13 23:16:33 +0000809 msgExpr->setArg(0, captureValueAsResult(arg));
John McCallfe96e0b2011-11-06 09:01:30 +0000810 }
811
812 return msg;
John McCall526ab472011-10-25 17:37:35 +0000813}
814
John McCallfe96e0b2011-11-06 09:01:30 +0000815/// @property-specific behavior for doing lvalue-to-rvalue conversion.
816ExprResult ObjCPropertyOpBuilder::buildRValueOperation(Expr *op) {
817 // Explicit properties always have getters, but implicit ones don't.
818 // Check that before proceeding.
Eli Friedmanfd41aee2012-11-29 03:13:49 +0000819 if (RefExpr->isImplicitProperty() && !RefExpr->getImplicitPropertyGetter()) {
John McCallfe96e0b2011-11-06 09:01:30 +0000820 S.Diag(RefExpr->getLocation(), diag::err_getter_not_found)
Eli Friedmanfd41aee2012-11-29 03:13:49 +0000821 << RefExpr->getSourceRange();
John McCall526ab472011-10-25 17:37:35 +0000822 return ExprError();
823 }
824
John McCallfe96e0b2011-11-06 09:01:30 +0000825 ExprResult result = PseudoOpBuilder::buildRValueOperation(op);
John McCall526ab472011-10-25 17:37:35 +0000826 if (result.isInvalid()) return ExprError();
827
John McCallfe96e0b2011-11-06 09:01:30 +0000828 if (RefExpr->isExplicitProperty() && !Getter->hasRelatedResultType())
829 S.DiagnosePropertyAccessorMismatch(RefExpr->getExplicitProperty(),
830 Getter, RefExpr->getLocation());
831
832 // As a special case, if the method returns 'id', try to get
833 // a better type from the property.
Fariborz Jahanian9277ff42014-06-17 23:35:13 +0000834 if (RefExpr->isExplicitProperty() && result.get()->isRValue()) {
Douglas Gregore83b9562015-07-07 03:57:53 +0000835 QualType receiverType = RefExpr->getReceiverType(S.Context);
836 QualType propType = RefExpr->getExplicitProperty()
837 ->getUsageType(receiverType);
Fariborz Jahanian9277ff42014-06-17 23:35:13 +0000838 if (result.get()->getType()->isObjCIdType()) {
839 if (const ObjCObjectPointerType *ptr
840 = propType->getAs<ObjCObjectPointerType>()) {
841 if (!ptr->isObjCIdType())
842 result = S.ImpCastExprToType(result.get(), propType, CK_BitCast);
843 }
844 }
845 if (S.getLangOpts().ObjCAutoRefCount) {
846 Qualifiers::ObjCLifetime LT = propType.getObjCLifetime();
847 if (LT == Qualifiers::OCL_Weak)
848 if (!S.Diags.isIgnored(diag::warn_arc_repeated_use_of_weak, RefExpr->getLocation()))
849 S.getCurFunction()->markSafeWeakUse(RefExpr);
John McCallfe96e0b2011-11-06 09:01:30 +0000850 }
851 }
852
John McCall526ab472011-10-25 17:37:35 +0000853 return result;
854}
855
John McCallfe96e0b2011-11-06 09:01:30 +0000856/// Try to build this as a call to a getter that returns a reference.
857///
858/// \return true if it was possible, whether or not it actually
859/// succeeded
860bool ObjCPropertyOpBuilder::tryBuildGetOfReference(Expr *op,
861 ExprResult &result) {
David Blaikiebbafb8a2012-03-11 07:00:24 +0000862 if (!S.getLangOpts().CPlusPlus) return false;
John McCallfe96e0b2011-11-06 09:01:30 +0000863
864 findGetter();
Olivier Goffart4c182c82014-08-04 17:28:05 +0000865 if (!Getter) {
866 // The property has no setter and no getter! This can happen if the type is
867 // invalid. Error have already been reported.
868 result = ExprError();
869 return true;
870 }
John McCallfe96e0b2011-11-06 09:01:30 +0000871
872 // Only do this if the getter returns an l-value reference type.
Alp Toker314cc812014-01-25 16:55:45 +0000873 QualType resultType = Getter->getReturnType();
John McCallfe96e0b2011-11-06 09:01:30 +0000874 if (!resultType->isLValueReferenceType()) return false;
875
876 result = buildRValueOperation(op);
877 return true;
878}
879
880/// @property-specific behavior for doing assignments.
881ExprResult
882ObjCPropertyOpBuilder::buildAssignmentOperation(Scope *Sc,
883 SourceLocation opcLoc,
884 BinaryOperatorKind opcode,
885 Expr *LHS, Expr *RHS) {
John McCall526ab472011-10-25 17:37:35 +0000886 assert(BinaryOperator::isAssignmentOp(opcode));
John McCall526ab472011-10-25 17:37:35 +0000887
888 // If there's no setter, we have no choice but to try to assign to
889 // the result of the getter.
John McCallfe96e0b2011-11-06 09:01:30 +0000890 if (!findSetter()) {
891 ExprResult result;
892 if (tryBuildGetOfReference(LHS, result)) {
893 if (result.isInvalid()) return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +0000894 return S.BuildBinOp(Sc, opcLoc, opcode, result.get(), RHS);
John McCall526ab472011-10-25 17:37:35 +0000895 }
896
897 // Otherwise, it's an error.
John McCallfe96e0b2011-11-06 09:01:30 +0000898 S.Diag(opcLoc, diag::err_nosetter_property_assignment)
899 << unsigned(RefExpr->isImplicitProperty())
900 << SetterSelector
John McCall526ab472011-10-25 17:37:35 +0000901 << LHS->getSourceRange() << RHS->getSourceRange();
902 return ExprError();
903 }
904
905 // If there is a setter, we definitely want to use it.
906
John McCallfe96e0b2011-11-06 09:01:30 +0000907 // Verify that we can do a compound assignment.
908 if (opcode != BO_Assign && !findGetter()) {
909 S.Diag(opcLoc, diag::err_nogetter_property_compound_assignment)
John McCall526ab472011-10-25 17:37:35 +0000910 << LHS->getSourceRange() << RHS->getSourceRange();
911 return ExprError();
912 }
913
John McCallfe96e0b2011-11-06 09:01:30 +0000914 ExprResult result =
915 PseudoOpBuilder::buildAssignmentOperation(Sc, opcLoc, opcode, LHS, RHS);
John McCall526ab472011-10-25 17:37:35 +0000916 if (result.isInvalid()) return ExprError();
917
John McCallfe96e0b2011-11-06 09:01:30 +0000918 // Various warnings about property assignments in ARC.
David Blaikiebbafb8a2012-03-11 07:00:24 +0000919 if (S.getLangOpts().ObjCAutoRefCount && InstanceReceiver) {
John McCallfe96e0b2011-11-06 09:01:30 +0000920 S.checkRetainCycles(InstanceReceiver->getSourceExpr(), RHS);
921 S.checkUnsafeExprAssigns(opcLoc, LHS, RHS);
922 }
923
John McCall526ab472011-10-25 17:37:35 +0000924 return result;
925}
John McCallfe96e0b2011-11-06 09:01:30 +0000926
927/// @property-specific behavior for doing increments and decrements.
928ExprResult
929ObjCPropertyOpBuilder::buildIncDecOperation(Scope *Sc, SourceLocation opcLoc,
930 UnaryOperatorKind opcode,
931 Expr *op) {
932 // If there's no setter, we have no choice but to try to assign to
933 // the result of the getter.
934 if (!findSetter()) {
935 ExprResult result;
936 if (tryBuildGetOfReference(op, result)) {
937 if (result.isInvalid()) return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +0000938 return S.BuildUnaryOp(Sc, opcLoc, opcode, result.get());
John McCallfe96e0b2011-11-06 09:01:30 +0000939 }
940
941 // Otherwise, it's an error.
942 S.Diag(opcLoc, diag::err_nosetter_property_incdec)
943 << unsigned(RefExpr->isImplicitProperty())
944 << unsigned(UnaryOperator::isDecrementOp(opcode))
945 << SetterSelector
946 << op->getSourceRange();
947 return ExprError();
948 }
949
950 // If there is a setter, we definitely want to use it.
951
952 // We also need a getter.
953 if (!findGetter()) {
954 assert(RefExpr->isImplicitProperty());
955 S.Diag(opcLoc, diag::err_nogetter_property_incdec)
956 << unsigned(UnaryOperator::isDecrementOp(opcode))
Fariborz Jahanianb525b522012-04-18 19:13:23 +0000957 << GetterSelector
John McCallfe96e0b2011-11-06 09:01:30 +0000958 << op->getSourceRange();
959 return ExprError();
960 }
961
962 return PseudoOpBuilder::buildIncDecOperation(Sc, opcLoc, opcode, op);
963}
964
Jordan Rosed3934582012-09-28 22:21:30 +0000965ExprResult ObjCPropertyOpBuilder::complete(Expr *SyntacticForm) {
Alp Tokerd4a3f0e2014-06-15 23:30:39 +0000966 if (S.getLangOpts().ObjCAutoRefCount && isWeakProperty() &&
967 !S.Diags.isIgnored(diag::warn_arc_repeated_use_of_weak,
968 SyntacticForm->getLocStart()))
Fariborz Jahanian6f829e32013-05-21 21:20:26 +0000969 S.recordUseOfEvaluatedWeak(SyntacticRefExpr,
970 SyntacticRefExpr->isMessagingGetter());
Jordan Rosed3934582012-09-28 22:21:30 +0000971
972 return PseudoOpBuilder::complete(SyntacticForm);
973}
974
Ted Kremeneke65b0862012-03-06 20:05:56 +0000975// ObjCSubscript build stuff.
976//
977
978/// objective-c subscripting-specific behavior for doing lvalue-to-rvalue
979/// conversion.
980/// FIXME. Remove this routine if it is proven that no additional
981/// specifity is needed.
982ExprResult ObjCSubscriptOpBuilder::buildRValueOperation(Expr *op) {
983 ExprResult result = PseudoOpBuilder::buildRValueOperation(op);
984 if (result.isInvalid()) return ExprError();
985 return result;
986}
987
988/// objective-c subscripting-specific behavior for doing assignments.
989ExprResult
990ObjCSubscriptOpBuilder::buildAssignmentOperation(Scope *Sc,
991 SourceLocation opcLoc,
992 BinaryOperatorKind opcode,
993 Expr *LHS, Expr *RHS) {
994 assert(BinaryOperator::isAssignmentOp(opcode));
995 // There must be a method to do the Index'ed assignment.
996 if (!findAtIndexSetter())
997 return ExprError();
998
999 // Verify that we can do a compound assignment.
1000 if (opcode != BO_Assign && !findAtIndexGetter())
1001 return ExprError();
1002
1003 ExprResult result =
1004 PseudoOpBuilder::buildAssignmentOperation(Sc, opcLoc, opcode, LHS, RHS);
1005 if (result.isInvalid()) return ExprError();
1006
1007 // Various warnings about objc Index'ed assignments in ARC.
David Blaikiebbafb8a2012-03-11 07:00:24 +00001008 if (S.getLangOpts().ObjCAutoRefCount && InstanceBase) {
Ted Kremeneke65b0862012-03-06 20:05:56 +00001009 S.checkRetainCycles(InstanceBase->getSourceExpr(), RHS);
1010 S.checkUnsafeExprAssigns(opcLoc, LHS, RHS);
1011 }
1012
1013 return result;
1014}
1015
1016/// Capture the base object of an Objective-C Index'ed expression.
1017Expr *ObjCSubscriptOpBuilder::rebuildAndCaptureObject(Expr *syntacticBase) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001018 assert(InstanceBase == nullptr);
1019
Ted Kremeneke65b0862012-03-06 20:05:56 +00001020 // Capture base expression in an OVE and rebuild the syntactic
1021 // form to use the OVE as its base expression.
1022 InstanceBase = capture(RefExpr->getBaseExpr());
1023 InstanceKey = capture(RefExpr->getKeyExpr());
Alexey Bataevf7630272015-11-25 12:01:00 +00001024
Ted Kremeneke65b0862012-03-06 20:05:56 +00001025 syntacticBase =
Alexey Bataevf7630272015-11-25 12:01:00 +00001026 Rebuilder(S, [=](Expr *, unsigned Idx) -> Expr * {
1027 switch (Idx) {
1028 case 0:
1029 return InstanceBase;
1030 case 1:
1031 return InstanceKey;
1032 default:
1033 llvm_unreachable("Unexpected index for ObjCSubscriptExpr");
1034 }
1035 }).rebuild(syntacticBase);
1036
Ted Kremeneke65b0862012-03-06 20:05:56 +00001037 return syntacticBase;
1038}
1039
1040/// CheckSubscriptingKind - This routine decide what type
1041/// of indexing represented by "FromE" is being done.
1042Sema::ObjCSubscriptKind
1043 Sema::CheckSubscriptingKind(Expr *FromE) {
1044 // If the expression already has integral or enumeration type, we're golden.
1045 QualType T = FromE->getType();
1046 if (T->isIntegralOrEnumerationType())
1047 return OS_Array;
1048
1049 // If we don't have a class type in C++, there's no way we can get an
1050 // expression of integral or enumeration type.
1051 const RecordType *RecordTy = T->getAs<RecordType>();
Fariborz Jahaniand13951f2014-09-10 20:55:31 +00001052 if (!RecordTy &&
1053 (T->isObjCObjectPointerType() || T->isVoidPointerType()))
Ted Kremeneke65b0862012-03-06 20:05:56 +00001054 // All other scalar cases are assumed to be dictionary indexing which
1055 // caller handles, with diagnostics if needed.
1056 return OS_Dictionary;
Fariborz Jahanianba0afde2012-03-28 17:56:49 +00001057 if (!getLangOpts().CPlusPlus ||
1058 !RecordTy || RecordTy->isIncompleteType()) {
Ted Kremeneke65b0862012-03-06 20:05:56 +00001059 // No indexing can be done. Issue diagnostics and quit.
Fariborz Jahanianba0afde2012-03-28 17:56:49 +00001060 const Expr *IndexExpr = FromE->IgnoreParenImpCasts();
1061 if (isa<StringLiteral>(IndexExpr))
1062 Diag(FromE->getExprLoc(), diag::err_objc_subscript_pointer)
1063 << T << FixItHint::CreateInsertion(FromE->getExprLoc(), "@");
1064 else
1065 Diag(FromE->getExprLoc(), diag::err_objc_subscript_type_conversion)
1066 << T;
Ted Kremeneke65b0862012-03-06 20:05:56 +00001067 return OS_Error;
1068 }
1069
1070 // We must have a complete class type.
1071 if (RequireCompleteType(FromE->getExprLoc(), T,
Douglas Gregor7bfb2d02012-05-04 16:32:21 +00001072 diag::err_objc_index_incomplete_class_type, FromE))
Ted Kremeneke65b0862012-03-06 20:05:56 +00001073 return OS_Error;
1074
1075 // Look for a conversion to an integral, enumeration type, or
1076 // objective-C pointer type.
Ted Kremeneke65b0862012-03-06 20:05:56 +00001077 int NoIntegrals=0, NoObjCIdPointers=0;
1078 SmallVector<CXXConversionDecl *, 4> ConversionDecls;
Benjamin Kramerb4ef6682015-02-06 17:25:10 +00001079
1080 for (NamedDecl *D : cast<CXXRecordDecl>(RecordTy->getDecl())
1081 ->getVisibleConversionFunctions()) {
1082 if (CXXConversionDecl *Conversion =
1083 dyn_cast<CXXConversionDecl>(D->getUnderlyingDecl())) {
Ted Kremeneke65b0862012-03-06 20:05:56 +00001084 QualType CT = Conversion->getConversionType().getNonReferenceType();
1085 if (CT->isIntegralOrEnumerationType()) {
1086 ++NoIntegrals;
1087 ConversionDecls.push_back(Conversion);
1088 }
1089 else if (CT->isObjCIdType() ||CT->isBlockPointerType()) {
1090 ++NoObjCIdPointers;
1091 ConversionDecls.push_back(Conversion);
1092 }
1093 }
1094 }
1095 if (NoIntegrals ==1 && NoObjCIdPointers == 0)
1096 return OS_Array;
1097 if (NoIntegrals == 0 && NoObjCIdPointers == 1)
1098 return OS_Dictionary;
1099 if (NoIntegrals == 0 && NoObjCIdPointers == 0) {
1100 // No conversion function was found. Issue diagnostic and return.
1101 Diag(FromE->getExprLoc(), diag::err_objc_subscript_type_conversion)
1102 << FromE->getType();
1103 return OS_Error;
1104 }
1105 Diag(FromE->getExprLoc(), diag::err_objc_multiple_subscript_type_conversion)
1106 << FromE->getType();
1107 for (unsigned int i = 0; i < ConversionDecls.size(); i++)
Richard Smith01d96982016-12-02 23:00:28 +00001108 Diag(ConversionDecls[i]->getLocation(),
1109 diag::note_conv_function_declared_at);
1110
Ted Kremeneke65b0862012-03-06 20:05:56 +00001111 return OS_Error;
1112}
1113
Fariborz Jahanian90804912012-08-02 18:03:58 +00001114/// CheckKeyForObjCARCConversion - This routine suggests bridge casting of CF
1115/// objects used as dictionary subscript key objects.
1116static void CheckKeyForObjCARCConversion(Sema &S, QualType ContainerT,
1117 Expr *Key) {
1118 if (ContainerT.isNull())
1119 return;
1120 // dictionary subscripting.
1121 // - (id)objectForKeyedSubscript:(id)key;
1122 IdentifierInfo *KeyIdents[] = {
1123 &S.Context.Idents.get("objectForKeyedSubscript")
1124 };
1125 Selector GetterSelector = S.Context.Selectors.getSelector(1, KeyIdents);
1126 ObjCMethodDecl *Getter = S.LookupMethodInObjectType(GetterSelector, ContainerT,
1127 true /*instance*/);
1128 if (!Getter)
1129 return;
Alp Toker03376dc2014-07-07 09:02:20 +00001130 QualType T = Getter->parameters()[0]->getType();
Fariborz Jahanian90804912012-08-02 18:03:58 +00001131 S.CheckObjCARCConversion(Key->getSourceRange(),
1132 T, Key, Sema::CCK_ImplicitConversion);
1133}
1134
Ted Kremeneke65b0862012-03-06 20:05:56 +00001135bool ObjCSubscriptOpBuilder::findAtIndexGetter() {
1136 if (AtIndexGetter)
1137 return true;
1138
1139 Expr *BaseExpr = RefExpr->getBaseExpr();
1140 QualType BaseT = BaseExpr->getType();
1141
1142 QualType ResultType;
1143 if (const ObjCObjectPointerType *PTy =
1144 BaseT->getAs<ObjCObjectPointerType>()) {
1145 ResultType = PTy->getPointeeType();
Ted Kremeneke65b0862012-03-06 20:05:56 +00001146 }
1147 Sema::ObjCSubscriptKind Res =
1148 S.CheckSubscriptingKind(RefExpr->getKeyExpr());
Fariborz Jahanian90804912012-08-02 18:03:58 +00001149 if (Res == Sema::OS_Error) {
1150 if (S.getLangOpts().ObjCAutoRefCount)
1151 CheckKeyForObjCARCConversion(S, ResultType,
1152 RefExpr->getKeyExpr());
Ted Kremeneke65b0862012-03-06 20:05:56 +00001153 return false;
Fariborz Jahanian90804912012-08-02 18:03:58 +00001154 }
Ted Kremeneke65b0862012-03-06 20:05:56 +00001155 bool arrayRef = (Res == Sema::OS_Array);
1156
1157 if (ResultType.isNull()) {
1158 S.Diag(BaseExpr->getExprLoc(), diag::err_objc_subscript_base_type)
1159 << BaseExpr->getType() << arrayRef;
1160 return false;
1161 }
1162 if (!arrayRef) {
1163 // dictionary subscripting.
1164 // - (id)objectForKeyedSubscript:(id)key;
1165 IdentifierInfo *KeyIdents[] = {
1166 &S.Context.Idents.get("objectForKeyedSubscript")
1167 };
1168 AtIndexGetterSelector = S.Context.Selectors.getSelector(1, KeyIdents);
1169 }
1170 else {
1171 // - (id)objectAtIndexedSubscript:(size_t)index;
1172 IdentifierInfo *KeyIdents[] = {
1173 &S.Context.Idents.get("objectAtIndexedSubscript")
1174 };
1175
1176 AtIndexGetterSelector = S.Context.Selectors.getSelector(1, KeyIdents);
1177 }
1178
1179 AtIndexGetter = S.LookupMethodInObjectType(AtIndexGetterSelector, ResultType,
1180 true /*instance*/);
1181 bool receiverIdType = (BaseT->isObjCIdType() ||
1182 BaseT->isObjCQualifiedIdType());
1183
David Blaikiebbafb8a2012-03-11 07:00:24 +00001184 if (!AtIndexGetter && S.getLangOpts().DebuggerObjCLiteral) {
Ted Kremeneke65b0862012-03-06 20:05:56 +00001185 AtIndexGetter = ObjCMethodDecl::Create(S.Context, SourceLocation(),
1186 SourceLocation(), AtIndexGetterSelector,
1187 S.Context.getObjCIdType() /*ReturnType*/,
Craig Topperc3ec1492014-05-26 06:22:03 +00001188 nullptr /*TypeSourceInfo */,
Ted Kremeneke65b0862012-03-06 20:05:56 +00001189 S.Context.getTranslationUnitDecl(),
1190 true /*Instance*/, false/*isVariadic*/,
Jordan Rosed01e83a2012-10-10 16:42:25 +00001191 /*isPropertyAccessor=*/false,
Ted Kremeneke65b0862012-03-06 20:05:56 +00001192 /*isImplicitlyDeclared=*/true, /*isDefined=*/false,
1193 ObjCMethodDecl::Required,
1194 false);
1195 ParmVarDecl *Argument = ParmVarDecl::Create(S.Context, AtIndexGetter,
1196 SourceLocation(), SourceLocation(),
1197 arrayRef ? &S.Context.Idents.get("index")
1198 : &S.Context.Idents.get("key"),
1199 arrayRef ? S.Context.UnsignedLongTy
1200 : S.Context.getObjCIdType(),
Craig Topperc3ec1492014-05-26 06:22:03 +00001201 /*TInfo=*/nullptr,
Ted Kremeneke65b0862012-03-06 20:05:56 +00001202 SC_None,
Craig Topperc3ec1492014-05-26 06:22:03 +00001203 nullptr);
Dmitri Gribenko44ebbd52013-05-05 00:41:58 +00001204 AtIndexGetter->setMethodParams(S.Context, Argument, None);
Ted Kremeneke65b0862012-03-06 20:05:56 +00001205 }
1206
1207 if (!AtIndexGetter) {
1208 if (!receiverIdType) {
1209 S.Diag(BaseExpr->getExprLoc(), diag::err_objc_subscript_method_not_found)
1210 << BaseExpr->getType() << 0 << arrayRef;
1211 return false;
1212 }
1213 AtIndexGetter =
1214 S.LookupInstanceMethodInGlobalPool(AtIndexGetterSelector,
1215 RefExpr->getSourceRange(),
Fariborz Jahanian890803f2015-04-15 17:26:21 +00001216 true);
Ted Kremeneke65b0862012-03-06 20:05:56 +00001217 }
1218
1219 if (AtIndexGetter) {
Alp Toker03376dc2014-07-07 09:02:20 +00001220 QualType T = AtIndexGetter->parameters()[0]->getType();
Ted Kremeneke65b0862012-03-06 20:05:56 +00001221 if ((arrayRef && !T->isIntegralOrEnumerationType()) ||
1222 (!arrayRef && !T->isObjCObjectPointerType())) {
1223 S.Diag(RefExpr->getKeyExpr()->getExprLoc(),
1224 arrayRef ? diag::err_objc_subscript_index_type
1225 : diag::err_objc_subscript_key_type) << T;
Alp Toker03376dc2014-07-07 09:02:20 +00001226 S.Diag(AtIndexGetter->parameters()[0]->getLocation(),
Ted Kremeneke65b0862012-03-06 20:05:56 +00001227 diag::note_parameter_type) << T;
1228 return false;
1229 }
Alp Toker314cc812014-01-25 16:55:45 +00001230 QualType R = AtIndexGetter->getReturnType();
Ted Kremeneke65b0862012-03-06 20:05:56 +00001231 if (!R->isObjCObjectPointerType()) {
1232 S.Diag(RefExpr->getKeyExpr()->getExprLoc(),
1233 diag::err_objc_indexing_method_result_type) << R << arrayRef;
1234 S.Diag(AtIndexGetter->getLocation(), diag::note_method_declared_at) <<
1235 AtIndexGetter->getDeclName();
1236 }
1237 }
1238 return true;
1239}
1240
1241bool ObjCSubscriptOpBuilder::findAtIndexSetter() {
1242 if (AtIndexSetter)
1243 return true;
1244
1245 Expr *BaseExpr = RefExpr->getBaseExpr();
1246 QualType BaseT = BaseExpr->getType();
1247
1248 QualType ResultType;
1249 if (const ObjCObjectPointerType *PTy =
1250 BaseT->getAs<ObjCObjectPointerType>()) {
1251 ResultType = PTy->getPointeeType();
Ted Kremeneke65b0862012-03-06 20:05:56 +00001252 }
1253
1254 Sema::ObjCSubscriptKind Res =
1255 S.CheckSubscriptingKind(RefExpr->getKeyExpr());
Fariborz Jahanian90804912012-08-02 18:03:58 +00001256 if (Res == Sema::OS_Error) {
1257 if (S.getLangOpts().ObjCAutoRefCount)
1258 CheckKeyForObjCARCConversion(S, ResultType,
1259 RefExpr->getKeyExpr());
Ted Kremeneke65b0862012-03-06 20:05:56 +00001260 return false;
Fariborz Jahanian90804912012-08-02 18:03:58 +00001261 }
Ted Kremeneke65b0862012-03-06 20:05:56 +00001262 bool arrayRef = (Res == Sema::OS_Array);
1263
1264 if (ResultType.isNull()) {
1265 S.Diag(BaseExpr->getExprLoc(), diag::err_objc_subscript_base_type)
1266 << BaseExpr->getType() << arrayRef;
1267 return false;
1268 }
1269
1270 if (!arrayRef) {
1271 // dictionary subscripting.
1272 // - (void)setObject:(id)object forKeyedSubscript:(id)key;
1273 IdentifierInfo *KeyIdents[] = {
1274 &S.Context.Idents.get("setObject"),
1275 &S.Context.Idents.get("forKeyedSubscript")
1276 };
1277 AtIndexSetterSelector = S.Context.Selectors.getSelector(2, KeyIdents);
1278 }
1279 else {
1280 // - (void)setObject:(id)object atIndexedSubscript:(NSInteger)index;
1281 IdentifierInfo *KeyIdents[] = {
1282 &S.Context.Idents.get("setObject"),
1283 &S.Context.Idents.get("atIndexedSubscript")
1284 };
1285 AtIndexSetterSelector = S.Context.Selectors.getSelector(2, KeyIdents);
1286 }
1287 AtIndexSetter = S.LookupMethodInObjectType(AtIndexSetterSelector, ResultType,
1288 true /*instance*/);
1289
1290 bool receiverIdType = (BaseT->isObjCIdType() ||
1291 BaseT->isObjCQualifiedIdType());
1292
David Blaikiebbafb8a2012-03-11 07:00:24 +00001293 if (!AtIndexSetter && S.getLangOpts().DebuggerObjCLiteral) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001294 TypeSourceInfo *ReturnTInfo = nullptr;
Ted Kremeneke65b0862012-03-06 20:05:56 +00001295 QualType ReturnType = S.Context.VoidTy;
Alp Toker314cc812014-01-25 16:55:45 +00001296 AtIndexSetter = ObjCMethodDecl::Create(
1297 S.Context, SourceLocation(), SourceLocation(), AtIndexSetterSelector,
1298 ReturnType, ReturnTInfo, S.Context.getTranslationUnitDecl(),
1299 true /*Instance*/, false /*isVariadic*/,
1300 /*isPropertyAccessor=*/false,
1301 /*isImplicitlyDeclared=*/true, /*isDefined=*/false,
1302 ObjCMethodDecl::Required, false);
Ted Kremeneke65b0862012-03-06 20:05:56 +00001303 SmallVector<ParmVarDecl *, 2> Params;
1304 ParmVarDecl *object = ParmVarDecl::Create(S.Context, AtIndexSetter,
1305 SourceLocation(), SourceLocation(),
1306 &S.Context.Idents.get("object"),
1307 S.Context.getObjCIdType(),
Craig Topperc3ec1492014-05-26 06:22:03 +00001308 /*TInfo=*/nullptr,
Ted Kremeneke65b0862012-03-06 20:05:56 +00001309 SC_None,
Craig Topperc3ec1492014-05-26 06:22:03 +00001310 nullptr);
Ted Kremeneke65b0862012-03-06 20:05:56 +00001311 Params.push_back(object);
1312 ParmVarDecl *key = ParmVarDecl::Create(S.Context, AtIndexSetter,
1313 SourceLocation(), SourceLocation(),
1314 arrayRef ? &S.Context.Idents.get("index")
1315 : &S.Context.Idents.get("key"),
1316 arrayRef ? S.Context.UnsignedLongTy
1317 : S.Context.getObjCIdType(),
Craig Topperc3ec1492014-05-26 06:22:03 +00001318 /*TInfo=*/nullptr,
Ted Kremeneke65b0862012-03-06 20:05:56 +00001319 SC_None,
Craig Topperc3ec1492014-05-26 06:22:03 +00001320 nullptr);
Ted Kremeneke65b0862012-03-06 20:05:56 +00001321 Params.push_back(key);
Dmitri Gribenko44ebbd52013-05-05 00:41:58 +00001322 AtIndexSetter->setMethodParams(S.Context, Params, None);
Ted Kremeneke65b0862012-03-06 20:05:56 +00001323 }
1324
1325 if (!AtIndexSetter) {
1326 if (!receiverIdType) {
1327 S.Diag(BaseExpr->getExprLoc(),
1328 diag::err_objc_subscript_method_not_found)
1329 << BaseExpr->getType() << 1 << arrayRef;
1330 return false;
1331 }
1332 AtIndexSetter =
1333 S.LookupInstanceMethodInGlobalPool(AtIndexSetterSelector,
1334 RefExpr->getSourceRange(),
Fariborz Jahanian890803f2015-04-15 17:26:21 +00001335 true);
Ted Kremeneke65b0862012-03-06 20:05:56 +00001336 }
1337
1338 bool err = false;
1339 if (AtIndexSetter && arrayRef) {
Alp Toker03376dc2014-07-07 09:02:20 +00001340 QualType T = AtIndexSetter->parameters()[1]->getType();
Ted Kremeneke65b0862012-03-06 20:05:56 +00001341 if (!T->isIntegralOrEnumerationType()) {
1342 S.Diag(RefExpr->getKeyExpr()->getExprLoc(),
1343 diag::err_objc_subscript_index_type) << T;
Alp Toker03376dc2014-07-07 09:02:20 +00001344 S.Diag(AtIndexSetter->parameters()[1]->getLocation(),
Ted Kremeneke65b0862012-03-06 20:05:56 +00001345 diag::note_parameter_type) << T;
1346 err = true;
1347 }
Alp Toker03376dc2014-07-07 09:02:20 +00001348 T = AtIndexSetter->parameters()[0]->getType();
Ted Kremeneke65b0862012-03-06 20:05:56 +00001349 if (!T->isObjCObjectPointerType()) {
1350 S.Diag(RefExpr->getBaseExpr()->getExprLoc(),
1351 diag::err_objc_subscript_object_type) << T << arrayRef;
Alp Toker03376dc2014-07-07 09:02:20 +00001352 S.Diag(AtIndexSetter->parameters()[0]->getLocation(),
Ted Kremeneke65b0862012-03-06 20:05:56 +00001353 diag::note_parameter_type) << T;
1354 err = true;
1355 }
1356 }
1357 else if (AtIndexSetter && !arrayRef)
1358 for (unsigned i=0; i <2; i++) {
Alp Toker03376dc2014-07-07 09:02:20 +00001359 QualType T = AtIndexSetter->parameters()[i]->getType();
Ted Kremeneke65b0862012-03-06 20:05:56 +00001360 if (!T->isObjCObjectPointerType()) {
1361 if (i == 1)
1362 S.Diag(RefExpr->getKeyExpr()->getExprLoc(),
1363 diag::err_objc_subscript_key_type) << T;
1364 else
1365 S.Diag(RefExpr->getBaseExpr()->getExprLoc(),
1366 diag::err_objc_subscript_dic_object_type) << T;
Alp Toker03376dc2014-07-07 09:02:20 +00001367 S.Diag(AtIndexSetter->parameters()[i]->getLocation(),
Ted Kremeneke65b0862012-03-06 20:05:56 +00001368 diag::note_parameter_type) << T;
1369 err = true;
1370 }
1371 }
1372
1373 return !err;
1374}
1375
1376// Get the object at "Index" position in the container.
1377// [BaseExpr objectAtIndexedSubscript : IndexExpr];
1378ExprResult ObjCSubscriptOpBuilder::buildGet() {
1379 if (!findAtIndexGetter())
1380 return ExprError();
1381
1382 QualType receiverType = InstanceBase->getType();
1383
1384 // Build a message-send.
1385 ExprResult msg;
1386 Expr *Index = InstanceKey;
1387
1388 // Arguments.
1389 Expr *args[] = { Index };
1390 assert(InstanceBase);
Fariborz Jahanian3d576402014-06-10 19:02:48 +00001391 if (AtIndexGetter)
1392 S.DiagnoseUseOfDecl(AtIndexGetter, GenericLoc);
Ted Kremeneke65b0862012-03-06 20:05:56 +00001393 msg = S.BuildInstanceMessageImplicit(InstanceBase, receiverType,
1394 GenericLoc,
1395 AtIndexGetterSelector, AtIndexGetter,
1396 MultiExprArg(args, 1));
1397 return msg;
1398}
1399
1400/// Store into the container the "op" object at "Index"'ed location
1401/// by building this messaging expression:
1402/// - (void)setObject:(id)object atIndexedSubscript:(NSInteger)index;
Dmitri Gribenkoadba9be2012-08-23 17:58:28 +00001403/// \param captureSetValueAsResult If true, capture the actual
Ted Kremeneke65b0862012-03-06 20:05:56 +00001404/// value being set as the value of the property operation.
1405ExprResult ObjCSubscriptOpBuilder::buildSet(Expr *op, SourceLocation opcLoc,
1406 bool captureSetValueAsResult) {
1407 if (!findAtIndexSetter())
1408 return ExprError();
Fariborz Jahanian3d576402014-06-10 19:02:48 +00001409 if (AtIndexSetter)
1410 S.DiagnoseUseOfDecl(AtIndexSetter, GenericLoc);
Ted Kremeneke65b0862012-03-06 20:05:56 +00001411 QualType receiverType = InstanceBase->getType();
1412 Expr *Index = InstanceKey;
1413
1414 // Arguments.
1415 Expr *args[] = { op, Index };
1416
1417 // Build a message-send.
1418 ExprResult msg = S.BuildInstanceMessageImplicit(InstanceBase, receiverType,
1419 GenericLoc,
1420 AtIndexSetterSelector,
1421 AtIndexSetter,
1422 MultiExprArg(args, 2));
1423
1424 if (!msg.isInvalid() && captureSetValueAsResult) {
1425 ObjCMessageExpr *msgExpr =
1426 cast<ObjCMessageExpr>(msg.get()->IgnoreImplicit());
1427 Expr *arg = msgExpr->getArg(0);
Fariborz Jahanian15dde892014-03-06 00:34:05 +00001428 if (CanCaptureValue(arg))
Eli Friedman00fa4292012-11-13 23:16:33 +00001429 msgExpr->setArg(0, captureValueAsResult(arg));
Ted Kremeneke65b0862012-03-06 20:05:56 +00001430 }
1431
1432 return msg;
1433}
1434
John McCallfe96e0b2011-11-06 09:01:30 +00001435//===----------------------------------------------------------------------===//
John McCall5e77d762013-04-16 07:28:30 +00001436// MSVC __declspec(property) references
1437//===----------------------------------------------------------------------===//
1438
Alexey Bataevf7630272015-11-25 12:01:00 +00001439MSPropertyRefExpr *
1440MSPropertyOpBuilder::getBaseMSProperty(MSPropertySubscriptExpr *E) {
1441 CallArgs.insert(CallArgs.begin(), E->getIdx());
1442 Expr *Base = E->getBase()->IgnoreParens();
1443 while (auto *MSPropSubscript = dyn_cast<MSPropertySubscriptExpr>(Base)) {
1444 CallArgs.insert(CallArgs.begin(), MSPropSubscript->getIdx());
1445 Base = MSPropSubscript->getBase()->IgnoreParens();
1446 }
1447 return cast<MSPropertyRefExpr>(Base);
1448}
1449
John McCall5e77d762013-04-16 07:28:30 +00001450Expr *MSPropertyOpBuilder::rebuildAndCaptureObject(Expr *syntacticBase) {
Alexey Bataev69103472015-10-14 04:05:42 +00001451 InstanceBase = capture(RefExpr->getBaseExpr());
Alexey Bataevf7630272015-11-25 12:01:00 +00001452 std::for_each(CallArgs.begin(), CallArgs.end(),
1453 [this](Expr *&Arg) { Arg = capture(Arg); });
1454 syntacticBase = Rebuilder(S, [=](Expr *, unsigned Idx) -> Expr * {
1455 switch (Idx) {
1456 case 0:
1457 return InstanceBase;
1458 default:
1459 assert(Idx <= CallArgs.size());
1460 return CallArgs[Idx - 1];
1461 }
1462 }).rebuild(syntacticBase);
John McCall5e77d762013-04-16 07:28:30 +00001463
1464 return syntacticBase;
1465}
1466
1467ExprResult MSPropertyOpBuilder::buildGet() {
1468 if (!RefExpr->getPropertyDecl()->hasGetter()) {
Aaron Ballman213cf412013-12-26 16:35:04 +00001469 S.Diag(RefExpr->getMemberLoc(), diag::err_no_accessor_for_property)
Aaron Ballman1bda4592014-01-03 01:09:27 +00001470 << 0 /* getter */ << RefExpr->getPropertyDecl();
John McCall5e77d762013-04-16 07:28:30 +00001471 return ExprError();
1472 }
1473
1474 UnqualifiedId GetterName;
1475 IdentifierInfo *II = RefExpr->getPropertyDecl()->getGetterId();
1476 GetterName.setIdentifier(II, RefExpr->getMemberLoc());
1477 CXXScopeSpec SS;
1478 SS.Adopt(RefExpr->getQualifierLoc());
Alexey Bataev69103472015-10-14 04:05:42 +00001479 ExprResult GetterExpr =
1480 S.ActOnMemberAccessExpr(S.getCurScope(), InstanceBase, SourceLocation(),
1481 RefExpr->isArrow() ? tok::arrow : tok::period, SS,
1482 SourceLocation(), GetterName, nullptr);
John McCall5e77d762013-04-16 07:28:30 +00001483 if (GetterExpr.isInvalid()) {
Aaron Ballman9e35bfe2013-12-26 15:46:38 +00001484 S.Diag(RefExpr->getMemberLoc(),
Richard Smithf8812672016-12-02 22:38:31 +00001485 diag::err_cannot_find_suitable_accessor) << 0 /* getter */
Aaron Ballman1bda4592014-01-03 01:09:27 +00001486 << RefExpr->getPropertyDecl();
John McCall5e77d762013-04-16 07:28:30 +00001487 return ExprError();
1488 }
1489
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001490 return S.ActOnCallExpr(S.getCurScope(), GetterExpr.get(),
Alexey Bataevf7630272015-11-25 12:01:00 +00001491 RefExpr->getSourceRange().getBegin(), CallArgs,
John McCall5e77d762013-04-16 07:28:30 +00001492 RefExpr->getSourceRange().getEnd());
1493}
1494
1495ExprResult MSPropertyOpBuilder::buildSet(Expr *op, SourceLocation sl,
1496 bool captureSetValueAsResult) {
1497 if (!RefExpr->getPropertyDecl()->hasSetter()) {
Aaron Ballman213cf412013-12-26 16:35:04 +00001498 S.Diag(RefExpr->getMemberLoc(), diag::err_no_accessor_for_property)
Aaron Ballman1bda4592014-01-03 01:09:27 +00001499 << 1 /* setter */ << RefExpr->getPropertyDecl();
John McCall5e77d762013-04-16 07:28:30 +00001500 return ExprError();
1501 }
1502
1503 UnqualifiedId SetterName;
1504 IdentifierInfo *II = RefExpr->getPropertyDecl()->getSetterId();
1505 SetterName.setIdentifier(II, RefExpr->getMemberLoc());
1506 CXXScopeSpec SS;
1507 SS.Adopt(RefExpr->getQualifierLoc());
Alexey Bataev69103472015-10-14 04:05:42 +00001508 ExprResult SetterExpr =
1509 S.ActOnMemberAccessExpr(S.getCurScope(), InstanceBase, SourceLocation(),
1510 RefExpr->isArrow() ? tok::arrow : tok::period, SS,
1511 SourceLocation(), SetterName, nullptr);
John McCall5e77d762013-04-16 07:28:30 +00001512 if (SetterExpr.isInvalid()) {
Aaron Ballman9e35bfe2013-12-26 15:46:38 +00001513 S.Diag(RefExpr->getMemberLoc(),
Richard Smithf8812672016-12-02 22:38:31 +00001514 diag::err_cannot_find_suitable_accessor) << 1 /* setter */
Aaron Ballman1bda4592014-01-03 01:09:27 +00001515 << RefExpr->getPropertyDecl();
John McCall5e77d762013-04-16 07:28:30 +00001516 return ExprError();
1517 }
1518
Alexey Bataevf7630272015-11-25 12:01:00 +00001519 SmallVector<Expr*, 4> ArgExprs;
1520 ArgExprs.append(CallArgs.begin(), CallArgs.end());
John McCall5e77d762013-04-16 07:28:30 +00001521 ArgExprs.push_back(op);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001522 return S.ActOnCallExpr(S.getCurScope(), SetterExpr.get(),
John McCall5e77d762013-04-16 07:28:30 +00001523 RefExpr->getSourceRange().getBegin(), ArgExprs,
1524 op->getSourceRange().getEnd());
1525}
1526
1527//===----------------------------------------------------------------------===//
John McCallfe96e0b2011-11-06 09:01:30 +00001528// General Sema routines.
1529//===----------------------------------------------------------------------===//
1530
1531ExprResult Sema::checkPseudoObjectRValue(Expr *E) {
1532 Expr *opaqueRef = E->IgnoreParens();
1533 if (ObjCPropertyRefExpr *refExpr
1534 = dyn_cast<ObjCPropertyRefExpr>(opaqueRef)) {
1535 ObjCPropertyOpBuilder builder(*this, refExpr);
1536 return builder.buildRValueOperation(E);
Ted Kremeneke65b0862012-03-06 20:05:56 +00001537 }
1538 else if (ObjCSubscriptRefExpr *refExpr
1539 = dyn_cast<ObjCSubscriptRefExpr>(opaqueRef)) {
1540 ObjCSubscriptOpBuilder builder(*this, refExpr);
1541 return builder.buildRValueOperation(E);
John McCall5e77d762013-04-16 07:28:30 +00001542 } else if (MSPropertyRefExpr *refExpr
1543 = dyn_cast<MSPropertyRefExpr>(opaqueRef)) {
1544 MSPropertyOpBuilder builder(*this, refExpr);
1545 return builder.buildRValueOperation(E);
Alexey Bataevf7630272015-11-25 12:01:00 +00001546 } else if (MSPropertySubscriptExpr *RefExpr =
1547 dyn_cast<MSPropertySubscriptExpr>(opaqueRef)) {
1548 MSPropertyOpBuilder Builder(*this, RefExpr);
1549 return Builder.buildRValueOperation(E);
John McCallfe96e0b2011-11-06 09:01:30 +00001550 } else {
1551 llvm_unreachable("unknown pseudo-object kind!");
1552 }
1553}
1554
1555/// Check an increment or decrement of a pseudo-object expression.
1556ExprResult Sema::checkPseudoObjectIncDec(Scope *Sc, SourceLocation opcLoc,
1557 UnaryOperatorKind opcode, Expr *op) {
1558 // Do nothing if the operand is dependent.
1559 if (op->isTypeDependent())
1560 return new (Context) UnaryOperator(op, opcode, Context.DependentTy,
1561 VK_RValue, OK_Ordinary, opcLoc);
1562
1563 assert(UnaryOperator::isIncrementDecrementOp(opcode));
1564 Expr *opaqueRef = op->IgnoreParens();
1565 if (ObjCPropertyRefExpr *refExpr
1566 = dyn_cast<ObjCPropertyRefExpr>(opaqueRef)) {
1567 ObjCPropertyOpBuilder builder(*this, refExpr);
1568 return builder.buildIncDecOperation(Sc, opcLoc, opcode, op);
Ted Kremeneke65b0862012-03-06 20:05:56 +00001569 } else if (isa<ObjCSubscriptRefExpr>(opaqueRef)) {
1570 Diag(opcLoc, diag::err_illegal_container_subscripting_op);
1571 return ExprError();
John McCall5e77d762013-04-16 07:28:30 +00001572 } else if (MSPropertyRefExpr *refExpr
1573 = dyn_cast<MSPropertyRefExpr>(opaqueRef)) {
1574 MSPropertyOpBuilder builder(*this, refExpr);
1575 return builder.buildIncDecOperation(Sc, opcLoc, opcode, op);
Alexey Bataevf7630272015-11-25 12:01:00 +00001576 } else if (MSPropertySubscriptExpr *RefExpr
1577 = dyn_cast<MSPropertySubscriptExpr>(opaqueRef)) {
1578 MSPropertyOpBuilder Builder(*this, RefExpr);
1579 return Builder.buildIncDecOperation(Sc, opcLoc, opcode, op);
John McCallfe96e0b2011-11-06 09:01:30 +00001580 } else {
1581 llvm_unreachable("unknown pseudo-object kind!");
1582 }
1583}
1584
1585ExprResult Sema::checkPseudoObjectAssignment(Scope *S, SourceLocation opcLoc,
1586 BinaryOperatorKind opcode,
1587 Expr *LHS, Expr *RHS) {
1588 // Do nothing if either argument is dependent.
1589 if (LHS->isTypeDependent() || RHS->isTypeDependent())
1590 return new (Context) BinaryOperator(LHS, RHS, opcode, Context.DependentTy,
Adam Nemet484aa452017-03-27 19:17:25 +00001591 VK_RValue, OK_Ordinary, opcLoc,
1592 FPOptions());
John McCallfe96e0b2011-11-06 09:01:30 +00001593
1594 // Filter out non-overload placeholder types in the RHS.
John McCalld5c98ae2011-11-15 01:35:18 +00001595 if (RHS->getType()->isNonOverloadPlaceholderType()) {
1596 ExprResult result = CheckPlaceholderExpr(RHS);
1597 if (result.isInvalid()) return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001598 RHS = result.get();
John McCallfe96e0b2011-11-06 09:01:30 +00001599 }
1600
1601 Expr *opaqueRef = LHS->IgnoreParens();
1602 if (ObjCPropertyRefExpr *refExpr
1603 = dyn_cast<ObjCPropertyRefExpr>(opaqueRef)) {
1604 ObjCPropertyOpBuilder builder(*this, refExpr);
1605 return builder.buildAssignmentOperation(S, opcLoc, opcode, LHS, RHS);
Ted Kremeneke65b0862012-03-06 20:05:56 +00001606 } else if (ObjCSubscriptRefExpr *refExpr
1607 = dyn_cast<ObjCSubscriptRefExpr>(opaqueRef)) {
1608 ObjCSubscriptOpBuilder builder(*this, refExpr);
1609 return builder.buildAssignmentOperation(S, opcLoc, opcode, LHS, RHS);
John McCall5e77d762013-04-16 07:28:30 +00001610 } else if (MSPropertyRefExpr *refExpr
1611 = dyn_cast<MSPropertyRefExpr>(opaqueRef)) {
Alexey Bataevf7630272015-11-25 12:01:00 +00001612 MSPropertyOpBuilder builder(*this, refExpr);
1613 return builder.buildAssignmentOperation(S, opcLoc, opcode, LHS, RHS);
1614 } else if (MSPropertySubscriptExpr *RefExpr
1615 = dyn_cast<MSPropertySubscriptExpr>(opaqueRef)) {
1616 MSPropertyOpBuilder Builder(*this, RefExpr);
1617 return Builder.buildAssignmentOperation(S, opcLoc, opcode, LHS, RHS);
John McCallfe96e0b2011-11-06 09:01:30 +00001618 } else {
1619 llvm_unreachable("unknown pseudo-object kind!");
1620 }
1621}
John McCalle9290822011-11-30 04:42:31 +00001622
1623/// Given a pseudo-object reference, rebuild it without the opaque
1624/// values. Basically, undo the behavior of rebuildAndCaptureObject.
1625/// This should never operate in-place.
1626static Expr *stripOpaqueValuesFromPseudoObjectRef(Sema &S, Expr *E) {
Alexey Bataevf7630272015-11-25 12:01:00 +00001627 return Rebuilder(S,
1628 [=](Expr *E, unsigned) -> Expr * {
1629 return cast<OpaqueValueExpr>(E)->getSourceExpr();
1630 })
1631 .rebuild(E);
John McCalle9290822011-11-30 04:42:31 +00001632}
1633
1634/// Given a pseudo-object expression, recreate what it looks like
1635/// syntactically without the attendant OpaqueValueExprs.
1636///
1637/// This is a hack which should be removed when TreeTransform is
1638/// capable of rebuilding a tree without stripping implicit
1639/// operations.
1640Expr *Sema::recreateSyntacticForm(PseudoObjectExpr *E) {
1641 Expr *syntax = E->getSyntacticForm();
1642 if (UnaryOperator *uop = dyn_cast<UnaryOperator>(syntax)) {
1643 Expr *op = stripOpaqueValuesFromPseudoObjectRef(*this, uop->getSubExpr());
1644 return new (Context) UnaryOperator(op, uop->getOpcode(), uop->getType(),
1645 uop->getValueKind(), uop->getObjectKind(),
1646 uop->getOperatorLoc());
1647 } else if (CompoundAssignOperator *cop
1648 = dyn_cast<CompoundAssignOperator>(syntax)) {
1649 Expr *lhs = stripOpaqueValuesFromPseudoObjectRef(*this, cop->getLHS());
1650 Expr *rhs = cast<OpaqueValueExpr>(cop->getRHS())->getSourceExpr();
1651 return new (Context) CompoundAssignOperator(lhs, rhs, cop->getOpcode(),
1652 cop->getType(),
1653 cop->getValueKind(),
1654 cop->getObjectKind(),
1655 cop->getComputationLHSType(),
1656 cop->getComputationResultType(),
Adam Nemet484aa452017-03-27 19:17:25 +00001657 cop->getOperatorLoc(),
1658 FPOptions());
John McCalle9290822011-11-30 04:42:31 +00001659 } else if (BinaryOperator *bop = dyn_cast<BinaryOperator>(syntax)) {
1660 Expr *lhs = stripOpaqueValuesFromPseudoObjectRef(*this, bop->getLHS());
1661 Expr *rhs = cast<OpaqueValueExpr>(bop->getRHS())->getSourceExpr();
1662 return new (Context) BinaryOperator(lhs, rhs, bop->getOpcode(),
1663 bop->getType(), bop->getValueKind(),
1664 bop->getObjectKind(),
Adam Nemet484aa452017-03-27 19:17:25 +00001665 bop->getOperatorLoc(), FPOptions());
John McCalle9290822011-11-30 04:42:31 +00001666 } else {
1667 assert(syntax->hasPlaceholderType(BuiltinType::PseudoObject));
1668 return stripOpaqueValuesFromPseudoObjectRef(*this, syntax);
1669 }
1670}