forked from OSchip/llvm-project
ObjectiveC migration. migration to NS_ENUM/SN_OPTION
- wip. llvm-svn: 186604
This commit is contained in:
parent
61b23b7edc
commit
92463274e6
|
@ -17,6 +17,8 @@ namespace clang {
|
|||
class ObjCInterfaceDecl;
|
||||
class ObjCProtocolDecl;
|
||||
class NSAPI;
|
||||
class EnumDecl;
|
||||
class TypedefDecl;
|
||||
class ParentMap;
|
||||
|
||||
namespace edit {
|
||||
|
@ -38,6 +40,10 @@ bool rewriteToObjCInterfaceDecl(const ObjCInterfaceDecl *IDecl,
|
|||
|
||||
bool rewriteToObjCSubscriptSyntax(const ObjCMessageExpr *Msg,
|
||||
const NSAPI &NS, Commit &commit);
|
||||
|
||||
bool rewriteToNSEnumDecl(const EnumDecl *EnumDcl,
|
||||
const TypedefDecl *TypedefDcl,
|
||||
const NSAPI &NS, Commit &commit);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -35,6 +35,8 @@ class ObjCMigrateASTConsumer : public ASTConsumer {
|
|||
void migrateObjCInterfaceDecl(ASTContext &Ctx, ObjCInterfaceDecl *D);
|
||||
void migrateProtocolConformance(ASTContext &Ctx,
|
||||
const ObjCImplementationDecl *ImpDecl);
|
||||
void migrateNSEnumDecl(ASTContext &Ctx, const EnumDecl *EnumDcl,
|
||||
const TypedefDecl *TypedefDcl);
|
||||
|
||||
public:
|
||||
std::string MigrateDir;
|
||||
|
@ -355,6 +357,25 @@ void ObjCMigrateASTConsumer::migrateProtocolConformance(ASTContext &Ctx,
|
|||
Editor->commit(commit);
|
||||
}
|
||||
|
||||
void ObjCMigrateASTConsumer::migrateNSEnumDecl(ASTContext &Ctx,
|
||||
const EnumDecl *EnumDcl,
|
||||
const TypedefDecl *TypedefDcl) {
|
||||
if (!EnumDcl->isCompleteDefinition() || EnumDcl->getIdentifier() ||
|
||||
!TypedefDcl->getIdentifier())
|
||||
return;
|
||||
|
||||
QualType qt = TypedefDcl->getTypeSourceInfo()->getType();
|
||||
if (!NSAPIObj->isObjCNSIntegerType(qt))
|
||||
return;
|
||||
|
||||
// NS_ENUM must be available.
|
||||
if (!Ctx.Idents.get("NS_ENUM").hasMacroDefinition())
|
||||
return;
|
||||
edit::Commit commit(*Editor);
|
||||
edit::rewriteToNSEnumDecl(EnumDcl, TypedefDcl, *NSAPIObj, commit);
|
||||
Editor->commit(commit);
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
class RewritesReceiver : public edit::EditsReceiver {
|
||||
|
@ -386,6 +407,12 @@ void ObjCMigrateASTConsumer::HandleTranslationUnit(ASTContext &Ctx) {
|
|||
else if (const ObjCImplementationDecl *ImpDecl =
|
||||
dyn_cast<ObjCImplementationDecl>(*D))
|
||||
migrateProtocolConformance(Ctx, ImpDecl);
|
||||
else if (const EnumDecl *ED = dyn_cast<EnumDecl>(*D)) {
|
||||
DeclContext::decl_iterator N = D;
|
||||
++N;
|
||||
if (const TypedefDecl *TD = dyn_cast<TypedefDecl>(*N))
|
||||
migrateNSEnumDecl(Ctx, ED, TD);
|
||||
}
|
||||
}
|
||||
|
||||
Rewriter rewriter(Ctx.getSourceManager(), Ctx.getLangOpts());
|
||||
|
|
|
@ -434,6 +434,19 @@ bool edit::rewriteToObjCInterfaceDecl(const ObjCInterfaceDecl *IDecl,
|
|||
return true;
|
||||
}
|
||||
|
||||
bool edit::rewriteToNSEnumDecl(const EnumDecl *EnumDcl,
|
||||
const TypedefDecl *TypedefDcl,
|
||||
const NSAPI &NS, Commit &commit) {
|
||||
std::string ClassString = "typedef NS_ENUM(NSInteger, ";
|
||||
ClassString += TypedefDcl->getIdentifier()->getName();
|
||||
ClassString += ')';
|
||||
SourceRange R(EnumDcl->getLocStart(), EnumDcl->getLocStart());
|
||||
commit.replace(R, ClassString);
|
||||
commit.remove(SourceRange(TypedefDcl->getLocStart(), TypedefDcl->getLocEnd()));
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
/// \brief Returns true if the immediate message arguments of \c Msg should not
|
||||
/// be rewritten because it will interfere with the rewrite of the parent
|
||||
/// message expression. e.g.
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
// RUN: rm -rf %t
|
||||
// RUN: %clang_cc1 -objcmt-migrate-property -mt-migrate-directory %t %s -x objective-c -fobjc-runtime-has-weak -fobjc-arc -fobjc-default-synthesize-properties -triple x86_64-apple-darwin11
|
||||
// RUN: c-arcmt-test -mt-migrate-directory %t | arcmt-test -verify-transformed-files %s.result
|
||||
// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -x objective-c -fobjc-runtime-has-weak -fobjc-arc -fobjc-default-synthesize-properties %s.result
|
||||
|
||||
typedef long NSInteger;
|
||||
#define NS_ENUM(_type, _name) enum _name : _type _name; enum _name : _type
|
||||
|
||||
enum {
|
||||
blah,
|
||||
blarg
|
||||
};
|
||||
typedef NSInteger wibble;
|
|
@ -0,0 +1,13 @@
|
|||
// RUN: rm -rf %t
|
||||
// RUN: %clang_cc1 -objcmt-migrate-property -mt-migrate-directory %t %s -x objective-c -fobjc-runtime-has-weak -fobjc-arc -fobjc-default-synthesize-properties -triple x86_64-apple-darwin11
|
||||
// RUN: c-arcmt-test -mt-migrate-directory %t | arcmt-test -verify-transformed-files %s.result
|
||||
// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -x objective-c -fobjc-runtime-has-weak -fobjc-arc -fobjc-default-synthesize-properties %s.result
|
||||
|
||||
typedef long NSInteger;
|
||||
#define NS_ENUM(_type, _name) enum _name : _type _name; enum _name : _type
|
||||
|
||||
typedef NS_ENUM(NSInteger, wibble) {
|
||||
blah,
|
||||
blarg
|
||||
};
|
||||
;
|
Loading…
Reference in New Issue