4545#include " clang/AST/Attr.h"
4646#include " clang/AST/DynamicRecursiveASTVisitor.h"
4747#include " clang/AST/ParentMap.h"
48+ #include " clang/AST/RecursiveASTVisitor.h"
4849#include " clang/Analysis/DomainSpecific/CocoaConventions.h"
4950#include " clang/Basic/SourceManager.h"
5051#include " clang/Lex/Lexer.h"
@@ -56,6 +57,33 @@ using namespace arcmt;
5657using namespace trans ;
5758
5859namespace {
60+ // FIXME: UnbridgedCastRewriter should probably just inherit from
61+ // BodyTransform (and this class shouldn't exist in the first place),
62+ // but I have so far been unable to untangle whatever is actually going
63+ // on in TraverseBlockDecl() that makes that not work properly...
64+ template <typename BODY_TRANS>
65+ class UnbridgedCastRewriterWrapper
66+ : public RecursiveASTVisitor<UnbridgedCastRewriterWrapper<BODY_TRANS>> {
67+ MigrationPass &Pass;
68+ Decl *ParentD;
69+
70+ typedef RecursiveASTVisitor<UnbridgedCastRewriterWrapper<BODY_TRANS>> base;
71+
72+ public:
73+ UnbridgedCastRewriterWrapper (MigrationPass &pass)
74+ : Pass(pass), ParentD(nullptr ) {}
75+
76+ bool TraverseStmt (Stmt *rootS) {
77+ if (rootS)
78+ BODY_TRANS (Pass).transformBody (rootS, ParentD);
79+ return true ;
80+ }
81+
82+ bool TraverseObjCMethodDecl (ObjCMethodDecl *D) {
83+ SaveAndRestore<Decl *> SetParent (ParentD, D);
84+ return base::TraverseObjCMethodDecl (D);
85+ }
86+ };
5987
6088class UnbridgedCastRewriter : public DynamicRecursiveASTVisitor {
6189 MigrationPass &Pass;
@@ -462,6 +490,6 @@ class UnbridgedCastRewriter : public DynamicRecursiveASTVisitor {
462490} // end anonymous namespace
463491
464492void trans::rewriteUnbridgedCasts (MigrationPass &pass) {
465- BodyTransform_OLD <UnbridgedCastRewriter> trans (pass);
493+ UnbridgedCastRewriterWrapper <UnbridgedCastRewriter> trans (pass);
466494 trans.TraverseDecl (pass.Ctx .getTranslationUnitDecl ());
467495}
0 commit comments