//===--- TransUnbridgedCasts.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 // //===----------------------------------------------------------------------===// // // rewriteUnbridgedCasts: // // A cast of non-objc pointer to an objc one is checked. If the non-objc pointer // is from a file-level variable, __bridge cast is used to convert it. // For the result of a function call that we know is +1/+0, // __bridge/CFBridgingRelease is used. // // NSString *str = (NSString *)kUTTypePlainText; // str = b ? kUTTypeRTF : kUTTypePlainText; // NSString *_uuidString = (NSString *)CFUUIDCreateString(kCFAllocatorDefault, // _uuid); // ----> // NSString *str = (__bridge NSString *)kUTTypePlainText; // str = (__bridge NSString *)(b ? kUTTypeRTF : kUTTypePlainText); // NSString *_uuidString = (NSString *) // CFBridgingRelease(CFUUIDCreateString(kCFAllocatorDefault, _uuid)); // // For a C pointer to ObjC, for casting 'self', __bridge is used. // // CFStringRef str = (CFStringRef)self; // ----> // CFStringRef str = (__bridge CFStringRef)self; // // Uses of Block_copy/Block_release macros are rewritten: // // c = Block_copy(b); // Block_release(c); // ----> // c = [b copy]; // <removed> // //===----------------------------------------------------------------------===// #include "Transforms.h" #include "Internals.h" #include "clang/AST/ASTContext.h" #include "clang/AST/Attr.h" #include "clang/AST/ParentMap.h" #include "clang/Analysis/DomainSpecific/CocoaConventions.h" #include "clang/Basic/SourceManager.h" #include "clang/Lex/Lexer.h" #include "clang/Sema/SemaDiagnostic.h" #include "llvm/ADT/SmallString.h" usingnamespaceclang; usingnamespacearcmt; usingnamespacetrans; namespace { class UnbridgedCastRewriter : public RecursiveASTVisitor<UnbridgedCastRewriter>{ … }; } // end anonymous namespace void trans::rewriteUnbridgedCasts(MigrationPass &pass) { … }