John McCall | 526ab47 | 2011-10-25 17:37:35 +0000 | [diff] [blame] | 1 | //===--- SemaPseudoObject.cpp - Semantic Analysis for Pseudo-Objects ------===// |
| 2 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
John McCall | 526ab47 | 2011-10-25 17:37:35 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | // |
| 9 | // This file implements semantic analysis for expressions involving |
| 10 | // pseudo-object references. Pseudo-objects are conceptual objects |
| 11 | // whose storage is entirely abstract and all accesses to which are |
| 12 | // translated through some sort of abstraction barrier. |
| 13 | // |
| 14 | // For example, Objective-C objects can have "properties", either |
| 15 | // declared or undeclared. A property may be accessed by writing |
| 16 | // expr.prop |
| 17 | // where 'expr' is an r-value of Objective-C pointer type and 'prop' |
| 18 | // is the name of the property. If this expression is used in a context |
| 19 | // needing an r-value, it is treated as if it were a message-send |
| 20 | // of the associated 'getter' selector, typically: |
| 21 | // [expr prop] |
| 22 | // If it is used as the LHS of a simple assignment, it is treated |
| 23 | // as a message-send of the associated 'setter' selector, typically: |
| 24 | // [expr setProp: RHS] |
| 25 | // If it is used as the LHS of a compound assignment, or the operand |
| 26 | // of a unary increment or decrement, both are required; for example, |
| 27 | // 'expr.prop *= 100' would be translated to: |
| 28 | // [expr setProp: [expr prop] * 100] |
| 29 | // |
| 30 | //===----------------------------------------------------------------------===// |
| 31 | |
| 32 | #include "clang/Sema/SemaInternal.h" |
Benjamin Kramer | f3ca2698 | 2014-05-10 16:31:55 +0000 | [diff] [blame] | 33 | #include "clang/AST/ExprCXX.h" |
John McCall | 526ab47 | 2011-10-25 17:37:35 +0000 | [diff] [blame] | 34 | #include "clang/AST/ExprObjC.h" |
Jordan Rose | a7d0384 | 2013-02-08 22:30:41 +0000 | [diff] [blame] | 35 | #include "clang/Basic/CharInfo.h" |
John McCall | 526ab47 | 2011-10-25 17:37:35 +0000 | [diff] [blame] | 36 | #include "clang/Lex/Preprocessor.h" |
Chandler Carruth | 3a02247 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 37 | #include "clang/Sema/Initialization.h" |
| 38 | #include "clang/Sema/ScopeInfo.h" |
Fariborz Jahanian | 3f88afa | 2012-05-24 22:48:38 +0000 | [diff] [blame] | 39 | #include "llvm/ADT/SmallString.h" |
John McCall | 526ab47 | 2011-10-25 17:37:35 +0000 | [diff] [blame] | 40 | |
| 41 | using namespace clang; |
| 42 | using namespace sema; |
| 43 | |
John McCall | fe96e0b | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 44 | namespace { |
| 45 | // Basically just a very focused copy of TreeTransform. |
Alexey Bataev | f763027 | 2015-11-25 12:01:00 +0000 | [diff] [blame] | 46 | struct Rebuilder { |
John McCall | fe96e0b | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 47 | Sema &S; |
Alexey Bataev | f763027 | 2015-11-25 12:01:00 +0000 | [diff] [blame] | 48 | unsigned MSPropertySubscriptCount; |
| 49 | typedef llvm::function_ref<Expr *(Expr *, unsigned)> SpecificRebuilderRefTy; |
| 50 | const SpecificRebuilderRefTy &SpecificCallback; |
| 51 | Rebuilder(Sema &S, const SpecificRebuilderRefTy &SpecificCallback) |
| 52 | : S(S), MSPropertySubscriptCount(0), |
| 53 | SpecificCallback(SpecificCallback) {} |
John McCall | fe96e0b | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 54 | |
Alexey Bataev | f763027 | 2015-11-25 12:01:00 +0000 | [diff] [blame] | 55 | Expr *rebuildObjCPropertyRefExpr(ObjCPropertyRefExpr *refExpr) { |
| 56 | // Fortunately, the constraint that we're rebuilding something |
| 57 | // with a base limits the number of cases here. |
| 58 | if (refExpr->isClassReceiver() || refExpr->isSuperReceiver()) |
| 59 | return refExpr; |
| 60 | |
| 61 | if (refExpr->isExplicitProperty()) { |
| 62 | return new (S.Context) ObjCPropertyRefExpr( |
| 63 | refExpr->getExplicitProperty(), refExpr->getType(), |
| 64 | refExpr->getValueKind(), refExpr->getObjectKind(), |
| 65 | refExpr->getLocation(), SpecificCallback(refExpr->getBase(), 0)); |
| 66 | } |
| 67 | return new (S.Context) ObjCPropertyRefExpr( |
| 68 | refExpr->getImplicitPropertyGetter(), |
| 69 | refExpr->getImplicitPropertySetter(), refExpr->getType(), |
| 70 | refExpr->getValueKind(), refExpr->getObjectKind(), |
| 71 | refExpr->getLocation(), SpecificCallback(refExpr->getBase(), 0)); |
| 72 | } |
| 73 | Expr *rebuildObjCSubscriptRefExpr(ObjCSubscriptRefExpr *refExpr) { |
| 74 | assert(refExpr->getBaseExpr()); |
| 75 | assert(refExpr->getKeyExpr()); |
| 76 | |
| 77 | return new (S.Context) ObjCSubscriptRefExpr( |
| 78 | SpecificCallback(refExpr->getBaseExpr(), 0), |
| 79 | SpecificCallback(refExpr->getKeyExpr(), 1), refExpr->getType(), |
| 80 | refExpr->getValueKind(), refExpr->getObjectKind(), |
| 81 | refExpr->getAtIndexMethodDecl(), refExpr->setAtIndexMethodDecl(), |
| 82 | refExpr->getRBracket()); |
| 83 | } |
| 84 | Expr *rebuildMSPropertyRefExpr(MSPropertyRefExpr *refExpr) { |
| 85 | assert(refExpr->getBaseExpr()); |
| 86 | |
| 87 | return new (S.Context) MSPropertyRefExpr( |
| 88 | SpecificCallback(refExpr->getBaseExpr(), 0), |
| 89 | refExpr->getPropertyDecl(), refExpr->isArrow(), refExpr->getType(), |
| 90 | refExpr->getValueKind(), refExpr->getQualifierLoc(), |
| 91 | refExpr->getMemberLoc()); |
| 92 | } |
| 93 | Expr *rebuildMSPropertySubscriptExpr(MSPropertySubscriptExpr *refExpr) { |
| 94 | assert(refExpr->getBase()); |
| 95 | assert(refExpr->getIdx()); |
| 96 | |
| 97 | auto *NewBase = rebuild(refExpr->getBase()); |
| 98 | ++MSPropertySubscriptCount; |
| 99 | return new (S.Context) MSPropertySubscriptExpr( |
| 100 | NewBase, |
| 101 | SpecificCallback(refExpr->getIdx(), MSPropertySubscriptCount), |
| 102 | refExpr->getType(), refExpr->getValueKind(), refExpr->getObjectKind(), |
| 103 | refExpr->getRBracketLoc()); |
| 104 | } |
John McCall | fe96e0b | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 105 | |
| 106 | Expr *rebuild(Expr *e) { |
| 107 | // Fast path: nothing to look through. |
Alexey Bataev | f763027 | 2015-11-25 12:01:00 +0000 | [diff] [blame] | 108 | if (auto *PRE = dyn_cast<ObjCPropertyRefExpr>(e)) |
| 109 | return rebuildObjCPropertyRefExpr(PRE); |
| 110 | if (auto *SRE = dyn_cast<ObjCSubscriptRefExpr>(e)) |
| 111 | return rebuildObjCSubscriptRefExpr(SRE); |
| 112 | if (auto *MSPRE = dyn_cast<MSPropertyRefExpr>(e)) |
| 113 | return rebuildMSPropertyRefExpr(MSPRE); |
| 114 | if (auto *MSPSE = dyn_cast<MSPropertySubscriptExpr>(e)) |
| 115 | return rebuildMSPropertySubscriptExpr(MSPSE); |
John McCall | fe96e0b | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 116 | |
| 117 | // Otherwise, we should look through and rebuild anything that |
| 118 | // IgnoreParens would. |
| 119 | |
| 120 | if (ParenExpr *parens = dyn_cast<ParenExpr>(e)) { |
| 121 | e = rebuild(parens->getSubExpr()); |
| 122 | return new (S.Context) ParenExpr(parens->getLParen(), |
| 123 | parens->getRParen(), |
| 124 | e); |
| 125 | } |
| 126 | |
| 127 | if (UnaryOperator *uop = dyn_cast<UnaryOperator>(e)) { |
| 128 | assert(uop->getOpcode() == UO_Extension); |
| 129 | e = rebuild(uop->getSubExpr()); |
| 130 | return new (S.Context) UnaryOperator(e, uop->getOpcode(), |
| 131 | uop->getType(), |
| 132 | uop->getValueKind(), |
| 133 | uop->getObjectKind(), |
Aaron Ballman | a503855 | 2018-01-09 13:07:03 +0000 | [diff] [blame] | 134 | uop->getOperatorLoc(), |
| 135 | uop->canOverflow()); |
John McCall | fe96e0b | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 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 Kramer | c215e76 | 2012-08-24 11:54:20 +0000 | [diff] [blame] | 156 | assocTypes, |
| 157 | assocs, |
John McCall | fe96e0b | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 158 | gse->getDefaultLoc(), |
| 159 | gse->getRParenLoc(), |
| 160 | gse->containsUnexpandedParameterPack(), |
| 161 | resultIndex); |
| 162 | } |
| 163 | |
Eli Friedman | 75807f2 | 2013-07-20 00:40:58 +0000 | [diff] [blame] | 164 | 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 McCall | fe96e0b | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 183 | llvm_unreachable("bad expression to rebuild!"); |
| 184 | } |
| 185 | }; |
| 186 | |
John McCall | fe96e0b | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 187 | class PseudoOpBuilder { |
| 188 | public: |
| 189 | Sema &S; |
| 190 | unsigned ResultIndex; |
| 191 | SourceLocation GenericLoc; |
Akira Hatanaka | 797afe3 | 2018-03-20 01:47:58 +0000 | [diff] [blame] | 192 | bool IsUnique; |
John McCall | fe96e0b | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 193 | SmallVector<Expr *, 4> Semantics; |
| 194 | |
Akira Hatanaka | 797afe3 | 2018-03-20 01:47:58 +0000 | [diff] [blame] | 195 | PseudoOpBuilder(Sema &S, SourceLocation genericLoc, bool IsUnique) |
John McCall | fe96e0b | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 196 | : S(S), ResultIndex(PseudoObjectExpr::NoResult), |
Akira Hatanaka | 797afe3 | 2018-03-20 01:47:58 +0000 | [diff] [blame] | 197 | GenericLoc(genericLoc), IsUnique(IsUnique) {} |
John McCall | fe96e0b | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 198 | |
Angel Garcia Gomez | 637d1e6 | 2015-10-20 13:23:58 +0000 | [diff] [blame] | 199 | virtual ~PseudoOpBuilder() {} |
Matt Beaumont-Gay | fb3cb9a | 2011-11-08 01:53:17 +0000 | [diff] [blame] | 200 | |
John McCall | fe96e0b | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 201 | /// Add a normal semantic expression. |
| 202 | void addSemanticExpr(Expr *semantic) { |
| 203 | Semantics.push_back(semantic); |
| 204 | } |
| 205 | |
| 206 | /// Add the 'result' semantic expression. |
| 207 | void addResultSemanticExpr(Expr *resultExpr) { |
| 208 | assert(ResultIndex == PseudoObjectExpr::NoResult); |
| 209 | ResultIndex = Semantics.size(); |
| 210 | Semantics.push_back(resultExpr); |
Akira Hatanaka | 797afe3 | 2018-03-20 01:47:58 +0000 | [diff] [blame] | 211 | // An OVE is not unique if it is used as the result expression. |
| 212 | if (auto *OVE = dyn_cast<OpaqueValueExpr>(Semantics.back())) |
| 213 | OVE->setIsUnique(false); |
John McCall | fe96e0b | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 214 | } |
| 215 | |
| 216 | ExprResult buildRValueOperation(Expr *op); |
| 217 | ExprResult buildAssignmentOperation(Scope *Sc, |
| 218 | SourceLocation opLoc, |
| 219 | BinaryOperatorKind opcode, |
| 220 | Expr *LHS, Expr *RHS); |
| 221 | ExprResult buildIncDecOperation(Scope *Sc, SourceLocation opLoc, |
| 222 | UnaryOperatorKind opcode, |
| 223 | Expr *op); |
| 224 | |
Jordan Rose | d393458 | 2012-09-28 22:21:30 +0000 | [diff] [blame] | 225 | virtual ExprResult complete(Expr *syntacticForm); |
John McCall | fe96e0b | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 226 | |
| 227 | OpaqueValueExpr *capture(Expr *op); |
| 228 | OpaqueValueExpr *captureValueAsResult(Expr *op); |
| 229 | |
| 230 | void setResultToLastSemantic() { |
| 231 | assert(ResultIndex == PseudoObjectExpr::NoResult); |
| 232 | ResultIndex = Semantics.size() - 1; |
Akira Hatanaka | 797afe3 | 2018-03-20 01:47:58 +0000 | [diff] [blame] | 233 | // An OVE is not unique if it is used as the result expression. |
| 234 | if (auto *OVE = dyn_cast<OpaqueValueExpr>(Semantics.back())) |
| 235 | OVE->setIsUnique(false); |
John McCall | fe96e0b | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 236 | } |
| 237 | |
| 238 | /// Return true if assignments have a non-void result. |
Alexey Bataev | 60520e2 | 2015-12-10 04:38:18 +0000 | [diff] [blame] | 239 | static bool CanCaptureValue(Expr *exp) { |
Fariborz Jahanian | 15dde89 | 2014-03-06 00:34:05 +0000 | [diff] [blame] | 240 | if (exp->isGLValue()) |
| 241 | return true; |
| 242 | QualType ty = exp->getType(); |
Eli Friedman | 00fa429 | 2012-11-13 23:16:33 +0000 | [diff] [blame] | 243 | assert(!ty->isIncompleteType()); |
| 244 | assert(!ty->isDependentType()); |
| 245 | |
| 246 | if (const CXXRecordDecl *ClassDecl = ty->getAsCXXRecordDecl()) |
| 247 | return ClassDecl->isTriviallyCopyable(); |
| 248 | return true; |
| 249 | } |
John McCall | fe96e0b | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 250 | |
| 251 | virtual Expr *rebuildAndCaptureObject(Expr *) = 0; |
| 252 | virtual ExprResult buildGet() = 0; |
| 253 | virtual ExprResult buildSet(Expr *, SourceLocation, |
| 254 | bool captureSetValueAsResult) = 0; |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 255 | /// Should the result of an assignment be the formal result of the |
Alexey Bataev | 60520e2 | 2015-12-10 04:38:18 +0000 | [diff] [blame] | 256 | /// setter call or the value that was passed to the setter? |
| 257 | /// |
| 258 | /// Different pseudo-object language features use different language rules |
| 259 | /// for this. |
| 260 | /// The default is to use the set value. Currently, this affects the |
| 261 | /// behavior of simple assignments, compound assignments, and prefix |
| 262 | /// increment and decrement. |
| 263 | /// Postfix increment and decrement always use the getter result as the |
| 264 | /// expression result. |
| 265 | /// |
| 266 | /// If this method returns true, and the set value isn't capturable for |
| 267 | /// some reason, the result of the expression will be void. |
| 268 | virtual bool captureSetValueAsResult() const { return true; } |
John McCall | fe96e0b | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 269 | }; |
| 270 | |
Dmitri Gribenko | 00bcdd3 | 2012-09-12 17:01:48 +0000 | [diff] [blame] | 271 | /// A PseudoOpBuilder for Objective-C \@properties. |
John McCall | fe96e0b | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 272 | class ObjCPropertyOpBuilder : public PseudoOpBuilder { |
| 273 | ObjCPropertyRefExpr *RefExpr; |
Argyrios Kyrtzidis | ab468b0 | 2012-03-30 00:19:18 +0000 | [diff] [blame] | 274 | ObjCPropertyRefExpr *SyntacticRefExpr; |
John McCall | fe96e0b | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 275 | OpaqueValueExpr *InstanceReceiver; |
| 276 | ObjCMethodDecl *Getter; |
| 277 | |
| 278 | ObjCMethodDecl *Setter; |
| 279 | Selector SetterSelector; |
Fariborz Jahanian | b525b52 | 2012-04-18 19:13:23 +0000 | [diff] [blame] | 280 | Selector GetterSelector; |
John McCall | fe96e0b | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 281 | |
| 282 | public: |
Akira Hatanaka | 797afe3 | 2018-03-20 01:47:58 +0000 | [diff] [blame] | 283 | ObjCPropertyOpBuilder(Sema &S, ObjCPropertyRefExpr *refExpr, bool IsUnique) |
| 284 | : PseudoOpBuilder(S, refExpr->getLocation(), IsUnique), |
| 285 | RefExpr(refExpr), SyntacticRefExpr(nullptr), |
| 286 | InstanceReceiver(nullptr), Getter(nullptr), Setter(nullptr) { |
John McCall | fe96e0b | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 287 | } |
| 288 | |
| 289 | ExprResult buildRValueOperation(Expr *op); |
| 290 | ExprResult buildAssignmentOperation(Scope *Sc, |
| 291 | SourceLocation opLoc, |
| 292 | BinaryOperatorKind opcode, |
| 293 | Expr *LHS, Expr *RHS); |
| 294 | ExprResult buildIncDecOperation(Scope *Sc, SourceLocation opLoc, |
| 295 | UnaryOperatorKind opcode, |
| 296 | Expr *op); |
| 297 | |
| 298 | bool tryBuildGetOfReference(Expr *op, ExprResult &result); |
Fariborz Jahanian | 3f88afa | 2012-05-24 22:48:38 +0000 | [diff] [blame] | 299 | bool findSetter(bool warn=true); |
John McCall | fe96e0b | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 300 | bool findGetter(); |
Olivier Goffart | f6fabcc | 2014-08-04 17:28:11 +0000 | [diff] [blame] | 301 | void DiagnoseUnsupportedPropertyUse(); |
John McCall | fe96e0b | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 302 | |
Craig Topper | e14c0f8 | 2014-03-12 04:55:44 +0000 | [diff] [blame] | 303 | Expr *rebuildAndCaptureObject(Expr *syntacticBase) override; |
| 304 | ExprResult buildGet() override; |
| 305 | ExprResult buildSet(Expr *op, SourceLocation, bool) override; |
| 306 | ExprResult complete(Expr *SyntacticForm) override; |
Jordan Rose | d393458 | 2012-09-28 22:21:30 +0000 | [diff] [blame] | 307 | |
| 308 | bool isWeakProperty() const; |
John McCall | fe96e0b | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 309 | }; |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 310 | |
| 311 | /// A PseudoOpBuilder for Objective-C array/dictionary indexing. |
| 312 | class ObjCSubscriptOpBuilder : public PseudoOpBuilder { |
| 313 | ObjCSubscriptRefExpr *RefExpr; |
| 314 | OpaqueValueExpr *InstanceBase; |
| 315 | OpaqueValueExpr *InstanceKey; |
| 316 | ObjCMethodDecl *AtIndexGetter; |
| 317 | Selector AtIndexGetterSelector; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 318 | |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 319 | ObjCMethodDecl *AtIndexSetter; |
| 320 | Selector AtIndexSetterSelector; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 321 | |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 322 | public: |
Akira Hatanaka | 797afe3 | 2018-03-20 01:47:58 +0000 | [diff] [blame] | 323 | ObjCSubscriptOpBuilder(Sema &S, ObjCSubscriptRefExpr *refExpr, bool IsUnique) |
| 324 | : PseudoOpBuilder(S, refExpr->getSourceRange().getBegin(), IsUnique), |
| 325 | RefExpr(refExpr), InstanceBase(nullptr), InstanceKey(nullptr), |
| 326 | AtIndexGetter(nullptr), AtIndexSetter(nullptr) {} |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 327 | |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 328 | ExprResult buildRValueOperation(Expr *op); |
| 329 | ExprResult buildAssignmentOperation(Scope *Sc, |
| 330 | SourceLocation opLoc, |
| 331 | BinaryOperatorKind opcode, |
| 332 | Expr *LHS, Expr *RHS); |
Craig Topper | e14c0f8 | 2014-03-12 04:55:44 +0000 | [diff] [blame] | 333 | Expr *rebuildAndCaptureObject(Expr *syntacticBase) override; |
| 334 | |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 335 | bool findAtIndexGetter(); |
| 336 | bool findAtIndexSetter(); |
Craig Topper | e14c0f8 | 2014-03-12 04:55:44 +0000 | [diff] [blame] | 337 | |
| 338 | ExprResult buildGet() override; |
| 339 | ExprResult buildSet(Expr *op, SourceLocation, bool) override; |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 340 | }; |
| 341 | |
John McCall | 5e77d76 | 2013-04-16 07:28:30 +0000 | [diff] [blame] | 342 | class MSPropertyOpBuilder : public PseudoOpBuilder { |
| 343 | MSPropertyRefExpr *RefExpr; |
Alexey Bataev | 6910347 | 2015-10-14 04:05:42 +0000 | [diff] [blame] | 344 | OpaqueValueExpr *InstanceBase; |
Alexey Bataev | f763027 | 2015-11-25 12:01:00 +0000 | [diff] [blame] | 345 | SmallVector<Expr *, 4> CallArgs; |
| 346 | |
| 347 | MSPropertyRefExpr *getBaseMSProperty(MSPropertySubscriptExpr *E); |
John McCall | 5e77d76 | 2013-04-16 07:28:30 +0000 | [diff] [blame] | 348 | |
| 349 | public: |
Akira Hatanaka | 797afe3 | 2018-03-20 01:47:58 +0000 | [diff] [blame] | 350 | MSPropertyOpBuilder(Sema &S, MSPropertyRefExpr *refExpr, bool IsUnique) |
| 351 | : PseudoOpBuilder(S, refExpr->getSourceRange().getBegin(), IsUnique), |
| 352 | RefExpr(refExpr), InstanceBase(nullptr) {} |
| 353 | MSPropertyOpBuilder(Sema &S, MSPropertySubscriptExpr *refExpr, bool IsUnique) |
| 354 | : PseudoOpBuilder(S, refExpr->getSourceRange().getBegin(), IsUnique), |
Alexey Bataev | f763027 | 2015-11-25 12:01:00 +0000 | [diff] [blame] | 355 | InstanceBase(nullptr) { |
| 356 | RefExpr = getBaseMSProperty(refExpr); |
| 357 | } |
John McCall | 5e77d76 | 2013-04-16 07:28:30 +0000 | [diff] [blame] | 358 | |
Craig Topper | e14c0f8 | 2014-03-12 04:55:44 +0000 | [diff] [blame] | 359 | Expr *rebuildAndCaptureObject(Expr *) override; |
| 360 | ExprResult buildGet() override; |
| 361 | ExprResult buildSet(Expr *op, SourceLocation, bool) override; |
Alexey Bataev | 60520e2 | 2015-12-10 04:38:18 +0000 | [diff] [blame] | 362 | bool captureSetValueAsResult() const override { return false; } |
John McCall | 5e77d76 | 2013-04-16 07:28:30 +0000 | [diff] [blame] | 363 | }; |
Alexander Kornienko | ab9db51 | 2015-06-22 23:07:51 +0000 | [diff] [blame] | 364 | } |
John McCall | fe96e0b | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 365 | |
| 366 | /// Capture the given expression in an OpaqueValueExpr. |
| 367 | OpaqueValueExpr *PseudoOpBuilder::capture(Expr *e) { |
| 368 | // Make a new OVE whose source is the given expression. |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 369 | OpaqueValueExpr *captured = |
John McCall | fe96e0b | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 370 | new (S.Context) OpaqueValueExpr(GenericLoc, e->getType(), |
Douglas Gregor | 2d5aea0 | 2012-02-23 22:17:26 +0000 | [diff] [blame] | 371 | e->getValueKind(), e->getObjectKind(), |
| 372 | e); |
Akira Hatanaka | 797afe3 | 2018-03-20 01:47:58 +0000 | [diff] [blame] | 373 | if (IsUnique) |
| 374 | captured->setIsUnique(true); |
| 375 | |
John McCall | fe96e0b | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 376 | // Make sure we bind that in the semantics. |
| 377 | addSemanticExpr(captured); |
| 378 | return captured; |
| 379 | } |
| 380 | |
| 381 | /// Capture the given expression as the result of this pseudo-object |
| 382 | /// operation. This routine is safe against expressions which may |
| 383 | /// already be captured. |
| 384 | /// |
Dmitri Gribenko | adba9be | 2012-08-23 17:58:28 +0000 | [diff] [blame] | 385 | /// \returns the captured expression, which will be the |
John McCall | fe96e0b | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 386 | /// same as the input if the input was already captured |
| 387 | OpaqueValueExpr *PseudoOpBuilder::captureValueAsResult(Expr *e) { |
| 388 | assert(ResultIndex == PseudoObjectExpr::NoResult); |
| 389 | |
| 390 | // If the expression hasn't already been captured, just capture it |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 391 | // and set the new semantic |
John McCall | fe96e0b | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 392 | if (!isa<OpaqueValueExpr>(e)) { |
| 393 | OpaqueValueExpr *cap = capture(e); |
| 394 | setResultToLastSemantic(); |
| 395 | return cap; |
| 396 | } |
| 397 | |
| 398 | // Otherwise, it must already be one of our semantic expressions; |
| 399 | // set ResultIndex to its index. |
| 400 | unsigned index = 0; |
| 401 | for (;; ++index) { |
| 402 | assert(index < Semantics.size() && |
| 403 | "captured expression not found in semantics!"); |
| 404 | if (e == Semantics[index]) break; |
| 405 | } |
| 406 | ResultIndex = index; |
Akira Hatanaka | 797afe3 | 2018-03-20 01:47:58 +0000 | [diff] [blame] | 407 | // An OVE is not unique if it is used as the result expression. |
| 408 | cast<OpaqueValueExpr>(e)->setIsUnique(false); |
John McCall | fe96e0b | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 409 | return cast<OpaqueValueExpr>(e); |
| 410 | } |
| 411 | |
| 412 | /// The routine which creates the final PseudoObjectExpr. |
| 413 | ExprResult PseudoOpBuilder::complete(Expr *syntactic) { |
| 414 | return PseudoObjectExpr::Create(S.Context, syntactic, |
| 415 | Semantics, ResultIndex); |
| 416 | } |
| 417 | |
| 418 | /// The main skeleton for building an r-value operation. |
| 419 | ExprResult PseudoOpBuilder::buildRValueOperation(Expr *op) { |
| 420 | Expr *syntacticBase = rebuildAndCaptureObject(op); |
| 421 | |
| 422 | ExprResult getExpr = buildGet(); |
| 423 | if (getExpr.isInvalid()) return ExprError(); |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 424 | addResultSemanticExpr(getExpr.get()); |
John McCall | fe96e0b | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 425 | |
| 426 | return complete(syntacticBase); |
| 427 | } |
| 428 | |
| 429 | /// The basic skeleton for building a simple or compound |
| 430 | /// assignment operation. |
| 431 | ExprResult |
| 432 | PseudoOpBuilder::buildAssignmentOperation(Scope *Sc, SourceLocation opcLoc, |
| 433 | BinaryOperatorKind opcode, |
| 434 | Expr *LHS, Expr *RHS) { |
| 435 | assert(BinaryOperator::isAssignmentOp(opcode)); |
| 436 | |
| 437 | Expr *syntacticLHS = rebuildAndCaptureObject(LHS); |
| 438 | OpaqueValueExpr *capturedRHS = capture(RHS); |
| 439 | |
John McCall | ee04aeb | 2015-08-22 00:35:27 +0000 | [diff] [blame] | 440 | // In some very specific cases, semantic analysis of the RHS as an |
| 441 | // expression may require it to be rewritten. In these cases, we |
| 442 | // cannot safely keep the OVE around. Fortunately, we don't really |
| 443 | // need to: we don't use this particular OVE in multiple places, and |
| 444 | // no clients rely that closely on matching up expressions in the |
| 445 | // semantic expression with expressions from the syntactic form. |
| 446 | Expr *semanticRHS = capturedRHS; |
| 447 | if (RHS->hasPlaceholderType() || isa<InitListExpr>(RHS)) { |
| 448 | semanticRHS = RHS; |
| 449 | Semantics.pop_back(); |
| 450 | } |
| 451 | |
John McCall | fe96e0b | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 452 | Expr *syntactic; |
| 453 | |
| 454 | ExprResult result; |
| 455 | if (opcode == BO_Assign) { |
John McCall | ee04aeb | 2015-08-22 00:35:27 +0000 | [diff] [blame] | 456 | result = semanticRHS; |
John McCall | fe96e0b | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 457 | syntactic = new (S.Context) BinaryOperator(syntacticLHS, capturedRHS, |
| 458 | opcode, capturedRHS->getType(), |
| 459 | capturedRHS->getValueKind(), |
Adam Nemet | 484aa45 | 2017-03-27 19:17:25 +0000 | [diff] [blame] | 460 | OK_Ordinary, opcLoc, |
| 461 | FPOptions()); |
John McCall | fe96e0b | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 462 | } else { |
| 463 | ExprResult opLHS = buildGet(); |
| 464 | if (opLHS.isInvalid()) return ExprError(); |
| 465 | |
| 466 | // Build an ordinary, non-compound operation. |
| 467 | BinaryOperatorKind nonCompound = |
| 468 | BinaryOperator::getOpForCompoundAssignment(opcode); |
John McCall | ee04aeb | 2015-08-22 00:35:27 +0000 | [diff] [blame] | 469 | result = S.BuildBinOp(Sc, opcLoc, nonCompound, opLHS.get(), semanticRHS); |
John McCall | fe96e0b | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 470 | if (result.isInvalid()) return ExprError(); |
| 471 | |
| 472 | syntactic = |
| 473 | new (S.Context) CompoundAssignOperator(syntacticLHS, capturedRHS, opcode, |
| 474 | result.get()->getType(), |
| 475 | result.get()->getValueKind(), |
| 476 | OK_Ordinary, |
| 477 | opLHS.get()->getType(), |
| 478 | result.get()->getType(), |
Adam Nemet | 484aa45 | 2017-03-27 19:17:25 +0000 | [diff] [blame] | 479 | opcLoc, FPOptions()); |
John McCall | fe96e0b | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 480 | } |
| 481 | |
| 482 | // The result of the assignment, if not void, is the value set into |
| 483 | // the l-value. |
Alexey Bataev | 60520e2 | 2015-12-10 04:38:18 +0000 | [diff] [blame] | 484 | result = buildSet(result.get(), opcLoc, captureSetValueAsResult()); |
John McCall | fe96e0b | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 485 | if (result.isInvalid()) return ExprError(); |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 486 | addSemanticExpr(result.get()); |
Alexey Bataev | 60520e2 | 2015-12-10 04:38:18 +0000 | [diff] [blame] | 487 | if (!captureSetValueAsResult() && !result.get()->getType()->isVoidType() && |
| 488 | (result.get()->isTypeDependent() || CanCaptureValue(result.get()))) |
| 489 | setResultToLastSemantic(); |
John McCall | fe96e0b | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 490 | |
| 491 | return complete(syntactic); |
| 492 | } |
| 493 | |
| 494 | /// The basic skeleton for building an increment or decrement |
| 495 | /// operation. |
| 496 | ExprResult |
| 497 | PseudoOpBuilder::buildIncDecOperation(Scope *Sc, SourceLocation opcLoc, |
| 498 | UnaryOperatorKind opcode, |
| 499 | Expr *op) { |
| 500 | assert(UnaryOperator::isIncrementDecrementOp(opcode)); |
| 501 | |
| 502 | Expr *syntacticOp = rebuildAndCaptureObject(op); |
| 503 | |
| 504 | // Load the value. |
| 505 | ExprResult result = buildGet(); |
| 506 | if (result.isInvalid()) return ExprError(); |
| 507 | |
| 508 | QualType resultType = result.get()->getType(); |
| 509 | |
| 510 | // That's the postfix result. |
John McCall | 0d9dd73 | 2013-04-16 22:32:04 +0000 | [diff] [blame] | 511 | if (UnaryOperator::isPostfix(opcode) && |
Fariborz Jahanian | 15dde89 | 2014-03-06 00:34:05 +0000 | [diff] [blame] | 512 | (result.get()->isTypeDependent() || CanCaptureValue(result.get()))) { |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 513 | result = capture(result.get()); |
John McCall | fe96e0b | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 514 | setResultToLastSemantic(); |
| 515 | } |
| 516 | |
| 517 | // Add or subtract a literal 1. |
| 518 | llvm::APInt oneV(S.Context.getTypeSize(S.Context.IntTy), 1); |
| 519 | Expr *one = IntegerLiteral::Create(S.Context, oneV, S.Context.IntTy, |
| 520 | GenericLoc); |
| 521 | |
| 522 | if (UnaryOperator::isIncrementOp(opcode)) { |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 523 | result = S.BuildBinOp(Sc, opcLoc, BO_Add, result.get(), one); |
John McCall | fe96e0b | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 524 | } else { |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 525 | result = S.BuildBinOp(Sc, opcLoc, BO_Sub, result.get(), one); |
John McCall | fe96e0b | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 526 | } |
| 527 | if (result.isInvalid()) return ExprError(); |
| 528 | |
| 529 | // Store that back into the result. The value stored is the result |
| 530 | // of a prefix operation. |
Alexey Bataev | 60520e2 | 2015-12-10 04:38:18 +0000 | [diff] [blame] | 531 | result = buildSet(result.get(), opcLoc, UnaryOperator::isPrefix(opcode) && |
| 532 | captureSetValueAsResult()); |
John McCall | fe96e0b | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 533 | if (result.isInvalid()) return ExprError(); |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 534 | addSemanticExpr(result.get()); |
Alexey Bataev | 60520e2 | 2015-12-10 04:38:18 +0000 | [diff] [blame] | 535 | if (UnaryOperator::isPrefix(opcode) && !captureSetValueAsResult() && |
| 536 | !result.get()->getType()->isVoidType() && |
Malcolm Parsons | fab3680 | 2018-04-16 08:31:08 +0000 | [diff] [blame] | 537 | (result.get()->isTypeDependent() || CanCaptureValue(result.get()))) |
| 538 | setResultToLastSemantic(); |
| 539 | |
| 540 | UnaryOperator *syntactic = new (S.Context) UnaryOperator( |
| 541 | syntacticOp, opcode, resultType, VK_LValue, OK_Ordinary, opcLoc, |
| 542 | !resultType->isDependentType() |
| 543 | ? S.Context.getTypeSize(resultType) >= |
| 544 | S.Context.getTypeSize(S.Context.IntTy) |
| 545 | : false); |
| 546 | return complete(syntactic); |
| 547 | } |
| 548 | |
John McCall | fe96e0b | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 549 | |
| 550 | //===----------------------------------------------------------------------===// |
| 551 | // Objective-C @property and implicit property references |
| 552 | //===----------------------------------------------------------------------===// |
| 553 | |
| 554 | /// Look up a method in the receiver type of an Objective-C property |
| 555 | /// reference. |
John McCall | 526ab47 | 2011-10-25 17:37:35 +0000 | [diff] [blame] | 556 | static ObjCMethodDecl *LookupMethodInReceiverType(Sema &S, Selector sel, |
| 557 | const ObjCPropertyRefExpr *PRE) { |
John McCall | 526ab47 | 2011-10-25 17:37:35 +0000 | [diff] [blame] | 558 | if (PRE->isObjectReceiver()) { |
Benjamin Kramer | 8dc5760 | 2011-10-28 13:21:18 +0000 | [diff] [blame] | 559 | const ObjCObjectPointerType *PT = |
| 560 | PRE->getBase()->getType()->castAs<ObjCObjectPointerType>(); |
John McCall | fe96e0b | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 561 | |
| 562 | // Special case for 'self' in class method implementations. |
| 563 | if (PT->isObjCClassType() && |
| 564 | S.isSelfExpr(const_cast<Expr*>(PRE->getBase()))) { |
| 565 | // This cast is safe because isSelfExpr is only true within |
| 566 | // methods. |
| 567 | ObjCMethodDecl *method = |
| 568 | cast<ObjCMethodDecl>(S.CurContext->getNonClosureAncestor()); |
| 569 | return S.LookupMethodInObjectType(sel, |
| 570 | S.Context.getObjCInterfaceType(method->getClassInterface()), |
| 571 | /*instance*/ false); |
| 572 | } |
| 573 | |
Benjamin Kramer | 8dc5760 | 2011-10-28 13:21:18 +0000 | [diff] [blame] | 574 | return S.LookupMethodInObjectType(sel, PT->getPointeeType(), true); |
John McCall | 526ab47 | 2011-10-25 17:37:35 +0000 | [diff] [blame] | 575 | } |
| 576 | |
Benjamin Kramer | 8dc5760 | 2011-10-28 13:21:18 +0000 | [diff] [blame] | 577 | if (PRE->isSuperReceiver()) { |
| 578 | if (const ObjCObjectPointerType *PT = |
| 579 | PRE->getSuperReceiverType()->getAs<ObjCObjectPointerType>()) |
| 580 | return S.LookupMethodInObjectType(sel, PT->getPointeeType(), true); |
| 581 | |
| 582 | return S.LookupMethodInObjectType(sel, PRE->getSuperReceiverType(), false); |
| 583 | } |
| 584 | |
| 585 | assert(PRE->isClassReceiver() && "Invalid expression"); |
| 586 | QualType IT = S.Context.getObjCInterfaceType(PRE->getClassReceiver()); |
| 587 | return S.LookupMethodInObjectType(sel, IT, false); |
John McCall | 526ab47 | 2011-10-25 17:37:35 +0000 | [diff] [blame] | 588 | } |
| 589 | |
Jordan Rose | d393458 | 2012-09-28 22:21:30 +0000 | [diff] [blame] | 590 | bool ObjCPropertyOpBuilder::isWeakProperty() const { |
| 591 | QualType T; |
| 592 | if (RefExpr->isExplicitProperty()) { |
| 593 | const ObjCPropertyDecl *Prop = RefExpr->getExplicitProperty(); |
| 594 | if (Prop->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_weak) |
Bob Wilson | f4f54e3 | 2016-05-25 05:41:57 +0000 | [diff] [blame] | 595 | return true; |
Jordan Rose | d393458 | 2012-09-28 22:21:30 +0000 | [diff] [blame] | 596 | |
| 597 | T = Prop->getType(); |
| 598 | } else if (Getter) { |
Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 599 | T = Getter->getReturnType(); |
Jordan Rose | d393458 | 2012-09-28 22:21:30 +0000 | [diff] [blame] | 600 | } else { |
| 601 | return false; |
| 602 | } |
| 603 | |
| 604 | return T.getObjCLifetime() == Qualifiers::OCL_Weak; |
| 605 | } |
| 606 | |
John McCall | fe96e0b | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 607 | bool ObjCPropertyOpBuilder::findGetter() { |
| 608 | if (Getter) return true; |
John McCall | 526ab47 | 2011-10-25 17:37:35 +0000 | [diff] [blame] | 609 | |
John McCall | cfef546 | 2011-11-07 22:49:50 +0000 | [diff] [blame] | 610 | // For implicit properties, just trust the lookup we already did. |
| 611 | if (RefExpr->isImplicitProperty()) { |
Fariborz Jahanian | b525b52 | 2012-04-18 19:13:23 +0000 | [diff] [blame] | 612 | if ((Getter = RefExpr->getImplicitPropertyGetter())) { |
| 613 | GetterSelector = Getter->getSelector(); |
| 614 | return true; |
| 615 | } |
| 616 | else { |
| 617 | // Must build the getter selector the hard way. |
| 618 | ObjCMethodDecl *setter = RefExpr->getImplicitPropertySetter(); |
| 619 | assert(setter && "both setter and getter are null - cannot happen"); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 620 | IdentifierInfo *setterName = |
Fariborz Jahanian | b525b52 | 2012-04-18 19:13:23 +0000 | [diff] [blame] | 621 | setter->getSelector().getIdentifierInfoForSlot(0); |
Alp Toker | 541d507 | 2014-06-07 23:30:53 +0000 | [diff] [blame] | 622 | IdentifierInfo *getterName = |
| 623 | &S.Context.Idents.get(setterName->getName().substr(3)); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 624 | GetterSelector = |
Fariborz Jahanian | b525b52 | 2012-04-18 19:13:23 +0000 | [diff] [blame] | 625 | S.PP.getSelectorTable().getNullarySelector(getterName); |
| 626 | return false; |
Fariborz Jahanian | b525b52 | 2012-04-18 19:13:23 +0000 | [diff] [blame] | 627 | } |
John McCall | cfef546 | 2011-11-07 22:49:50 +0000 | [diff] [blame] | 628 | } |
| 629 | |
| 630 | ObjCPropertyDecl *prop = RefExpr->getExplicitProperty(); |
| 631 | Getter = LookupMethodInReceiverType(S, prop->getGetterName(), RefExpr); |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 632 | return (Getter != nullptr); |
John McCall | fe96e0b | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 633 | } |
| 634 | |
| 635 | /// Try to find the most accurate setter declaration for the property |
| 636 | /// reference. |
| 637 | /// |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 638 | /// \return true if a setter was found, in which case Setter |
Fariborz Jahanian | 3f88afa | 2012-05-24 22:48:38 +0000 | [diff] [blame] | 639 | bool ObjCPropertyOpBuilder::findSetter(bool warn) { |
John McCall | fe96e0b | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 640 | // For implicit properties, just trust the lookup we already did. |
| 641 | if (RefExpr->isImplicitProperty()) { |
| 642 | if (ObjCMethodDecl *setter = RefExpr->getImplicitPropertySetter()) { |
| 643 | Setter = setter; |
| 644 | SetterSelector = setter->getSelector(); |
| 645 | return true; |
John McCall | 526ab47 | 2011-10-25 17:37:35 +0000 | [diff] [blame] | 646 | } else { |
John McCall | fe96e0b | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 647 | IdentifierInfo *getterName = |
| 648 | RefExpr->getImplicitPropertyGetter()->getSelector() |
| 649 | .getIdentifierInfoForSlot(0); |
| 650 | SetterSelector = |
Adrian Prantl | a4ce906 | 2013-06-07 22:29:12 +0000 | [diff] [blame] | 651 | SelectorTable::constructSetterSelector(S.PP.getIdentifierTable(), |
| 652 | S.PP.getSelectorTable(), |
| 653 | getterName); |
John McCall | fe96e0b | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 654 | return false; |
John McCall | 526ab47 | 2011-10-25 17:37:35 +0000 | [diff] [blame] | 655 | } |
John McCall | fe96e0b | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 656 | } |
| 657 | |
| 658 | // For explicit properties, this is more involved. |
| 659 | ObjCPropertyDecl *prop = RefExpr->getExplicitProperty(); |
| 660 | SetterSelector = prop->getSetterName(); |
| 661 | |
| 662 | // Do a normal method lookup first. |
| 663 | if (ObjCMethodDecl *setter = |
| 664 | LookupMethodInReceiverType(S, SetterSelector, RefExpr)) { |
Jordan Rose | d01e83a | 2012-10-10 16:42:25 +0000 | [diff] [blame] | 665 | if (setter->isPropertyAccessor() && warn) |
Fariborz Jahanian | 3f88afa | 2012-05-24 22:48:38 +0000 | [diff] [blame] | 666 | if (const ObjCInterfaceDecl *IFace = |
| 667 | dyn_cast<ObjCInterfaceDecl>(setter->getDeclContext())) { |
Craig Topper | bf3e327 | 2014-08-30 16:55:52 +0000 | [diff] [blame] | 668 | StringRef thisPropertyName = prop->getName(); |
Jordan Rose | a7d0384 | 2013-02-08 22:30:41 +0000 | [diff] [blame] | 669 | // Try flipping the case of the first character. |
Fariborz Jahanian | 3f88afa | 2012-05-24 22:48:38 +0000 | [diff] [blame] | 670 | char front = thisPropertyName.front(); |
Jordan Rose | a7d0384 | 2013-02-08 22:30:41 +0000 | [diff] [blame] | 671 | front = isLowercase(front) ? toUppercase(front) : toLowercase(front); |
Fariborz Jahanian | 3f88afa | 2012-05-24 22:48:38 +0000 | [diff] [blame] | 672 | SmallString<100> PropertyName = thisPropertyName; |
| 673 | PropertyName[0] = front; |
| 674 | IdentifierInfo *AltMember = &S.PP.getIdentifierTable().get(PropertyName); |
Manman Ren | 5b78640 | 2016-01-28 18:49:28 +0000 | [diff] [blame] | 675 | if (ObjCPropertyDecl *prop1 = IFace->FindPropertyDeclaration( |
| 676 | AltMember, prop->getQueryKind())) |
Fariborz Jahanian | 3f88afa | 2012-05-24 22:48:38 +0000 | [diff] [blame] | 677 | if (prop != prop1 && (prop1->getSetterMethodDecl() == setter)) { |
Richard Smith | f881267 | 2016-12-02 22:38:31 +0000 | [diff] [blame] | 678 | S.Diag(RefExpr->getExprLoc(), diag::err_property_setter_ambiguous_use) |
Aaron Ballman | 1fb3955 | 2014-01-03 14:23:03 +0000 | [diff] [blame] | 679 | << prop << prop1 << setter->getSelector(); |
Fariborz Jahanian | 3f88afa | 2012-05-24 22:48:38 +0000 | [diff] [blame] | 680 | S.Diag(prop->getLocation(), diag::note_property_declare); |
| 681 | S.Diag(prop1->getLocation(), diag::note_property_declare); |
| 682 | } |
| 683 | } |
John McCall | fe96e0b | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 684 | Setter = setter; |
| 685 | return true; |
| 686 | } |
| 687 | |
| 688 | // That can fail in the somewhat crazy situation that we're |
| 689 | // type-checking a message send within the @interface declaration |
| 690 | // that declared the @property. But it's not clear that that's |
| 691 | // valuable to support. |
| 692 | |
| 693 | return false; |
| 694 | } |
| 695 | |
Olivier Goffart | f6fabcc | 2014-08-04 17:28:11 +0000 | [diff] [blame] | 696 | void ObjCPropertyOpBuilder::DiagnoseUnsupportedPropertyUse() { |
Fariborz Jahanian | 5551328 | 2014-05-28 18:12:10 +0000 | [diff] [blame] | 697 | if (S.getCurLexicalContext()->isObjCContainer() && |
| 698 | S.getCurLexicalContext()->getDeclKind() != Decl::ObjCCategoryImpl && |
| 699 | S.getCurLexicalContext()->getDeclKind() != Decl::ObjCImplementation) { |
| 700 | if (ObjCPropertyDecl *prop = RefExpr->getExplicitProperty()) { |
| 701 | S.Diag(RefExpr->getLocation(), |
| 702 | diag::err_property_function_in_objc_container); |
| 703 | S.Diag(prop->getLocation(), diag::note_property_declare); |
Fariborz Jahanian | 5551328 | 2014-05-28 18:12:10 +0000 | [diff] [blame] | 704 | } |
| 705 | } |
Fariborz Jahanian | 5551328 | 2014-05-28 18:12:10 +0000 | [diff] [blame] | 706 | } |
| 707 | |
John McCall | fe96e0b | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 708 | /// Capture the base object of an Objective-C property expression. |
| 709 | Expr *ObjCPropertyOpBuilder::rebuildAndCaptureObject(Expr *syntacticBase) { |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 710 | assert(InstanceReceiver == nullptr); |
John McCall | fe96e0b | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 711 | |
| 712 | // If we have a base, capture it in an OVE and rebuild the syntactic |
| 713 | // form to use the OVE as its base. |
| 714 | if (RefExpr->isObjectReceiver()) { |
| 715 | InstanceReceiver = capture(RefExpr->getBase()); |
Alexey Bataev | f763027 | 2015-11-25 12:01:00 +0000 | [diff] [blame] | 716 | syntacticBase = Rebuilder(S, [=](Expr *, unsigned) -> Expr * { |
| 717 | return InstanceReceiver; |
| 718 | }).rebuild(syntacticBase); |
John McCall | fe96e0b | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 719 | } |
| 720 | |
Argyrios Kyrtzidis | ab468b0 | 2012-03-30 00:19:18 +0000 | [diff] [blame] | 721 | if (ObjCPropertyRefExpr * |
| 722 | refE = dyn_cast<ObjCPropertyRefExpr>(syntacticBase->IgnoreParens())) |
| 723 | SyntacticRefExpr = refE; |
| 724 | |
John McCall | fe96e0b | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 725 | return syntacticBase; |
| 726 | } |
| 727 | |
| 728 | /// Load from an Objective-C property reference. |
| 729 | ExprResult ObjCPropertyOpBuilder::buildGet() { |
| 730 | findGetter(); |
Olivier Goffart | f6fabcc | 2014-08-04 17:28:11 +0000 | [diff] [blame] | 731 | if (!Getter) { |
| 732 | DiagnoseUnsupportedPropertyUse(); |
| 733 | return ExprError(); |
| 734 | } |
Argyrios Kyrtzidis | ab468b0 | 2012-03-30 00:19:18 +0000 | [diff] [blame] | 735 | |
| 736 | if (SyntacticRefExpr) |
| 737 | SyntacticRefExpr->setIsMessagingGetter(); |
| 738 | |
Douglas Gregor | e83b956 | 2015-07-07 03:57:53 +0000 | [diff] [blame] | 739 | QualType receiverType = RefExpr->getReceiverType(S.Context); |
Fariborz Jahanian | 89ea961 | 2014-06-16 17:25:41 +0000 | [diff] [blame] | 740 | if (!Getter->isImplicit()) |
| 741 | S.DiagnoseUseOfDecl(Getter, GenericLoc, nullptr, true); |
John McCall | fe96e0b | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 742 | // Build a message-send. |
| 743 | ExprResult msg; |
Fariborz Jahanian | 29cdbc6 | 2014-04-21 20:22:17 +0000 | [diff] [blame] | 744 | if ((Getter->isInstanceMethod() && !RefExpr->isClassReceiver()) || |
| 745 | RefExpr->isObjectReceiver()) { |
John McCall | fe96e0b | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 746 | assert(InstanceReceiver || RefExpr->isSuperReceiver()); |
Argyrios Kyrtzidis | a80f1bf | 2012-01-12 02:34:39 +0000 | [diff] [blame] | 747 | msg = S.BuildInstanceMessageImplicit(InstanceReceiver, receiverType, |
| 748 | GenericLoc, Getter->getSelector(), |
Dmitri Gribenko | 78852e9 | 2013-05-05 20:40:26 +0000 | [diff] [blame] | 749 | Getter, None); |
John McCall | fe96e0b | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 750 | } else { |
Argyrios Kyrtzidis | a80f1bf | 2012-01-12 02:34:39 +0000 | [diff] [blame] | 751 | msg = S.BuildClassMessageImplicit(receiverType, RefExpr->isSuperReceiver(), |
Dmitri Gribenko | 78852e9 | 2013-05-05 20:40:26 +0000 | [diff] [blame] | 752 | GenericLoc, Getter->getSelector(), |
| 753 | Getter, None); |
John McCall | fe96e0b | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 754 | } |
| 755 | return msg; |
| 756 | } |
John McCall | 526ab47 | 2011-10-25 17:37:35 +0000 | [diff] [blame] | 757 | |
John McCall | fe96e0b | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 758 | /// Store to an Objective-C property reference. |
| 759 | /// |
Dmitri Gribenko | adba9be | 2012-08-23 17:58:28 +0000 | [diff] [blame] | 760 | /// \param captureSetValueAsResult If true, capture the actual |
John McCall | fe96e0b | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 761 | /// value being set as the value of the property operation. |
| 762 | ExprResult ObjCPropertyOpBuilder::buildSet(Expr *op, SourceLocation opcLoc, |
| 763 | bool captureSetValueAsResult) { |
Olivier Goffart | f6fabcc | 2014-08-04 17:28:11 +0000 | [diff] [blame] | 764 | if (!findSetter(false)) { |
| 765 | DiagnoseUnsupportedPropertyUse(); |
| 766 | return ExprError(); |
| 767 | } |
John McCall | fe96e0b | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 768 | |
Argyrios Kyrtzidis | ab468b0 | 2012-03-30 00:19:18 +0000 | [diff] [blame] | 769 | if (SyntacticRefExpr) |
| 770 | SyntacticRefExpr->setIsMessagingSetter(); |
| 771 | |
Douglas Gregor | e83b956 | 2015-07-07 03:57:53 +0000 | [diff] [blame] | 772 | QualType receiverType = RefExpr->getReceiverType(S.Context); |
John McCall | fe96e0b | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 773 | |
| 774 | // Use assignment constraints when possible; they give us better |
| 775 | // diagnostics. "When possible" basically means anything except a |
| 776 | // C++ class type. |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 777 | if (!S.getLangOpts().CPlusPlus || !op->getType()->isRecordType()) { |
Douglas Gregor | e83b956 | 2015-07-07 03:57:53 +0000 | [diff] [blame] | 778 | QualType paramType = (*Setter->param_begin())->getType() |
| 779 | .substObjCMemberType( |
| 780 | receiverType, |
| 781 | Setter->getDeclContext(), |
| 782 | ObjCSubstitutionContext::Parameter); |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 783 | if (!S.getLangOpts().CPlusPlus || !paramType->isRecordType()) { |
John McCall | fe96e0b | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 784 | ExprResult opResult = op; |
| 785 | Sema::AssignConvertType assignResult |
| 786 | = S.CheckSingleAssignmentConstraints(paramType, opResult); |
Richard Smith | e15a370 | 2016-10-06 23:12:58 +0000 | [diff] [blame] | 787 | if (opResult.isInvalid() || |
| 788 | S.DiagnoseAssignmentResult(assignResult, opcLoc, paramType, |
John McCall | fe96e0b | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 789 | op->getType(), opResult.get(), |
| 790 | Sema::AA_Assigning)) |
| 791 | return ExprError(); |
| 792 | |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 793 | op = opResult.get(); |
John McCall | fe96e0b | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 794 | assert(op && "successful assignment left argument invalid?"); |
John McCall | 526ab47 | 2011-10-25 17:37:35 +0000 | [diff] [blame] | 795 | } |
| 796 | } |
| 797 | |
John McCall | fe96e0b | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 798 | // Arguments. |
| 799 | Expr *args[] = { op }; |
John McCall | 526ab47 | 2011-10-25 17:37:35 +0000 | [diff] [blame] | 800 | |
John McCall | fe96e0b | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 801 | // Build a message-send. |
| 802 | ExprResult msg; |
Fariborz Jahanian | 89ea961 | 2014-06-16 17:25:41 +0000 | [diff] [blame] | 803 | if (!Setter->isImplicit()) |
| 804 | S.DiagnoseUseOfDecl(Setter, GenericLoc, nullptr, true); |
Fariborz Jahanian | 29cdbc6 | 2014-04-21 20:22:17 +0000 | [diff] [blame] | 805 | if ((Setter->isInstanceMethod() && !RefExpr->isClassReceiver()) || |
| 806 | RefExpr->isObjectReceiver()) { |
Argyrios Kyrtzidis | a80f1bf | 2012-01-12 02:34:39 +0000 | [diff] [blame] | 807 | msg = S.BuildInstanceMessageImplicit(InstanceReceiver, receiverType, |
| 808 | GenericLoc, SetterSelector, Setter, |
| 809 | MultiExprArg(args, 1)); |
John McCall | fe96e0b | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 810 | } else { |
Argyrios Kyrtzidis | a80f1bf | 2012-01-12 02:34:39 +0000 | [diff] [blame] | 811 | msg = S.BuildClassMessageImplicit(receiverType, RefExpr->isSuperReceiver(), |
| 812 | GenericLoc, |
| 813 | SetterSelector, Setter, |
| 814 | MultiExprArg(args, 1)); |
John McCall | fe96e0b | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 815 | } |
| 816 | |
| 817 | if (!msg.isInvalid() && captureSetValueAsResult) { |
| 818 | ObjCMessageExpr *msgExpr = |
| 819 | cast<ObjCMessageExpr>(msg.get()->IgnoreImplicit()); |
| 820 | Expr *arg = msgExpr->getArg(0); |
Fariborz Jahanian | 15dde89 | 2014-03-06 00:34:05 +0000 | [diff] [blame] | 821 | if (CanCaptureValue(arg)) |
Eli Friedman | 00fa429 | 2012-11-13 23:16:33 +0000 | [diff] [blame] | 822 | msgExpr->setArg(0, captureValueAsResult(arg)); |
John McCall | fe96e0b | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 823 | } |
| 824 | |
| 825 | return msg; |
John McCall | 526ab47 | 2011-10-25 17:37:35 +0000 | [diff] [blame] | 826 | } |
| 827 | |
John McCall | fe96e0b | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 828 | /// @property-specific behavior for doing lvalue-to-rvalue conversion. |
| 829 | ExprResult ObjCPropertyOpBuilder::buildRValueOperation(Expr *op) { |
| 830 | // Explicit properties always have getters, but implicit ones don't. |
| 831 | // Check that before proceeding. |
Eli Friedman | fd41aee | 2012-11-29 03:13:49 +0000 | [diff] [blame] | 832 | if (RefExpr->isImplicitProperty() && !RefExpr->getImplicitPropertyGetter()) { |
John McCall | fe96e0b | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 833 | S.Diag(RefExpr->getLocation(), diag::err_getter_not_found) |
Eli Friedman | fd41aee | 2012-11-29 03:13:49 +0000 | [diff] [blame] | 834 | << RefExpr->getSourceRange(); |
John McCall | 526ab47 | 2011-10-25 17:37:35 +0000 | [diff] [blame] | 835 | return ExprError(); |
| 836 | } |
| 837 | |
John McCall | fe96e0b | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 838 | ExprResult result = PseudoOpBuilder::buildRValueOperation(op); |
John McCall | 526ab47 | 2011-10-25 17:37:35 +0000 | [diff] [blame] | 839 | if (result.isInvalid()) return ExprError(); |
| 840 | |
John McCall | fe96e0b | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 841 | if (RefExpr->isExplicitProperty() && !Getter->hasRelatedResultType()) |
| 842 | S.DiagnosePropertyAccessorMismatch(RefExpr->getExplicitProperty(), |
| 843 | Getter, RefExpr->getLocation()); |
| 844 | |
| 845 | // As a special case, if the method returns 'id', try to get |
| 846 | // a better type from the property. |
Fariborz Jahanian | 9277ff4 | 2014-06-17 23:35:13 +0000 | [diff] [blame] | 847 | if (RefExpr->isExplicitProperty() && result.get()->isRValue()) { |
Douglas Gregor | e83b956 | 2015-07-07 03:57:53 +0000 | [diff] [blame] | 848 | QualType receiverType = RefExpr->getReceiverType(S.Context); |
| 849 | QualType propType = RefExpr->getExplicitProperty() |
| 850 | ->getUsageType(receiverType); |
Fariborz Jahanian | 9277ff4 | 2014-06-17 23:35:13 +0000 | [diff] [blame] | 851 | if (result.get()->getType()->isObjCIdType()) { |
| 852 | if (const ObjCObjectPointerType *ptr |
| 853 | = propType->getAs<ObjCObjectPointerType>()) { |
| 854 | if (!ptr->isObjCIdType()) |
| 855 | result = S.ImpCastExprToType(result.get(), propType, CK_BitCast); |
| 856 | } |
| 857 | } |
Brian Kelley | cafd912 | 2017-03-29 17:55:11 +0000 | [diff] [blame] | 858 | if (propType.getObjCLifetime() == Qualifiers::OCL_Weak && |
| 859 | !S.Diags.isIgnored(diag::warn_arc_repeated_use_of_weak, |
| 860 | RefExpr->getLocation())) |
| 861 | S.getCurFunction()->markSafeWeakUse(RefExpr); |
John McCall | fe96e0b | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 862 | } |
| 863 | |
John McCall | 526ab47 | 2011-10-25 17:37:35 +0000 | [diff] [blame] | 864 | return result; |
| 865 | } |
| 866 | |
John McCall | fe96e0b | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 867 | /// Try to build this as a call to a getter that returns a reference. |
| 868 | /// |
| 869 | /// \return true if it was possible, whether or not it actually |
| 870 | /// succeeded |
| 871 | bool ObjCPropertyOpBuilder::tryBuildGetOfReference(Expr *op, |
| 872 | ExprResult &result) { |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 873 | if (!S.getLangOpts().CPlusPlus) return false; |
John McCall | fe96e0b | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 874 | |
| 875 | findGetter(); |
Olivier Goffart | 4c182c8 | 2014-08-04 17:28:05 +0000 | [diff] [blame] | 876 | if (!Getter) { |
| 877 | // The property has no setter and no getter! This can happen if the type is |
| 878 | // invalid. Error have already been reported. |
| 879 | result = ExprError(); |
| 880 | return true; |
| 881 | } |
John McCall | fe96e0b | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 882 | |
| 883 | // Only do this if the getter returns an l-value reference type. |
Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 884 | QualType resultType = Getter->getReturnType(); |
John McCall | fe96e0b | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 885 | if (!resultType->isLValueReferenceType()) return false; |
| 886 | |
| 887 | result = buildRValueOperation(op); |
| 888 | return true; |
| 889 | } |
| 890 | |
| 891 | /// @property-specific behavior for doing assignments. |
| 892 | ExprResult |
| 893 | ObjCPropertyOpBuilder::buildAssignmentOperation(Scope *Sc, |
| 894 | SourceLocation opcLoc, |
| 895 | BinaryOperatorKind opcode, |
| 896 | Expr *LHS, Expr *RHS) { |
John McCall | 526ab47 | 2011-10-25 17:37:35 +0000 | [diff] [blame] | 897 | assert(BinaryOperator::isAssignmentOp(opcode)); |
John McCall | 526ab47 | 2011-10-25 17:37:35 +0000 | [diff] [blame] | 898 | |
| 899 | // If there's no setter, we have no choice but to try to assign to |
| 900 | // the result of the getter. |
John McCall | fe96e0b | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 901 | if (!findSetter()) { |
| 902 | ExprResult result; |
| 903 | if (tryBuildGetOfReference(LHS, result)) { |
| 904 | if (result.isInvalid()) return ExprError(); |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 905 | return S.BuildBinOp(Sc, opcLoc, opcode, result.get(), RHS); |
John McCall | 526ab47 | 2011-10-25 17:37:35 +0000 | [diff] [blame] | 906 | } |
| 907 | |
| 908 | // Otherwise, it's an error. |
John McCall | fe96e0b | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 909 | S.Diag(opcLoc, diag::err_nosetter_property_assignment) |
| 910 | << unsigned(RefExpr->isImplicitProperty()) |
| 911 | << SetterSelector |
John McCall | 526ab47 | 2011-10-25 17:37:35 +0000 | [diff] [blame] | 912 | << LHS->getSourceRange() << RHS->getSourceRange(); |
| 913 | return ExprError(); |
| 914 | } |
| 915 | |
| 916 | // If there is a setter, we definitely want to use it. |
| 917 | |
John McCall | fe96e0b | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 918 | // Verify that we can do a compound assignment. |
| 919 | if (opcode != BO_Assign && !findGetter()) { |
| 920 | S.Diag(opcLoc, diag::err_nogetter_property_compound_assignment) |
John McCall | 526ab47 | 2011-10-25 17:37:35 +0000 | [diff] [blame] | 921 | << LHS->getSourceRange() << RHS->getSourceRange(); |
| 922 | return ExprError(); |
| 923 | } |
| 924 | |
John McCall | fe96e0b | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 925 | ExprResult result = |
| 926 | PseudoOpBuilder::buildAssignmentOperation(Sc, opcLoc, opcode, LHS, RHS); |
John McCall | 526ab47 | 2011-10-25 17:37:35 +0000 | [diff] [blame] | 927 | if (result.isInvalid()) return ExprError(); |
| 928 | |
John McCall | fe96e0b | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 929 | // Various warnings about property assignments in ARC. |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 930 | if (S.getLangOpts().ObjCAutoRefCount && InstanceReceiver) { |
John McCall | fe96e0b | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 931 | S.checkRetainCycles(InstanceReceiver->getSourceExpr(), RHS); |
| 932 | S.checkUnsafeExprAssigns(opcLoc, LHS, RHS); |
| 933 | } |
| 934 | |
John McCall | 526ab47 | 2011-10-25 17:37:35 +0000 | [diff] [blame] | 935 | return result; |
| 936 | } |
John McCall | fe96e0b | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 937 | |
| 938 | /// @property-specific behavior for doing increments and decrements. |
| 939 | ExprResult |
| 940 | ObjCPropertyOpBuilder::buildIncDecOperation(Scope *Sc, SourceLocation opcLoc, |
| 941 | UnaryOperatorKind opcode, |
| 942 | Expr *op) { |
| 943 | // If there's no setter, we have no choice but to try to assign to |
| 944 | // the result of the getter. |
| 945 | if (!findSetter()) { |
| 946 | ExprResult result; |
| 947 | if (tryBuildGetOfReference(op, result)) { |
| 948 | if (result.isInvalid()) return ExprError(); |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 949 | return S.BuildUnaryOp(Sc, opcLoc, opcode, result.get()); |
John McCall | fe96e0b | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 950 | } |
| 951 | |
| 952 | // Otherwise, it's an error. |
| 953 | S.Diag(opcLoc, diag::err_nosetter_property_incdec) |
| 954 | << unsigned(RefExpr->isImplicitProperty()) |
| 955 | << unsigned(UnaryOperator::isDecrementOp(opcode)) |
| 956 | << SetterSelector |
| 957 | << op->getSourceRange(); |
| 958 | return ExprError(); |
| 959 | } |
| 960 | |
| 961 | // If there is a setter, we definitely want to use it. |
| 962 | |
| 963 | // We also need a getter. |
| 964 | if (!findGetter()) { |
| 965 | assert(RefExpr->isImplicitProperty()); |
| 966 | S.Diag(opcLoc, diag::err_nogetter_property_incdec) |
| 967 | << unsigned(UnaryOperator::isDecrementOp(opcode)) |
Fariborz Jahanian | b525b52 | 2012-04-18 19:13:23 +0000 | [diff] [blame] | 968 | << GetterSelector |
John McCall | fe96e0b | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 969 | << op->getSourceRange(); |
| 970 | return ExprError(); |
| 971 | } |
| 972 | |
| 973 | return PseudoOpBuilder::buildIncDecOperation(Sc, opcLoc, opcode, op); |
| 974 | } |
| 975 | |
Jordan Rose | d393458 | 2012-09-28 22:21:30 +0000 | [diff] [blame] | 976 | ExprResult ObjCPropertyOpBuilder::complete(Expr *SyntacticForm) { |
Reid Kleckner | 04f9bca | 2018-03-07 22:48:35 +0000 | [diff] [blame] | 977 | if (isWeakProperty() && !S.isUnevaluatedContext() && |
Alp Toker | d4a3f0e | 2014-06-15 23:30:39 +0000 | [diff] [blame] | 978 | !S.Diags.isIgnored(diag::warn_arc_repeated_use_of_weak, |
Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 979 | SyntacticForm->getBeginLoc())) |
Reid Kleckner | 04f9bca | 2018-03-07 22:48:35 +0000 | [diff] [blame] | 980 | S.getCurFunction()->recordUseOfWeak(SyntacticRefExpr, |
| 981 | SyntacticRefExpr->isMessagingGetter()); |
Jordan Rose | d393458 | 2012-09-28 22:21:30 +0000 | [diff] [blame] | 982 | |
| 983 | return PseudoOpBuilder::complete(SyntacticForm); |
| 984 | } |
| 985 | |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 986 | // ObjCSubscript build stuff. |
| 987 | // |
| 988 | |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 989 | /// objective-c subscripting-specific behavior for doing lvalue-to-rvalue |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 990 | /// conversion. |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 991 | /// FIXME. Remove this routine if it is proven that no additional |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 992 | /// specifity is needed. |
| 993 | ExprResult ObjCSubscriptOpBuilder::buildRValueOperation(Expr *op) { |
| 994 | ExprResult result = PseudoOpBuilder::buildRValueOperation(op); |
| 995 | if (result.isInvalid()) return ExprError(); |
| 996 | return result; |
| 997 | } |
| 998 | |
| 999 | /// objective-c subscripting-specific behavior for doing assignments. |
| 1000 | ExprResult |
| 1001 | ObjCSubscriptOpBuilder::buildAssignmentOperation(Scope *Sc, |
| 1002 | SourceLocation opcLoc, |
| 1003 | BinaryOperatorKind opcode, |
| 1004 | Expr *LHS, Expr *RHS) { |
| 1005 | assert(BinaryOperator::isAssignmentOp(opcode)); |
| 1006 | // There must be a method to do the Index'ed assignment. |
| 1007 | if (!findAtIndexSetter()) |
| 1008 | return ExprError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1009 | |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 1010 | // Verify that we can do a compound assignment. |
| 1011 | if (opcode != BO_Assign && !findAtIndexGetter()) |
| 1012 | return ExprError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1013 | |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 1014 | ExprResult result = |
| 1015 | PseudoOpBuilder::buildAssignmentOperation(Sc, opcLoc, opcode, LHS, RHS); |
| 1016 | if (result.isInvalid()) return ExprError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1017 | |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 1018 | // Various warnings about objc Index'ed assignments in ARC. |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 1019 | if (S.getLangOpts().ObjCAutoRefCount && InstanceBase) { |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 1020 | S.checkRetainCycles(InstanceBase->getSourceExpr(), RHS); |
| 1021 | S.checkUnsafeExprAssigns(opcLoc, LHS, RHS); |
| 1022 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1023 | |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 1024 | return result; |
| 1025 | } |
| 1026 | |
| 1027 | /// Capture the base object of an Objective-C Index'ed expression. |
| 1028 | Expr *ObjCSubscriptOpBuilder::rebuildAndCaptureObject(Expr *syntacticBase) { |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 1029 | assert(InstanceBase == nullptr); |
| 1030 | |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 1031 | // Capture base expression in an OVE and rebuild the syntactic |
| 1032 | // form to use the OVE as its base expression. |
| 1033 | InstanceBase = capture(RefExpr->getBaseExpr()); |
| 1034 | InstanceKey = capture(RefExpr->getKeyExpr()); |
Alexey Bataev | f763027 | 2015-11-25 12:01:00 +0000 | [diff] [blame] | 1035 | |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 1036 | syntacticBase = |
Alexey Bataev | f763027 | 2015-11-25 12:01:00 +0000 | [diff] [blame] | 1037 | Rebuilder(S, [=](Expr *, unsigned Idx) -> Expr * { |
| 1038 | switch (Idx) { |
| 1039 | case 0: |
| 1040 | return InstanceBase; |
| 1041 | case 1: |
| 1042 | return InstanceKey; |
| 1043 | default: |
| 1044 | llvm_unreachable("Unexpected index for ObjCSubscriptExpr"); |
| 1045 | } |
| 1046 | }).rebuild(syntacticBase); |
| 1047 | |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 1048 | return syntacticBase; |
| 1049 | } |
| 1050 | |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1051 | /// CheckSubscriptingKind - This routine decide what type |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 1052 | /// of indexing represented by "FromE" is being done. |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1053 | Sema::ObjCSubscriptKind |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 1054 | Sema::CheckSubscriptingKind(Expr *FromE) { |
| 1055 | // If the expression already has integral or enumeration type, we're golden. |
| 1056 | QualType T = FromE->getType(); |
| 1057 | if (T->isIntegralOrEnumerationType()) |
| 1058 | return OS_Array; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1059 | |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 1060 | // If we don't have a class type in C++, there's no way we can get an |
| 1061 | // expression of integral or enumeration type. |
| 1062 | const RecordType *RecordTy = T->getAs<RecordType>(); |
Fariborz Jahanian | d13951f | 2014-09-10 20:55:31 +0000 | [diff] [blame] | 1063 | if (!RecordTy && |
| 1064 | (T->isObjCObjectPointerType() || T->isVoidPointerType())) |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 1065 | // All other scalar cases are assumed to be dictionary indexing which |
| 1066 | // caller handles, with diagnostics if needed. |
| 1067 | return OS_Dictionary; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1068 | if (!getLangOpts().CPlusPlus || |
Fariborz Jahanian | ba0afde | 2012-03-28 17:56:49 +0000 | [diff] [blame] | 1069 | !RecordTy || RecordTy->isIncompleteType()) { |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 1070 | // No indexing can be done. Issue diagnostics and quit. |
Fariborz Jahanian | ba0afde | 2012-03-28 17:56:49 +0000 | [diff] [blame] | 1071 | const Expr *IndexExpr = FromE->IgnoreParenImpCasts(); |
| 1072 | if (isa<StringLiteral>(IndexExpr)) |
| 1073 | Diag(FromE->getExprLoc(), diag::err_objc_subscript_pointer) |
| 1074 | << T << FixItHint::CreateInsertion(FromE->getExprLoc(), "@"); |
| 1075 | else |
| 1076 | Diag(FromE->getExprLoc(), diag::err_objc_subscript_type_conversion) |
| 1077 | << T; |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 1078 | return OS_Error; |
| 1079 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1080 | |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 1081 | // We must have a complete class type. |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1082 | if (RequireCompleteType(FromE->getExprLoc(), T, |
Douglas Gregor | 7bfb2d0 | 2012-05-04 16:32:21 +0000 | [diff] [blame] | 1083 | diag::err_objc_index_incomplete_class_type, FromE)) |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 1084 | return OS_Error; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1085 | |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 1086 | // Look for a conversion to an integral, enumeration type, or |
| 1087 | // objective-C pointer type. |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 1088 | int NoIntegrals=0, NoObjCIdPointers=0; |
| 1089 | SmallVector<CXXConversionDecl *, 4> ConversionDecls; |
Benjamin Kramer | b4ef668 | 2015-02-06 17:25:10 +0000 | [diff] [blame] | 1090 | |
| 1091 | for (NamedDecl *D : cast<CXXRecordDecl>(RecordTy->getDecl()) |
| 1092 | ->getVisibleConversionFunctions()) { |
| 1093 | if (CXXConversionDecl *Conversion = |
| 1094 | dyn_cast<CXXConversionDecl>(D->getUnderlyingDecl())) { |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 1095 | QualType CT = Conversion->getConversionType().getNonReferenceType(); |
| 1096 | if (CT->isIntegralOrEnumerationType()) { |
| 1097 | ++NoIntegrals; |
| 1098 | ConversionDecls.push_back(Conversion); |
| 1099 | } |
| 1100 | else if (CT->isObjCIdType() ||CT->isBlockPointerType()) { |
| 1101 | ++NoObjCIdPointers; |
| 1102 | ConversionDecls.push_back(Conversion); |
| 1103 | } |
| 1104 | } |
| 1105 | } |
| 1106 | if (NoIntegrals ==1 && NoObjCIdPointers == 0) |
| 1107 | return OS_Array; |
| 1108 | if (NoIntegrals == 0 && NoObjCIdPointers == 1) |
| 1109 | return OS_Dictionary; |
| 1110 | if (NoIntegrals == 0 && NoObjCIdPointers == 0) { |
| 1111 | // No conversion function was found. Issue diagnostic and return. |
| 1112 | Diag(FromE->getExprLoc(), diag::err_objc_subscript_type_conversion) |
| 1113 | << FromE->getType(); |
| 1114 | return OS_Error; |
| 1115 | } |
| 1116 | Diag(FromE->getExprLoc(), diag::err_objc_multiple_subscript_type_conversion) |
| 1117 | << FromE->getType(); |
| 1118 | for (unsigned int i = 0; i < ConversionDecls.size(); i++) |
Richard Smith | 01d9698 | 2016-12-02 23:00:28 +0000 | [diff] [blame] | 1119 | Diag(ConversionDecls[i]->getLocation(), |
| 1120 | diag::note_conv_function_declared_at); |
| 1121 | |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 1122 | return OS_Error; |
| 1123 | } |
| 1124 | |
Fariborz Jahanian | 9080491 | 2012-08-02 18:03:58 +0000 | [diff] [blame] | 1125 | /// CheckKeyForObjCARCConversion - This routine suggests bridge casting of CF |
| 1126 | /// objects used as dictionary subscript key objects. |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1127 | static void CheckKeyForObjCARCConversion(Sema &S, QualType ContainerT, |
Fariborz Jahanian | 9080491 | 2012-08-02 18:03:58 +0000 | [diff] [blame] | 1128 | Expr *Key) { |
| 1129 | if (ContainerT.isNull()) |
| 1130 | return; |
| 1131 | // dictionary subscripting. |
| 1132 | // - (id)objectForKeyedSubscript:(id)key; |
| 1133 | IdentifierInfo *KeyIdents[] = { |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1134 | &S.Context.Idents.get("objectForKeyedSubscript") |
Fariborz Jahanian | 9080491 | 2012-08-02 18:03:58 +0000 | [diff] [blame] | 1135 | }; |
| 1136 | Selector GetterSelector = S.Context.Selectors.getSelector(1, KeyIdents); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1137 | ObjCMethodDecl *Getter = S.LookupMethodInObjectType(GetterSelector, ContainerT, |
Fariborz Jahanian | 9080491 | 2012-08-02 18:03:58 +0000 | [diff] [blame] | 1138 | true /*instance*/); |
| 1139 | if (!Getter) |
| 1140 | return; |
Alp Toker | 03376dc | 2014-07-07 09:02:20 +0000 | [diff] [blame] | 1141 | QualType T = Getter->parameters()[0]->getType(); |
Brian Kelley | 11352a8 | 2017-03-29 18:09:02 +0000 | [diff] [blame] | 1142 | S.CheckObjCConversion(Key->getSourceRange(), T, Key, |
| 1143 | Sema::CCK_ImplicitConversion); |
Fariborz Jahanian | 9080491 | 2012-08-02 18:03:58 +0000 | [diff] [blame] | 1144 | } |
| 1145 | |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 1146 | bool ObjCSubscriptOpBuilder::findAtIndexGetter() { |
| 1147 | if (AtIndexGetter) |
| 1148 | return true; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1149 | |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 1150 | Expr *BaseExpr = RefExpr->getBaseExpr(); |
| 1151 | QualType BaseT = BaseExpr->getType(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1152 | |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 1153 | QualType ResultType; |
| 1154 | if (const ObjCObjectPointerType *PTy = |
| 1155 | BaseT->getAs<ObjCObjectPointerType>()) { |
| 1156 | ResultType = PTy->getPointeeType(); |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 1157 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1158 | Sema::ObjCSubscriptKind Res = |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 1159 | S.CheckSubscriptingKind(RefExpr->getKeyExpr()); |
Fariborz Jahanian | 9080491 | 2012-08-02 18:03:58 +0000 | [diff] [blame] | 1160 | if (Res == Sema::OS_Error) { |
| 1161 | if (S.getLangOpts().ObjCAutoRefCount) |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1162 | CheckKeyForObjCARCConversion(S, ResultType, |
Fariborz Jahanian | 9080491 | 2012-08-02 18:03:58 +0000 | [diff] [blame] | 1163 | RefExpr->getKeyExpr()); |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 1164 | return false; |
Fariborz Jahanian | 9080491 | 2012-08-02 18:03:58 +0000 | [diff] [blame] | 1165 | } |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 1166 | bool arrayRef = (Res == Sema::OS_Array); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1167 | |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 1168 | if (ResultType.isNull()) { |
| 1169 | S.Diag(BaseExpr->getExprLoc(), diag::err_objc_subscript_base_type) |
| 1170 | << BaseExpr->getType() << arrayRef; |
| 1171 | return false; |
| 1172 | } |
| 1173 | if (!arrayRef) { |
| 1174 | // dictionary subscripting. |
| 1175 | // - (id)objectForKeyedSubscript:(id)key; |
| 1176 | IdentifierInfo *KeyIdents[] = { |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1177 | &S.Context.Idents.get("objectForKeyedSubscript") |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 1178 | }; |
| 1179 | AtIndexGetterSelector = S.Context.Selectors.getSelector(1, KeyIdents); |
| 1180 | } |
| 1181 | else { |
| 1182 | // - (id)objectAtIndexedSubscript:(size_t)index; |
| 1183 | IdentifierInfo *KeyIdents[] = { |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1184 | &S.Context.Idents.get("objectAtIndexedSubscript") |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 1185 | }; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1186 | |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 1187 | AtIndexGetterSelector = S.Context.Selectors.getSelector(1, KeyIdents); |
| 1188 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1189 | |
| 1190 | AtIndexGetter = S.LookupMethodInObjectType(AtIndexGetterSelector, ResultType, |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 1191 | true /*instance*/); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1192 | |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 1193 | if (!AtIndexGetter && S.getLangOpts().DebuggerObjCLiteral) { |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1194 | AtIndexGetter = ObjCMethodDecl::Create(S.Context, SourceLocation(), |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 1195 | SourceLocation(), AtIndexGetterSelector, |
| 1196 | S.Context.getObjCIdType() /*ReturnType*/, |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 1197 | nullptr /*TypeSourceInfo */, |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 1198 | S.Context.getTranslationUnitDecl(), |
| 1199 | true /*Instance*/, false/*isVariadic*/, |
Jordan Rose | d01e83a | 2012-10-10 16:42:25 +0000 | [diff] [blame] | 1200 | /*isPropertyAccessor=*/false, |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 1201 | /*isImplicitlyDeclared=*/true, /*isDefined=*/false, |
| 1202 | ObjCMethodDecl::Required, |
| 1203 | false); |
| 1204 | ParmVarDecl *Argument = ParmVarDecl::Create(S.Context, AtIndexGetter, |
| 1205 | SourceLocation(), SourceLocation(), |
| 1206 | arrayRef ? &S.Context.Idents.get("index") |
| 1207 | : &S.Context.Idents.get("key"), |
| 1208 | arrayRef ? S.Context.UnsignedLongTy |
| 1209 | : S.Context.getObjCIdType(), |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 1210 | /*TInfo=*/nullptr, |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 1211 | SC_None, |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 1212 | nullptr); |
Dmitri Gribenko | 44ebbd5 | 2013-05-05 00:41:58 +0000 | [diff] [blame] | 1213 | AtIndexGetter->setMethodParams(S.Context, Argument, None); |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 1214 | } |
| 1215 | |
| 1216 | if (!AtIndexGetter) { |
Alex Lorenz | 4b9f80c | 2017-07-11 10:18:35 +0000 | [diff] [blame] | 1217 | if (!BaseT->isObjCIdType()) { |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 1218 | S.Diag(BaseExpr->getExprLoc(), diag::err_objc_subscript_method_not_found) |
| 1219 | << BaseExpr->getType() << 0 << arrayRef; |
| 1220 | return false; |
| 1221 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1222 | AtIndexGetter = |
| 1223 | S.LookupInstanceMethodInGlobalPool(AtIndexGetterSelector, |
| 1224 | RefExpr->getSourceRange(), |
Fariborz Jahanian | 890803f | 2015-04-15 17:26:21 +0000 | [diff] [blame] | 1225 | true); |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 1226 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1227 | |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 1228 | if (AtIndexGetter) { |
Alp Toker | 03376dc | 2014-07-07 09:02:20 +0000 | [diff] [blame] | 1229 | QualType T = AtIndexGetter->parameters()[0]->getType(); |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 1230 | if ((arrayRef && !T->isIntegralOrEnumerationType()) || |
| 1231 | (!arrayRef && !T->isObjCObjectPointerType())) { |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1232 | S.Diag(RefExpr->getKeyExpr()->getExprLoc(), |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 1233 | arrayRef ? diag::err_objc_subscript_index_type |
| 1234 | : diag::err_objc_subscript_key_type) << T; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1235 | S.Diag(AtIndexGetter->parameters()[0]->getLocation(), |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 1236 | diag::note_parameter_type) << T; |
| 1237 | return false; |
| 1238 | } |
Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 1239 | QualType R = AtIndexGetter->getReturnType(); |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 1240 | if (!R->isObjCObjectPointerType()) { |
| 1241 | S.Diag(RefExpr->getKeyExpr()->getExprLoc(), |
| 1242 | diag::err_objc_indexing_method_result_type) << R << arrayRef; |
| 1243 | S.Diag(AtIndexGetter->getLocation(), diag::note_method_declared_at) << |
| 1244 | AtIndexGetter->getDeclName(); |
| 1245 | } |
| 1246 | } |
| 1247 | return true; |
| 1248 | } |
| 1249 | |
| 1250 | bool ObjCSubscriptOpBuilder::findAtIndexSetter() { |
| 1251 | if (AtIndexSetter) |
| 1252 | return true; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1253 | |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 1254 | Expr *BaseExpr = RefExpr->getBaseExpr(); |
| 1255 | QualType BaseT = BaseExpr->getType(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1256 | |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 1257 | QualType ResultType; |
| 1258 | if (const ObjCObjectPointerType *PTy = |
| 1259 | BaseT->getAs<ObjCObjectPointerType>()) { |
| 1260 | ResultType = PTy->getPointeeType(); |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 1261 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1262 | |
| 1263 | Sema::ObjCSubscriptKind Res = |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 1264 | S.CheckSubscriptingKind(RefExpr->getKeyExpr()); |
Fariborz Jahanian | 9080491 | 2012-08-02 18:03:58 +0000 | [diff] [blame] | 1265 | if (Res == Sema::OS_Error) { |
| 1266 | if (S.getLangOpts().ObjCAutoRefCount) |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1267 | CheckKeyForObjCARCConversion(S, ResultType, |
Fariborz Jahanian | 9080491 | 2012-08-02 18:03:58 +0000 | [diff] [blame] | 1268 | RefExpr->getKeyExpr()); |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 1269 | return false; |
Fariborz Jahanian | 9080491 | 2012-08-02 18:03:58 +0000 | [diff] [blame] | 1270 | } |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 1271 | bool arrayRef = (Res == Sema::OS_Array); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1272 | |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 1273 | if (ResultType.isNull()) { |
| 1274 | S.Diag(BaseExpr->getExprLoc(), diag::err_objc_subscript_base_type) |
| 1275 | << BaseExpr->getType() << arrayRef; |
| 1276 | return false; |
| 1277 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1278 | |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 1279 | if (!arrayRef) { |
| 1280 | // dictionary subscripting. |
| 1281 | // - (void)setObject:(id)object forKeyedSubscript:(id)key; |
| 1282 | IdentifierInfo *KeyIdents[] = { |
| 1283 | &S.Context.Idents.get("setObject"), |
| 1284 | &S.Context.Idents.get("forKeyedSubscript") |
| 1285 | }; |
| 1286 | AtIndexSetterSelector = S.Context.Selectors.getSelector(2, KeyIdents); |
| 1287 | } |
| 1288 | else { |
| 1289 | // - (void)setObject:(id)object atIndexedSubscript:(NSInteger)index; |
| 1290 | IdentifierInfo *KeyIdents[] = { |
| 1291 | &S.Context.Idents.get("setObject"), |
| 1292 | &S.Context.Idents.get("atIndexedSubscript") |
| 1293 | }; |
| 1294 | AtIndexSetterSelector = S.Context.Selectors.getSelector(2, KeyIdents); |
| 1295 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1296 | AtIndexSetter = S.LookupMethodInObjectType(AtIndexSetterSelector, ResultType, |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 1297 | true /*instance*/); |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 1298 | |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 1299 | if (!AtIndexSetter && S.getLangOpts().DebuggerObjCLiteral) { |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 1300 | TypeSourceInfo *ReturnTInfo = nullptr; |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 1301 | QualType ReturnType = S.Context.VoidTy; |
Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 1302 | AtIndexSetter = ObjCMethodDecl::Create( |
| 1303 | S.Context, SourceLocation(), SourceLocation(), AtIndexSetterSelector, |
| 1304 | ReturnType, ReturnTInfo, S.Context.getTranslationUnitDecl(), |
| 1305 | true /*Instance*/, false /*isVariadic*/, |
| 1306 | /*isPropertyAccessor=*/false, |
| 1307 | /*isImplicitlyDeclared=*/true, /*isDefined=*/false, |
| 1308 | ObjCMethodDecl::Required, false); |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 1309 | SmallVector<ParmVarDecl *, 2> Params; |
| 1310 | ParmVarDecl *object = ParmVarDecl::Create(S.Context, AtIndexSetter, |
| 1311 | SourceLocation(), SourceLocation(), |
| 1312 | &S.Context.Idents.get("object"), |
| 1313 | S.Context.getObjCIdType(), |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 1314 | /*TInfo=*/nullptr, |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 1315 | SC_None, |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 1316 | nullptr); |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 1317 | Params.push_back(object); |
| 1318 | ParmVarDecl *key = ParmVarDecl::Create(S.Context, AtIndexSetter, |
| 1319 | SourceLocation(), SourceLocation(), |
| 1320 | arrayRef ? &S.Context.Idents.get("index") |
| 1321 | : &S.Context.Idents.get("key"), |
| 1322 | arrayRef ? S.Context.UnsignedLongTy |
| 1323 | : S.Context.getObjCIdType(), |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 1324 | /*TInfo=*/nullptr, |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 1325 | SC_None, |
Craig Topper | c3ec149 | 2014-05-26 06:22:03 +0000 | [diff] [blame] | 1326 | nullptr); |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 1327 | Params.push_back(key); |
Dmitri Gribenko | 44ebbd5 | 2013-05-05 00:41:58 +0000 | [diff] [blame] | 1328 | AtIndexSetter->setMethodParams(S.Context, Params, None); |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 1329 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1330 | |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 1331 | if (!AtIndexSetter) { |
Alex Lorenz | 4b9f80c | 2017-07-11 10:18:35 +0000 | [diff] [blame] | 1332 | if (!BaseT->isObjCIdType()) { |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1333 | S.Diag(BaseExpr->getExprLoc(), |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 1334 | diag::err_objc_subscript_method_not_found) |
| 1335 | << BaseExpr->getType() << 1 << arrayRef; |
| 1336 | return false; |
| 1337 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1338 | AtIndexSetter = |
| 1339 | S.LookupInstanceMethodInGlobalPool(AtIndexSetterSelector, |
| 1340 | RefExpr->getSourceRange(), |
Fariborz Jahanian | 890803f | 2015-04-15 17:26:21 +0000 | [diff] [blame] | 1341 | true); |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 1342 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1343 | |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 1344 | bool err = false; |
| 1345 | if (AtIndexSetter && arrayRef) { |
Alp Toker | 03376dc | 2014-07-07 09:02:20 +0000 | [diff] [blame] | 1346 | QualType T = AtIndexSetter->parameters()[1]->getType(); |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 1347 | if (!T->isIntegralOrEnumerationType()) { |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1348 | S.Diag(RefExpr->getKeyExpr()->getExprLoc(), |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 1349 | diag::err_objc_subscript_index_type) << T; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1350 | S.Diag(AtIndexSetter->parameters()[1]->getLocation(), |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 1351 | diag::note_parameter_type) << T; |
| 1352 | err = true; |
| 1353 | } |
Alp Toker | 03376dc | 2014-07-07 09:02:20 +0000 | [diff] [blame] | 1354 | T = AtIndexSetter->parameters()[0]->getType(); |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 1355 | if (!T->isObjCObjectPointerType()) { |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1356 | S.Diag(RefExpr->getBaseExpr()->getExprLoc(), |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 1357 | diag::err_objc_subscript_object_type) << T << arrayRef; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1358 | S.Diag(AtIndexSetter->parameters()[0]->getLocation(), |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 1359 | diag::note_parameter_type) << T; |
| 1360 | err = true; |
| 1361 | } |
| 1362 | } |
| 1363 | else if (AtIndexSetter && !arrayRef) |
| 1364 | for (unsigned i=0; i <2; i++) { |
Alp Toker | 03376dc | 2014-07-07 09:02:20 +0000 | [diff] [blame] | 1365 | QualType T = AtIndexSetter->parameters()[i]->getType(); |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 1366 | if (!T->isObjCObjectPointerType()) { |
| 1367 | if (i == 1) |
| 1368 | S.Diag(RefExpr->getKeyExpr()->getExprLoc(), |
| 1369 | diag::err_objc_subscript_key_type) << T; |
| 1370 | else |
| 1371 | S.Diag(RefExpr->getBaseExpr()->getExprLoc(), |
| 1372 | diag::err_objc_subscript_dic_object_type) << T; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1373 | S.Diag(AtIndexSetter->parameters()[i]->getLocation(), |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 1374 | diag::note_parameter_type) << T; |
| 1375 | err = true; |
| 1376 | } |
| 1377 | } |
| 1378 | |
| 1379 | return !err; |
| 1380 | } |
| 1381 | |
| 1382 | // Get the object at "Index" position in the container. |
| 1383 | // [BaseExpr objectAtIndexedSubscript : IndexExpr]; |
| 1384 | ExprResult ObjCSubscriptOpBuilder::buildGet() { |
| 1385 | if (!findAtIndexGetter()) |
| 1386 | return ExprError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1387 | |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 1388 | QualType receiverType = InstanceBase->getType(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1389 | |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 1390 | // Build a message-send. |
| 1391 | ExprResult msg; |
| 1392 | Expr *Index = InstanceKey; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1393 | |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 1394 | // Arguments. |
| 1395 | Expr *args[] = { Index }; |
| 1396 | assert(InstanceBase); |
Fariborz Jahanian | 3d57640 | 2014-06-10 19:02:48 +0000 | [diff] [blame] | 1397 | if (AtIndexGetter) |
| 1398 | S.DiagnoseUseOfDecl(AtIndexGetter, GenericLoc); |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 1399 | msg = S.BuildInstanceMessageImplicit(InstanceBase, receiverType, |
| 1400 | GenericLoc, |
| 1401 | AtIndexGetterSelector, AtIndexGetter, |
| 1402 | MultiExprArg(args, 1)); |
| 1403 | return msg; |
| 1404 | } |
| 1405 | |
| 1406 | /// Store into the container the "op" object at "Index"'ed location |
| 1407 | /// by building this messaging expression: |
| 1408 | /// - (void)setObject:(id)object atIndexedSubscript:(NSInteger)index; |
Dmitri Gribenko | adba9be | 2012-08-23 17:58:28 +0000 | [diff] [blame] | 1409 | /// \param captureSetValueAsResult If true, capture the actual |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 1410 | /// value being set as the value of the property operation. |
| 1411 | ExprResult ObjCSubscriptOpBuilder::buildSet(Expr *op, SourceLocation opcLoc, |
| 1412 | bool captureSetValueAsResult) { |
| 1413 | if (!findAtIndexSetter()) |
| 1414 | return ExprError(); |
Fariborz Jahanian | 3d57640 | 2014-06-10 19:02:48 +0000 | [diff] [blame] | 1415 | if (AtIndexSetter) |
| 1416 | S.DiagnoseUseOfDecl(AtIndexSetter, GenericLoc); |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 1417 | QualType receiverType = InstanceBase->getType(); |
| 1418 | Expr *Index = InstanceKey; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1419 | |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 1420 | // Arguments. |
| 1421 | Expr *args[] = { op, Index }; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1422 | |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 1423 | // Build a message-send. |
| 1424 | ExprResult msg = S.BuildInstanceMessageImplicit(InstanceBase, receiverType, |
| 1425 | GenericLoc, |
| 1426 | AtIndexSetterSelector, |
| 1427 | AtIndexSetter, |
| 1428 | MultiExprArg(args, 2)); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1429 | |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 1430 | if (!msg.isInvalid() && captureSetValueAsResult) { |
| 1431 | ObjCMessageExpr *msgExpr = |
| 1432 | cast<ObjCMessageExpr>(msg.get()->IgnoreImplicit()); |
| 1433 | Expr *arg = msgExpr->getArg(0); |
Fariborz Jahanian | 15dde89 | 2014-03-06 00:34:05 +0000 | [diff] [blame] | 1434 | if (CanCaptureValue(arg)) |
Eli Friedman | 00fa429 | 2012-11-13 23:16:33 +0000 | [diff] [blame] | 1435 | msgExpr->setArg(0, captureValueAsResult(arg)); |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 1436 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1437 | |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 1438 | return msg; |
| 1439 | } |
| 1440 | |
John McCall | fe96e0b | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 1441 | //===----------------------------------------------------------------------===// |
John McCall | 5e77d76 | 2013-04-16 07:28:30 +0000 | [diff] [blame] | 1442 | // MSVC __declspec(property) references |
| 1443 | //===----------------------------------------------------------------------===// |
| 1444 | |
Alexey Bataev | f763027 | 2015-11-25 12:01:00 +0000 | [diff] [blame] | 1445 | MSPropertyRefExpr * |
| 1446 | MSPropertyOpBuilder::getBaseMSProperty(MSPropertySubscriptExpr *E) { |
| 1447 | CallArgs.insert(CallArgs.begin(), E->getIdx()); |
| 1448 | Expr *Base = E->getBase()->IgnoreParens(); |
| 1449 | while (auto *MSPropSubscript = dyn_cast<MSPropertySubscriptExpr>(Base)) { |
| 1450 | CallArgs.insert(CallArgs.begin(), MSPropSubscript->getIdx()); |
| 1451 | Base = MSPropSubscript->getBase()->IgnoreParens(); |
| 1452 | } |
| 1453 | return cast<MSPropertyRefExpr>(Base); |
| 1454 | } |
| 1455 | |
John McCall | 5e77d76 | 2013-04-16 07:28:30 +0000 | [diff] [blame] | 1456 | Expr *MSPropertyOpBuilder::rebuildAndCaptureObject(Expr *syntacticBase) { |
Alexey Bataev | 6910347 | 2015-10-14 04:05:42 +0000 | [diff] [blame] | 1457 | InstanceBase = capture(RefExpr->getBaseExpr()); |
Aaron Ballman | 72f6563 | 2017-11-03 20:09:17 +0000 | [diff] [blame] | 1458 | llvm::for_each(CallArgs, [this](Expr *&Arg) { Arg = capture(Arg); }); |
Alexey Bataev | f763027 | 2015-11-25 12:01:00 +0000 | [diff] [blame] | 1459 | syntacticBase = Rebuilder(S, [=](Expr *, unsigned Idx) -> Expr * { |
| 1460 | switch (Idx) { |
| 1461 | case 0: |
| 1462 | return InstanceBase; |
| 1463 | default: |
| 1464 | assert(Idx <= CallArgs.size()); |
| 1465 | return CallArgs[Idx - 1]; |
| 1466 | } |
| 1467 | }).rebuild(syntacticBase); |
John McCall | 5e77d76 | 2013-04-16 07:28:30 +0000 | [diff] [blame] | 1468 | |
| 1469 | return syntacticBase; |
| 1470 | } |
| 1471 | |
| 1472 | ExprResult MSPropertyOpBuilder::buildGet() { |
| 1473 | if (!RefExpr->getPropertyDecl()->hasGetter()) { |
Aaron Ballman | 213cf41 | 2013-12-26 16:35:04 +0000 | [diff] [blame] | 1474 | S.Diag(RefExpr->getMemberLoc(), diag::err_no_accessor_for_property) |
Aaron Ballman | 1bda459 | 2014-01-03 01:09:27 +0000 | [diff] [blame] | 1475 | << 0 /* getter */ << RefExpr->getPropertyDecl(); |
John McCall | 5e77d76 | 2013-04-16 07:28:30 +0000 | [diff] [blame] | 1476 | return ExprError(); |
| 1477 | } |
| 1478 | |
| 1479 | UnqualifiedId GetterName; |
| 1480 | IdentifierInfo *II = RefExpr->getPropertyDecl()->getGetterId(); |
| 1481 | GetterName.setIdentifier(II, RefExpr->getMemberLoc()); |
| 1482 | CXXScopeSpec SS; |
| 1483 | SS.Adopt(RefExpr->getQualifierLoc()); |
Alexey Bataev | 6910347 | 2015-10-14 04:05:42 +0000 | [diff] [blame] | 1484 | ExprResult GetterExpr = |
| 1485 | S.ActOnMemberAccessExpr(S.getCurScope(), InstanceBase, SourceLocation(), |
| 1486 | RefExpr->isArrow() ? tok::arrow : tok::period, SS, |
| 1487 | SourceLocation(), GetterName, nullptr); |
John McCall | 5e77d76 | 2013-04-16 07:28:30 +0000 | [diff] [blame] | 1488 | if (GetterExpr.isInvalid()) { |
Aaron Ballman | 9e35bfe | 2013-12-26 15:46:38 +0000 | [diff] [blame] | 1489 | S.Diag(RefExpr->getMemberLoc(), |
Richard Smith | f881267 | 2016-12-02 22:38:31 +0000 | [diff] [blame] | 1490 | diag::err_cannot_find_suitable_accessor) << 0 /* getter */ |
Aaron Ballman | 1bda459 | 2014-01-03 01:09:27 +0000 | [diff] [blame] | 1491 | << RefExpr->getPropertyDecl(); |
John McCall | 5e77d76 | 2013-04-16 07:28:30 +0000 | [diff] [blame] | 1492 | return ExprError(); |
| 1493 | } |
| 1494 | |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 1495 | return S.ActOnCallExpr(S.getCurScope(), GetterExpr.get(), |
Alexey Bataev | f763027 | 2015-11-25 12:01:00 +0000 | [diff] [blame] | 1496 | RefExpr->getSourceRange().getBegin(), CallArgs, |
John McCall | 5e77d76 | 2013-04-16 07:28:30 +0000 | [diff] [blame] | 1497 | RefExpr->getSourceRange().getEnd()); |
| 1498 | } |
| 1499 | |
| 1500 | ExprResult MSPropertyOpBuilder::buildSet(Expr *op, SourceLocation sl, |
| 1501 | bool captureSetValueAsResult) { |
| 1502 | if (!RefExpr->getPropertyDecl()->hasSetter()) { |
Aaron Ballman | 213cf41 | 2013-12-26 16:35:04 +0000 | [diff] [blame] | 1503 | S.Diag(RefExpr->getMemberLoc(), diag::err_no_accessor_for_property) |
Aaron Ballman | 1bda459 | 2014-01-03 01:09:27 +0000 | [diff] [blame] | 1504 | << 1 /* setter */ << RefExpr->getPropertyDecl(); |
John McCall | 5e77d76 | 2013-04-16 07:28:30 +0000 | [diff] [blame] | 1505 | return ExprError(); |
| 1506 | } |
| 1507 | |
| 1508 | UnqualifiedId SetterName; |
| 1509 | IdentifierInfo *II = RefExpr->getPropertyDecl()->getSetterId(); |
| 1510 | SetterName.setIdentifier(II, RefExpr->getMemberLoc()); |
| 1511 | CXXScopeSpec SS; |
| 1512 | SS.Adopt(RefExpr->getQualifierLoc()); |
Alexey Bataev | 6910347 | 2015-10-14 04:05:42 +0000 | [diff] [blame] | 1513 | ExprResult SetterExpr = |
| 1514 | S.ActOnMemberAccessExpr(S.getCurScope(), InstanceBase, SourceLocation(), |
| 1515 | RefExpr->isArrow() ? tok::arrow : tok::period, SS, |
| 1516 | SourceLocation(), SetterName, nullptr); |
John McCall | 5e77d76 | 2013-04-16 07:28:30 +0000 | [diff] [blame] | 1517 | if (SetterExpr.isInvalid()) { |
Aaron Ballman | 9e35bfe | 2013-12-26 15:46:38 +0000 | [diff] [blame] | 1518 | S.Diag(RefExpr->getMemberLoc(), |
Richard Smith | f881267 | 2016-12-02 22:38:31 +0000 | [diff] [blame] | 1519 | diag::err_cannot_find_suitable_accessor) << 1 /* setter */ |
Aaron Ballman | 1bda459 | 2014-01-03 01:09:27 +0000 | [diff] [blame] | 1520 | << RefExpr->getPropertyDecl(); |
John McCall | 5e77d76 | 2013-04-16 07:28:30 +0000 | [diff] [blame] | 1521 | return ExprError(); |
| 1522 | } |
| 1523 | |
Alexey Bataev | f763027 | 2015-11-25 12:01:00 +0000 | [diff] [blame] | 1524 | SmallVector<Expr*, 4> ArgExprs; |
| 1525 | ArgExprs.append(CallArgs.begin(), CallArgs.end()); |
John McCall | 5e77d76 | 2013-04-16 07:28:30 +0000 | [diff] [blame] | 1526 | ArgExprs.push_back(op); |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 1527 | return S.ActOnCallExpr(S.getCurScope(), SetterExpr.get(), |
John McCall | 5e77d76 | 2013-04-16 07:28:30 +0000 | [diff] [blame] | 1528 | RefExpr->getSourceRange().getBegin(), ArgExprs, |
| 1529 | op->getSourceRange().getEnd()); |
| 1530 | } |
| 1531 | |
| 1532 | //===----------------------------------------------------------------------===// |
John McCall | fe96e0b | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 1533 | // General Sema routines. |
| 1534 | //===----------------------------------------------------------------------===// |
| 1535 | |
| 1536 | ExprResult Sema::checkPseudoObjectRValue(Expr *E) { |
| 1537 | Expr *opaqueRef = E->IgnoreParens(); |
| 1538 | if (ObjCPropertyRefExpr *refExpr |
| 1539 | = dyn_cast<ObjCPropertyRefExpr>(opaqueRef)) { |
Akira Hatanaka | 797afe3 | 2018-03-20 01:47:58 +0000 | [diff] [blame] | 1540 | ObjCPropertyOpBuilder builder(*this, refExpr, true); |
John McCall | fe96e0b | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 1541 | return builder.buildRValueOperation(E); |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 1542 | } |
| 1543 | else if (ObjCSubscriptRefExpr *refExpr |
| 1544 | = dyn_cast<ObjCSubscriptRefExpr>(opaqueRef)) { |
Akira Hatanaka | 797afe3 | 2018-03-20 01:47:58 +0000 | [diff] [blame] | 1545 | ObjCSubscriptOpBuilder builder(*this, refExpr, true); |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 1546 | return builder.buildRValueOperation(E); |
John McCall | 5e77d76 | 2013-04-16 07:28:30 +0000 | [diff] [blame] | 1547 | } else if (MSPropertyRefExpr *refExpr |
| 1548 | = dyn_cast<MSPropertyRefExpr>(opaqueRef)) { |
Akira Hatanaka | 797afe3 | 2018-03-20 01:47:58 +0000 | [diff] [blame] | 1549 | MSPropertyOpBuilder builder(*this, refExpr, true); |
John McCall | 5e77d76 | 2013-04-16 07:28:30 +0000 | [diff] [blame] | 1550 | return builder.buildRValueOperation(E); |
Alexey Bataev | f763027 | 2015-11-25 12:01:00 +0000 | [diff] [blame] | 1551 | } else if (MSPropertySubscriptExpr *RefExpr = |
| 1552 | dyn_cast<MSPropertySubscriptExpr>(opaqueRef)) { |
Akira Hatanaka | 797afe3 | 2018-03-20 01:47:58 +0000 | [diff] [blame] | 1553 | MSPropertyOpBuilder Builder(*this, RefExpr, true); |
Alexey Bataev | f763027 | 2015-11-25 12:01:00 +0000 | [diff] [blame] | 1554 | return Builder.buildRValueOperation(E); |
John McCall | fe96e0b | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 1555 | } else { |
| 1556 | llvm_unreachable("unknown pseudo-object kind!"); |
| 1557 | } |
| 1558 | } |
| 1559 | |
| 1560 | /// Check an increment or decrement of a pseudo-object expression. |
| 1561 | ExprResult Sema::checkPseudoObjectIncDec(Scope *Sc, SourceLocation opcLoc, |
| 1562 | UnaryOperatorKind opcode, Expr *op) { |
| 1563 | // Do nothing if the operand is dependent. |
| 1564 | if (op->isTypeDependent()) |
| 1565 | return new (Context) UnaryOperator(op, opcode, Context.DependentTy, |
Aaron Ballman | a503855 | 2018-01-09 13:07:03 +0000 | [diff] [blame] | 1566 | VK_RValue, OK_Ordinary, opcLoc, false); |
John McCall | fe96e0b | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 1567 | |
| 1568 | assert(UnaryOperator::isIncrementDecrementOp(opcode)); |
| 1569 | Expr *opaqueRef = op->IgnoreParens(); |
| 1570 | if (ObjCPropertyRefExpr *refExpr |
| 1571 | = dyn_cast<ObjCPropertyRefExpr>(opaqueRef)) { |
Akira Hatanaka | 797afe3 | 2018-03-20 01:47:58 +0000 | [diff] [blame] | 1572 | ObjCPropertyOpBuilder builder(*this, refExpr, false); |
John McCall | fe96e0b | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 1573 | return builder.buildIncDecOperation(Sc, opcLoc, opcode, op); |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 1574 | } else if (isa<ObjCSubscriptRefExpr>(opaqueRef)) { |
| 1575 | Diag(opcLoc, diag::err_illegal_container_subscripting_op); |
| 1576 | return ExprError(); |
John McCall | 5e77d76 | 2013-04-16 07:28:30 +0000 | [diff] [blame] | 1577 | } else if (MSPropertyRefExpr *refExpr |
| 1578 | = dyn_cast<MSPropertyRefExpr>(opaqueRef)) { |
Akira Hatanaka | 797afe3 | 2018-03-20 01:47:58 +0000 | [diff] [blame] | 1579 | MSPropertyOpBuilder builder(*this, refExpr, false); |
John McCall | 5e77d76 | 2013-04-16 07:28:30 +0000 | [diff] [blame] | 1580 | return builder.buildIncDecOperation(Sc, opcLoc, opcode, op); |
Alexey Bataev | f763027 | 2015-11-25 12:01:00 +0000 | [diff] [blame] | 1581 | } else if (MSPropertySubscriptExpr *RefExpr |
| 1582 | = dyn_cast<MSPropertySubscriptExpr>(opaqueRef)) { |
Akira Hatanaka | 797afe3 | 2018-03-20 01:47:58 +0000 | [diff] [blame] | 1583 | MSPropertyOpBuilder Builder(*this, RefExpr, false); |
Alexey Bataev | f763027 | 2015-11-25 12:01:00 +0000 | [diff] [blame] | 1584 | return Builder.buildIncDecOperation(Sc, opcLoc, opcode, op); |
John McCall | fe96e0b | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 1585 | } else { |
| 1586 | llvm_unreachable("unknown pseudo-object kind!"); |
| 1587 | } |
| 1588 | } |
| 1589 | |
| 1590 | ExprResult Sema::checkPseudoObjectAssignment(Scope *S, SourceLocation opcLoc, |
| 1591 | BinaryOperatorKind opcode, |
| 1592 | Expr *LHS, Expr *RHS) { |
| 1593 | // Do nothing if either argument is dependent. |
| 1594 | if (LHS->isTypeDependent() || RHS->isTypeDependent()) |
| 1595 | return new (Context) BinaryOperator(LHS, RHS, opcode, Context.DependentTy, |
Adam Nemet | 484aa45 | 2017-03-27 19:17:25 +0000 | [diff] [blame] | 1596 | VK_RValue, OK_Ordinary, opcLoc, |
| 1597 | FPOptions()); |
John McCall | fe96e0b | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 1598 | |
| 1599 | // Filter out non-overload placeholder types in the RHS. |
John McCall | d5c98ae | 2011-11-15 01:35:18 +0000 | [diff] [blame] | 1600 | if (RHS->getType()->isNonOverloadPlaceholderType()) { |
| 1601 | ExprResult result = CheckPlaceholderExpr(RHS); |
| 1602 | if (result.isInvalid()) return ExprError(); |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 1603 | RHS = result.get(); |
John McCall | fe96e0b | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 1604 | } |
| 1605 | |
Akira Hatanaka | 797afe3 | 2018-03-20 01:47:58 +0000 | [diff] [blame] | 1606 | bool IsSimpleAssign = opcode == BO_Assign; |
John McCall | fe96e0b | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 1607 | Expr *opaqueRef = LHS->IgnoreParens(); |
| 1608 | if (ObjCPropertyRefExpr *refExpr |
| 1609 | = dyn_cast<ObjCPropertyRefExpr>(opaqueRef)) { |
Akira Hatanaka | 797afe3 | 2018-03-20 01:47:58 +0000 | [diff] [blame] | 1610 | ObjCPropertyOpBuilder builder(*this, refExpr, IsSimpleAssign); |
John McCall | fe96e0b | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 1611 | return builder.buildAssignmentOperation(S, opcLoc, opcode, LHS, RHS); |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 1612 | } else if (ObjCSubscriptRefExpr *refExpr |
| 1613 | = dyn_cast<ObjCSubscriptRefExpr>(opaqueRef)) { |
Akira Hatanaka | 797afe3 | 2018-03-20 01:47:58 +0000 | [diff] [blame] | 1614 | ObjCSubscriptOpBuilder builder(*this, refExpr, IsSimpleAssign); |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 1615 | return builder.buildAssignmentOperation(S, opcLoc, opcode, LHS, RHS); |
John McCall | 5e77d76 | 2013-04-16 07:28:30 +0000 | [diff] [blame] | 1616 | } else if (MSPropertyRefExpr *refExpr |
| 1617 | = dyn_cast<MSPropertyRefExpr>(opaqueRef)) { |
Akira Hatanaka | 797afe3 | 2018-03-20 01:47:58 +0000 | [diff] [blame] | 1618 | MSPropertyOpBuilder builder(*this, refExpr, IsSimpleAssign); |
Alexey Bataev | f763027 | 2015-11-25 12:01:00 +0000 | [diff] [blame] | 1619 | return builder.buildAssignmentOperation(S, opcLoc, opcode, LHS, RHS); |
| 1620 | } else if (MSPropertySubscriptExpr *RefExpr |
| 1621 | = dyn_cast<MSPropertySubscriptExpr>(opaqueRef)) { |
Akira Hatanaka | 797afe3 | 2018-03-20 01:47:58 +0000 | [diff] [blame] | 1622 | MSPropertyOpBuilder Builder(*this, RefExpr, IsSimpleAssign); |
Alexey Bataev | f763027 | 2015-11-25 12:01:00 +0000 | [diff] [blame] | 1623 | return Builder.buildAssignmentOperation(S, opcLoc, opcode, LHS, RHS); |
John McCall | fe96e0b | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 1624 | } else { |
| 1625 | llvm_unreachable("unknown pseudo-object kind!"); |
| 1626 | } |
| 1627 | } |
John McCall | e929082 | 2011-11-30 04:42:31 +0000 | [diff] [blame] | 1628 | |
| 1629 | /// Given a pseudo-object reference, rebuild it without the opaque |
| 1630 | /// values. Basically, undo the behavior of rebuildAndCaptureObject. |
| 1631 | /// This should never operate in-place. |
| 1632 | static Expr *stripOpaqueValuesFromPseudoObjectRef(Sema &S, Expr *E) { |
Alexey Bataev | f763027 | 2015-11-25 12:01:00 +0000 | [diff] [blame] | 1633 | return Rebuilder(S, |
| 1634 | [=](Expr *E, unsigned) -> Expr * { |
| 1635 | return cast<OpaqueValueExpr>(E)->getSourceExpr(); |
| 1636 | }) |
| 1637 | .rebuild(E); |
John McCall | e929082 | 2011-11-30 04:42:31 +0000 | [diff] [blame] | 1638 | } |
| 1639 | |
| 1640 | /// Given a pseudo-object expression, recreate what it looks like |
| 1641 | /// syntactically without the attendant OpaqueValueExprs. |
| 1642 | /// |
| 1643 | /// This is a hack which should be removed when TreeTransform is |
| 1644 | /// capable of rebuilding a tree without stripping implicit |
| 1645 | /// operations. |
| 1646 | Expr *Sema::recreateSyntacticForm(PseudoObjectExpr *E) { |
Malcolm Parsons | fab3680 | 2018-04-16 08:31:08 +0000 | [diff] [blame] | 1647 | Expr *syntax = E->getSyntacticForm(); |
| 1648 | if (UnaryOperator *uop = dyn_cast<UnaryOperator>(syntax)) { |
| 1649 | Expr *op = stripOpaqueValuesFromPseudoObjectRef(*this, uop->getSubExpr()); |
| 1650 | return new (Context) UnaryOperator( |
| 1651 | op, uop->getOpcode(), uop->getType(), uop->getValueKind(), |
| 1652 | uop->getObjectKind(), uop->getOperatorLoc(), uop->canOverflow()); |
| 1653 | } else if (CompoundAssignOperator *cop |
| 1654 | = dyn_cast<CompoundAssignOperator>(syntax)) { |
| 1655 | Expr *lhs = stripOpaqueValuesFromPseudoObjectRef(*this, cop->getLHS()); |
John McCall | e929082 | 2011-11-30 04:42:31 +0000 | [diff] [blame] | 1656 | Expr *rhs = cast<OpaqueValueExpr>(cop->getRHS())->getSourceExpr(); |
| 1657 | return new (Context) CompoundAssignOperator(lhs, rhs, cop->getOpcode(), |
| 1658 | cop->getType(), |
| 1659 | cop->getValueKind(), |
| 1660 | cop->getObjectKind(), |
| 1661 | cop->getComputationLHSType(), |
| 1662 | cop->getComputationResultType(), |
Adam Nemet | 484aa45 | 2017-03-27 19:17:25 +0000 | [diff] [blame] | 1663 | cop->getOperatorLoc(), |
| 1664 | FPOptions()); |
John McCall | e929082 | 2011-11-30 04:42:31 +0000 | [diff] [blame] | 1665 | } else if (BinaryOperator *bop = dyn_cast<BinaryOperator>(syntax)) { |
| 1666 | Expr *lhs = stripOpaqueValuesFromPseudoObjectRef(*this, bop->getLHS()); |
| 1667 | Expr *rhs = cast<OpaqueValueExpr>(bop->getRHS())->getSourceExpr(); |
| 1668 | return new (Context) BinaryOperator(lhs, rhs, bop->getOpcode(), |
| 1669 | bop->getType(), bop->getValueKind(), |
| 1670 | bop->getObjectKind(), |
Adam Nemet | 484aa45 | 2017-03-27 19:17:25 +0000 | [diff] [blame] | 1671 | bop->getOperatorLoc(), FPOptions()); |
John McCall | e929082 | 2011-11-30 04:42:31 +0000 | [diff] [blame] | 1672 | } else { |
| 1673 | assert(syntax->hasPlaceholderType(BuiltinType::PseudoObject)); |
| 1674 | return stripOpaqueValuesFromPseudoObjectRef(*this, syntax); |
| 1675 | } |
| 1676 | } |