- wip.
llvm-svn: 186604
class ObjCInterfaceDecl;
class ObjCProtocolDecl;
class NSAPI;
+ class EnumDecl;
+ class TypedefDecl;
class ParentMap;
namespace edit {
bool rewriteToObjCSubscriptSyntax(const ObjCMessageExpr *Msg,
const NSAPI &NS, Commit &commit);
+
+bool rewriteToNSEnumDecl(const EnumDecl *EnumDcl,
+ const TypedefDecl *TypedefDcl,
+ const NSAPI &NS, Commit &commit);
}
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;
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 {
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());
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.
--- /dev/null
+// 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;
--- /dev/null
+// 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
+};
+;