return lookupInstanceVariable(IVarName, ClassDeclared);
}
+ ObjCProtocolDecl *lookupNestedProtocol(IdentifierInfo *Name);
+
// Lookup a method. First, we search locally. If a method isn't
// found, we search referenced protocols and class categories.
ObjCMethodDecl *lookupMethod(Selector Sel, bool isInstance,
return NULL;
}
+ObjCProtocolDecl *
+ObjCInterfaceDecl::lookupNestedProtocol(IdentifierInfo *Name) {
+ for (ObjCInterfaceDecl::all_protocol_iterator P =
+ all_referenced_protocol_begin(), PE = all_referenced_protocol_end();
+ P != PE; ++P)
+ if ((*P)->lookupProtocolNamed(Name))
+ return (*P);
+ ObjCInterfaceDecl *SuperClass = getSuperClass();
+ return SuperClass ? SuperClass->lookupNestedProtocol(Name) : NULL;
+}
+
/// lookupMethod - This method returns an instance/class method by looking in
/// the class, its categories, and its super classes (using a linear search).
/// When argument category "C" is specified, any implicit method found
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(),
// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -x objective-c -fobjc-runtime-has-weak -fobjc-arc -fobjc-default-synthesize-properties %s.result
@class NSString;
-@interface NSObject @end
+@protocol NSCopying @end
+
+@interface NSObject <NSCopying>
+@end
+
+@interface NSDictionary : NSObject
+@end
@interface I : NSObject {
int ivarVal;
- (NSString *) UnavailProp2;
- (void) setUnavailProp2 : (NSString *)Val __attribute__((unavailable));
+- (NSDictionary*) undoAction;
+- (void) setUndoAction: (NSDictionary*)Arg;
@end
@implementation I
// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -x objective-c -fobjc-runtime-has-weak -fobjc-arc -fobjc-default-synthesize-properties %s.result
@class NSString;
-@interface NSObject @end
+@protocol NSCopying @end
+
+@interface NSObject <NSCopying>
+@end
+
+@interface NSDictionary : NSObject
+@end
@interface I : NSObject {
int ivarVal;
}
-@property(weak) NSString *__weak WeakProp;
+@property(weak) NSString * WeakProp;
-@property(copy) NSString * StrongProp;
+@property NSString * StrongProp;
- (NSString *) UnavailProp __attribute__((unavailable));
- (NSString *) UnavailProp2;
- (void) setUnavailProp2 : (NSString *)Val __attribute__((unavailable));
+@property(copy) NSDictionary * undoAction;
+
@end
@implementation I
-@property(copy) NSArray * names2;
-@property(copy) NSArray * names3;
-@property(copy) NSArray *__strong names4;
-@property(copy) NSArray * names1;
+@property NSArray * names2;
+@property NSArray * names3;
+@property NSArray * names4;
+@property NSArray * names1;
@end