r186716 - ObjectiveC migrator: Another use case of enum
Fariborz Jahanian
fjahanian at apple.com
Fri Jul 19 13:18:36 PDT 2013
Author: fjahanian
Date: Fri Jul 19 15:18:36 2013
New Revision: 186716
URL: http://llvm.org/viewvc/llvm-project?rev=186716&view=rev
Log:
ObjectiveC migrator: Another use case of enum
declaration which can be migrated to NS_ENUM.
Modified:
cfe/trunk/lib/ARCMigrate/ObjCMT.cpp
cfe/trunk/test/ARCMT/objcmt-ns-macros.m
cfe/trunk/test/ARCMT/objcmt-ns-macros.m.result
Modified: cfe/trunk/lib/ARCMigrate/ObjCMT.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/ARCMigrate/ObjCMT.cpp?rev=186716&r1=186715&r2=186716&view=diff
==============================================================================
--- cfe/trunk/lib/ARCMigrate/ObjCMT.cpp (original)
+++ cfe/trunk/lib/ARCMigrate/ObjCMT.cpp Fri Jul 19 15:18:36 2013
@@ -384,7 +384,7 @@ static bool rewriteToNSEnumDecl(const En
const TypedefDecl *TypedefDcl,
const NSAPI &NS, edit::Commit &commit,
bool IsNSIntegerType) {
- std::string ClassString =
+ std::string ClassString =
IsNSIntegerType ? "typedef NS_ENUM(NSInteger, " : "typedef NS_OPTIONS(NSUInteger, ";
ClassString += TypedefDcl->getIdentifier()->getName();
ClassString += ')';
@@ -399,6 +399,19 @@ static bool rewriteToNSEnumDecl(const En
return false;
}
+static bool rewriteToNSEnumDecl(const EnumDecl *EnumDcl,
+ const TypedefDecl *TypedefDcl,
+ const NSAPI &NS, edit::Commit &commit) {
+ std::string ClassString = "NS_ENUM(NSInteger, ";
+ ClassString += TypedefDcl->getIdentifier()->getName();
+ ClassString += ')';
+ SourceRange R(EnumDcl->getLocStart(), EnumDcl->getLocStart());
+ commit.replace(R, ClassString);
+ SourceLocation TypedefLoc = TypedefDcl->getLocEnd();
+ commit.remove(SourceRange(TypedefLoc, TypedefLoc));
+ return true;
+}
+
void ObjCMigrateASTConsumer::migrateProtocolConformance(ASTContext &Ctx,
const ObjCImplementationDecl *ImpDecl) {
const ObjCInterfaceDecl *IDecl = ImpDecl->getClassInterface();
@@ -466,8 +479,24 @@ void ObjCMigrateASTConsumer::migrateNSEn
QualType qt = TypedefDcl->getTypeSourceInfo()->getType();
bool IsNSIntegerType = NSAPIObj->isObjCNSIntegerType(qt);
bool IsNSUIntegerType = !IsNSIntegerType && NSAPIObj->isObjCNSUIntegerType(qt);
- if (!IsNSIntegerType && !IsNSUIntegerType)
- return;
+ if (!IsNSIntegerType && !IsNSUIntegerType) {
+ // Also check for typedef enum {...} TD;
+ if (const EnumType *EnumTy = qt->getAs<EnumType>()) {
+ if (EnumTy->getDecl() == EnumDcl) {
+ // NS_ENUM must be available.
+ if (!Ctx.Idents.get("NS_ENUM").hasMacroDefinition())
+ return;
+ edit::Commit commit(*Editor);
+ rewriteToNSEnumDecl(EnumDcl, TypedefDcl, *NSAPIObj, commit);
+ Editor->commit(commit);
+ return;
+ }
+ else
+ return;
+ }
+ else
+ return;
+ }
// NS_ENUM must be available.
if (IsNSIntegerType && !Ctx.Idents.get("NS_ENUM").hasMacroDefinition())
Modified: cfe/trunk/test/ARCMT/objcmt-ns-macros.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/ARCMT/objcmt-ns-macros.m?rev=186716&r1=186715&r2=186716&view=diff
==============================================================================
--- cfe/trunk/test/ARCMT/objcmt-ns-macros.m (original)
+++ cfe/trunk/test/ARCMT/objcmt-ns-macros.m Fri Jul 19 15:18:36 2013
@@ -27,6 +27,14 @@ enum {
typedef NSUInteger UITableViewCellStyle;
+typedef enum {
+ UIViewAnimationTransitionNone,
+ UIViewAnimationTransitionFlipFromLeft,
+ UIViewAnimationTransitionFlipFromRight,
+ UIViewAnimationTransitionCurlUp,
+ UIViewAnimationTransitionCurlDown,
+} UIViewAnimationTransition;
+
enum {
UNOne,
UNTwo
Modified: cfe/trunk/test/ARCMT/objcmt-ns-macros.m.result
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/ARCMT/objcmt-ns-macros.m.result?rev=186716&r1=186715&r2=186716&view=diff
==============================================================================
--- cfe/trunk/test/ARCMT/objcmt-ns-macros.m.result (original)
+++ cfe/trunk/test/ARCMT/objcmt-ns-macros.m.result Fri Jul 19 15:18:36 2013
@@ -27,6 +27,14 @@ typedef NS_OPTIONS(NSUInteger, UITableVi
+typedef NS_ENUM(NSInteger, UIViewAnimationTransition) {
+ UIViewAnimationTransitionNone,
+ UIViewAnimationTransitionFlipFromLeft,
+ UIViewAnimationTransitionFlipFromRight,
+ UIViewAnimationTransitionCurlUp,
+ UIViewAnimationTransitionCurlDown,
+} ;
+
enum {
UNOne,
UNTwo
More information about the cfe-commits
mailing list