blob: 211032c44ea9d85bc27e4bffa79b68107ba07c23 [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(),
Lang Hames5de91cc2012-10-02 04:45:10 +0000450 OK_Ordinary, opcLoc, false);
John McCallfe96e0b2011-11-06 09:01:30 +0000451 } else {
452 ExprResult opLHS = buildGet();
453 if (opLHS.isInvalid()) return ExprError();
454
455 // Build an ordinary, non-compound operation.
456 BinaryOperatorKind nonCompound =
457 BinaryOperator::getOpForCompoundAssignment(opcode);
John McCallee04aeb2015-08-22 00:35:27 +0000458 result = S.BuildBinOp(Sc, opcLoc, nonCompound, opLHS.get(), semanticRHS);
John McCallfe96e0b2011-11-06 09:01:30 +0000459 if (result.isInvalid()) return ExprError();
460
461 syntactic =
462 new (S.Context) CompoundAssignOperator(syntacticLHS, capturedRHS, opcode,
463 result.get()->getType(),
464 result.get()->getValueKind(),
465 OK_Ordinary,
466 opLHS.get()->getType(),
467 result.get()->getType(),
Lang Hames5de91cc2012-10-02 04:45:10 +0000468 opcLoc, false);
John McCallfe96e0b2011-11-06 09:01:30 +0000469 }
470
471 // The result of the assignment, if not void, is the value set into
472 // the l-value.
Alexey Bataev60520e22015-12-10 04:38:18 +0000473 result = buildSet(result.get(), opcLoc, captureSetValueAsResult());
John McCallfe96e0b2011-11-06 09:01:30 +0000474 if (result.isInvalid()) return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +0000475 addSemanticExpr(result.get());
Alexey Bataev60520e22015-12-10 04:38:18 +0000476 if (!captureSetValueAsResult() && !result.get()->getType()->isVoidType() &&
477 (result.get()->isTypeDependent() || CanCaptureValue(result.get())))
478 setResultToLastSemantic();
John McCallfe96e0b2011-11-06 09:01:30 +0000479
480 return complete(syntactic);
481}
482
483/// The basic skeleton for building an increment or decrement
484/// operation.
485ExprResult
486PseudoOpBuilder::buildIncDecOperation(Scope *Sc, SourceLocation opcLoc,
487 UnaryOperatorKind opcode,
488 Expr *op) {
489 assert(UnaryOperator::isIncrementDecrementOp(opcode));
490
491 Expr *syntacticOp = rebuildAndCaptureObject(op);
492
493 // Load the value.
494 ExprResult result = buildGet();
495 if (result.isInvalid()) return ExprError();
496
497 QualType resultType = result.get()->getType();
498
499 // That's the postfix result.
John McCall0d9dd732013-04-16 22:32:04 +0000500 if (UnaryOperator::isPostfix(opcode) &&
Fariborz Jahanian15dde892014-03-06 00:34:05 +0000501 (result.get()->isTypeDependent() || CanCaptureValue(result.get()))) {
Nikola Smiljanic01a75982014-05-29 10:55:11 +0000502 result = capture(result.get());
John McCallfe96e0b2011-11-06 09:01:30 +0000503 setResultToLastSemantic();
504 }
505
506 // Add or subtract a literal 1.
507 llvm::APInt oneV(S.Context.getTypeSize(S.Context.IntTy), 1);
508 Expr *one = IntegerLiteral::Create(S.Context, oneV, S.Context.IntTy,
509 GenericLoc);
510
511 if (UnaryOperator::isIncrementOp(opcode)) {
Nikola Smiljanic01a75982014-05-29 10:55:11 +0000512 result = S.BuildBinOp(Sc, opcLoc, BO_Add, result.get(), one);
John McCallfe96e0b2011-11-06 09:01:30 +0000513 } else {
Nikola Smiljanic01a75982014-05-29 10:55:11 +0000514 result = S.BuildBinOp(Sc, opcLoc, BO_Sub, result.get(), one);
John McCallfe96e0b2011-11-06 09:01:30 +0000515 }
516 if (result.isInvalid()) return ExprError();
517
518 // Store that back into the result. The value stored is the result
519 // of a prefix operation.
Alexey Bataev60520e22015-12-10 04:38:18 +0000520 result = buildSet(result.get(), opcLoc, UnaryOperator::isPrefix(opcode) &&
521 captureSetValueAsResult());
John McCallfe96e0b2011-11-06 09:01:30 +0000522 if (result.isInvalid()) return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +0000523 addSemanticExpr(result.get());
Alexey Bataev60520e22015-12-10 04:38:18 +0000524 if (UnaryOperator::isPrefix(opcode) && !captureSetValueAsResult() &&
525 !result.get()->getType()->isVoidType() &&
526 (result.get()->isTypeDependent() || CanCaptureValue(result.get())))
527 setResultToLastSemantic();
John McCallfe96e0b2011-11-06 09:01:30 +0000528
529 UnaryOperator *syntactic =
530 new (S.Context) UnaryOperator(syntacticOp, opcode, resultType,
531 VK_LValue, OK_Ordinary, opcLoc);
532 return complete(syntactic);
533}
534
535
536//===----------------------------------------------------------------------===//
537// Objective-C @property and implicit property references
538//===----------------------------------------------------------------------===//
539
540/// Look up a method in the receiver type of an Objective-C property
541/// reference.
John McCall526ab472011-10-25 17:37:35 +0000542static ObjCMethodDecl *LookupMethodInReceiverType(Sema &S, Selector sel,
543 const ObjCPropertyRefExpr *PRE) {
John McCall526ab472011-10-25 17:37:35 +0000544 if (PRE->isObjectReceiver()) {
Benjamin Kramer8dc57602011-10-28 13:21:18 +0000545 const ObjCObjectPointerType *PT =
546 PRE->getBase()->getType()->castAs<ObjCObjectPointerType>();
John McCallfe96e0b2011-11-06 09:01:30 +0000547
548 // Special case for 'self' in class method implementations.
549 if (PT->isObjCClassType() &&
550 S.isSelfExpr(const_cast<Expr*>(PRE->getBase()))) {
551 // This cast is safe because isSelfExpr is only true within
552 // methods.
553 ObjCMethodDecl *method =
554 cast<ObjCMethodDecl>(S.CurContext->getNonClosureAncestor());
555 return S.LookupMethodInObjectType(sel,
556 S.Context.getObjCInterfaceType(method->getClassInterface()),
557 /*instance*/ false);
558 }
559
Benjamin Kramer8dc57602011-10-28 13:21:18 +0000560 return S.LookupMethodInObjectType(sel, PT->getPointeeType(), true);
John McCall526ab472011-10-25 17:37:35 +0000561 }
562
Benjamin Kramer8dc57602011-10-28 13:21:18 +0000563 if (PRE->isSuperReceiver()) {
564 if (const ObjCObjectPointerType *PT =
565 PRE->getSuperReceiverType()->getAs<ObjCObjectPointerType>())
566 return S.LookupMethodInObjectType(sel, PT->getPointeeType(), true);
567
568 return S.LookupMethodInObjectType(sel, PRE->getSuperReceiverType(), false);
569 }
570
571 assert(PRE->isClassReceiver() && "Invalid expression");
572 QualType IT = S.Context.getObjCInterfaceType(PRE->getClassReceiver());
573 return S.LookupMethodInObjectType(sel, IT, false);
John McCall526ab472011-10-25 17:37:35 +0000574}
575
Jordan Rosed3934582012-09-28 22:21:30 +0000576bool ObjCPropertyOpBuilder::isWeakProperty() const {
577 QualType T;
578 if (RefExpr->isExplicitProperty()) {
579 const ObjCPropertyDecl *Prop = RefExpr->getExplicitProperty();
580 if (Prop->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_weak)
Bob Wilsonf4f54e32016-05-25 05:41:57 +0000581 return true;
Jordan Rosed3934582012-09-28 22:21:30 +0000582
583 T = Prop->getType();
584 } else if (Getter) {
Alp Toker314cc812014-01-25 16:55:45 +0000585 T = Getter->getReturnType();
Jordan Rosed3934582012-09-28 22:21:30 +0000586 } else {
587 return false;
588 }
589
590 return T.getObjCLifetime() == Qualifiers::OCL_Weak;
591}
592
John McCallfe96e0b2011-11-06 09:01:30 +0000593bool ObjCPropertyOpBuilder::findGetter() {
594 if (Getter) return true;
John McCall526ab472011-10-25 17:37:35 +0000595
John McCallcfef5462011-11-07 22:49:50 +0000596 // For implicit properties, just trust the lookup we already did.
597 if (RefExpr->isImplicitProperty()) {
Fariborz Jahanianb525b522012-04-18 19:13:23 +0000598 if ((Getter = RefExpr->getImplicitPropertyGetter())) {
599 GetterSelector = Getter->getSelector();
600 return true;
601 }
602 else {
603 // Must build the getter selector the hard way.
604 ObjCMethodDecl *setter = RefExpr->getImplicitPropertySetter();
605 assert(setter && "both setter and getter are null - cannot happen");
606 IdentifierInfo *setterName =
607 setter->getSelector().getIdentifierInfoForSlot(0);
Alp Toker541d5072014-06-07 23:30:53 +0000608 IdentifierInfo *getterName =
609 &S.Context.Idents.get(setterName->getName().substr(3));
Fariborz Jahanianb525b522012-04-18 19:13:23 +0000610 GetterSelector =
611 S.PP.getSelectorTable().getNullarySelector(getterName);
612 return false;
Fariborz Jahanianb525b522012-04-18 19:13:23 +0000613 }
John McCallcfef5462011-11-07 22:49:50 +0000614 }
615
616 ObjCPropertyDecl *prop = RefExpr->getExplicitProperty();
617 Getter = LookupMethodInReceiverType(S, prop->getGetterName(), RefExpr);
Craig Topperc3ec1492014-05-26 06:22:03 +0000618 return (Getter != nullptr);
John McCallfe96e0b2011-11-06 09:01:30 +0000619}
620
621/// Try to find the most accurate setter declaration for the property
622/// reference.
623///
624/// \return true if a setter was found, in which case Setter
Fariborz Jahanian3f88afa2012-05-24 22:48:38 +0000625bool ObjCPropertyOpBuilder::findSetter(bool warn) {
John McCallfe96e0b2011-11-06 09:01:30 +0000626 // For implicit properties, just trust the lookup we already did.
627 if (RefExpr->isImplicitProperty()) {
628 if (ObjCMethodDecl *setter = RefExpr->getImplicitPropertySetter()) {
629 Setter = setter;
630 SetterSelector = setter->getSelector();
631 return true;
John McCall526ab472011-10-25 17:37:35 +0000632 } else {
John McCallfe96e0b2011-11-06 09:01:30 +0000633 IdentifierInfo *getterName =
634 RefExpr->getImplicitPropertyGetter()->getSelector()
635 .getIdentifierInfoForSlot(0);
636 SetterSelector =
Adrian Prantla4ce9062013-06-07 22:29:12 +0000637 SelectorTable::constructSetterSelector(S.PP.getIdentifierTable(),
638 S.PP.getSelectorTable(),
639 getterName);
John McCallfe96e0b2011-11-06 09:01:30 +0000640 return false;
John McCall526ab472011-10-25 17:37:35 +0000641 }
John McCallfe96e0b2011-11-06 09:01:30 +0000642 }
643
644 // For explicit properties, this is more involved.
645 ObjCPropertyDecl *prop = RefExpr->getExplicitProperty();
646 SetterSelector = prop->getSetterName();
647
648 // Do a normal method lookup first.
649 if (ObjCMethodDecl *setter =
650 LookupMethodInReceiverType(S, SetterSelector, RefExpr)) {
Jordan Rosed01e83a2012-10-10 16:42:25 +0000651 if (setter->isPropertyAccessor() && warn)
Fariborz Jahanian3f88afa2012-05-24 22:48:38 +0000652 if (const ObjCInterfaceDecl *IFace =
653 dyn_cast<ObjCInterfaceDecl>(setter->getDeclContext())) {
Craig Topperbf3e3272014-08-30 16:55:52 +0000654 StringRef thisPropertyName = prop->getName();
Jordan Rosea7d03842013-02-08 22:30:41 +0000655 // Try flipping the case of the first character.
Fariborz Jahanian3f88afa2012-05-24 22:48:38 +0000656 char front = thisPropertyName.front();
Jordan Rosea7d03842013-02-08 22:30:41 +0000657 front = isLowercase(front) ? toUppercase(front) : toLowercase(front);
Fariborz Jahanian3f88afa2012-05-24 22:48:38 +0000658 SmallString<100> PropertyName = thisPropertyName;
659 PropertyName[0] = front;
660 IdentifierInfo *AltMember = &S.PP.getIdentifierTable().get(PropertyName);
Manman Ren5b786402016-01-28 18:49:28 +0000661 if (ObjCPropertyDecl *prop1 = IFace->FindPropertyDeclaration(
662 AltMember, prop->getQueryKind()))
Fariborz Jahanian3f88afa2012-05-24 22:48:38 +0000663 if (prop != prop1 && (prop1->getSetterMethodDecl() == setter)) {
Richard Smithf8812672016-12-02 22:38:31 +0000664 S.Diag(RefExpr->getExprLoc(), diag::err_property_setter_ambiguous_use)
Aaron Ballman1fb39552014-01-03 14:23:03 +0000665 << prop << prop1 << setter->getSelector();
Fariborz Jahanian3f88afa2012-05-24 22:48:38 +0000666 S.Diag(prop->getLocation(), diag::note_property_declare);
667 S.Diag(prop1->getLocation(), diag::note_property_declare);
668 }
669 }
John McCallfe96e0b2011-11-06 09:01:30 +0000670 Setter = setter;
671 return true;
672 }
673
674 // That can fail in the somewhat crazy situation that we're
675 // type-checking a message send within the @interface declaration
676 // that declared the @property. But it's not clear that that's
677 // valuable to support.
678
679 return false;
680}
681
Olivier Goffartf6fabcc2014-08-04 17:28:11 +0000682void ObjCPropertyOpBuilder::DiagnoseUnsupportedPropertyUse() {
Fariborz Jahanian55513282014-05-28 18:12:10 +0000683 if (S.getCurLexicalContext()->isObjCContainer() &&
684 S.getCurLexicalContext()->getDeclKind() != Decl::ObjCCategoryImpl &&
685 S.getCurLexicalContext()->getDeclKind() != Decl::ObjCImplementation) {
686 if (ObjCPropertyDecl *prop = RefExpr->getExplicitProperty()) {
687 S.Diag(RefExpr->getLocation(),
688 diag::err_property_function_in_objc_container);
689 S.Diag(prop->getLocation(), diag::note_property_declare);
Fariborz Jahanian55513282014-05-28 18:12:10 +0000690 }
691 }
Fariborz Jahanian55513282014-05-28 18:12:10 +0000692}
693
John McCallfe96e0b2011-11-06 09:01:30 +0000694/// Capture the base object of an Objective-C property expression.
695Expr *ObjCPropertyOpBuilder::rebuildAndCaptureObject(Expr *syntacticBase) {
Craig Topperc3ec1492014-05-26 06:22:03 +0000696 assert(InstanceReceiver == nullptr);
John McCallfe96e0b2011-11-06 09:01:30 +0000697
698 // If we have a base, capture it in an OVE and rebuild the syntactic
699 // form to use the OVE as its base.
700 if (RefExpr->isObjectReceiver()) {
701 InstanceReceiver = capture(RefExpr->getBase());
Alexey Bataevf7630272015-11-25 12:01:00 +0000702 syntacticBase = Rebuilder(S, [=](Expr *, unsigned) -> Expr * {
703 return InstanceReceiver;
704 }).rebuild(syntacticBase);
John McCallfe96e0b2011-11-06 09:01:30 +0000705 }
706
Argyrios Kyrtzidisab468b02012-03-30 00:19:18 +0000707 if (ObjCPropertyRefExpr *
708 refE = dyn_cast<ObjCPropertyRefExpr>(syntacticBase->IgnoreParens()))
709 SyntacticRefExpr = refE;
710
John McCallfe96e0b2011-11-06 09:01:30 +0000711 return syntacticBase;
712}
713
714/// Load from an Objective-C property reference.
715ExprResult ObjCPropertyOpBuilder::buildGet() {
716 findGetter();
Olivier Goffartf6fabcc2014-08-04 17:28:11 +0000717 if (!Getter) {
718 DiagnoseUnsupportedPropertyUse();
719 return ExprError();
720 }
Argyrios Kyrtzidisab468b02012-03-30 00:19:18 +0000721
722 if (SyntacticRefExpr)
723 SyntacticRefExpr->setIsMessagingGetter();
724
Douglas Gregore83b9562015-07-07 03:57:53 +0000725 QualType receiverType = RefExpr->getReceiverType(S.Context);
Fariborz Jahanian89ea9612014-06-16 17:25:41 +0000726 if (!Getter->isImplicit())
727 S.DiagnoseUseOfDecl(Getter, GenericLoc, nullptr, true);
John McCallfe96e0b2011-11-06 09:01:30 +0000728 // Build a message-send.
729 ExprResult msg;
Fariborz Jahanian29cdbc62014-04-21 20:22:17 +0000730 if ((Getter->isInstanceMethod() && !RefExpr->isClassReceiver()) ||
731 RefExpr->isObjectReceiver()) {
John McCallfe96e0b2011-11-06 09:01:30 +0000732 assert(InstanceReceiver || RefExpr->isSuperReceiver());
Argyrios Kyrtzidisa80f1bf2012-01-12 02:34:39 +0000733 msg = S.BuildInstanceMessageImplicit(InstanceReceiver, receiverType,
734 GenericLoc, Getter->getSelector(),
Dmitri Gribenko78852e92013-05-05 20:40:26 +0000735 Getter, None);
John McCallfe96e0b2011-11-06 09:01:30 +0000736 } else {
Argyrios Kyrtzidisa80f1bf2012-01-12 02:34:39 +0000737 msg = S.BuildClassMessageImplicit(receiverType, RefExpr->isSuperReceiver(),
Dmitri Gribenko78852e92013-05-05 20:40:26 +0000738 GenericLoc, Getter->getSelector(),
739 Getter, None);
John McCallfe96e0b2011-11-06 09:01:30 +0000740 }
741 return msg;
742}
John McCall526ab472011-10-25 17:37:35 +0000743
John McCallfe96e0b2011-11-06 09:01:30 +0000744/// Store to an Objective-C property reference.
745///
Dmitri Gribenkoadba9be2012-08-23 17:58:28 +0000746/// \param captureSetValueAsResult If true, capture the actual
John McCallfe96e0b2011-11-06 09:01:30 +0000747/// value being set as the value of the property operation.
748ExprResult ObjCPropertyOpBuilder::buildSet(Expr *op, SourceLocation opcLoc,
749 bool captureSetValueAsResult) {
Olivier Goffartf6fabcc2014-08-04 17:28:11 +0000750 if (!findSetter(false)) {
751 DiagnoseUnsupportedPropertyUse();
752 return ExprError();
753 }
John McCallfe96e0b2011-11-06 09:01:30 +0000754
Argyrios Kyrtzidisab468b02012-03-30 00:19:18 +0000755 if (SyntacticRefExpr)
756 SyntacticRefExpr->setIsMessagingSetter();
757
Douglas Gregore83b9562015-07-07 03:57:53 +0000758 QualType receiverType = RefExpr->getReceiverType(S.Context);
John McCallfe96e0b2011-11-06 09:01:30 +0000759
760 // Use assignment constraints when possible; they give us better
761 // diagnostics. "When possible" basically means anything except a
762 // C++ class type.
David Blaikiebbafb8a2012-03-11 07:00:24 +0000763 if (!S.getLangOpts().CPlusPlus || !op->getType()->isRecordType()) {
Douglas Gregore83b9562015-07-07 03:57:53 +0000764 QualType paramType = (*Setter->param_begin())->getType()
765 .substObjCMemberType(
766 receiverType,
767 Setter->getDeclContext(),
768 ObjCSubstitutionContext::Parameter);
David Blaikiebbafb8a2012-03-11 07:00:24 +0000769 if (!S.getLangOpts().CPlusPlus || !paramType->isRecordType()) {
John McCallfe96e0b2011-11-06 09:01:30 +0000770 ExprResult opResult = op;
771 Sema::AssignConvertType assignResult
772 = S.CheckSingleAssignmentConstraints(paramType, opResult);
Richard Smithe15a3702016-10-06 23:12:58 +0000773 if (opResult.isInvalid() ||
774 S.DiagnoseAssignmentResult(assignResult, opcLoc, paramType,
John McCallfe96e0b2011-11-06 09:01:30 +0000775 op->getType(), opResult.get(),
776 Sema::AA_Assigning))
777 return ExprError();
778
Nikola Smiljanic01a75982014-05-29 10:55:11 +0000779 op = opResult.get();
John McCallfe96e0b2011-11-06 09:01:30 +0000780 assert(op && "successful assignment left argument invalid?");
John McCall526ab472011-10-25 17:37:35 +0000781 }
782 }
783
John McCallfe96e0b2011-11-06 09:01:30 +0000784 // Arguments.
785 Expr *args[] = { op };
John McCall526ab472011-10-25 17:37:35 +0000786
John McCallfe96e0b2011-11-06 09:01:30 +0000787 // Build a message-send.
788 ExprResult msg;
Fariborz Jahanian89ea9612014-06-16 17:25:41 +0000789 if (!Setter->isImplicit())
790 S.DiagnoseUseOfDecl(Setter, GenericLoc, nullptr, true);
Fariborz Jahanian29cdbc62014-04-21 20:22:17 +0000791 if ((Setter->isInstanceMethod() && !RefExpr->isClassReceiver()) ||
792 RefExpr->isObjectReceiver()) {
Argyrios Kyrtzidisa80f1bf2012-01-12 02:34:39 +0000793 msg = S.BuildInstanceMessageImplicit(InstanceReceiver, receiverType,
794 GenericLoc, SetterSelector, Setter,
795 MultiExprArg(args, 1));
John McCallfe96e0b2011-11-06 09:01:30 +0000796 } else {
Argyrios Kyrtzidisa80f1bf2012-01-12 02:34:39 +0000797 msg = S.BuildClassMessageImplicit(receiverType, RefExpr->isSuperReceiver(),
798 GenericLoc,
799 SetterSelector, Setter,
800 MultiExprArg(args, 1));
John McCallfe96e0b2011-11-06 09:01:30 +0000801 }
802
803 if (!msg.isInvalid() && captureSetValueAsResult) {
804 ObjCMessageExpr *msgExpr =
805 cast<ObjCMessageExpr>(msg.get()->IgnoreImplicit());
806 Expr *arg = msgExpr->getArg(0);
Fariborz Jahanian15dde892014-03-06 00:34:05 +0000807 if (CanCaptureValue(arg))
Eli Friedman00fa4292012-11-13 23:16:33 +0000808 msgExpr->setArg(0, captureValueAsResult(arg));
John McCallfe96e0b2011-11-06 09:01:30 +0000809 }
810
811 return msg;
John McCall526ab472011-10-25 17:37:35 +0000812}
813
John McCallfe96e0b2011-11-06 09:01:30 +0000814/// @property-specific behavior for doing lvalue-to-rvalue conversion.
815ExprResult ObjCPropertyOpBuilder::buildRValueOperation(Expr *op) {
816 // Explicit properties always have getters, but implicit ones don't.
817 // Check that before proceeding.
Eli Friedmanfd41aee2012-11-29 03:13:49 +0000818 if (RefExpr->isImplicitProperty() && !RefExpr->getImplicitPropertyGetter()) {
John McCallfe96e0b2011-11-06 09:01:30 +0000819 S.Diag(RefExpr->getLocation(), diag::err_getter_not_found)
Eli Friedmanfd41aee2012-11-29 03:13:49 +0000820 << RefExpr->getSourceRange();
John McCall526ab472011-10-25 17:37:35 +0000821 return ExprError();
822 }
823
John McCallfe96e0b2011-11-06 09:01:30 +0000824 ExprResult result = PseudoOpBuilder::buildRValueOperation(op);
John McCall526ab472011-10-25 17:37:35 +0000825 if (result.isInvalid()) return ExprError();
826
John McCallfe96e0b2011-11-06 09:01:30 +0000827 if (RefExpr->isExplicitProperty() && !Getter->hasRelatedResultType())
828 S.DiagnosePropertyAccessorMismatch(RefExpr->getExplicitProperty(),
829 Getter, RefExpr->getLocation());
830
831 // As a special case, if the method returns 'id', try to get
832 // a better type from the property.
Fariborz Jahanian9277ff42014-06-17 23:35:13 +0000833 if (RefExpr->isExplicitProperty() && result.get()->isRValue()) {
Douglas Gregore83b9562015-07-07 03:57:53 +0000834 QualType receiverType = RefExpr->getReceiverType(S.Context);
835 QualType propType = RefExpr->getExplicitProperty()
836 ->getUsageType(receiverType);
Fariborz Jahanian9277ff42014-06-17 23:35:13 +0000837 if (result.get()->getType()->isObjCIdType()) {
838 if (const ObjCObjectPointerType *ptr
839 = propType->getAs<ObjCObjectPointerType>()) {
840 if (!ptr->isObjCIdType())
841 result = S.ImpCastExprToType(result.get(), propType, CK_BitCast);
842 }
843 }
844 if (S.getLangOpts().ObjCAutoRefCount) {
845 Qualifiers::ObjCLifetime LT = propType.getObjCLifetime();
846 if (LT == Qualifiers::OCL_Weak)
847 if (!S.Diags.isIgnored(diag::warn_arc_repeated_use_of_weak, RefExpr->getLocation()))
848 S.getCurFunction()->markSafeWeakUse(RefExpr);
John McCallfe96e0b2011-11-06 09:01:30 +0000849 }
850 }
851
John McCall526ab472011-10-25 17:37:35 +0000852 return result;
853}
854
John McCallfe96e0b2011-11-06 09:01:30 +0000855/// Try to build this as a call to a getter that returns a reference.
856///
857/// \return true if it was possible, whether or not it actually
858/// succeeded
859bool ObjCPropertyOpBuilder::tryBuildGetOfReference(Expr *op,
860 ExprResult &result) {
David Blaikiebbafb8a2012-03-11 07:00:24 +0000861 if (!S.getLangOpts().CPlusPlus) return false;
John McCallfe96e0b2011-11-06 09:01:30 +0000862
863 findGetter();
Olivier Goffart4c182c82014-08-04 17:28:05 +0000864 if (!Getter) {
865 // The property has no setter and no getter! This can happen if the type is
866 // invalid. Error have already been reported.
867 result = ExprError();
868 return true;
869 }
John McCallfe96e0b2011-11-06 09:01:30 +0000870
871 // Only do this if the getter returns an l-value reference type.
Alp Toker314cc812014-01-25 16:55:45 +0000872 QualType resultType = Getter->getReturnType();
John McCallfe96e0b2011-11-06 09:01:30 +0000873 if (!resultType->isLValueReferenceType()) return false;
874
875 result = buildRValueOperation(op);
876 return true;
877}
878
879/// @property-specific behavior for doing assignments.
880ExprResult
881ObjCPropertyOpBuilder::buildAssignmentOperation(Scope *Sc,
882 SourceLocation opcLoc,
883 BinaryOperatorKind opcode,
884 Expr *LHS, Expr *RHS) {
John McCall526ab472011-10-25 17:37:35 +0000885 assert(BinaryOperator::isAssignmentOp(opcode));
John McCall526ab472011-10-25 17:37:35 +0000886
887 // If there's no setter, we have no choice but to try to assign to
888 // the result of the getter.
John McCallfe96e0b2011-11-06 09:01:30 +0000889 if (!findSetter()) {
890 ExprResult result;
891 if (tryBuildGetOfReference(LHS, result)) {
892 if (result.isInvalid()) return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +0000893 return S.BuildBinOp(Sc, opcLoc, opcode, result.get(), RHS);
John McCall526ab472011-10-25 17:37:35 +0000894 }
895
896 // Otherwise, it's an error.
John McCallfe96e0b2011-11-06 09:01:30 +0000897 S.Diag(opcLoc, diag::err_nosetter_property_assignment)
898 << unsigned(RefExpr->isImplicitProperty())
899 << SetterSelector
John McCall526ab472011-10-25 17:37:35 +0000900 << LHS->getSourceRange() << RHS->getSourceRange();
901 return ExprError();
902 }
903
904 // If there is a setter, we definitely want to use it.
905
John McCallfe96e0b2011-11-06 09:01:30 +0000906 // Verify that we can do a compound assignment.
907 if (opcode != BO_Assign && !findGetter()) {
908 S.Diag(opcLoc, diag::err_nogetter_property_compound_assignment)
John McCall526ab472011-10-25 17:37:35 +0000909 << LHS->getSourceRange() << RHS->getSourceRange();
910 return ExprError();
911 }
912
John McCallfe96e0b2011-11-06 09:01:30 +0000913 ExprResult result =
914 PseudoOpBuilder::buildAssignmentOperation(Sc, opcLoc, opcode, LHS, RHS);
John McCall526ab472011-10-25 17:37:35 +0000915 if (result.isInvalid()) return ExprError();
916
John McCallfe96e0b2011-11-06 09:01:30 +0000917 // Various warnings about property assignments in ARC.
David Blaikiebbafb8a2012-03-11 07:00:24 +0000918 if (S.getLangOpts().ObjCAutoRefCount && InstanceReceiver) {
John McCallfe96e0b2011-11-06 09:01:30 +0000919 S.checkRetainCycles(InstanceReceiver->getSourceExpr(), RHS);
920 S.checkUnsafeExprAssigns(opcLoc, LHS, RHS);
921 }
922
John McCall526ab472011-10-25 17:37:35 +0000923 return result;
924}
John McCallfe96e0b2011-11-06 09:01:30 +0000925
926/// @property-specific behavior for doing increments and decrements.
927ExprResult
928ObjCPropertyOpBuilder::buildIncDecOperation(Scope *Sc, SourceLocation opcLoc,
929 UnaryOperatorKind opcode,
930 Expr *op) {
931 // If there's no setter, we have no choice but to try to assign to
932 // the result of the getter.
933 if (!findSetter()) {
934 ExprResult result;
935 if (tryBuildGetOfReference(op, result)) {
936 if (result.isInvalid()) return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +0000937 return S.BuildUnaryOp(Sc, opcLoc, opcode, result.get());
John McCallfe96e0b2011-11-06 09:01:30 +0000938 }
939
940 // Otherwise, it's an error.
941 S.Diag(opcLoc, diag::err_nosetter_property_incdec)
942 << unsigned(RefExpr->isImplicitProperty())
943 << unsigned(UnaryOperator::isDecrementOp(opcode))
944 << SetterSelector
945 << op->getSourceRange();
946 return ExprError();
947 }
948
949 // If there is a setter, we definitely want to use it.
950
951 // We also need a getter.
952 if (!findGetter()) {
953 assert(RefExpr->isImplicitProperty());
954 S.Diag(opcLoc, diag::err_nogetter_property_incdec)
955 << unsigned(UnaryOperator::isDecrementOp(opcode))
Fariborz Jahanianb525b522012-04-18 19:13:23 +0000956 << GetterSelector
John McCallfe96e0b2011-11-06 09:01:30 +0000957 << op->getSourceRange();
958 return ExprError();
959 }
960
961 return PseudoOpBuilder::buildIncDecOperation(Sc, opcLoc, opcode, op);
962}
963
Jordan Rosed3934582012-09-28 22:21:30 +0000964ExprResult ObjCPropertyOpBuilder::complete(Expr *SyntacticForm) {
Alp Tokerd4a3f0e2014-06-15 23:30:39 +0000965 if (S.getLangOpts().ObjCAutoRefCount && isWeakProperty() &&
966 !S.Diags.isIgnored(diag::warn_arc_repeated_use_of_weak,
967 SyntacticForm->getLocStart()))
Fariborz Jahanian6f829e32013-05-21 21:20:26 +0000968 S.recordUseOfEvaluatedWeak(SyntacticRefExpr,
969 SyntacticRefExpr->isMessagingGetter());
Jordan Rosed3934582012-09-28 22:21:30 +0000970
971 return PseudoOpBuilder::complete(SyntacticForm);
972}
973
Ted Kremeneke65b0862012-03-06 20:05:56 +0000974// ObjCSubscript build stuff.
975//
976
977/// objective-c subscripting-specific behavior for doing lvalue-to-rvalue
978/// conversion.
979/// FIXME. Remove this routine if it is proven that no additional
980/// specifity is needed.
981ExprResult ObjCSubscriptOpBuilder::buildRValueOperation(Expr *op) {
982 ExprResult result = PseudoOpBuilder::buildRValueOperation(op);
983 if (result.isInvalid()) return ExprError();
984 return result;
985}
986
987/// objective-c subscripting-specific behavior for doing assignments.
988ExprResult
989ObjCSubscriptOpBuilder::buildAssignmentOperation(Scope *Sc,
990 SourceLocation opcLoc,
991 BinaryOperatorKind opcode,
992 Expr *LHS, Expr *RHS) {
993 assert(BinaryOperator::isAssignmentOp(opcode));
994 // There must be a method to do the Index'ed assignment.
995 if (!findAtIndexSetter())
996 return ExprError();
997
998 // Verify that we can do a compound assignment.
999 if (opcode != BO_Assign && !findAtIndexGetter())
1000 return ExprError();
1001
1002 ExprResult result =
1003 PseudoOpBuilder::buildAssignmentOperation(Sc, opcLoc, opcode, LHS, RHS);
1004 if (result.isInvalid()) return ExprError();
1005
1006 // Various warnings about objc Index'ed assignments in ARC.
David Blaikiebbafb8a2012-03-11 07:00:24 +00001007 if (S.getLangOpts().ObjCAutoRefCount && InstanceBase) {
Ted Kremeneke65b0862012-03-06 20:05:56 +00001008 S.checkRetainCycles(InstanceBase->getSourceExpr(), RHS);
1009 S.checkUnsafeExprAssigns(opcLoc, LHS, RHS);
1010 }
1011
1012 return result;
1013}
1014
1015/// Capture the base object of an Objective-C Index'ed expression.
1016Expr *ObjCSubscriptOpBuilder::rebuildAndCaptureObject(Expr *syntacticBase) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001017 assert(InstanceBase == nullptr);
1018
Ted Kremeneke65b0862012-03-06 20:05:56 +00001019 // Capture base expression in an OVE and rebuild the syntactic
1020 // form to use the OVE as its base expression.
1021 InstanceBase = capture(RefExpr->getBaseExpr());
1022 InstanceKey = capture(RefExpr->getKeyExpr());
Alexey Bataevf7630272015-11-25 12:01:00 +00001023
Ted Kremeneke65b0862012-03-06 20:05:56 +00001024 syntacticBase =
Alexey Bataevf7630272015-11-25 12:01:00 +00001025 Rebuilder(S, [=](Expr *, unsigned Idx) -> Expr * {
1026 switch (Idx) {
1027 case 0:
1028 return InstanceBase;
1029 case 1:
1030 return InstanceKey;
1031 default:
1032 llvm_unreachable("Unexpected index for ObjCSubscriptExpr");
1033 }
1034 }).rebuild(syntacticBase);
1035
Ted Kremeneke65b0862012-03-06 20:05:56 +00001036 return syntacticBase;
1037}
1038
1039/// CheckSubscriptingKind - This routine decide what type
1040/// of indexing represented by "FromE" is being done.
1041Sema::ObjCSubscriptKind
1042 Sema::CheckSubscriptingKind(Expr *FromE) {
1043 // If the expression already has integral or enumeration type, we're golden.
1044 QualType T = FromE->getType();
1045 if (T->isIntegralOrEnumerationType())
1046 return OS_Array;
1047
1048 // If we don't have a class type in C++, there's no way we can get an
1049 // expression of integral or enumeration type.
1050 const RecordType *RecordTy = T->getAs<RecordType>();
Fariborz Jahaniand13951f2014-09-10 20:55:31 +00001051 if (!RecordTy &&
1052 (T->isObjCObjectPointerType() || T->isVoidPointerType()))
Ted Kremeneke65b0862012-03-06 20:05:56 +00001053 // All other scalar cases are assumed to be dictionary indexing which
1054 // caller handles, with diagnostics if needed.
1055 return OS_Dictionary;
Fariborz Jahanianba0afde2012-03-28 17:56:49 +00001056 if (!getLangOpts().CPlusPlus ||
1057 !RecordTy || RecordTy->isIncompleteType()) {
Ted Kremeneke65b0862012-03-06 20:05:56 +00001058 // No indexing can be done. Issue diagnostics and quit.
Fariborz Jahanianba0afde2012-03-28 17:56:49 +00001059 const Expr *IndexExpr = FromE->IgnoreParenImpCasts();
1060 if (isa<StringLiteral>(IndexExpr))
1061 Diag(FromE->getExprLoc(), diag::err_objc_subscript_pointer)
1062 << T << FixItHint::CreateInsertion(FromE->getExprLoc(), "@");
1063 else
1064 Diag(FromE->getExprLoc(), diag::err_objc_subscript_type_conversion)
1065 << T;
Ted Kremeneke65b0862012-03-06 20:05:56 +00001066 return OS_Error;
1067 }
1068
1069 // We must have a complete class type.
1070 if (RequireCompleteType(FromE->getExprLoc(), T,
Douglas Gregor7bfb2d02012-05-04 16:32:21 +00001071 diag::err_objc_index_incomplete_class_type, FromE))
Ted Kremeneke65b0862012-03-06 20:05:56 +00001072 return OS_Error;
1073
1074 // Look for a conversion to an integral, enumeration type, or
1075 // objective-C pointer type.
Ted Kremeneke65b0862012-03-06 20:05:56 +00001076 int NoIntegrals=0, NoObjCIdPointers=0;
1077 SmallVector<CXXConversionDecl *, 4> ConversionDecls;
Benjamin Kramerb4ef6682015-02-06 17:25:10 +00001078
1079 for (NamedDecl *D : cast<CXXRecordDecl>(RecordTy->getDecl())
1080 ->getVisibleConversionFunctions()) {
1081 if (CXXConversionDecl *Conversion =
1082 dyn_cast<CXXConversionDecl>(D->getUnderlyingDecl())) {
Ted Kremeneke65b0862012-03-06 20:05:56 +00001083 QualType CT = Conversion->getConversionType().getNonReferenceType();
1084 if (CT->isIntegralOrEnumerationType()) {
1085 ++NoIntegrals;
1086 ConversionDecls.push_back(Conversion);
1087 }
1088 else if (CT->isObjCIdType() ||CT->isBlockPointerType()) {
1089 ++NoObjCIdPointers;
1090 ConversionDecls.push_back(Conversion);
1091 }
1092 }
1093 }
1094 if (NoIntegrals ==1 && NoObjCIdPointers == 0)
1095 return OS_Array;
1096 if (NoIntegrals == 0 && NoObjCIdPointers == 1)
1097 return OS_Dictionary;
1098 if (NoIntegrals == 0 && NoObjCIdPointers == 0) {
1099 // No conversion function was found. Issue diagnostic and return.
1100 Diag(FromE->getExprLoc(), diag::err_objc_subscript_type_conversion)
1101 << FromE->getType();
1102 return OS_Error;
1103 }
1104 Diag(FromE->getExprLoc(), diag::err_objc_multiple_subscript_type_conversion)
1105 << FromE->getType();
1106 for (unsigned int i = 0; i < ConversionDecls.size(); i++)
1107 Diag(ConversionDecls[i]->getLocation(), diag::not_conv_function_declared_at);
1108
1109 return OS_Error;
1110}
1111
Fariborz Jahanian90804912012-08-02 18:03:58 +00001112/// CheckKeyForObjCARCConversion - This routine suggests bridge casting of CF
1113/// objects used as dictionary subscript key objects.
1114static void CheckKeyForObjCARCConversion(Sema &S, QualType ContainerT,
1115 Expr *Key) {
1116 if (ContainerT.isNull())
1117 return;
1118 // dictionary subscripting.
1119 // - (id)objectForKeyedSubscript:(id)key;
1120 IdentifierInfo *KeyIdents[] = {
1121 &S.Context.Idents.get("objectForKeyedSubscript")
1122 };
1123 Selector GetterSelector = S.Context.Selectors.getSelector(1, KeyIdents);
1124 ObjCMethodDecl *Getter = S.LookupMethodInObjectType(GetterSelector, ContainerT,
1125 true /*instance*/);
1126 if (!Getter)
1127 return;
Alp Toker03376dc2014-07-07 09:02:20 +00001128 QualType T = Getter->parameters()[0]->getType();
Fariborz Jahanian90804912012-08-02 18:03:58 +00001129 S.CheckObjCARCConversion(Key->getSourceRange(),
1130 T, Key, Sema::CCK_ImplicitConversion);
1131}
1132
Ted Kremeneke65b0862012-03-06 20:05:56 +00001133bool ObjCSubscriptOpBuilder::findAtIndexGetter() {
1134 if (AtIndexGetter)
1135 return true;
1136
1137 Expr *BaseExpr = RefExpr->getBaseExpr();
1138 QualType BaseT = BaseExpr->getType();
1139
1140 QualType ResultType;
1141 if (const ObjCObjectPointerType *PTy =
1142 BaseT->getAs<ObjCObjectPointerType>()) {
1143 ResultType = PTy->getPointeeType();
Ted Kremeneke65b0862012-03-06 20:05:56 +00001144 }
1145 Sema::ObjCSubscriptKind Res =
1146 S.CheckSubscriptingKind(RefExpr->getKeyExpr());
Fariborz Jahanian90804912012-08-02 18:03:58 +00001147 if (Res == Sema::OS_Error) {
1148 if (S.getLangOpts().ObjCAutoRefCount)
1149 CheckKeyForObjCARCConversion(S, ResultType,
1150 RefExpr->getKeyExpr());
Ted Kremeneke65b0862012-03-06 20:05:56 +00001151 return false;
Fariborz Jahanian90804912012-08-02 18:03:58 +00001152 }
Ted Kremeneke65b0862012-03-06 20:05:56 +00001153 bool arrayRef = (Res == Sema::OS_Array);
1154
1155 if (ResultType.isNull()) {
1156 S.Diag(BaseExpr->getExprLoc(), diag::err_objc_subscript_base_type)
1157 << BaseExpr->getType() << arrayRef;
1158 return false;
1159 }
1160 if (!arrayRef) {
1161 // dictionary subscripting.
1162 // - (id)objectForKeyedSubscript:(id)key;
1163 IdentifierInfo *KeyIdents[] = {
1164 &S.Context.Idents.get("objectForKeyedSubscript")
1165 };
1166 AtIndexGetterSelector = S.Context.Selectors.getSelector(1, KeyIdents);
1167 }
1168 else {
1169 // - (id)objectAtIndexedSubscript:(size_t)index;
1170 IdentifierInfo *KeyIdents[] = {
1171 &S.Context.Idents.get("objectAtIndexedSubscript")
1172 };
1173
1174 AtIndexGetterSelector = S.Context.Selectors.getSelector(1, KeyIdents);
1175 }
1176
1177 AtIndexGetter = S.LookupMethodInObjectType(AtIndexGetterSelector, ResultType,
1178 true /*instance*/);
1179 bool receiverIdType = (BaseT->isObjCIdType() ||
1180 BaseT->isObjCQualifiedIdType());
1181
David Blaikiebbafb8a2012-03-11 07:00:24 +00001182 if (!AtIndexGetter && S.getLangOpts().DebuggerObjCLiteral) {
Ted Kremeneke65b0862012-03-06 20:05:56 +00001183 AtIndexGetter = ObjCMethodDecl::Create(S.Context, SourceLocation(),
1184 SourceLocation(), AtIndexGetterSelector,
1185 S.Context.getObjCIdType() /*ReturnType*/,
Craig Topperc3ec1492014-05-26 06:22:03 +00001186 nullptr /*TypeSourceInfo */,
Ted Kremeneke65b0862012-03-06 20:05:56 +00001187 S.Context.getTranslationUnitDecl(),
1188 true /*Instance*/, false/*isVariadic*/,
Jordan Rosed01e83a2012-10-10 16:42:25 +00001189 /*isPropertyAccessor=*/false,
Ted Kremeneke65b0862012-03-06 20:05:56 +00001190 /*isImplicitlyDeclared=*/true, /*isDefined=*/false,
1191 ObjCMethodDecl::Required,
1192 false);
1193 ParmVarDecl *Argument = ParmVarDecl::Create(S.Context, AtIndexGetter,
1194 SourceLocation(), SourceLocation(),
1195 arrayRef ? &S.Context.Idents.get("index")
1196 : &S.Context.Idents.get("key"),
1197 arrayRef ? S.Context.UnsignedLongTy
1198 : S.Context.getObjCIdType(),
Craig Topperc3ec1492014-05-26 06:22:03 +00001199 /*TInfo=*/nullptr,
Ted Kremeneke65b0862012-03-06 20:05:56 +00001200 SC_None,
Craig Topperc3ec1492014-05-26 06:22:03 +00001201 nullptr);
Dmitri Gribenko44ebbd52013-05-05 00:41:58 +00001202 AtIndexGetter->setMethodParams(S.Context, Argument, None);
Ted Kremeneke65b0862012-03-06 20:05:56 +00001203 }
1204
1205 if (!AtIndexGetter) {
1206 if (!receiverIdType) {
1207 S.Diag(BaseExpr->getExprLoc(), diag::err_objc_subscript_method_not_found)
1208 << BaseExpr->getType() << 0 << arrayRef;
1209 return false;
1210 }
1211 AtIndexGetter =
1212 S.LookupInstanceMethodInGlobalPool(AtIndexGetterSelector,
1213 RefExpr->getSourceRange(),
Fariborz Jahanian890803f2015-04-15 17:26:21 +00001214 true);
Ted Kremeneke65b0862012-03-06 20:05:56 +00001215 }
1216
1217 if (AtIndexGetter) {
Alp Toker03376dc2014-07-07 09:02:20 +00001218 QualType T = AtIndexGetter->parameters()[0]->getType();
Ted Kremeneke65b0862012-03-06 20:05:56 +00001219 if ((arrayRef && !T->isIntegralOrEnumerationType()) ||
1220 (!arrayRef && !T->isObjCObjectPointerType())) {
1221 S.Diag(RefExpr->getKeyExpr()->getExprLoc(),
1222 arrayRef ? diag::err_objc_subscript_index_type
1223 : diag::err_objc_subscript_key_type) << T;
Alp Toker03376dc2014-07-07 09:02:20 +00001224 S.Diag(AtIndexGetter->parameters()[0]->getLocation(),
Ted Kremeneke65b0862012-03-06 20:05:56 +00001225 diag::note_parameter_type) << T;
1226 return false;
1227 }
Alp Toker314cc812014-01-25 16:55:45 +00001228 QualType R = AtIndexGetter->getReturnType();
Ted Kremeneke65b0862012-03-06 20:05:56 +00001229 if (!R->isObjCObjectPointerType()) {
1230 S.Diag(RefExpr->getKeyExpr()->getExprLoc(),
1231 diag::err_objc_indexing_method_result_type) << R << arrayRef;
1232 S.Diag(AtIndexGetter->getLocation(), diag::note_method_declared_at) <<
1233 AtIndexGetter->getDeclName();
1234 }
1235 }
1236 return true;
1237}
1238
1239bool ObjCSubscriptOpBuilder::findAtIndexSetter() {
1240 if (AtIndexSetter)
1241 return true;
1242
1243 Expr *BaseExpr = RefExpr->getBaseExpr();
1244 QualType BaseT = BaseExpr->getType();
1245
1246 QualType ResultType;
1247 if (const ObjCObjectPointerType *PTy =
1248 BaseT->getAs<ObjCObjectPointerType>()) {
1249 ResultType = PTy->getPointeeType();
Ted Kremeneke65b0862012-03-06 20:05:56 +00001250 }
1251
1252 Sema::ObjCSubscriptKind Res =
1253 S.CheckSubscriptingKind(RefExpr->getKeyExpr());
Fariborz Jahanian90804912012-08-02 18:03:58 +00001254 if (Res == Sema::OS_Error) {
1255 if (S.getLangOpts().ObjCAutoRefCount)
1256 CheckKeyForObjCARCConversion(S, ResultType,
1257 RefExpr->getKeyExpr());
Ted Kremeneke65b0862012-03-06 20:05:56 +00001258 return false;
Fariborz Jahanian90804912012-08-02 18:03:58 +00001259 }
Ted Kremeneke65b0862012-03-06 20:05:56 +00001260 bool arrayRef = (Res == Sema::OS_Array);
1261
1262 if (ResultType.isNull()) {
1263 S.Diag(BaseExpr->getExprLoc(), diag::err_objc_subscript_base_type)
1264 << BaseExpr->getType() << arrayRef;
1265 return false;
1266 }
1267
1268 if (!arrayRef) {
1269 // dictionary subscripting.
1270 // - (void)setObject:(id)object forKeyedSubscript:(id)key;
1271 IdentifierInfo *KeyIdents[] = {
1272 &S.Context.Idents.get("setObject"),
1273 &S.Context.Idents.get("forKeyedSubscript")
1274 };
1275 AtIndexSetterSelector = S.Context.Selectors.getSelector(2, KeyIdents);
1276 }
1277 else {
1278 // - (void)setObject:(id)object atIndexedSubscript:(NSInteger)index;
1279 IdentifierInfo *KeyIdents[] = {
1280 &S.Context.Idents.get("setObject"),
1281 &S.Context.Idents.get("atIndexedSubscript")
1282 };
1283 AtIndexSetterSelector = S.Context.Selectors.getSelector(2, KeyIdents);
1284 }
1285 AtIndexSetter = S.LookupMethodInObjectType(AtIndexSetterSelector, ResultType,
1286 true /*instance*/);
1287
1288 bool receiverIdType = (BaseT->isObjCIdType() ||
1289 BaseT->isObjCQualifiedIdType());
1290
David Blaikiebbafb8a2012-03-11 07:00:24 +00001291 if (!AtIndexSetter && S.getLangOpts().DebuggerObjCLiteral) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001292 TypeSourceInfo *ReturnTInfo = nullptr;
Ted Kremeneke65b0862012-03-06 20:05:56 +00001293 QualType ReturnType = S.Context.VoidTy;
Alp Toker314cc812014-01-25 16:55:45 +00001294 AtIndexSetter = ObjCMethodDecl::Create(
1295 S.Context, SourceLocation(), SourceLocation(), AtIndexSetterSelector,
1296 ReturnType, ReturnTInfo, S.Context.getTranslationUnitDecl(),
1297 true /*Instance*/, false /*isVariadic*/,
1298 /*isPropertyAccessor=*/false,
1299 /*isImplicitlyDeclared=*/true, /*isDefined=*/false,
1300 ObjCMethodDecl::Required, false);
Ted Kremeneke65b0862012-03-06 20:05:56 +00001301 SmallVector<ParmVarDecl *, 2> Params;
1302 ParmVarDecl *object = ParmVarDecl::Create(S.Context, AtIndexSetter,
1303 SourceLocation(), SourceLocation(),
1304 &S.Context.Idents.get("object"),
1305 S.Context.getObjCIdType(),
Craig Topperc3ec1492014-05-26 06:22:03 +00001306 /*TInfo=*/nullptr,
Ted Kremeneke65b0862012-03-06 20:05:56 +00001307 SC_None,
Craig Topperc3ec1492014-05-26 06:22:03 +00001308 nullptr);
Ted Kremeneke65b0862012-03-06 20:05:56 +00001309 Params.push_back(object);
1310 ParmVarDecl *key = ParmVarDecl::Create(S.Context, AtIndexSetter,
1311 SourceLocation(), SourceLocation(),
1312 arrayRef ? &S.Context.Idents.get("index")
1313 : &S.Context.Idents.get("key"),
1314 arrayRef ? S.Context.UnsignedLongTy
1315 : S.Context.getObjCIdType(),
Craig Topperc3ec1492014-05-26 06:22:03 +00001316 /*TInfo=*/nullptr,
Ted Kremeneke65b0862012-03-06 20:05:56 +00001317 SC_None,
Craig Topperc3ec1492014-05-26 06:22:03 +00001318 nullptr);
Ted Kremeneke65b0862012-03-06 20:05:56 +00001319 Params.push_back(key);
Dmitri Gribenko44ebbd52013-05-05 00:41:58 +00001320 AtIndexSetter->setMethodParams(S.Context, Params, None);
Ted Kremeneke65b0862012-03-06 20:05:56 +00001321 }
1322
1323 if (!AtIndexSetter) {
1324 if (!receiverIdType) {
1325 S.Diag(BaseExpr->getExprLoc(),
1326 diag::err_objc_subscript_method_not_found)
1327 << BaseExpr->getType() << 1 << arrayRef;
1328 return false;
1329 }
1330 AtIndexSetter =
1331 S.LookupInstanceMethodInGlobalPool(AtIndexSetterSelector,
1332 RefExpr->getSourceRange(),
Fariborz Jahanian890803f2015-04-15 17:26:21 +00001333 true);
Ted Kremeneke65b0862012-03-06 20:05:56 +00001334 }
1335
1336 bool err = false;
1337 if (AtIndexSetter && arrayRef) {
Alp Toker03376dc2014-07-07 09:02:20 +00001338 QualType T = AtIndexSetter->parameters()[1]->getType();
Ted Kremeneke65b0862012-03-06 20:05:56 +00001339 if (!T->isIntegralOrEnumerationType()) {
1340 S.Diag(RefExpr->getKeyExpr()->getExprLoc(),
1341 diag::err_objc_subscript_index_type) << T;
Alp Toker03376dc2014-07-07 09:02:20 +00001342 S.Diag(AtIndexSetter->parameters()[1]->getLocation(),
Ted Kremeneke65b0862012-03-06 20:05:56 +00001343 diag::note_parameter_type) << T;
1344 err = true;
1345 }
Alp Toker03376dc2014-07-07 09:02:20 +00001346 T = AtIndexSetter->parameters()[0]->getType();
Ted Kremeneke65b0862012-03-06 20:05:56 +00001347 if (!T->isObjCObjectPointerType()) {
1348 S.Diag(RefExpr->getBaseExpr()->getExprLoc(),
1349 diag::err_objc_subscript_object_type) << T << arrayRef;
Alp Toker03376dc2014-07-07 09:02:20 +00001350 S.Diag(AtIndexSetter->parameters()[0]->getLocation(),
Ted Kremeneke65b0862012-03-06 20:05:56 +00001351 diag::note_parameter_type) << T;
1352 err = true;
1353 }
1354 }
1355 else if (AtIndexSetter && !arrayRef)
1356 for (unsigned i=0; i <2; i++) {
Alp Toker03376dc2014-07-07 09:02:20 +00001357 QualType T = AtIndexSetter->parameters()[i]->getType();
Ted Kremeneke65b0862012-03-06 20:05:56 +00001358 if (!T->isObjCObjectPointerType()) {
1359 if (i == 1)
1360 S.Diag(RefExpr->getKeyExpr()->getExprLoc(),
1361 diag::err_objc_subscript_key_type) << T;
1362 else
1363 S.Diag(RefExpr->getBaseExpr()->getExprLoc(),
1364 diag::err_objc_subscript_dic_object_type) << T;
Alp Toker03376dc2014-07-07 09:02:20 +00001365 S.Diag(AtIndexSetter->parameters()[i]->getLocation(),
Ted Kremeneke65b0862012-03-06 20:05:56 +00001366 diag::note_parameter_type) << T;
1367 err = true;
1368 }
1369 }
1370
1371 return !err;
1372}
1373
1374// Get the object at "Index" position in the container.
1375// [BaseExpr objectAtIndexedSubscript : IndexExpr];
1376ExprResult ObjCSubscriptOpBuilder::buildGet() {
1377 if (!findAtIndexGetter())
1378 return ExprError();
1379
1380 QualType receiverType = InstanceBase->getType();
1381
1382 // Build a message-send.
1383 ExprResult msg;
1384 Expr *Index = InstanceKey;
1385
1386 // Arguments.
1387 Expr *args[] = { Index };
1388 assert(InstanceBase);
Fariborz Jahanian3d576402014-06-10 19:02:48 +00001389 if (AtIndexGetter)
1390 S.DiagnoseUseOfDecl(AtIndexGetter, GenericLoc);
Ted Kremeneke65b0862012-03-06 20:05:56 +00001391 msg = S.BuildInstanceMessageImplicit(InstanceBase, receiverType,
1392 GenericLoc,
1393 AtIndexGetterSelector, AtIndexGetter,
1394 MultiExprArg(args, 1));
1395 return msg;
1396}
1397
1398/// Store into the container the "op" object at "Index"'ed location
1399/// by building this messaging expression:
1400/// - (void)setObject:(id)object atIndexedSubscript:(NSInteger)index;
Dmitri Gribenkoadba9be2012-08-23 17:58:28 +00001401/// \param captureSetValueAsResult If true, capture the actual
Ted Kremeneke65b0862012-03-06 20:05:56 +00001402/// value being set as the value of the property operation.
1403ExprResult ObjCSubscriptOpBuilder::buildSet(Expr *op, SourceLocation opcLoc,
1404 bool captureSetValueAsResult) {
1405 if (!findAtIndexSetter())
1406 return ExprError();
Fariborz Jahanian3d576402014-06-10 19:02:48 +00001407 if (AtIndexSetter)
1408 S.DiagnoseUseOfDecl(AtIndexSetter, GenericLoc);
Ted Kremeneke65b0862012-03-06 20:05:56 +00001409 QualType receiverType = InstanceBase->getType();
1410 Expr *Index = InstanceKey;
1411
1412 // Arguments.
1413 Expr *args[] = { op, Index };
1414
1415 // Build a message-send.
1416 ExprResult msg = S.BuildInstanceMessageImplicit(InstanceBase, receiverType,
1417 GenericLoc,
1418 AtIndexSetterSelector,
1419 AtIndexSetter,
1420 MultiExprArg(args, 2));
1421
1422 if (!msg.isInvalid() && captureSetValueAsResult) {
1423 ObjCMessageExpr *msgExpr =
1424 cast<ObjCMessageExpr>(msg.get()->IgnoreImplicit());
1425 Expr *arg = msgExpr->getArg(0);
Fariborz Jahanian15dde892014-03-06 00:34:05 +00001426 if (CanCaptureValue(arg))
Eli Friedman00fa4292012-11-13 23:16:33 +00001427 msgExpr->setArg(0, captureValueAsResult(arg));
Ted Kremeneke65b0862012-03-06 20:05:56 +00001428 }
1429
1430 return msg;
1431}
1432
John McCallfe96e0b2011-11-06 09:01:30 +00001433//===----------------------------------------------------------------------===//
John McCall5e77d762013-04-16 07:28:30 +00001434// MSVC __declspec(property) references
1435//===----------------------------------------------------------------------===//
1436
Alexey Bataevf7630272015-11-25 12:01:00 +00001437MSPropertyRefExpr *
1438MSPropertyOpBuilder::getBaseMSProperty(MSPropertySubscriptExpr *E) {
1439 CallArgs.insert(CallArgs.begin(), E->getIdx());
1440 Expr *Base = E->getBase()->IgnoreParens();
1441 while (auto *MSPropSubscript = dyn_cast<MSPropertySubscriptExpr>(Base)) {
1442 CallArgs.insert(CallArgs.begin(), MSPropSubscript->getIdx());
1443 Base = MSPropSubscript->getBase()->IgnoreParens();
1444 }
1445 return cast<MSPropertyRefExpr>(Base);
1446}
1447
John McCall5e77d762013-04-16 07:28:30 +00001448Expr *MSPropertyOpBuilder::rebuildAndCaptureObject(Expr *syntacticBase) {
Alexey Bataev69103472015-10-14 04:05:42 +00001449 InstanceBase = capture(RefExpr->getBaseExpr());
Alexey Bataevf7630272015-11-25 12:01:00 +00001450 std::for_each(CallArgs.begin(), CallArgs.end(),
1451 [this](Expr *&Arg) { Arg = capture(Arg); });
1452 syntacticBase = Rebuilder(S, [=](Expr *, unsigned Idx) -> Expr * {
1453 switch (Idx) {
1454 case 0:
1455 return InstanceBase;
1456 default:
1457 assert(Idx <= CallArgs.size());
1458 return CallArgs[Idx - 1];
1459 }
1460 }).rebuild(syntacticBase);
John McCall5e77d762013-04-16 07:28:30 +00001461
1462 return syntacticBase;
1463}
1464
1465ExprResult MSPropertyOpBuilder::buildGet() {
1466 if (!RefExpr->getPropertyDecl()->hasGetter()) {
Aaron Ballman213cf412013-12-26 16:35:04 +00001467 S.Diag(RefExpr->getMemberLoc(), diag::err_no_accessor_for_property)
Aaron Ballman1bda4592014-01-03 01:09:27 +00001468 << 0 /* getter */ << RefExpr->getPropertyDecl();
John McCall5e77d762013-04-16 07:28:30 +00001469 return ExprError();
1470 }
1471
1472 UnqualifiedId GetterName;
1473 IdentifierInfo *II = RefExpr->getPropertyDecl()->getGetterId();
1474 GetterName.setIdentifier(II, RefExpr->getMemberLoc());
1475 CXXScopeSpec SS;
1476 SS.Adopt(RefExpr->getQualifierLoc());
Alexey Bataev69103472015-10-14 04:05:42 +00001477 ExprResult GetterExpr =
1478 S.ActOnMemberAccessExpr(S.getCurScope(), InstanceBase, SourceLocation(),
1479 RefExpr->isArrow() ? tok::arrow : tok::period, SS,
1480 SourceLocation(), GetterName, nullptr);
John McCall5e77d762013-04-16 07:28:30 +00001481 if (GetterExpr.isInvalid()) {
Aaron Ballman9e35bfe2013-12-26 15:46:38 +00001482 S.Diag(RefExpr->getMemberLoc(),
Richard Smithf8812672016-12-02 22:38:31 +00001483 diag::err_cannot_find_suitable_accessor) << 0 /* getter */
Aaron Ballman1bda4592014-01-03 01:09:27 +00001484 << RefExpr->getPropertyDecl();
John McCall5e77d762013-04-16 07:28:30 +00001485 return ExprError();
1486 }
1487
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001488 return S.ActOnCallExpr(S.getCurScope(), GetterExpr.get(),
Alexey Bataevf7630272015-11-25 12:01:00 +00001489 RefExpr->getSourceRange().getBegin(), CallArgs,
John McCall5e77d762013-04-16 07:28:30 +00001490 RefExpr->getSourceRange().getEnd());
1491}
1492
1493ExprResult MSPropertyOpBuilder::buildSet(Expr *op, SourceLocation sl,
1494 bool captureSetValueAsResult) {
1495 if (!RefExpr->getPropertyDecl()->hasSetter()) {
Aaron Ballman213cf412013-12-26 16:35:04 +00001496 S.Diag(RefExpr->getMemberLoc(), diag::err_no_accessor_for_property)
Aaron Ballman1bda4592014-01-03 01:09:27 +00001497 << 1 /* setter */ << RefExpr->getPropertyDecl();
John McCall5e77d762013-04-16 07:28:30 +00001498 return ExprError();
1499 }
1500
1501 UnqualifiedId SetterName;
1502 IdentifierInfo *II = RefExpr->getPropertyDecl()->getSetterId();
1503 SetterName.setIdentifier(II, RefExpr->getMemberLoc());
1504 CXXScopeSpec SS;
1505 SS.Adopt(RefExpr->getQualifierLoc());
Alexey Bataev69103472015-10-14 04:05:42 +00001506 ExprResult SetterExpr =
1507 S.ActOnMemberAccessExpr(S.getCurScope(), InstanceBase, SourceLocation(),
1508 RefExpr->isArrow() ? tok::arrow : tok::period, SS,
1509 SourceLocation(), SetterName, nullptr);
John McCall5e77d762013-04-16 07:28:30 +00001510 if (SetterExpr.isInvalid()) {
Aaron Ballman9e35bfe2013-12-26 15:46:38 +00001511 S.Diag(RefExpr->getMemberLoc(),
Richard Smithf8812672016-12-02 22:38:31 +00001512 diag::err_cannot_find_suitable_accessor) << 1 /* setter */
Aaron Ballman1bda4592014-01-03 01:09:27 +00001513 << RefExpr->getPropertyDecl();
John McCall5e77d762013-04-16 07:28:30 +00001514 return ExprError();
1515 }
1516
Alexey Bataevf7630272015-11-25 12:01:00 +00001517 SmallVector<Expr*, 4> ArgExprs;
1518 ArgExprs.append(CallArgs.begin(), CallArgs.end());
John McCall5e77d762013-04-16 07:28:30 +00001519 ArgExprs.push_back(op);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001520 return S.ActOnCallExpr(S.getCurScope(), SetterExpr.get(),
John McCall5e77d762013-04-16 07:28:30 +00001521 RefExpr->getSourceRange().getBegin(), ArgExprs,
1522 op->getSourceRange().getEnd());
1523}
1524
1525//===----------------------------------------------------------------------===//
John McCallfe96e0b2011-11-06 09:01:30 +00001526// General Sema routines.
1527//===----------------------------------------------------------------------===//
1528
1529ExprResult Sema::checkPseudoObjectRValue(Expr *E) {
1530 Expr *opaqueRef = E->IgnoreParens();
1531 if (ObjCPropertyRefExpr *refExpr
1532 = dyn_cast<ObjCPropertyRefExpr>(opaqueRef)) {
1533 ObjCPropertyOpBuilder builder(*this, refExpr);
1534 return builder.buildRValueOperation(E);
Ted Kremeneke65b0862012-03-06 20:05:56 +00001535 }
1536 else if (ObjCSubscriptRefExpr *refExpr
1537 = dyn_cast<ObjCSubscriptRefExpr>(opaqueRef)) {
1538 ObjCSubscriptOpBuilder builder(*this, refExpr);
1539 return builder.buildRValueOperation(E);
John McCall5e77d762013-04-16 07:28:30 +00001540 } else if (MSPropertyRefExpr *refExpr
1541 = dyn_cast<MSPropertyRefExpr>(opaqueRef)) {
1542 MSPropertyOpBuilder builder(*this, refExpr);
1543 return builder.buildRValueOperation(E);
Alexey Bataevf7630272015-11-25 12:01:00 +00001544 } else if (MSPropertySubscriptExpr *RefExpr =
1545 dyn_cast<MSPropertySubscriptExpr>(opaqueRef)) {
1546 MSPropertyOpBuilder Builder(*this, RefExpr);
1547 return Builder.buildRValueOperation(E);
John McCallfe96e0b2011-11-06 09:01:30 +00001548 } else {
1549 llvm_unreachable("unknown pseudo-object kind!");
1550 }
1551}
1552
1553/// Check an increment or decrement of a pseudo-object expression.
1554ExprResult Sema::checkPseudoObjectIncDec(Scope *Sc, SourceLocation opcLoc,
1555 UnaryOperatorKind opcode, Expr *op) {
1556 // Do nothing if the operand is dependent.
1557 if (op->isTypeDependent())
1558 return new (Context) UnaryOperator(op, opcode, Context.DependentTy,
1559 VK_RValue, OK_Ordinary, opcLoc);
1560
1561 assert(UnaryOperator::isIncrementDecrementOp(opcode));
1562 Expr *opaqueRef = op->IgnoreParens();
1563 if (ObjCPropertyRefExpr *refExpr
1564 = dyn_cast<ObjCPropertyRefExpr>(opaqueRef)) {
1565 ObjCPropertyOpBuilder builder(*this, refExpr);
1566 return builder.buildIncDecOperation(Sc, opcLoc, opcode, op);
Ted Kremeneke65b0862012-03-06 20:05:56 +00001567 } else if (isa<ObjCSubscriptRefExpr>(opaqueRef)) {
1568 Diag(opcLoc, diag::err_illegal_container_subscripting_op);
1569 return ExprError();
John McCall5e77d762013-04-16 07:28:30 +00001570 } else if (MSPropertyRefExpr *refExpr
1571 = dyn_cast<MSPropertyRefExpr>(opaqueRef)) {
1572 MSPropertyOpBuilder builder(*this, refExpr);
1573 return builder.buildIncDecOperation(Sc, opcLoc, opcode, op);
Alexey Bataevf7630272015-11-25 12:01:00 +00001574 } else if (MSPropertySubscriptExpr *RefExpr
1575 = dyn_cast<MSPropertySubscriptExpr>(opaqueRef)) {
1576 MSPropertyOpBuilder Builder(*this, RefExpr);
1577 return Builder.buildIncDecOperation(Sc, opcLoc, opcode, op);
John McCallfe96e0b2011-11-06 09:01:30 +00001578 } else {
1579 llvm_unreachable("unknown pseudo-object kind!");
1580 }
1581}
1582
1583ExprResult Sema::checkPseudoObjectAssignment(Scope *S, SourceLocation opcLoc,
1584 BinaryOperatorKind opcode,
1585 Expr *LHS, Expr *RHS) {
1586 // Do nothing if either argument is dependent.
1587 if (LHS->isTypeDependent() || RHS->isTypeDependent())
1588 return new (Context) BinaryOperator(LHS, RHS, opcode, Context.DependentTy,
Lang Hames5de91cc2012-10-02 04:45:10 +00001589 VK_RValue, OK_Ordinary, opcLoc, false);
John McCallfe96e0b2011-11-06 09:01:30 +00001590
1591 // Filter out non-overload placeholder types in the RHS.
John McCalld5c98ae2011-11-15 01:35:18 +00001592 if (RHS->getType()->isNonOverloadPlaceholderType()) {
1593 ExprResult result = CheckPlaceholderExpr(RHS);
1594 if (result.isInvalid()) return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001595 RHS = result.get();
John McCallfe96e0b2011-11-06 09:01:30 +00001596 }
1597
1598 Expr *opaqueRef = LHS->IgnoreParens();
1599 if (ObjCPropertyRefExpr *refExpr
1600 = dyn_cast<ObjCPropertyRefExpr>(opaqueRef)) {
1601 ObjCPropertyOpBuilder builder(*this, refExpr);
1602 return builder.buildAssignmentOperation(S, opcLoc, opcode, LHS, RHS);
Ted Kremeneke65b0862012-03-06 20:05:56 +00001603 } else if (ObjCSubscriptRefExpr *refExpr
1604 = dyn_cast<ObjCSubscriptRefExpr>(opaqueRef)) {
1605 ObjCSubscriptOpBuilder builder(*this, refExpr);
1606 return builder.buildAssignmentOperation(S, opcLoc, opcode, LHS, RHS);
John McCall5e77d762013-04-16 07:28:30 +00001607 } else if (MSPropertyRefExpr *refExpr
1608 = dyn_cast<MSPropertyRefExpr>(opaqueRef)) {
Alexey Bataevf7630272015-11-25 12:01:00 +00001609 MSPropertyOpBuilder builder(*this, refExpr);
1610 return builder.buildAssignmentOperation(S, opcLoc, opcode, LHS, RHS);
1611 } else if (MSPropertySubscriptExpr *RefExpr
1612 = dyn_cast<MSPropertySubscriptExpr>(opaqueRef)) {
1613 MSPropertyOpBuilder Builder(*this, RefExpr);
1614 return Builder.buildAssignmentOperation(S, opcLoc, opcode, LHS, RHS);
John McCallfe96e0b2011-11-06 09:01:30 +00001615 } else {
1616 llvm_unreachable("unknown pseudo-object kind!");
1617 }
1618}
John McCalle9290822011-11-30 04:42:31 +00001619
1620/// Given a pseudo-object reference, rebuild it without the opaque
1621/// values. Basically, undo the behavior of rebuildAndCaptureObject.
1622/// This should never operate in-place.
1623static Expr *stripOpaqueValuesFromPseudoObjectRef(Sema &S, Expr *E) {
Alexey Bataevf7630272015-11-25 12:01:00 +00001624 return Rebuilder(S,
1625 [=](Expr *E, unsigned) -> Expr * {
1626 return cast<OpaqueValueExpr>(E)->getSourceExpr();
1627 })
1628 .rebuild(E);
John McCalle9290822011-11-30 04:42:31 +00001629}
1630
1631/// Given a pseudo-object expression, recreate what it looks like
1632/// syntactically without the attendant OpaqueValueExprs.
1633///
1634/// This is a hack which should be removed when TreeTransform is
1635/// capable of rebuilding a tree without stripping implicit
1636/// operations.
1637Expr *Sema::recreateSyntacticForm(PseudoObjectExpr *E) {
1638 Expr *syntax = E->getSyntacticForm();
1639 if (UnaryOperator *uop = dyn_cast<UnaryOperator>(syntax)) {
1640 Expr *op = stripOpaqueValuesFromPseudoObjectRef(*this, uop->getSubExpr());
1641 return new (Context) UnaryOperator(op, uop->getOpcode(), uop->getType(),
1642 uop->getValueKind(), uop->getObjectKind(),
1643 uop->getOperatorLoc());
1644 } else if (CompoundAssignOperator *cop
1645 = dyn_cast<CompoundAssignOperator>(syntax)) {
1646 Expr *lhs = stripOpaqueValuesFromPseudoObjectRef(*this, cop->getLHS());
1647 Expr *rhs = cast<OpaqueValueExpr>(cop->getRHS())->getSourceExpr();
1648 return new (Context) CompoundAssignOperator(lhs, rhs, cop->getOpcode(),
1649 cop->getType(),
1650 cop->getValueKind(),
1651 cop->getObjectKind(),
1652 cop->getComputationLHSType(),
1653 cop->getComputationResultType(),
Lang Hames5de91cc2012-10-02 04:45:10 +00001654 cop->getOperatorLoc(), false);
John McCalle9290822011-11-30 04:42:31 +00001655 } else if (BinaryOperator *bop = dyn_cast<BinaryOperator>(syntax)) {
1656 Expr *lhs = stripOpaqueValuesFromPseudoObjectRef(*this, bop->getLHS());
1657 Expr *rhs = cast<OpaqueValueExpr>(bop->getRHS())->getSourceExpr();
1658 return new (Context) BinaryOperator(lhs, rhs, bop->getOpcode(),
1659 bop->getType(), bop->getValueKind(),
1660 bop->getObjectKind(),
Lang Hames5de91cc2012-10-02 04:45:10 +00001661 bop->getOperatorLoc(), false);
John McCalle9290822011-11-30 04:42:31 +00001662 } else {
1663 assert(syntax->hasPlaceholderType(BuiltinType::PseudoObject));
1664 return stripOpaqueValuesFromPseudoObjectRef(*this, syntax);
1665 }
1666}