]> granicus.if.org Git - clang/commitdiff
ObjectiveC migrator: infer NS_ENUM even when user
authorFariborz Jahanian <fjahanian@apple.com>
Fri, 30 Aug 2013 17:46:01 +0000 (17:46 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Fri, 30 Aug 2013 17:46:01 +0000 (17:46 +0000)
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
test/ARCMT/objcmt-ns-macros.m
test/ARCMT/objcmt-ns-macros.m.result

index 0aca657ffdb7728591da626cea4ab85614738b10..f5754f87cd2ce9c2dcf54edf63b291580f13b53a 100644 (file)
@@ -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);
 }
 
index 1ee675cd746a17b7b14a4906d6d6a76065c2be70..ec6e3d44c7367705bdc8f93a13aa7cd9084844ba 100644 (file)
@@ -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;
+
index cd0fc8789dad740472c7e70dcc5b307261c24449..80c84bdfbea8ad7cc7efd8975f347b99ea8f4f67 100644 (file)
@@ -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
+};
+
+