blob: 050512fbbecdb3d3792a59e8f4cd5c16e6334e19 [file] [log] [blame]
Argyrios Kyrtzidis7196d062011-06-21 20:20:39 +00001//===--- TransProperties.cpp - Tranformations to ARC mode -----------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
Argyrios Kyrtzidis14c4b442011-07-13 19:22:00 +000010// rewriteProperties:
Argyrios Kyrtzidis7196d062011-06-21 20:20:39 +000011//
Argyrios Kyrtzidis14c4b442011-07-13 19:22:00 +000012// - Adds strong/weak/unsafe_unretained ownership specifier to properties that
13// are missing one.
14// - Migrates properties from (retain) to (strong) and (assign) to
15// (unsafe_unretained/weak).
16// - If a property is synthesized, adds the ownership specifier in the ivar
17// backing the property.
Argyrios Kyrtzidis7196d062011-06-21 20:20:39 +000018//
19// @interface Foo : NSObject {
20// NSObject *x;
21// }
22// @property (assign) id x;
23// @end
24// ---->
25// @interface Foo : NSObject {
26// NSObject *__weak x;
27// }
28// @property (weak) id x;
29// @end
30//
31//===----------------------------------------------------------------------===//
32
33#include "Transforms.h"
34#include "Internals.h"
35#include "clang/Sema/SemaDiagnostic.h"
36#include "clang/Basic/SourceManager.h"
37#include "clang/Lex/Lexer.h"
Argyrios Kyrtzidis14c4b442011-07-13 19:22:00 +000038#include <map>
Argyrios Kyrtzidis7196d062011-06-21 20:20:39 +000039
40using namespace clang;
41using namespace arcmt;
42using namespace trans;
Argyrios Kyrtzidis7196d062011-06-21 20:20:39 +000043
44namespace {
45
Argyrios Kyrtzidis14c4b442011-07-13 19:22:00 +000046class PropertiesRewriter {
Argyrios Kyrtzidisb0e1e122011-11-07 18:46:46 +000047 MigrationContext &MigrateCtx;
Argyrios Kyrtzidis7196d062011-06-21 20:20:39 +000048 MigrationPass &Pass;
Argyrios Kyrtzidis18fd0c62011-07-27 05:28:18 +000049 ObjCImplementationDecl *CurImplD;
Argyrios Kyrtzidis44679012011-10-18 19:49:19 +000050
51 enum PropActionKind {
52 PropAction_None,
53 PropAction_RetainToStrong,
54 PropAction_RetainRemoved,
Argyrios Kyrtzidisb0e1e122011-11-07 18:46:46 +000055 PropAction_AssignRemoved,
Argyrios Kyrtzidis44679012011-10-18 19:49:19 +000056 PropAction_AssignRewritten,
57 PropAction_MaybeAddStrong,
58 PropAction_MaybeAddWeakOrUnsafe
59 };
Argyrios Kyrtzidis14c4b442011-07-13 19:22:00 +000060
Argyrios Kyrtzidis7196d062011-06-21 20:20:39 +000061 struct PropData {
62 ObjCPropertyDecl *PropD;
63 ObjCIvarDecl *IvarD;
Argyrios Kyrtzidis14c4b442011-07-13 19:22:00 +000064 ObjCPropertyImplDecl *ImplD;
65
66 PropData(ObjCPropertyDecl *propD) : PropD(propD), IvarD(0), ImplD(0) { }
Argyrios Kyrtzidis7196d062011-06-21 20:20:39 +000067 };
68
Chris Lattner5f9e2722011-07-23 10:55:15 +000069 typedef SmallVector<PropData, 2> PropsTy;
Argyrios Kyrtzidis14c4b442011-07-13 19:22:00 +000070 typedef std::map<unsigned, PropsTy> AtPropDeclsTy;
71 AtPropDeclsTy AtProps;
Argyrios Kyrtzidis44679012011-10-18 19:49:19 +000072 llvm::DenseMap<IdentifierInfo *, PropActionKind> ActionOnProp;
Argyrios Kyrtzidis7196d062011-06-21 20:20:39 +000073
74public:
Argyrios Kyrtzidisb0e1e122011-11-07 18:46:46 +000075 explicit PropertiesRewriter(MigrationContext &MigrateCtx)
76 : MigrateCtx(MigrateCtx), Pass(MigrateCtx.Pass) { }
Argyrios Kyrtzidis7196d062011-06-21 20:20:39 +000077
Argyrios Kyrtzidis44679012011-10-18 19:49:19 +000078 static void collectProperties(ObjCContainerDecl *D, AtPropDeclsTy &AtProps) {
79 for (ObjCInterfaceDecl::prop_iterator
80 propI = D->prop_begin(),
81 propE = D->prop_end(); propI != propE; ++propI) {
82 if (propI->getAtLoc().isInvalid())
83 continue;
84 PropsTy &props = AtProps[propI->getAtLoc().getRawEncoding()];
85 props.push_back(*propI);
86 }
87 }
88
Argyrios Kyrtzidis7196d062011-06-21 20:20:39 +000089 void doTransform(ObjCImplementationDecl *D) {
Argyrios Kyrtzidis18fd0c62011-07-27 05:28:18 +000090 CurImplD = D;
Argyrios Kyrtzidis14c4b442011-07-13 19:22:00 +000091 ObjCInterfaceDecl *iface = D->getClassInterface();
92 if (!iface)
93 return;
Argyrios Kyrtzidis7196d062011-06-21 20:20:39 +000094
Argyrios Kyrtzidis44679012011-10-18 19:49:19 +000095 collectProperties(iface, AtProps);
Argyrios Kyrtzidis7196d062011-06-21 20:20:39 +000096
97 typedef DeclContext::specific_decl_iterator<ObjCPropertyImplDecl>
98 prop_impl_iterator;
99 for (prop_impl_iterator
100 I = prop_impl_iterator(D->decls_begin()),
101 E = prop_impl_iterator(D->decls_end()); I != E; ++I) {
Argyrios Kyrtzidis14c4b442011-07-13 19:22:00 +0000102 ObjCPropertyImplDecl *implD = *I;
103 if (implD->getPropertyImplementation() != ObjCPropertyImplDecl::Synthesize)
104 continue;
105 ObjCPropertyDecl *propD = implD->getPropertyDecl();
106 if (!propD || propD->isInvalidDecl())
107 continue;
108 ObjCIvarDecl *ivarD = implD->getPropertyIvarDecl();
109 if (!ivarD || ivarD->isInvalidDecl())
110 continue;
111 unsigned rawAtLoc = propD->getAtLoc().getRawEncoding();
112 AtPropDeclsTy::iterator findAtLoc = AtProps.find(rawAtLoc);
113 if (findAtLoc == AtProps.end())
114 continue;
115
116 PropsTy &props = findAtLoc->second;
Argyrios Kyrtzidis7196d062011-06-21 20:20:39 +0000117 for (PropsTy::iterator I = props.begin(), E = props.end(); I != E; ++I) {
118 if (I->PropD == propD) {
119 I->IvarD = ivarD;
Argyrios Kyrtzidis14c4b442011-07-13 19:22:00 +0000120 I->ImplD = implD;
121 break;
Argyrios Kyrtzidis7196d062011-06-21 20:20:39 +0000122 }
123 }
124 }
125
Argyrios Kyrtzidis14c4b442011-07-13 19:22:00 +0000126 for (AtPropDeclsTy::iterator
127 I = AtProps.begin(), E = AtProps.end(); I != E; ++I) {
128 SourceLocation atLoc = SourceLocation::getFromRawEncoding(I->first);
129 PropsTy &props = I->second;
Argyrios Kyrtzidis1d5fb8f2011-11-06 18:58:07 +0000130 if (!getPropertyType(props)->isObjCRetainableType())
Argyrios Kyrtzidis14c4b442011-07-13 19:22:00 +0000131 continue;
Argyrios Kyrtzidisbf8455c2011-11-07 18:40:32 +0000132 if (hasIvarWithExplicitARCOwnership(props))
Argyrios Kyrtzidis14c4b442011-07-13 19:22:00 +0000133 continue;
134
135 Transaction Trans(Pass.TA);
136 rewriteProperty(props, atLoc);
137 }
Argyrios Kyrtzidis44679012011-10-18 19:49:19 +0000138
139 AtPropDeclsTy AtExtProps;
140 // Look through extensions.
141 for (ObjCCategoryDecl *Cat = iface->getCategoryList();
142 Cat; Cat = Cat->getNextClassCategory())
143 if (Cat->IsClassExtension())
144 collectProperties(Cat, AtExtProps);
145
146 for (AtPropDeclsTy::iterator
147 I = AtExtProps.begin(), E = AtExtProps.end(); I != E; ++I) {
148 SourceLocation atLoc = SourceLocation::getFromRawEncoding(I->first);
149 PropsTy &props = I->second;
150 Transaction Trans(Pass.TA);
151 doActionForExtensionProp(props, atLoc);
152 }
Argyrios Kyrtzidis7196d062011-06-21 20:20:39 +0000153 }
154
155private:
Argyrios Kyrtzidis44679012011-10-18 19:49:19 +0000156 void doPropAction(PropActionKind kind,
157 PropsTy &props, SourceLocation atLoc,
158 bool markAction = true) {
159 if (markAction)
160 for (PropsTy::iterator I = props.begin(), E = props.end(); I != E; ++I)
161 ActionOnProp[I->PropD->getIdentifier()] = kind;
162
163 switch (kind) {
164 case PropAction_None:
165 return;
166 case PropAction_RetainToStrong:
167 rewriteAttribute("retain", "strong", atLoc);
168 return;
169 case PropAction_RetainRemoved:
170 removeAttribute("retain", atLoc);
171 return;
Argyrios Kyrtzidisb0e1e122011-11-07 18:46:46 +0000172 case PropAction_AssignRemoved:
173 return removeAssignForDefaultStrong(props, atLoc);
Argyrios Kyrtzidis44679012011-10-18 19:49:19 +0000174 case PropAction_AssignRewritten:
175 return rewriteAssign(props, atLoc);
176 case PropAction_MaybeAddStrong:
177 return maybeAddStrongAttr(props, atLoc);
178 case PropAction_MaybeAddWeakOrUnsafe:
179 return maybeAddWeakOrUnsafeUnretainedAttr(props, atLoc);
180 }
181 }
182
183 void doActionForExtensionProp(PropsTy &props, SourceLocation atLoc) {
184 llvm::DenseMap<IdentifierInfo *, PropActionKind>::iterator I;
185 I = ActionOnProp.find(props[0].PropD->getIdentifier());
186 if (I == ActionOnProp.end())
187 return;
188
189 doPropAction(I->second, props, atLoc, false);
190 }
191
192 void rewriteProperty(PropsTy &props, SourceLocation atLoc) {
Argyrios Kyrtzidis14c4b442011-07-13 19:22:00 +0000193 ObjCPropertyDecl::PropertyAttributeKind propAttrs = getPropertyAttrs(props);
194
195 if (propAttrs & (ObjCPropertyDecl::OBJC_PR_copy |
196 ObjCPropertyDecl::OBJC_PR_unsafe_unretained |
197 ObjCPropertyDecl::OBJC_PR_strong |
198 ObjCPropertyDecl::OBJC_PR_weak))
199 return;
200
201 if (propAttrs & ObjCPropertyDecl::OBJC_PR_retain) {
Argyrios Kyrtzidis01b2b9b2011-10-17 23:14:16 +0000202 if (propAttrs & ObjCPropertyDecl::OBJC_PR_readonly)
Argyrios Kyrtzidis44679012011-10-18 19:49:19 +0000203 return doPropAction(PropAction_RetainToStrong, props, atLoc);
Argyrios Kyrtzidis01b2b9b2011-10-17 23:14:16 +0000204 else
Argyrios Kyrtzidis44679012011-10-18 19:49:19 +0000205 // strong is the default.
206 return doPropAction(PropAction_RetainRemoved, props, atLoc);
Argyrios Kyrtzidis14c4b442011-07-13 19:22:00 +0000207 }
208
Argyrios Kyrtzidisb0e1e122011-11-07 18:46:46 +0000209 bool HasIvarAssignedAPlusOneObject = hasIvarAssignedAPlusOneObject(props);
210
Argyrios Kyrtzidis18fd0c62011-07-27 05:28:18 +0000211 if (propAttrs & ObjCPropertyDecl::OBJC_PR_assign) {
Argyrios Kyrtzidisb0e1e122011-11-07 18:46:46 +0000212 if (HasIvarAssignedAPlusOneObject ||
213 (Pass.isGCMigration() && !hasGCWeak(props, atLoc))) {
214 return doPropAction(PropAction_AssignRemoved, props, atLoc);
Argyrios Kyrtzidis18fd0c62011-07-27 05:28:18 +0000215 }
Argyrios Kyrtzidis44679012011-10-18 19:49:19 +0000216 return doPropAction(PropAction_AssignRewritten, props, atLoc);
Argyrios Kyrtzidis18fd0c62011-07-27 05:28:18 +0000217 }
218
Argyrios Kyrtzidisb0e1e122011-11-07 18:46:46 +0000219 if (HasIvarAssignedAPlusOneObject ||
220 (Pass.isGCMigration() && !hasGCWeak(props, atLoc)))
Argyrios Kyrtzidis44679012011-10-18 19:49:19 +0000221 return doPropAction(PropAction_MaybeAddStrong, props, atLoc);
Argyrios Kyrtzidis14c4b442011-07-13 19:22:00 +0000222
Argyrios Kyrtzidis44679012011-10-18 19:49:19 +0000223 return doPropAction(PropAction_MaybeAddWeakOrUnsafe, props, atLoc);
Argyrios Kyrtzidis14c4b442011-07-13 19:22:00 +0000224 }
225
Argyrios Kyrtzidisb0e1e122011-11-07 18:46:46 +0000226 void removeAssignForDefaultStrong(PropsTy &props,
227 SourceLocation atLoc) const {
228 removeAttribute("retain", atLoc);
229 if (!removeAttribute("assign", atLoc))
230 return;
231
232 for (PropsTy::iterator I = props.begin(), E = props.end(); I != E; ++I) {
233 if (I->ImplD)
234 Pass.TA.clearDiagnostic(diag::err_arc_assign_property_ownership,
235 I->ImplD->getLocation());
236 }
237 }
238
Argyrios Kyrtzidis14c4b442011-07-13 19:22:00 +0000239 void rewriteAssign(PropsTy &props, SourceLocation atLoc) const {
Argyrios Kyrtzidisb0e1e122011-11-07 18:46:46 +0000240 bool canUseWeak = canApplyWeak(Pass.Ctx, getPropertyType(props),
241 /*AllowOnUnknownClass=*/Pass.isGCMigration());
Argyrios Kyrtzidis14c4b442011-07-13 19:22:00 +0000242
243 bool rewroteAttr = rewriteAttribute("assign",
244 canUseWeak ? "weak" : "unsafe_unretained",
245 atLoc);
246 if (!rewroteAttr)
247 canUseWeak = false;
248
249 for (PropsTy::iterator I = props.begin(), E = props.end(); I != E; ++I) {
250 if (isUserDeclared(I->IvarD))
251 Pass.TA.insert(I->IvarD->getLocation(),
252 canUseWeak ? "__weak " : "__unsafe_unretained ");
253 if (I->ImplD)
254 Pass.TA.clearDiagnostic(diag::err_arc_assign_property_ownership,
255 I->ImplD->getLocation());
256 }
257 }
258
259 void maybeAddWeakOrUnsafeUnretainedAttr(PropsTy &props,
260 SourceLocation atLoc) const {
261 ObjCPropertyDecl::PropertyAttributeKind propAttrs = getPropertyAttrs(props);
Argyrios Kyrtzidis14c4b442011-07-13 19:22:00 +0000262
Argyrios Kyrtzidisb0e1e122011-11-07 18:46:46 +0000263 bool canUseWeak = canApplyWeak(Pass.Ctx, getPropertyType(props),
264 /*AllowOnUnknownClass=*/Pass.isGCMigration());
Argyrios Kyrtzidis18fd0c62011-07-27 05:28:18 +0000265 if (!(propAttrs & ObjCPropertyDecl::OBJC_PR_readonly) ||
266 !hasAllIvarsBacked(props)) {
267 bool addedAttr = addAttribute(canUseWeak ? "weak" : "unsafe_unretained",
268 atLoc);
269 if (!addedAttr)
270 canUseWeak = false;
271 }
Argyrios Kyrtzidis14c4b442011-07-13 19:22:00 +0000272
273 for (PropsTy::iterator I = props.begin(), E = props.end(); I != E; ++I) {
274 if (isUserDeclared(I->IvarD))
275 Pass.TA.insert(I->IvarD->getLocation(),
276 canUseWeak ? "__weak " : "__unsafe_unretained ");
277 if (I->ImplD) {
278 Pass.TA.clearDiagnostic(diag::err_arc_assign_property_ownership,
279 I->ImplD->getLocation());
280 Pass.TA.clearDiagnostic(
281 diag::err_arc_objc_property_default_assign_on_object,
282 I->ImplD->getLocation());
283 }
284 }
285 }
286
Argyrios Kyrtzidis18fd0c62011-07-27 05:28:18 +0000287 void maybeAddStrongAttr(PropsTy &props, SourceLocation atLoc) const {
288 ObjCPropertyDecl::PropertyAttributeKind propAttrs = getPropertyAttrs(props);
289
290 if (!(propAttrs & ObjCPropertyDecl::OBJC_PR_readonly) ||
291 !hasAllIvarsBacked(props)) {
292 addAttribute("strong", atLoc);
293 }
294
295 for (PropsTy::iterator I = props.begin(), E = props.end(); I != E; ++I) {
296 if (I->ImplD) {
297 Pass.TA.clearDiagnostic(diag::err_arc_assign_property_ownership,
298 I->ImplD->getLocation());
299 Pass.TA.clearDiagnostic(
300 diag::err_arc_objc_property_default_assign_on_object,
301 I->ImplD->getLocation());
302 }
303 }
304 }
305
Argyrios Kyrtzidis01b2b9b2011-10-17 23:14:16 +0000306 bool removeAttribute(StringRef fromAttr, SourceLocation atLoc) const {
307 return rewriteAttribute(fromAttr, StringRef(), atLoc);
308 }
309
Chris Lattner5f9e2722011-07-23 10:55:15 +0000310 bool rewriteAttribute(StringRef fromAttr, StringRef toAttr,
Argyrios Kyrtzidis14c4b442011-07-13 19:22:00 +0000311 SourceLocation atLoc) const {
Argyrios Kyrtzidisb0e1e122011-11-07 18:46:46 +0000312 return MigrateCtx.rewritePropertyAttribute(fromAttr, toAttr, atLoc);
Argyrios Kyrtzidis14c4b442011-07-13 19:22:00 +0000313 }
314
Chris Lattner5f9e2722011-07-23 10:55:15 +0000315 bool addAttribute(StringRef attr, SourceLocation atLoc) const {
Argyrios Kyrtzidis14c4b442011-07-13 19:22:00 +0000316 if (atLoc.isMacroID())
317 return false;
318
319 SourceManager &SM = Pass.Ctx.getSourceManager();
320
321 // Break down the source location.
322 std::pair<FileID, unsigned> locInfo = SM.getDecomposedLoc(atLoc);
323
324 // Try to load the file buffer.
325 bool invalidTemp = false;
Chris Lattner5f9e2722011-07-23 10:55:15 +0000326 StringRef file = SM.getBufferData(locInfo.first, &invalidTemp);
Argyrios Kyrtzidis14c4b442011-07-13 19:22:00 +0000327 if (invalidTemp)
328 return false;
329
330 const char *tokenBegin = file.data() + locInfo.second;
331
332 // Lex from the start of the given location.
333 Lexer lexer(SM.getLocForStartOfFile(locInfo.first),
334 Pass.Ctx.getLangOptions(),
335 file.begin(), tokenBegin, file.end());
336 Token tok;
337 lexer.LexFromRawLexer(tok);
338 if (tok.isNot(tok::at)) return false;
339 lexer.LexFromRawLexer(tok);
340 if (tok.isNot(tok::raw_identifier)) return false;
Chris Lattner5f9e2722011-07-23 10:55:15 +0000341 if (StringRef(tok.getRawIdentifierData(), tok.getLength())
Argyrios Kyrtzidis14c4b442011-07-13 19:22:00 +0000342 != "property")
343 return false;
344 lexer.LexFromRawLexer(tok);
345
346 if (tok.isNot(tok::l_paren)) {
347 Pass.TA.insert(tok.getLocation(), std::string("(") + attr.str() + ") ");
348 return true;
349 }
350
Argyrios Kyrtzidis7196d062011-06-21 20:20:39 +0000351 lexer.LexFromRawLexer(tok);
352 if (tok.is(tok::r_paren)) {
Argyrios Kyrtzidis14c4b442011-07-13 19:22:00 +0000353 Pass.TA.insert(tok.getLocation(), attr);
354 return true;
355 }
356
357 if (tok.isNot(tok::raw_identifier)) return false;
358
359 Pass.TA.insert(tok.getLocation(), std::string(attr) + ", ");
360 return true;
361 }
362
Argyrios Kyrtzidis18fd0c62011-07-27 05:28:18 +0000363 class PlusOneAssign : public RecursiveASTVisitor<PlusOneAssign> {
364 ObjCIvarDecl *Ivar;
365 public:
366 PlusOneAssign(ObjCIvarDecl *D) : Ivar(D) {}
367
368 bool VisitBinAssign(BinaryOperator *E) {
369 Expr *lhs = E->getLHS()->IgnoreParenImpCasts();
370 if (ObjCIvarRefExpr *RE = dyn_cast<ObjCIvarRefExpr>(lhs)) {
371 if (RE->getDecl() != Ivar)
372 return true;
373
Argyrios Kyrtzidis94a90162011-08-10 21:46:48 +0000374 if (ObjCMessageExpr *
375 ME = dyn_cast<ObjCMessageExpr>(E->getRHS()->IgnoreParenCasts()))
376 if (ME->getMethodFamily() == OMF_retain)
377 return false;
378
Argyrios Kyrtzidis18fd0c62011-07-27 05:28:18 +0000379 ImplicitCastExpr *implCE = dyn_cast<ImplicitCastExpr>(E->getRHS());
380 while (implCE && implCE->getCastKind() == CK_BitCast)
381 implCE = dyn_cast<ImplicitCastExpr>(implCE->getSubExpr());
382
John McCall33e56f32011-09-10 06:18:15 +0000383 if (implCE && implCE->getCastKind() == CK_ARCConsumeObject)
Argyrios Kyrtzidis18fd0c62011-07-27 05:28:18 +0000384 return false;
385 }
386
387 return true;
388 }
389 };
390
391 bool hasIvarAssignedAPlusOneObject(PropsTy &props) const {
392 for (PropsTy::iterator I = props.begin(), E = props.end(); I != E; ++I) {
393 PlusOneAssign oneAssign(I->IvarD);
394 bool notFound = oneAssign.TraverseDecl(CurImplD);
395 if (!notFound)
396 return true;
397 }
398
399 return false;
400 }
401
Argyrios Kyrtzidisbf8455c2011-11-07 18:40:32 +0000402 bool hasIvarWithExplicitARCOwnership(PropsTy &props) const {
403 if (Pass.isGCMigration())
404 return false;
405
Argyrios Kyrtzidis14c4b442011-07-13 19:22:00 +0000406 for (PropsTy::iterator I = props.begin(), E = props.end(); I != E; ++I) {
407 if (isUserDeclared(I->IvarD)) {
408 if (isa<AttributedType>(I->IvarD->getType()))
409 return true;
410 if (I->IvarD->getType().getLocalQualifiers().getObjCLifetime()
411 != Qualifiers::OCL_Strong)
412 return true;
Argyrios Kyrtzidis7196d062011-06-21 20:20:39 +0000413 }
414 }
415
Argyrios Kyrtzidis14c4b442011-07-13 19:22:00 +0000416 return false;
417 }
418
Argyrios Kyrtzidis18fd0c62011-07-27 05:28:18 +0000419 bool hasAllIvarsBacked(PropsTy &props) const {
Argyrios Kyrtzidis14c4b442011-07-13 19:22:00 +0000420 for (PropsTy::iterator I = props.begin(), E = props.end(); I != E; ++I)
Argyrios Kyrtzidis18fd0c62011-07-27 05:28:18 +0000421 if (!isUserDeclared(I->IvarD))
Argyrios Kyrtzidis14c4b442011-07-13 19:22:00 +0000422 return false;
423
424 return true;
425 }
426
Argyrios Kyrtzidisb0e1e122011-11-07 18:46:46 +0000427 // \brief Returns true if all declarations in the @property have GC __weak.
428 bool hasGCWeak(PropsTy &props, SourceLocation atLoc) const {
429 if (!Pass.isGCMigration())
430 return false;
431 if (props.empty())
432 return false;
433 return MigrateCtx.AtPropsWeak.count(atLoc.getRawEncoding());
434 }
435
Argyrios Kyrtzidis14c4b442011-07-13 19:22:00 +0000436 bool isUserDeclared(ObjCIvarDecl *ivarD) const {
437 return ivarD && !ivarD->getSynthesize();
438 }
439
440 QualType getPropertyType(PropsTy &props) const {
441 assert(!props.empty());
Argyrios Kyrtzidis1d5fb8f2011-11-06 18:58:07 +0000442 QualType ty = props[0].PropD->getType().getUnqualifiedType();
Argyrios Kyrtzidis14c4b442011-07-13 19:22:00 +0000443
444#ifndef NDEBUG
445 for (PropsTy::iterator I = props.begin(), E = props.end(); I != E; ++I)
Argyrios Kyrtzidis1d5fb8f2011-11-06 18:58:07 +0000446 assert(ty == I->PropD->getType().getUnqualifiedType());
Argyrios Kyrtzidis14c4b442011-07-13 19:22:00 +0000447#endif
448
449 return ty;
450 }
451
452 ObjCPropertyDecl::PropertyAttributeKind
453 getPropertyAttrs(PropsTy &props) const {
454 assert(!props.empty());
455 ObjCPropertyDecl::PropertyAttributeKind
456 attrs = props[0].PropD->getPropertyAttributesAsWritten();
457
458#ifndef NDEBUG
459 for (PropsTy::iterator I = props.begin(), E = props.end(); I != E; ++I)
460 assert(attrs == I->PropD->getPropertyAttributesAsWritten());
461#endif
462
463 return attrs;
Argyrios Kyrtzidis7196d062011-06-21 20:20:39 +0000464 }
465};
466
Argyrios Kyrtzidis7196d062011-06-21 20:20:39 +0000467} // anonymous namespace
468
Argyrios Kyrtzidisb0d5db12011-11-06 18:57:57 +0000469void PropertyRewriteTraverser::traverseObjCImplementation(
470 ObjCImplementationContext &ImplCtx) {
Argyrios Kyrtzidisb0e1e122011-11-07 18:46:46 +0000471 PropertiesRewriter(ImplCtx.getMigrationContext())
Argyrios Kyrtzidisb0d5db12011-11-06 18:57:57 +0000472 .doTransform(ImplCtx.getImplementationDecl());
Argyrios Kyrtzidis7196d062011-06-21 20:20:39 +0000473}