@@ -32,29 +32,34 @@ using namespace trans;
3232
3333namespace {
3434
35- class RetainReleaseDeallocRemover : public DynamicRecursiveASTVisitor {
35+ class RetainReleaseDeallocRemover : public BodyTransform {
3636 Stmt *Body;
37- MigrationPass &Pass;
3837
3938 ExprSet Removables;
4039 std::unique_ptr<ParentMap> StmtMap;
40+ bool TraversingBody = false ;
4141
4242 Selector DelegateSel, FinalizeSel;
4343
4444public:
4545 RetainReleaseDeallocRemover (MigrationPass &pass)
46- : Body( nullptr ), Pass(pass ) {
46+ : BodyTransform(pass ), Body( nullptr ) {
4747 DelegateSel =
4848 Pass.Ctx .Selectors .getNullarySelector (&Pass.Ctx .Idents .get (" delegate" ));
4949 FinalizeSel =
5050 Pass.Ctx .Selectors .getNullarySelector (&Pass.Ctx .Idents .get (" finalize" ));
5151 }
5252
53- void transformBody (Stmt *body, Decl *ParentD) {
53+ bool TraverseStmt (Stmt *body) override {
54+ if (TraversingBody)
55+ return BodyTransform::TraverseStmt (body);
56+
57+ llvm::SaveAndRestore Restore{TraversingBody, true };
5458 Body = body;
5559 collectRemovables (body, Removables);
5660 StmtMap.reset (new ParentMap (body));
57- TraverseStmt (body);
61+ BodyTransform::TraverseStmt (body);
62+ return true ;
5863 }
5964
6065 bool VisitObjCMessageExpr (ObjCMessageExpr *E) override {
@@ -453,6 +458,6 @@ class RetainReleaseDeallocRemover : public DynamicRecursiveASTVisitor {
453458} // anonymous namespace
454459
455460void trans::removeRetainReleaseDeallocFinalize (MigrationPass &pass) {
456- BodyTransform< RetainReleaseDeallocRemover> trans (pass);
461+ RetainReleaseDeallocRemover trans (pass);
457462 trans.TraverseDecl (pass.Ctx .getTranslationUnitDecl ());
458463}
0 commit comments