diff options
author | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2011-11-06 18:58:17 +0000 |
---|---|---|
committer | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2011-11-06 18:58:17 +0000 |
commit | 17ac3197941b9f135424dfe3900577a04407c5c2 (patch) | |
tree | 2789016e833d6ca1f50a2cd3694be4eb11758a78 /lib/ARCMigrate | |
parent | dbbdec994f5a96b5c25aaa679cd86ecabf545f7b (diff) |
[arcmt] In GC, clear redundant __strong's.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@143886 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/ARCMigrate')
-rw-r--r-- | lib/ARCMigrate/TransGCAttrs.cpp | 40 | ||||
-rw-r--r-- | lib/ARCMigrate/Transforms.h | 2 |
2 files changed, 34 insertions, 8 deletions
diff --git a/lib/ARCMigrate/TransGCAttrs.cpp b/lib/ARCMigrate/TransGCAttrs.cpp index 60573a44e8..a85cad4d44 100644 --- a/lib/ARCMigrate/TransGCAttrs.cpp +++ b/lib/ARCMigrate/TransGCAttrs.cpp @@ -101,7 +101,7 @@ public: MigrationContext::GCAttrOccurrence &Attr = MigrateCtx.GCAttrs.back(); Attr.Kind = Kind; - Attr.Loc = Loc; + Attr.Loc = SM.getImmediateExpansionRange(Loc).first; Attr.ModifiedType = TL.getModifiedLoc().getType(); Attr.Dcl = D; Attr.FullyMigratable = FullyMigratable; @@ -163,18 +163,43 @@ public: } // anonymous namespace +static void clearRedundantStrongs(MigrationContext &MigrateCtx) { + TransformActions &TA = MigrateCtx.Pass.TA; + + for (unsigned i = 0, e = MigrateCtx.GCAttrs.size(); i != e; ++i) { + MigrationContext::GCAttrOccurrence &Attr = MigrateCtx.GCAttrs[i]; + if (Attr.Kind == MigrationContext::GCAttrOccurrence::Strong && + Attr.FullyMigratable && Attr.Dcl) { + TypeSourceInfo *TInfo = 0; + if (DeclaratorDecl *DD = dyn_cast<DeclaratorDecl>(Attr.Dcl)) + TInfo = DD->getTypeSourceInfo(); + else if (ObjCPropertyDecl *PD = dyn_cast<ObjCPropertyDecl>(Attr.Dcl)) + TInfo = PD->getTypeSourceInfo(); + if (!TInfo) + continue; + + if (TInfo->getType().getObjCLifetime() == Qualifiers::OCL_Strong) { + Transaction Trans(TA); + TA.remove(Attr.Loc); + } + } + } +} + void GCAttrsTraverser::traverseTU(MigrationContext &MigrateCtx) { GCAttrsCollector(MigrateCtx).TraverseDecl( MigrateCtx.Pass.Ctx.getTranslationUnitDecl()); -#if 0 + clearRedundantStrongs(MigrateCtx); +} + +void MigrationContext::dumpGCAttrs() { llvm::errs() << "\n################\n"; - for (unsigned i = 0, e = MigrateCtx.GCAttrs.size(); i != e; ++i) { - MigrationContext::GCAttrOccurrence &Attr = MigrateCtx.GCAttrs[i]; + for (unsigned i = 0, e = GCAttrs.size(); i != e; ++i) { + GCAttrOccurrence &Attr = GCAttrs[i]; llvm::errs() << "KIND: " - << (Attr.Kind == MigrationContext::GCAttrOccurrence::Strong ? "strong" - : "weak"); + << (Attr.Kind == GCAttrOccurrence::Strong ? "strong" : "weak"); llvm::errs() << "\nLOC: "; - Attr.Loc.dump(MigrateCtx.Pass.Ctx.getSourceManager()); + Attr.Loc.dump(Pass.Ctx.getSourceManager()); llvm::errs() << "\nTYPE: "; Attr.ModifiedType.dump(); if (Attr.Dcl) { @@ -187,5 +212,4 @@ void GCAttrsTraverser::traverseTU(MigrationContext &MigrateCtx) { llvm::errs() << "\n----------------\n"; } llvm::errs() << "\n################\n"; -#endif } diff --git a/lib/ARCMigrate/Transforms.h b/lib/ARCMigrate/Transforms.h index 540426b81a..3f1e737e23 100644 --- a/lib/ARCMigrate/Transforms.h +++ b/lib/ARCMigrate/Transforms.h @@ -111,6 +111,8 @@ public: bool isGCOwnedNonObjC(QualType T); void traverse(TranslationUnitDecl *TU); + + void dumpGCAttrs(); }; class PropertyRewriteTraverser : public ASTTraverser { |