//===--- TransAutoreleasePool.cpp - Transformations to ARC mode -----------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // // rewriteAutoreleasePool: // // Calls to NSAutoreleasePools will be rewritten as an @autorelease scope. // // NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; // ... // [pool release]; // ----> // @autorelease { // ... // } // // An NSAutoreleasePool will not be touched if: // - There is not a corresponding -release/-drain in the same scope // - Not all references of the NSAutoreleasePool variable can be removed // - There is a variable that is declared inside the intended @autorelease scope // which is also used outside it. // //===----------------------------------------------------------------------===// #include "Transforms.h" #include "Internals.h" #include "clang/AST/ASTContext.h" #include "clang/Basic/SourceManager.h" #include "clang/Sema/SemaDiagnostic.h" #include <map> usingnamespaceclang; usingnamespacearcmt; usingnamespacetrans; namespace { class ReleaseCollector : public RecursiveASTVisitor<ReleaseCollector> { … }; } namespace { class AutoreleasePoolRewriter : public RecursiveASTVisitor<AutoreleasePoolRewriter> { … }; } // anonymous namespace void trans::rewriteAutoreleasePool(MigrationPass &pass) { … }