Objective-C SDK modernizer to use NS_ENUM/NS_OPTIONS macros

with typed enums. rdar://19352510

llvm-svn: 227104
This commit is contained in:
Fariborz Jahanian 2015-01-26 17:41:03 +00:00
parent 8108ef0a93
commit 4732d43cc2
3 changed files with 51 additions and 4 deletions

View 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) {

View 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;

View 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
};