diff options
author | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2013-12-11 21:39:00 +0000 |
---|---|---|
committer | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2013-12-11 21:39:00 +0000 |
commit | 3f72934bba66d46c756f6c1cc165154c4ca69ec1 (patch) | |
tree | 8b90f5ab5b8c70b6860068f63715fa92acae5e1a /clang/lib/ARCMigrate/ObjCMT.cpp | |
parent | e439f92a6ca5e9b4fd8d9cfbbdb6cc2e376dd088 (diff) | |
download | bcm5719-llvm-3f72934bba66d46c756f6c1cc165154c4ca69ec1.tar.gz bcm5719-llvm-3f72934bba66d46c756f6c1cc165154c4ca69ec1.zip |
[objcmt] When whitelisting the headers we want to modify, allow changing the
the ObjC implementation declarations, just don't change implementations for
classes that are not in the whitelisted headers.
For example, if we change a method to return 'instancetype' we should also
update the method definition in the implementation.
llvm-svn: 197075
Diffstat (limited to 'clang/lib/ARCMigrate/ObjCMT.cpp')
-rw-r--r-- | clang/lib/ARCMigrate/ObjCMT.cpp | 52 |
1 files changed, 43 insertions, 9 deletions
diff --git a/clang/lib/ARCMigrate/ObjCMT.cpp b/clang/lib/ARCMigrate/ObjCMT.cpp index c14fca2738d..b2dcd4f9c77 100644 --- a/clang/lib/ARCMigrate/ObjCMT.cpp +++ b/clang/lib/ARCMigrate/ObjCMT.cpp @@ -144,6 +144,30 @@ protected: return WhiteListFilenames.find(llvm::sys::path::filename(Path)) != WhiteListFilenames.end(); } + bool canModifyFile(const FileEntry *FE) { + if (!FE) + return false; + return canModifyFile(FE->getName()); + } + bool canModifyFile(FileID FID) { + if (FID.isInvalid()) + return false; + return canModifyFile(PP.getSourceManager().getFileEntryForID(FID)); + } + + bool canModify(const Decl *D) { + if (!D) + return false; + if (const ObjCCategoryImplDecl *CatImpl = dyn_cast<ObjCCategoryImplDecl>(D)) + return canModify(CatImpl->getCategoryDecl()); + if (const ObjCImplementationDecl *Impl = dyn_cast<ObjCImplementationDecl>(D)) + return canModify(Impl->getClassInterface()); + if (const ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(D)) + return canModify(cast<Decl>(MD->getDeclContext())); + + FileID FID = PP.getSourceManager().getFileID(D->getLocation()); + return canModifyFile(FID); + } }; } @@ -1651,20 +1675,25 @@ void ObjCMigrateASTConsumer::HandleTranslationUnit(ASTContext &Ctx) { } if (ObjCInterfaceDecl *CDecl = dyn_cast<ObjCInterfaceDecl>(*D)) - migrateObjCInterfaceDecl(Ctx, CDecl); + if (canModify(CDecl)) + migrateObjCInterfaceDecl(Ctx, CDecl); if (ObjCCategoryDecl *CatDecl = dyn_cast<ObjCCategoryDecl>(*D)) { - migrateObjCInterfaceDecl(Ctx, CatDecl); + if (canModify(CatDecl)) + migrateObjCInterfaceDecl(Ctx, CatDecl); } else if (ObjCProtocolDecl *PDecl = dyn_cast<ObjCProtocolDecl>(*D)) ObjCProtocolDecls.insert(PDecl); else if (const ObjCImplementationDecl *ImpDecl = dyn_cast<ObjCImplementationDecl>(*D)) { - if (ASTMigrateActions & FrontendOptions::ObjCMT_ProtocolConformance) + if ((ASTMigrateActions & FrontendOptions::ObjCMT_ProtocolConformance) && + canModify(ImpDecl)) migrateProtocolConformance(Ctx, ImpDecl); } else if (const EnumDecl *ED = dyn_cast<EnumDecl>(*D)) { if (!(ASTMigrateActions & FrontendOptions::ObjCMT_NsMacros)) continue; + if (!canModify(ED)) + continue; DeclContext::decl_iterator N = D; if (++N != DEnd) { const TypedefDecl *TD = dyn_cast<TypedefDecl>(*N); @@ -1677,6 +1706,8 @@ void ObjCMigrateASTConsumer::HandleTranslationUnit(ASTContext &Ctx) { else if (const TypedefDecl *TD = dyn_cast<TypedefDecl>(*D)) { if (!(ASTMigrateActions & FrontendOptions::ObjCMT_NsMacros)) continue; + if (!canModify(TD)) + continue; DeclContext::decl_iterator N = D; if (++N == DEnd) continue; @@ -1698,22 +1729,27 @@ void ObjCMigrateASTConsumer::HandleTranslationUnit(ASTContext &Ctx) { CacheObjCNSIntegerTypedefed(TD); } else if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(*D)) { - if (ASTMigrateActions & FrontendOptions::ObjCMT_Annotation) + if ((ASTMigrateActions & FrontendOptions::ObjCMT_Annotation) && + canModify(FD)) migrateCFAnnotation(Ctx, FD); } if (ObjCContainerDecl *CDecl = dyn_cast<ObjCContainerDecl>(*D)) { + bool CanModify = canModify(CDecl); // migrate methods which can have instancetype as their result type. - if (ASTMigrateActions & FrontendOptions::ObjCMT_Instancetype) + if ((ASTMigrateActions & FrontendOptions::ObjCMT_Instancetype) && + CanModify) migrateAllMethodInstaceType(Ctx, CDecl); // annotate methods with CF annotations. - if (ASTMigrateActions & FrontendOptions::ObjCMT_Annotation) + if ((ASTMigrateActions & FrontendOptions::ObjCMT_Annotation) && + CanModify) migrateARCSafeAnnotation(Ctx, CDecl); } if (const ObjCImplementationDecl * ImplD = dyn_cast<ObjCImplementationDecl>(*D)) { - if (ASTMigrateActions & FrontendOptions::ObjCMT_DesignatedInitializer) + if ((ASTMigrateActions & FrontendOptions::ObjCMT_DesignatedInitializer) && + canModify(ImplD)) inferDesignatedInitializers(Ctx, ImplD); } } @@ -1733,8 +1769,6 @@ void ObjCMigrateASTConsumer::HandleTranslationUnit(ASTContext &Ctx) { assert(file); if (IsReallyASystemHeader(Ctx, file, FID)) continue; - if (!canModifyFile(file->getName())) - continue; SmallString<512> newText; llvm::raw_svector_ostream vecOS(newText); buf.write(vecOS); |