From c9820ebfeff30598ebd7369c5daf5bde10df934b Mon Sep 17 00:00:00 2001 From: Fariborz Jahanian Date: Fri, 30 Aug 2013 17:46:01 +0000 Subject: [PATCH] ObjectiveC migrator: infer NS_ENUM even when user specified NSUInteger as the followup typedef. With this change, NS_OPTIONS is only inferred based on looking up how enumerators are speficied (if they her hexadecimal, power of 2, or have bitwise constant expressions). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@189682 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/ARCMigrate/ObjCMT.cpp | 22 +++++++++++++--------- test/ARCMT/objcmt-ns-macros.m | 18 ++++++++++++++++++ test/ARCMT/objcmt-ns-macros.m.result | 20 +++++++++++++++++++- 3 files changed, 50 insertions(+), 10 deletions(-) diff --git a/lib/ARCMigrate/ObjCMT.cpp b/lib/ARCMigrate/ObjCMT.cpp index 0aca657ffd..f5754f87cd 100644 --- a/lib/ARCMigrate/ObjCMT.cpp +++ b/lib/ARCMigrate/ObjCMT.cpp @@ -497,9 +497,16 @@ static bool rewriteToObjCInterfaceDecl(const ObjCInterfaceDecl *IDecl, static bool rewriteToNSEnumDecl(const EnumDecl *EnumDcl, const TypedefDecl *TypedefDcl, const NSAPI &NS, edit::Commit &commit, - bool IsNSIntegerType) { - std::string ClassString = - IsNSIntegerType ? "typedef NS_ENUM(NSInteger, " : "typedef NS_OPTIONS(NSUInteger, "; + bool IsNSIntegerType, + bool NSOptions) { + std::string ClassString; + if (NSOptions) + ClassString = "typedef NS_OPTIONS(NSUInteger, "; + else + ClassString = + IsNSIntegerType ? "typedef NS_ENUM(NSInteger, " + : "typedef NS_ENUM(NSUInteger, "; + ClassString += TypedefDcl->getIdentifier()->getName(); ClassString += ')'; SourceRange R(EnumDcl->getLocStart(), EnumDcl->getLocStart()); @@ -653,12 +660,9 @@ void ObjCMigrateASTConsumer::migrateNSEnumDecl(ASTContext &Ctx, } return; } - if (IsNSIntegerType && UseNSOptionsMacro(PP, Ctx, EnumDcl)) { - // We may still use NS_OPTIONS based on what we find in the enumertor list. - IsNSIntegerType = false; - IsNSUIntegerType = true; - } + // We may still use NS_OPTIONS based on what we find in the enumertor list. + bool NSOptions = UseNSOptionsMacro(PP, Ctx, EnumDcl); // NS_ENUM must be available. if (IsNSIntegerType && !Ctx.Idents.get("NS_ENUM").hasMacroDefinition()) return; @@ -666,7 +670,7 @@ void ObjCMigrateASTConsumer::migrateNSEnumDecl(ASTContext &Ctx, if (IsNSUIntegerType && !Ctx.Idents.get("NS_OPTIONS").hasMacroDefinition()) return; edit::Commit commit(*Editor); - rewriteToNSEnumDecl(EnumDcl, TypedefDcl, *NSAPIObj, commit, IsNSIntegerType); + rewriteToNSEnumDecl(EnumDcl, TypedefDcl, *NSAPIObj, commit, IsNSIntegerType, NSOptions); Editor->commit(commit); } diff --git a/test/ARCMT/objcmt-ns-macros.m b/test/ARCMT/objcmt-ns-macros.m index 1ee675cd74..ec6e3d44c7 100644 --- a/test/ARCMT/objcmt-ns-macros.m +++ b/test/ARCMT/objcmt-ns-macros.m @@ -92,3 +92,21 @@ enum { UIView1 = 0XBADBEEF }; typedef NSInteger UIStyle; + +enum { + NSTIFFFileType, + NSBMPFileType, + NSGIFFileType, + NSJPEGFileType, + NSPNGFileType, + NSJPEG2000FileType +}; +typedef NSUInteger NSBitmapImageFileType; + +enum { + NSWarningAlertStyle = 0, + NSInformationalAlertStyle = 1, + NSCriticalAlertStyle = 2 +}; +typedef NSUInteger NSAlertStyle; + diff --git a/test/ARCMT/objcmt-ns-macros.m.result b/test/ARCMT/objcmt-ns-macros.m.result index cd0fc8789d..80c84bdfbe 100644 --- a/test/ARCMT/objcmt-ns-macros.m.result +++ b/test/ARCMT/objcmt-ns-macros.m.result @@ -15,7 +15,7 @@ typedef NS_ENUM(NSInteger, wibble) { }; -typedef NS_OPTIONS(NSUInteger, UITableViewCellStyle) { +typedef NS_ENUM(NSUInteger, UITableViewCellStyle) { UIViewAutoresizingNone = 0, UIViewAutoresizingFlexibleLeftMargin, UIViewAutoresizingFlexibleWidth, @@ -92,3 +92,21 @@ typedef NS_OPTIONS(NSUInteger, UIStyle) { UIView1 = 0XBADBEEF }; + +typedef NS_ENUM(NSUInteger, NSBitmapImageFileType) { + NSTIFFFileType, + NSBMPFileType, + NSGIFFileType, + NSJPEGFileType, + NSPNGFileType, + NSJPEG2000FileType +}; + + +typedef NS_ENUM(NSUInteger, NSAlertStyle) { + NSWarningAlertStyle = 0, + NSInformationalAlertStyle = 1, + NSCriticalAlertStyle = 2 +}; + + -- 2.40.0