28 if (!EnableCFBridgeFns)
29 EnableCFBridgeFns = SemaRef.isKnownName(
"CFBridgingRetain") &&
30 SemaRef.isKnownName(
"CFBridgingRelease");
31 return *EnableCFBridgeFns;
39 bool AllowOnUnknownClass) {
50 AllowOnUnknownClass =
true;
56 if (!AllowOnUnknownClass && (!Class || Class->getName() ==
"NSObject"))
58 if (!AllowOnUnknownClass && !Class->hasDefinition())
60 if (Class && Class->isArcWeakrefUnavailable())
77 if (
const FullExpr *FE = dyn_cast<FullExpr>(E))
88 if (FD->hasAttr<CFReturnsRetainedAttr>())
92 FD->getIdentifier() &&
93 FD->getParent()->isTranslationUnit() &&
94 FD->isExternallyVisible() &&
96 FD->getIdentifier()->getName())) {
97 StringRef fname = FD->getIdentifier()->getName();
98 if (fname.endswith(
"Retain") || fname.contains(
"Create") ||
99 fname.contains(
"Copy"))
106 while (implCE && implCE->
getCastKind() == CK_BitCast)
107 implCE = dyn_cast<ImplicitCastExpr>(implCE->
getSubExpr());
109 return implCE && implCE->
getCastKind() == CK_ARCConsumeObject;
139 std::pair<FileID, unsigned> locInfo =
SM.getDecomposedLoc(loc);
142 bool invalidTemp =
false;
143 StringRef file =
SM.getBufferData(locInfo.first, &invalidTemp);
147 const char *tokenBegin = file.data() + locInfo.second;
150 Lexer lexer(
SM.getLocForStartOfFile(locInfo.first),
152 file.begin(), tokenBegin, file.end());
155 if (tok.
isNot(tok::semi)) {
198 return DRE->getDecl()->getDeclContext()->isFileContext() &&
199 DRE->getDecl()->isExternallyVisible();
216 ReferenceClear(
ExprSet &refs) : Refs(refs) { }
217 bool VisitDeclRefExpr(
DeclRefExpr *E) { Refs.erase(E);
return true; }
226 : Dcl(D), Refs(refs) { }
239 RemovablesCollector(
ExprSet &removables)
240 : Removables(removables) { }
242 bool shouldWalkTypesOfTypeLocs()
const {
return false; }
244 bool TraverseStmtExpr(
StmtExpr *E) {
247 I = S->body_begin(), E = S->body_end(); I != E; ++I) {
256 for (
auto *I : S->body())
261 bool VisitIfStmt(
IfStmt *S) {
272 bool VisitDoStmt(
DoStmt *S) {
277 bool VisitForStmt(
ForStmt *S) {
288 while (
auto *
Label = dyn_cast<LabelStmt>(S))
289 S =
Label->getSubStmt();
290 if (
auto *E = dyn_cast<Expr>(S))
292 if (
auto *E = dyn_cast<Expr>(S))
293 Removables.insert(E);
300 ReferenceClear(refs).TraverseStmt(S);
304 ReferenceCollector(D, refs).TraverseStmt(S);
308 RemovablesCollector(exprs).TraverseStmt(S);
324 bool shouldWalkTypesOfTypeLocs()
const {
return false; }
331 (*I)->traverseObjCImplementation(ImplCtx);
333 return base::TraverseObjCImplementationDecl(D);
336 bool TraverseStmt(
Stmt *rootS) {
344 (*I)->traverseBody(BodyCtx);
361 if (AttrT->getAttrKind() == attr::ObjCOwnership)
362 return !AttrT->getModifiedType()->isObjCRetainableType();
387 std::pair<FileID, unsigned> locInfo =
SM.getDecomposedLoc(atLoc);
390 bool invalidTemp =
false;
391 StringRef file =
SM.getBufferData(locInfo.first, &invalidTemp);
395 const char *tokenBegin = file.data() + locInfo.second;
398 Lexer lexer(
SM.getLocForStartOfFile(locInfo.first),
400 file.begin(), tokenBegin, file.end());
403 if (tok.
isNot(tok::at))
return false;
405 if (tok.
isNot(tok::raw_identifier))
return false;
409 if (tok.
isNot(tok::l_paren))
return false;
411 Token BeforeTok = tok;
417 if (tok.
is(tok::r_paren))
421 if (tok.
isNot(tok::raw_identifier))
return false;
423 if (!toAttr.empty()) {
433 if (AttrLoc.
isValid() && AfterTok.
is(tok::unknown))
435 }
while (tok.
isNot(tok::comma) && tok.
isNot(tok::r_paren));
436 if (tok.
is(tok::r_paren))
443 if (toAttr.empty() && AttrLoc.
isValid() && AfterTok.
isNot(tok::unknown)) {
445 if (BeforeTok.
is(tok::l_paren) && AfterTok.
is(tok::r_paren)) {
448 }
else if (BeforeTok.
is(tok::l_paren) && AfterTok.
is(tok::comma)) {
468 std::pair<FileID, unsigned> locInfo =
SM.getDecomposedLoc(atLoc);
471 bool invalidTemp =
false;
472 StringRef file =
SM.getBufferData(locInfo.first, &invalidTemp);
476 const char *tokenBegin = file.data() + locInfo.second;
479 Lexer lexer(
SM.getLocForStartOfFile(locInfo.first),
481 file.begin(), tokenBegin, file.end());
484 if (tok.
isNot(tok::at))
return false;
486 if (tok.
isNot(tok::raw_identifier))
return false;
491 if (tok.
isNot(tok::l_paren)) {
497 if (tok.
is(tok::r_paren)) {
502 if (tok.
isNot(tok::raw_identifier))
return false;
511 (*I)->traverseTU(*
this);
513 ASTTransform(*this).TraverseDecl(TU);
525 for (impl_iterator I = impl_iterator(DC->
decls_begin()),
526 E = impl_iterator(DC->
decls_end()); I != E; ++I) {
527 for (
const auto *MD : I->instance_methods()) {
531 if (MD->isInstanceMethod() && MD->getSelector() == FinalizeSel) {
535 "#if !__has_feature(objc_arc)\n");
540 std::string str =
"\n#endif\n";
583 bool NoFinalizeRemoval) {
584 std::vector<TransformFn> transforms;
Defines the clang::ASTContext interface.
Defines the clang::Preprocessor interface.
Defines the SourceManager interface.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
SourceManager & getSourceManager()
TranslationUnitDecl * getTranslationUnitDecl() const
const LangOptions & getLangOpts() const
SelectorTable & Selectors
QualType getBaseElementType(const ArrayType *VAT) const
Return the innermost element type of an array type.
const TargetInfo & getTargetInfo() const
An attributed type is a type to which a type attribute has been applied.
A builtin binary operation expression such as "x + y" or "x <= y".
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
CastKind getCastKind() const
static CharSourceRange getTokenRange(SourceRange R)
CompoundStmt - This represents a group of statements like { stmt stmt }.
ConditionalOperator - The ?: ternary operator.
specific_decl_iterator - Iterates over a subrange of declarations stored in a DeclContext,...
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
decl_iterator decls_end() const
decl_iterator decls_begin() const
A reference to a declared variable, function, enum, etc.
DoStmt - This represents a 'do/while' stmt.
This represents one expression.
Expr * IgnoreParenCasts() LLVM_READONLY
Skip past any parentheses and casts which might surround this expression until reaching a fixed point...
Expr * IgnoreImplicit() LLVM_READONLY
Skip past any implicit AST nodes which might surround this expression until reaching a fixed point.
bool HasSideEffects(const ASTContext &Ctx, bool IncludePossibleEffects=true) const
HasSideEffects - This routine returns true for all those expressions which have any effect other than...
ForStmt - This represents a 'for (init;cond;inc)' stmt.
FullExpr - Represents a "full-expression" node.
Represents a function declaration or definition.
IdentifierInfo & get(StringRef Name)
Return the identifier token info for the specified named identifier.
IfStmt - This represents an if/then/else.
ImplicitCastExpr - Allows us to explicitly represent implicit type conversions, which have no direct ...
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Lexer - This provides a simple interface that turns a text buffer into a stream of tokens.
static StringRef getSourceText(CharSourceRange Range, const SourceManager &SM, const LangOptions &LangOpts, bool *Invalid=nullptr)
Returns a string for the source that the range encompasses.
bool LexFromRawLexer(Token &Result)
LexFromRawLexer - Lex a token from a designated raw lexer (one with no associated preprocessor object...
static bool isAtEndOfMacroExpansion(SourceLocation loc, const SourceManager &SM, const LangOptions &LangOpts, SourceLocation *MacroEnd=nullptr)
Returns true if the given MacroID location points at the last token of the macro expansion.
static SourceLocation getLocForEndOfToken(SourceLocation Loc, unsigned Offset, const SourceManager &SM, const LangOptions &LangOpts)
Computes the source location just past the end of the token at this source location.
ObjCImplementationDecl - Represents a class definition - this is where method definitions are specifi...
Represents an ObjC class declaration.
An expression that sends a message to the given Objective-C object or class.
Expr * getInstanceReceiver()
Returns the object expression (receiver) for an instance message, or null for a message that is not a...
ObjCMethodFamily getMethodFamily() const
@ SuperInstance
The receiver is the instance of the superclass object.
@ Instance
The receiver is an object instance.
ReceiverKind getReceiverKind() const
Determine the kind of receiver that this message is being sent to.
ObjCMethodDecl - Represents an instance or class method declaration.
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Represents a pointer to an Objective C object.
PointerType - C99 6.7.5.1 - Pointer Declarators.
bool isMacroDefined(StringRef Id)
A (possibly-)qualified type.
bool isNull() const
Return true if this QualType doesn't point to a type yet.
A class that does preorder or postorder depth-first traversal on the entire Clang AST and visits each...
Base for LValueReferenceType and RValueReferenceType.
Selector getNullarySelector(IdentifierInfo *ID)
Smart pointer class that efficiently represents Objective-C method names.
Encodes a location in the source.
bool isValid() const
Return true if this is a valid SourceLocation object.
SourceLocation getLocWithOffset(IntTy Offset) const
Return a source location with the specified offset from this SourceLocation.
This class handles loading and caching of source files into memory.
A trivial tuple used to represent a source range.
SourceLocation getEnd() const
SourceLocation getBegin() const
StmtExpr - This is the GNU Statement Expression extension: ({int X=4; X;}).
CompoundStmt * getSubStmt()
Stmt - This represents one statement.
const llvm::Triple & getTriple() const
Returns the target triple of the primary target.
Token - This structure provides full information about a lexed token.
SourceLocation getLocation() const
Return a source location identifier for the specified offset in the current file.
bool is(tok::TokenKind K) const
is/isNot - Predicates to check if this token is a specific kind, as in "if (Tok.is(tok::l_brace)) {....
bool isNot(tok::TokenKind K) const
void startToken()
Reset all flags to cleared.
StringRef getRawIdentifier() const
getRawIdentifier - For a raw identifier token (i.e., an identifier lexed in raw mode),...
The top declaration context.
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee.
const T * getAs() const
Member-template getAs<specific type>'.
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
WhileStmt - This represents a 'while' stmt.
bool isGCMigration() const
bool CFBridgingFunctionsDefined()
void traverse(TranslationUnitDecl *TU)
bool addPropertyAttribute(StringRef attr, SourceLocation atLoc)
traverser_iterator traversers_begin()
std::vector< ASTTraverser * >::iterator traverser_iterator
bool rewritePropertyAttribute(StringRef fromAttr, StringRef toAttr, SourceLocation atLoc)
void addTraverser(ASTTraverser *traverser)
bool isGCOwnedNonObjC(QualType T)
traverser_iterator traversers_end()
Defines the clang::TargetInfo interface.
StringRef getNilString(MigrationPass &Pass)
Returns "nil" or "0" if 'nil' macro is not actually defined.
bool hasSideEffects(Expr *E, ASTContext &Ctx)
void removeRetainReleaseDeallocFinalize(MigrationPass &pass)
bool canApplyWeak(ASTContext &Ctx, QualType type, bool AllowOnUnknownClass=false)
Determine whether we can add weak to the given type.
void removeEmptyStatementsAndDeallocFinalize(MigrationPass &pass)
void collectRefs(ValueDecl *D, Stmt *S, ExprSet &refs)
void clearRefsIn(Stmt *S, ExprSet &refs)
void rewriteAutoreleasePool(MigrationPass &pass)
void rewriteUnbridgedCasts(MigrationPass &pass)
void rewriteUnusedInitDelegate(MigrationPass &pass)
bool isPlusOneAssign(const BinaryOperator *E)
void checkAPIUses(MigrationPass &pass)
bool isPlusOne(const Expr *E)
SourceLocation findLocationAfterSemi(SourceLocation loc, ASTContext &Ctx, bool IsDecl=false)
'Loc' is the end of a statement range.
bool isGlobalVar(Expr *E)
void removeZeroOutPropsInDeallocFinalize(MigrationPass &pass)
SourceLocation findSemiAfterLocation(SourceLocation loc, ASTContext &Ctx, bool IsDecl=false)
'Loc' is the end of a statement range.
void makeAssignARCSafe(MigrationPass &pass)
void collectRemovables(Stmt *S, ExprSet &exprs)
std::vector< TransformFn > getAllTransformations(LangOptions::GCMode OrigGCMode, bool NoFinalizeRemoval)
const internal::VariadicAllOfMatcher< Attr > attr
Matches attributes.
const internal::VariadicAllOfMatcher< Type > type
Matches Types in the clang AST.
bool isRefType(QualType RetTy, StringRef Prefix, StringRef Name=StringRef())