From b5b3f816d3c2543e11fb4f0b235041beafd81a1e Mon Sep 17 00:00:00 2001 From: Fariborz Jahanian Date: Wed, 16 Oct 2013 22:35:19 +0000 Subject: [PATCH] ObjectiveC migrator. Remove blank lines when inferring property from setter/getter methods. // rdar://15200949 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@192853 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/ARCMigrate/ObjCMT.cpp | 9 ++++--- test/ARCMT/objcmt-arc-cf-annotations.m.result | 2 -- test/ARCMT/objcmt-atomic-property.m.result | 27 ------------------- test/ARCMT/objcmt-property.m.result | 27 ------------------- 4 files changed, 6 insertions(+), 59 deletions(-) diff --git a/lib/ARCMigrate/ObjCMT.cpp b/lib/ARCMigrate/ObjCMT.cpp index 60ab4f271f..deb391f967 100644 --- a/lib/ARCMigrate/ObjCMT.cpp +++ b/lib/ARCMigrate/ObjCMT.cpp @@ -273,7 +273,7 @@ void MigrateBlockOrFunctionPointerTypeVariable(std::string & PropertyString, } -static bool rewriteToObjCProperty(const ObjCMethodDecl *Getter, +static void rewriteToObjCProperty(const ObjCMethodDecl *Getter, const ObjCMethodDecl *Setter, const NSAPI &NS, edit::Commit &commit, unsigned LengthOfPrefix, @@ -393,9 +393,12 @@ static bool rewriteToObjCProperty(const ObjCMethodDecl *Getter, SourceLocation EndLoc = Setter->getDeclaratorEndLoc(); // Get location past ';' EndLoc = EndLoc.getLocWithOffset(1); - commit.remove(CharSourceRange::getCharRange(Setter->getLocStart(), EndLoc)); + SourceLocation BeginOfSetterDclLoc = Setter->getLocStart(); + // FIXME. This assumes that setter decl; is immediately preceeded by eoln. + // It is trying to remove the setter method decl. line entirely. + BeginOfSetterDclLoc = BeginOfSetterDclLoc.getLocWithOffset(-1); + commit.remove(SourceRange(BeginOfSetterDclLoc, EndLoc)); } - return true; } void ObjCMigrateASTConsumer::migrateObjCInterfaceDecl(ASTContext &Ctx, diff --git a/test/ARCMT/objcmt-arc-cf-annotations.m.result b/test/ARCMT/objcmt-arc-cf-annotations.m.result index 949016a897..7e0a9042f5 100644 --- a/test/ARCMT/objcmt-arc-cf-annotations.m.result +++ b/test/ARCMT/objcmt-arc-cf-annotations.m.result @@ -2089,7 +2089,5 @@ CFAttributedStringRef CFAttributedCreate(void *CFObj CF_CONSUMED) CF_RETURNS_RET @interface Action @property (nonatomic) SEL action; - @property (nonatomic, assign) id target; - @end diff --git a/test/ARCMT/objcmt-atomic-property.m.result b/test/ARCMT/objcmt-atomic-property.m.result index f764488bb6..668c8218d5 100644 --- a/test/ARCMT/objcmt-atomic-property.m.result +++ b/test/ARCMT/objcmt-atomic-property.m.result @@ -21,23 +21,19 @@ typedef char BOOL; @interface I : NSObject { int ivarVal; } - @property (weak) NSString *WeakProp; @property (retain) NSString *StrongProp; - - (NSString *) UnavailProp __attribute__((unavailable)); - (void) setUnavailProp : (NSString *)Val; @property (retain) NSString *UnavailProp1 __attribute__((unavailable)); - - (NSString *) UnavailProp2; - (void) setUnavailProp2 : (NSString *)Val __attribute__((unavailable)); @property (copy) NSDictionary *undoAction; - @end @implementation I @@ -52,10 +48,6 @@ typedef char BOOL; NSArray *_names3; NSArray *_names4; } - - - - @property (retain) NSArray *names2; @property (retain) NSArray *names3; @property (retain) NSArray *names4; @@ -67,26 +59,19 @@ typedef char BOOL; @interface NSInvocation @property (assign) id target; - @property (assign) id dataSource; @property (assign) id xxxdelegateYYY; - - @property (retain) id MYtarget; - @property (retain) id targetX; - @property int value; - @property (getter=isContinuous) BOOL continuous; - - (id) isAnObject; - (void)setAnObject : (id) object; @@ -102,7 +87,6 @@ typedef char BOOL; @property (getter=getStringValue, retain) NSString *stringValue; @property (getter=getCounterValue, readonly) BOOL counterValue; - @property (getter=getns_dixtionary, readonly) NSDictionary *ns_dixtionary; - (BOOL)is3bar; // watch out @@ -119,26 +103,19 @@ typedef char BOOL; @interface NSInvocation(CAT) @property (assign) id target; - @property (assign) id dataSource; @property (assign) id xxxdelegateYYY; - - @property (retain) id MYtarget; - @property (retain) id targetX; - @property int value; - @property (getter=isContinuous) BOOL continuous; - - (id) isAnObject; - (void)setAnObject : (id) object; @@ -189,7 +166,6 @@ DEPRECATED @property (retain) NSURL *appStoreReceiptURLX NS_AVAILABLE; - // Do not infer a property. - (NSURL *)appStoreReceiptURLY ; - (void) setAppStoreReceiptURLY : (NSURL *)object NS_AVAILABLE; @@ -206,7 +182,6 @@ DEPRECATED @property (retain) id method1 ALIGNED NS_AVAILABLE; - - (NSURL *)init; // No Change + (id)alloc; // No Change @@ -222,8 +197,6 @@ DEPRECATED @interface NSArray @property (readonly) id (^expressionBlock)(id, NSArray *, NSMutableDictionary *); @property (copy) id (^MyBlock)(id, NSArray *, NSMutableDictionary *); - @property (readonly) id (*expressionFuncptr)(id, NSArray *, NSMutableDictionary *); @property id (*MyFuncptr)(id, NSArray *, NSMutableDictionary *); - @end diff --git a/test/ARCMT/objcmt-property.m.result b/test/ARCMT/objcmt-property.m.result index a3db9be1b6..bdb135b42a 100644 --- a/test/ARCMT/objcmt-property.m.result +++ b/test/ARCMT/objcmt-property.m.result @@ -21,23 +21,19 @@ typedef char BOOL; @interface I : NSObject { int ivarVal; } - @property (nonatomic, weak) NSString *WeakProp; @property (nonatomic, retain) NSString *StrongProp; - - (NSString *) UnavailProp __attribute__((unavailable)); - (void) setUnavailProp : (NSString *)Val; @property (nonatomic, retain) NSString *UnavailProp1 __attribute__((unavailable)); - - (NSString *) UnavailProp2; - (void) setUnavailProp2 : (NSString *)Val __attribute__((unavailable)); @property (nonatomic, copy) NSDictionary *undoAction; - @end @implementation I @@ -52,10 +48,6 @@ typedef char BOOL; NSArray *_names3; NSArray *_names4; } - - - - @property (nonatomic, retain) NSArray *names2; @property (nonatomic, retain) NSArray *names3; @property (nonatomic, retain) NSArray *names4; @@ -67,26 +59,19 @@ typedef char BOOL; @interface NSInvocation @property (nonatomic, assign) id target; - @property (nonatomic, assign) id dataSource; @property (nonatomic, assign) id xxxdelegateYYY; - - @property (nonatomic, retain) id MYtarget; - @property (nonatomic, retain) id targetX; - @property (nonatomic) int value; - @property (nonatomic, getter=isContinuous) BOOL continuous; - - (id) isAnObject; - (void)setAnObject : (id) object; @@ -102,7 +87,6 @@ typedef char BOOL; @property (nonatomic, getter=getStringValue, retain) NSString *stringValue; @property (nonatomic, getter=getCounterValue, readonly) BOOL counterValue; - @property (nonatomic, getter=getns_dixtionary, readonly) NSDictionary *ns_dixtionary; - (BOOL)is3bar; // watch out @@ -119,26 +103,19 @@ typedef char BOOL; @interface NSInvocation(CAT) @property (nonatomic, assign) id target; - @property (nonatomic, assign) id dataSource; @property (nonatomic, assign) id xxxdelegateYYY; - - @property (nonatomic, retain) id MYtarget; - @property (nonatomic, retain) id targetX; - @property (nonatomic) int value; - @property (nonatomic, getter=isContinuous) BOOL continuous; - - (id) isAnObject; - (void)setAnObject : (id) object; @@ -189,7 +166,6 @@ DEPRECATED @property (nonatomic, retain) NSURL *appStoreReceiptURLX NS_AVAILABLE; - // Do not infer a property. - (NSURL *)appStoreReceiptURLY ; - (void) setAppStoreReceiptURLY : (NSURL *)object NS_AVAILABLE; @@ -206,7 +182,6 @@ DEPRECATED @property (nonatomic, retain) id method1 ALIGNED NS_AVAILABLE; - - (NSURL *)init; // No Change + (id)alloc; // No Change @@ -222,10 +197,8 @@ DEPRECATED @interface NSArray @property (nonatomic, readonly) id (^expressionBlock)(id, NSArray *, NSMutableDictionary *); @property (nonatomic, copy) id (^MyBlock)(id, NSArray *, NSMutableDictionary *); - @property (nonatomic, readonly) id (*expressionFuncptr)(id, NSArray *, NSMutableDictionary *); @property (nonatomic) id (*MyFuncptr)(id, NSArray *, NSMutableDictionary *); - @end // rdar://15231241 -- 2.40.0