diff options
| author | Fariborz Jahanian <fjahanian@apple.com> | 2013-08-30 17:46:01 +0000 |
|---|---|---|
| committer | Fariborz Jahanian <fjahanian@apple.com> | 2013-08-30 17:46:01 +0000 |
| commit | ff3476e4999948bd8f986c284d1eba6e2e118ba9 (patch) | |
| tree | afe8063aeae9ae0bf0818419835cc6f275da69ab | |
| parent | f5b5f1f7f69e28cf9cda353d00ffa651eb10d891 (diff) | |
| download | bcm5719-llvm-ff3476e4999948bd8f986c284d1eba6e2e118ba9.tar.gz bcm5719-llvm-ff3476e4999948bd8f986c284d1eba6e2e118ba9.zip | |
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).
llvm-svn: 189682
| -rw-r--r-- | clang/lib/ARCMigrate/ObjCMT.cpp | 22 | ||||
| -rw-r--r-- | clang/test/ARCMT/objcmt-ns-macros.m | 18 | ||||
| -rw-r--r-- | clang/test/ARCMT/objcmt-ns-macros.m.result | 20 |
3 files changed, 50 insertions, 10 deletions
diff --git a/clang/lib/ARCMigrate/ObjCMT.cpp b/clang/lib/ARCMigrate/ObjCMT.cpp index 0aca657ffdb..f5754f87cd2 100644 --- a/clang/lib/ARCMigrate/ObjCMT.cpp +++ b/clang/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/clang/test/ARCMT/objcmt-ns-macros.m b/clang/test/ARCMT/objcmt-ns-macros.m index 1ee675cd746..ec6e3d44c73 100644 --- a/clang/test/ARCMT/objcmt-ns-macros.m +++ b/clang/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/clang/test/ARCMT/objcmt-ns-macros.m.result b/clang/test/ARCMT/objcmt-ns-macros.m.result index cd0fc8789da..80c84bdfbea 100644 --- a/clang/test/ARCMT/objcmt-ns-macros.m.result +++ b/clang/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 +}; + + |

