summaryrefslogtreecommitdiff
path: root/lib/Edit
diff options
context:
space:
mode:
authorFariborz Jahanian <fjahanian@apple.com>2013-07-10 21:30:22 +0000
committerFariborz Jahanian <fjahanian@apple.com>2013-07-10 21:30:22 +0000
commit07b1bbe648a21b8cdbc073fb6a409422c49921bb (patch)
tree2a14dd0157c690c359b68e8bca944026680e79aa /lib/Edit
parent7b309b0107093d0d2b4df2ce1deddd9bd4698cff (diff)
downloadclang-07b1bbe648a21b8cdbc073fb6a409422c49921bb.tar.gz
ObjC migrator: Improve on hueristics.
migrate to 'copy attribute if Object class implements NSCopying otherwise assume implied 'strong'. Remove lifetime qualifier on property as it has moved to property's attribute. Added TODO comment for future work by poking into setter implementation. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@186037 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Edit')
-rw-r--r--lib/Edit/RewriteObjCFoundationAPI.cpp25
1 files changed, 20 insertions, 5 deletions
diff --git a/lib/Edit/RewriteObjCFoundationAPI.cpp b/lib/Edit/RewriteObjCFoundationAPI.cpp
index e257a0b6f1..8d24003d94 100644
--- a/lib/Edit/RewriteObjCFoundationAPI.cpp
+++ b/lib/Edit/RewriteObjCFoundationAPI.cpp
@@ -358,23 +358,38 @@ bool edit::rewriteToObjCLiteralSyntax(const ObjCMessageExpr *Msg,
bool edit::rewriteToObjCProperty(const ObjCMethodDecl *Getter,
const ObjCMethodDecl *Setter,
const NSAPI &NS, Commit &commit) {
+ ASTContext &Context = NS.getASTContext();
std::string PropertyString = "@property";
const ParmVarDecl *argDecl = *Setter->param_begin();
- QualType ArgType = argDecl->getType();
+ QualType ArgType = Context.getCanonicalType(argDecl->getType());
Qualifiers::ObjCLifetime propertyLifetime = ArgType.getObjCLifetime();
if (ArgType->isObjCRetainableType() &&
propertyLifetime == Qualifiers::OCL_Strong) {
- PropertyString += "(copy)";
+ if (const ObjCObjectPointerType *ObjPtrTy =
+ ArgType->getAs<ObjCObjectPointerType>()) {
+ ObjCInterfaceDecl *IDecl = ObjPtrTy->getObjectType()->getInterface();
+ if (IDecl &&
+ IDecl->lookupNestedProtocol(&Context.Idents.get("NSCopying")))
+ PropertyString += "(copy)";
+ }
}
else if (propertyLifetime == Qualifiers::OCL_Weak)
+ // TODO. More precise determination of 'weak' attribute requires
+ // looking into setter's implementation for backing weak ivar.
PropertyString += "(weak)";
else
PropertyString += "(unsafe_unretained)";
-
- QualType PropQT = Getter->getResultType();
+
+ // strip off any ARC lifetime qualifier.
+ QualType CanResultTy = Context.getCanonicalType(Getter->getResultType());
+ if (CanResultTy.getQualifiers().hasObjCLifetime()) {
+ Qualifiers Qs = CanResultTy.getQualifiers();
+ Qs.removeObjCLifetime();
+ CanResultTy = Context.getQualifiedType(CanResultTy.getUnqualifiedType(), Qs);
+ }
PropertyString += " ";
- PropertyString += PropQT.getAsString(NS.getASTContext().getPrintingPolicy());
+ PropertyString += CanResultTy.getAsString(Context.getPrintingPolicy());
PropertyString += " ";
PropertyString += Getter->getNameAsString();
commit.replace(CharSourceRange::getCharRange(Getter->getLocStart(),