diff options
author | Fariborz Jahanian <fjahanian@apple.com> | 2014-10-06 23:50:37 +0000 |
---|---|---|
committer | Fariborz Jahanian <fjahanian@apple.com> | 2014-10-06 23:50:37 +0000 |
commit | 35ee87debe55cdf4e41611f33cb43b933840d5b2 (patch) | |
tree | 5e2d9551ea7b1ce34ed11c2c8ce99b99e4b84549 /clang/lib/ARCMigrate/ObjCMT.cpp | |
parent | c62436c60a332cd213d87e2fce52a8589856512d (diff) | |
download | bcm5719-llvm-35ee87debe55cdf4e41611f33cb43b933840d5b2.tar.gz bcm5719-llvm-35ee87debe55cdf4e41611f33cb43b933840d5b2.zip |
Objective-C SDK modernizer. Patch to support modernization
to NS_ENUM/NS_OPTION macros when typedef names are other
than NSInteger/NSUInteger (int8_t, etc.).
rdar://18532199
llvm-svn: 219173
Diffstat (limited to 'clang/lib/ARCMigrate/ObjCMT.cpp')
-rw-r--r-- | clang/lib/ARCMigrate/ObjCMT.cpp | 42 |
1 files changed, 26 insertions, 16 deletions
diff --git a/clang/lib/ARCMigrate/ObjCMT.cpp b/clang/lib/ARCMigrate/ObjCMT.cpp index ea1914c085c..f9c6e6e644f 100644 --- a/clang/lib/ARCMigrate/ObjCMT.cpp +++ b/clang/lib/ARCMigrate/ObjCMT.cpp @@ -584,18 +584,32 @@ static bool rewriteToObjCInterfaceDecl(const ObjCInterfaceDecl *IDecl, return true; } +static StringRef GetUnsignedName(StringRef NSIntegerName) { + StringRef UnsignedName = llvm::StringSwitch<StringRef>(NSIntegerName) + .Case("int8_t", "uint8_t") + .Case("int16_t", "uint16_t") + .Case("int32_t", "uint32_t") + .Case("NSInteger", "NSUInteger") + .Case("int64_t", "uint64_t") + .Default(NSIntegerName); + return UnsignedName; +} + static bool rewriteToNSEnumDecl(const EnumDecl *EnumDcl, const TypedefDecl *TypedefDcl, const NSAPI &NS, edit::Commit &commit, - bool IsNSIntegerType, + StringRef NSIntegerName, bool NSOptions) { std::string ClassString; - if (NSOptions) - ClassString = "typedef NS_OPTIONS(NSUInteger, "; - else - ClassString = - IsNSIntegerType ? "typedef NS_ENUM(NSInteger, " - : "typedef NS_ENUM(NSUInteger, "; + if (NSOptions) { + ClassString = "typedef NS_OPTIONS("; + ClassString += GetUnsignedName(NSIntegerName); + } + else { + ClassString = "typedef NS_ENUM("; + ClassString += NSIntegerName; + } + ClassString += ", "; ClassString += TypedefDcl->getIdentifier()->getName(); ClassString += ')'; @@ -788,10 +802,9 @@ bool ObjCMigrateASTConsumer::migrateNSEnumDecl(ASTContext &Ctx, return false; QualType qt = TypedefDcl->getTypeSourceInfo()->getType(); - bool IsNSIntegerType = NSAPIObj->isObjCNSIntegerType(qt); - bool IsNSUIntegerType = !IsNSIntegerType && NSAPIObj->isObjCNSUIntegerType(qt); + StringRef NSIntegerName = NSAPIObj->GetNSIntegralKind(qt); - if (!IsNSIntegerType && !IsNSUIntegerType) { + if (NSIntegerName.empty()) { // Also check for typedef enum {...} TD; if (const EnumType *EnumTy = qt->getAs<EnumType>()) { if (EnumTy->getDecl() == EnumDcl) { @@ -813,15 +826,12 @@ bool ObjCMigrateASTConsumer::migrateNSEnumDecl(ASTContext &Ctx, // 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 false; - // NS_OPTIONS must be available. - if (IsNSUIntegerType && !Ctx.Idents.get("NS_OPTIONS").hasMacroDefinition()) + // For sanity check, see if macro NS_ENUM can be seen. + if (!Ctx.Idents.get("NS_ENUM").hasMacroDefinition()) return false; edit::Commit commit(*Editor); bool Res = rewriteToNSEnumDecl(EnumDcl, TypedefDcl, *NSAPIObj, - commit, IsNSIntegerType, NSOptions); + commit, NSIntegerName, NSOptions); Editor->commit(commit); return Res; } |