]> granicus.if.org Git - clang/commitdiff
ObjectiveC migrator: Infer NS_OPTIONS when if there is at
authorFariborz Jahanian <fjahanian@apple.com>
Mon, 23 Sep 2013 20:27:06 +0000 (20:27 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Mon, 23 Sep 2013 20:27:06 +0000 (20:27 +0000)
least one hex enumerator, all others are also
hex enumerator (0 enumerator is excepted).
// rdar://15044304

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@191222 91177308-0d34-0410-b5e6-96231b3b80d8

lib/ARCMigrate/ObjCMT.cpp
test/ARCMT/objcmt-ns-macros.m
test/ARCMT/objcmt-ns-macros.m.result

index cffa625d3bd00649d6205b8a6ab0ed22e3de8864..c29a2de46b5b511b7af030ecbe5333c730c3ad3e 100644 (file)
@@ -498,7 +498,7 @@ static bool rewriteToNSMacroDecl(const EnumDecl *EnumDcl,
 static bool UseNSOptionsMacro(Preprocessor &PP, ASTContext &Ctx,
                               const EnumDecl *EnumDcl) {
   bool PowerOfTwo = true;
-  bool FoundHexdecimalEnumerator = false;
+  bool AllHexdecimalEnumerator = true;
   uint64_t MaxPowerOfTwoVal = 0;
   for (EnumDecl::enumerator_iterator EI = EnumDcl->enumerator_begin(),
        EE = EnumDcl->enumerator_end(); EI != EE; ++EI) {
@@ -506,6 +506,7 @@ static bool UseNSOptionsMacro(Preprocessor &PP, ASTContext &Ctx,
     const Expr *InitExpr = Enumerator->getInitExpr();
     if (!InitExpr) {
       PowerOfTwo = false;
+      AllHexdecimalEnumerator = false;
       continue;
     }
     InitExpr = InitExpr->IgnoreParenCasts();
@@ -520,7 +521,8 @@ static bool UseNSOptionsMacro(Preprocessor &PP, ASTContext &Ctx,
       else if (EnumVal > MaxPowerOfTwoVal)
         MaxPowerOfTwoVal = EnumVal;
     }
-    if (!FoundHexdecimalEnumerator) {
+    if (AllHexdecimalEnumerator && EnumVal) {
+      bool FoundHexdecimalEnumerator = false;
       SourceLocation EndLoc = Enumerator->getLocEnd();
       Token Tok;
       if (!PP.getRawToken(EndLoc, Tok, /*IgnoreWhiteSpace=*/true))
@@ -529,9 +531,11 @@ static bool UseNSOptionsMacro(Preprocessor &PP, ASTContext &Ctx,
             FoundHexdecimalEnumerator =
               (StringLit[0] == '0' && (toLowercase(StringLit[1]) == 'x'));
         }
+      if (!FoundHexdecimalEnumerator)
+        AllHexdecimalEnumerator = false;
     }
   }
-  return FoundHexdecimalEnumerator || (PowerOfTwo && (MaxPowerOfTwoVal > 2));
+  return AllHexdecimalEnumerator || (PowerOfTwo && (MaxPowerOfTwoVal > 2));
 }
 
 void ObjCMigrateASTConsumer::migrateProtocolConformance(ASTContext &Ctx,   
index edc3ffd40439a75b8a73e0971d12bf60fe7539fe..6ee4625128ab4b5abd76190332ca3b94c6561dd4 100644 (file)
@@ -146,3 +146,61 @@ enum {
 };
 
 typedef NSUInteger NSFOptions;
+
+typedef enum {
+  UIP0One = 0,
+  UIP0Two = 1,
+  UIP0Three = 2,
+  UIP0Four = 10,
+  UIP0Last = 0x100
+} UIP;
+
+typedef enum {
+  UIPZero = 0x0,
+  UIPOne = 0x1,
+  UIPTwo = 0x2,
+  UIP10 = 0x10,
+  UIPHundred = 0x100
+} UIP_3;
+
+typedef enum {
+  UIP4Zero = 0x0,
+  UIP4One = 0x1,
+  UIP4Two = 0x2,
+  UIP410 = 0x10,
+  UIP4Hundred = 100
+} UIP4_3;
+
+typedef enum {
+  UIP5Zero = 0x0,
+  UIP5Two = 0x2,
+  UIP510 = 0x3,
+  UIP5Hundred = 0x4
+} UIP5_3;
+
+typedef enum {
+  UIP6Zero = 0x0,
+  UIP6One = 0x1,
+  UIP6Two = 0x2,
+  UIP610 = 10,
+  UIP6Hundred = 0x100
+} UIP6_3;
+
+typedef enum {
+  UIP7Zero = 0x0,
+  UIP7One = 1,
+  UIP7Two = 0x2,
+  UIP710 = 10,
+  UIP7Hundred = 100
+} UIP7_3;
+
+
+typedef enum {
+  Random = 0,
+  Random1 = 2,
+  Random2 = 4,
+  Random3 = 0x12345,
+  Random4 = 0x3444444,
+  Random5 = 0xbadbeef,
+  Random6
+} UIP8_3;
index 674de3e9168d11074b5f8170463cebb3677ca183..e6318f2e2bfc2e0233cc90c9117cb4f34149cab1 100644 (file)
@@ -146,3 +146,61 @@ typedef NS_OPTIONS(NSUInteger, NSFOptions) {
 };
 
 
+
+typedef NS_ENUM(NSInteger, UIP) {
+  UIP0One = 0,
+  UIP0Two = 1,
+  UIP0Three = 2,
+  UIP0Four = 10,
+  UIP0Last = 0x100
+} ;
+
+typedef NS_OPTIONS(NSUInteger, UIP_3) {
+  UIPZero = 0x0,
+  UIPOne = 0x1,
+  UIPTwo = 0x2,
+  UIP10 = 0x10,
+  UIPHundred = 0x100
+} ;
+
+typedef NS_ENUM(NSInteger, UIP4_3) {
+  UIP4Zero = 0x0,
+  UIP4One = 0x1,
+  UIP4Two = 0x2,
+  UIP410 = 0x10,
+  UIP4Hundred = 100
+} ;
+
+typedef NS_OPTIONS(NSUInteger, UIP5_3) {
+  UIP5Zero = 0x0,
+  UIP5Two = 0x2,
+  UIP510 = 0x3,
+  UIP5Hundred = 0x4
+} ;
+
+typedef NS_ENUM(NSInteger, UIP6_3) {
+  UIP6Zero = 0x0,
+  UIP6One = 0x1,
+  UIP6Two = 0x2,
+  UIP610 = 10,
+  UIP6Hundred = 0x100
+} ;
+
+typedef NS_ENUM(NSInteger, UIP7_3) {
+  UIP7Zero = 0x0,
+  UIP7One = 1,
+  UIP7Two = 0x2,
+  UIP710 = 10,
+  UIP7Hundred = 100
+} ;
+
+
+typedef NS_ENUM(NSInteger, UIP8_3) {
+  Random = 0,
+  Random1 = 2,
+  Random2 = 4,
+  Random3 = 0x12345,
+  Random4 = 0x3444444,
+  Random5 = 0xbadbeef,
+  Random6
+} ;