]> granicus.if.org Git - clang/commitdiff
Objective-C SDK modernizer to use NS_ENUM/NS_OPTIONS macros
authorFariborz Jahanian <fjahanian@apple.com>
Mon, 26 Jan 2015 17:41:03 +0000 (17:41 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Mon, 26 Jan 2015 17:41:03 +0000 (17:41 +0000)
with typed enums. rdar://19352510

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

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

index 59feea11e137a72c273c479a3c4e16a9eb450467..cd1a2caab4b8f3df3315c82b07f0d6a007dc1080 100644 (file)
@@ -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) {
index 1d5583b92f2660e34ba353262d435f497f1f5c16..795b94a8256cbc630fe83a8c2f195d59de4292ff 100644 (file)
@@ -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;
index 63eec7d37edef64b8f5c7e7948a1cb7aaecb0fb7..094c4441ef6c4bea15820e39ce65bc026dd7d596 100644 (file)
@@ -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
+};