From: Fariborz Jahanian Date: Mon, 26 Jan 2015 17:41:03 +0000 (+0000) Subject: Objective-C SDK modernizer to use NS_ENUM/NS_OPTIONS macros X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=138133f406699ca702ceb68dcd227025faa81979;p=clang Objective-C SDK modernizer to use NS_ENUM/NS_OPTIONS macros with typed enums. rdar://19352510 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@227104 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/ARCMigrate/ObjCMT.cpp b/lib/ARCMigrate/ObjCMT.cpp index 59feea11e1..cd1a2caab4 100644 --- a/lib/ARCMigrate/ObjCMT.cpp +++ b/lib/ARCMigrate/ObjCMT.cpp @@ -788,7 +788,22 @@ static void rewriteToNSMacroDecl(ASTContext &Ctx, ClassString += TypedefDcl->getIdentifier()->getName(); ClassString += ')'; - SourceRange R(EnumDcl->getLocStart(), EnumDcl->getLocStart()); + SourceLocation EndLoc; + if (EnumDcl->getIntegerTypeSourceInfo()) { + TypeSourceInfo *TSourceInfo = EnumDcl->getIntegerTypeSourceInfo(); + TypeLoc TLoc = TSourceInfo->getTypeLoc(); + EndLoc = TLoc.getLocEnd(); + const char *lbrace = Ctx.getSourceManager().getCharacterData(EndLoc); + unsigned count = 0; + if (lbrace) + while (lbrace[count] != '{') + ++count; + if (count > 0) + EndLoc = EndLoc.getLocWithOffset(count-1); + } + else + EndLoc = EnumDcl->getLocStart(); + SourceRange R(EnumDcl->getLocStart(), EndLoc); commit.replace(R, ClassString); // This is to remove spaces between '}' and typedef name. SourceLocation StartTypedefLoc = EnumDcl->getLocEnd(); @@ -910,7 +925,7 @@ bool ObjCMigrateASTConsumer::migrateNSEnumDecl(ASTContext &Ctx, const EnumDecl *EnumDcl, const TypedefDecl *TypedefDcl) { if (!EnumDcl->isCompleteDefinition() || EnumDcl->getIdentifier() || - EnumDcl->isDeprecated() || EnumDcl->getIntegerTypeSourceInfo()) + EnumDcl->isDeprecated()) return false; if (!TypedefDcl) { if (NSIntegerTypedefed) { diff --git a/test/ARCMT/objcmt-ns-macros.m b/test/ARCMT/objcmt-ns-macros.m index 1d5583b92f..795b94a825 100644 --- a/test/ARCMT/objcmt-ns-macros.m +++ b/test/ARCMT/objcmt-ns-macros.m @@ -363,3 +363,19 @@ enum UIU8one = 1 }; typedef uint8_t UI8Type; + +// rdar://19352510 +typedef enum : NSInteger {zero} MyEnum; + +typedef enum : NSUInteger {two} MyEnumNSUInteger; + +typedef enum : int {three, four} MyEnumint; + +typedef enum : unsigned long {five} MyEnumlonglong; + +typedef enum : unsigned long long { + ll1, + ll2= 0xff, + ll3, + ll4 +} MyEnumunsignedlonglong; diff --git a/test/ARCMT/objcmt-ns-macros.m.result b/test/ARCMT/objcmt-ns-macros.m.result index 63eec7d37e..094c4441ef 100644 --- a/test/ARCMT/objcmt-ns-macros.m.result +++ b/test/ARCMT/objcmt-ns-macros.m.result @@ -291,11 +291,11 @@ typedef NS_ENUM(NSUInteger, NSSelectionDirection) { // standard window buttons // rdar://18262255 -typedef enum : NSUInteger { +typedef NS_ENUM(NSUInteger, Thing) { ThingOne, ThingTwo, ThingThree, -} Thing; +}; // rdar://18498539 typedef NS_ENUM(unsigned int, NumericEnum) { @@ -342,3 +342,19 @@ typedef NS_ENUM(uint8_t, UI8Type) { UIU8one = 1 }; + +// rdar://19352510 +typedef NS_ENUM(NSInteger, MyEnum) {zero}; + +typedef NS_ENUM(NSUInteger, MyEnumNSUInteger) {two}; + +typedef NS_ENUM(int, MyEnumint) {three, four}; + +typedef NS_ENUM(unsigned long, MyEnumlonglong) {five}; + +typedef NS_ENUM(unsigned long long, MyEnumunsignedlonglong) { + ll1, + ll2= 0xff, + ll3, + ll4 +};