r187000 - ObjC migrator: more knobs toward doing
Fariborz Jahanian
fjahanian at apple.com
Tue Jul 23 15:42:28 PDT 2013
Author: fjahanian
Date: Tue Jul 23 17:42:28 2013
New Revision: 187000
URL: http://llvm.org/viewvc/llvm-project?rev=187000&view=rev
Log:
ObjC migrator: more knobs toward doing
instancetype migration.
Modified:
cfe/trunk/include/clang/Basic/IdentifierTable.h
cfe/trunk/lib/ARCMigrate/ObjCMT.cpp
cfe/trunk/lib/Basic/IdentifierTable.cpp
Modified: cfe/trunk/include/clang/Basic/IdentifierTable.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/IdentifierTable.h?rev=187000&r1=186999&r2=187000&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/IdentifierTable.h (original)
+++ cfe/trunk/include/clang/Basic/IdentifierTable.h Tue Jul 23 17:42:28 2013
@@ -637,8 +637,6 @@ class Selector {
}
static ObjCMethodFamily getMethodFamilyImpl(Selector sel);
-
- static ObjCInstanceTypeFamily getInstTypeMethodFamilyImpl(Selector sel);
public:
friend class SelectorTable; // only the SelectorTable can create these
@@ -714,6 +712,8 @@ public:
static Selector getTombstoneMarker() {
return Selector(uintptr_t(-2));
}
+
+ static ObjCInstanceTypeFamily getInstTypeMethodFamily(Selector sel);
};
/// \brief This table allows us to fully hide how we implement
Modified: cfe/trunk/lib/ARCMigrate/ObjCMT.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/ARCMigrate/ObjCMT.cpp?rev=187000&r1=186999&r2=187000&view=diff
==============================================================================
--- cfe/trunk/lib/ARCMigrate/ObjCMT.cpp (original)
+++ cfe/trunk/lib/ARCMigrate/ObjCMT.cpp Tue Jul 23 17:42:28 2013
@@ -38,6 +38,7 @@ class ObjCMigrateASTConsumer : public AS
const ObjCImplementationDecl *ImpDecl);
void migrateNSEnumDecl(ASTContext &Ctx, const EnumDecl *EnumDcl,
const TypedefDecl *TypedefDcl);
+ void migrateInstanceType(ASTContext &Ctx, ObjCContainerDecl *CDecl);
public:
std::string MigrateDir;
@@ -546,6 +547,43 @@ void ObjCMigrateASTConsumer::migrateNSEn
Editor->commit(commit);
}
+static void
+migrateMethodInstanceType(ASTContext &Ctx,
+ ObjCContainerDecl *CDecl,
+ ObjCMethodDecl *OM) {
+ ObjCInstanceTypeFamily OIT_Family =
+ Selector::getInstTypeMethodFamily(OM->getSelector());
+ if (OIT_Family == OIT_None)
+ return;
+ // TODO. Many more to come
+ if (OIT_Family != OIT_Array)
+ return;
+ if (!OM->getResultType()->isObjCIdType())
+ return;
+
+ ObjCInterfaceDecl *IDecl = dyn_cast<ObjCInterfaceDecl>(CDecl);
+ if (!IDecl) {
+ if (ObjCCategoryDecl *CatDecl = dyn_cast<ObjCCategoryDecl>(CDecl))
+ IDecl = CatDecl->getClassInterface();
+ else if (ObjCImplDecl *ImpDecl = dyn_cast<ObjCImplDecl>(CDecl))
+ IDecl = ImpDecl->getClassInterface();
+ }
+ if (!IDecl || !IDecl->lookupInheritedClass(&Ctx.Idents.get("NSArray")))
+ return;
+
+}
+
+void ObjCMigrateASTConsumer::migrateInstanceType(ASTContext &Ctx,
+ ObjCContainerDecl *CDecl) {
+ // migrate methods which can have instancetype as their result type.
+ for (ObjCContainerDecl::method_iterator M = CDecl->meth_begin(),
+ MEnd = CDecl->meth_end();
+ M != MEnd; ++M) {
+ ObjCMethodDecl *Method = (*M);
+ migrateMethodInstanceType(Ctx, CDecl, Method);
+ }
+}
+
namespace {
class RewritesReceiver : public edit::EditsReceiver {
@@ -584,6 +622,9 @@ void ObjCMigrateASTConsumer::HandleTrans
if (const TypedefDecl *TD = dyn_cast<TypedefDecl>(*N))
migrateNSEnumDecl(Ctx, ED, TD);
}
+ // migrate methods which can have instancetype as their result type.
+ if (ObjCContainerDecl *CDecl = dyn_cast<ObjCContainerDecl>(*D))
+ migrateInstanceType(Ctx, CDecl);
}
Rewriter rewriter(Ctx.getSourceManager(), Ctx.getLangOpts());
Modified: cfe/trunk/lib/Basic/IdentifierTable.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/IdentifierTable.cpp?rev=187000&r1=186999&r2=187000&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/IdentifierTable.cpp (original)
+++ cfe/trunk/lib/Basic/IdentifierTable.cpp Tue Jul 23 17:42:28 2013
@@ -452,7 +452,7 @@ ObjCMethodFamily Selector::getMethodFami
return OMF_None;
}
-ObjCInstanceTypeFamily Selector::getInstTypeMethodFamilyImpl(Selector sel) {
+ObjCInstanceTypeFamily Selector::getInstTypeMethodFamily(Selector sel) {
IdentifierInfo *first = sel.getIdentifierInfoForSlot(0);
if (!first) return OIT_None;
More information about the cfe-commits
mailing list