1 //===--- TransARCAssign.cpp - Transformations to ARC mode -----------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
12 // Add '__strong' where appropriate.
14 // for (id x in collection) {
18 // for (__strong id x in collection) {
22 //===----------------------------------------------------------------------===//
24 #include "Transforms.h"
25 #include "Internals.h"
26 #include "clang/AST/ASTContext.h"
27 #include "clang/Sema/SemaDiagnostic.h"
29 using namespace clang;
30 using namespace arcmt;
31 using namespace trans;
35 class ARCAssignChecker : public RecursiveASTVisitor<ARCAssignChecker> {
37 llvm::DenseSet<VarDecl *> ModifiedVars;
40 ARCAssignChecker(MigrationPass &pass) : Pass(pass) { }
42 bool VisitBinaryOperator(BinaryOperator *Exp) {
43 if (Exp->getType()->isDependentType())
46 Expr *E = Exp->getLHS();
47 SourceLocation OrigLoc = E->getExprLoc();
48 SourceLocation Loc = OrigLoc;
49 DeclRefExpr *declRef = dyn_cast<DeclRefExpr>(E->IgnoreParenCasts());
50 if (declRef && isa<VarDecl>(declRef->getDecl())) {
51 ASTContext &Ctx = Pass.Ctx;
52 Expr::isModifiableLvalueResult IsLV = E->isModifiableLvalue(Ctx, &Loc);
53 if (IsLV != Expr::MLV_ConstQualified)
55 VarDecl *var = cast<VarDecl>(declRef->getDecl());
56 if (var->isARCPseudoStrong()) {
57 Transaction Trans(Pass.TA);
58 if (Pass.TA.clearDiagnostic(diag::err_typecheck_arr_assign_enumeration,
59 Exp->getOperatorLoc())) {
60 if (!ModifiedVars.count(var)) {
61 TypeLoc TLoc = var->getTypeSourceInfo()->getTypeLoc();
62 Pass.TA.insert(TLoc.getBeginLoc(), "__strong ");
63 ModifiedVars.insert(var);
73 } // anonymous namespace
75 void trans::makeAssignARCSafe(MigrationPass &pass) {
76 ARCAssignChecker assignCheck(pass);
77 assignCheck.TraverseDecl(pass.Ctx.getTranslationUnitDecl());