Argyrios Kyrtzidis | f38fa73 | 2011-11-06 18:58:03 +0000 | [diff] [blame] | 1 | //===--- TransGCAttrs.cpp - Transformations to ARC mode --------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #include "Transforms.h" |
| 11 | #include "Internals.h" |
Benjamin Kramer | 471c8b4 | 2012-07-04 20:19:54 +0000 | [diff] [blame] | 12 | #include "clang/AST/ASTContext.h" |
Argyrios Kyrtzidis | f38fa73 | 2011-11-06 18:58:03 +0000 | [diff] [blame] | 13 | #include "clang/Basic/SourceManager.h" |
Benjamin Kramer | 471c8b4 | 2012-07-04 20:19:54 +0000 | [diff] [blame] | 14 | #include "clang/Lex/Lexer.h" |
Argyrios Kyrtzidis | 12192cf | 2011-11-07 18:40:29 +0000 | [diff] [blame] | 15 | #include "clang/Sema/SemaDiagnostic.h" |
Benjamin Kramer | 8fe83e1 | 2012-02-04 13:45:25 +0000 | [diff] [blame] | 16 | #include "llvm/ADT/SmallString.h" |
Argyrios Kyrtzidis | b0e1e12 | 2011-11-07 18:46:46 +0000 | [diff] [blame] | 17 | #include "llvm/ADT/TinyPtrVector.h" |
Benjamin Kramer | 471c8b4 | 2012-07-04 20:19:54 +0000 | [diff] [blame] | 18 | #include "llvm/Support/SaveAndRestore.h" |
Argyrios Kyrtzidis | f38fa73 | 2011-11-06 18:58:03 +0000 | [diff] [blame] | 19 | |
| 20 | using namespace clang; |
| 21 | using namespace arcmt; |
| 22 | using namespace trans; |
| 23 | |
| 24 | namespace { |
| 25 | |
| 26 | /// \brief Collects all the places where GC attributes __strong/__weak occur. |
| 27 | class GCAttrsCollector : public RecursiveASTVisitor<GCAttrsCollector> { |
| 28 | MigrationContext &MigrateCtx; |
| 29 | bool FullyMigratable; |
Argyrios Kyrtzidis | b0e1e12 | 2011-11-07 18:46:46 +0000 | [diff] [blame] | 30 | std::vector<ObjCPropertyDecl *> &AllProps; |
Argyrios Kyrtzidis | f38fa73 | 2011-11-06 18:58:03 +0000 | [diff] [blame] | 31 | |
| 32 | typedef RecursiveASTVisitor<GCAttrsCollector> base; |
| 33 | public: |
Argyrios Kyrtzidis | b0e1e12 | 2011-11-07 18:46:46 +0000 | [diff] [blame] | 34 | GCAttrsCollector(MigrationContext &ctx, |
| 35 | std::vector<ObjCPropertyDecl *> &AllProps) |
| 36 | : MigrateCtx(ctx), FullyMigratable(false), |
| 37 | AllProps(AllProps) { } |
Argyrios Kyrtzidis | f38fa73 | 2011-11-06 18:58:03 +0000 | [diff] [blame] | 38 | |
| 39 | bool shouldWalkTypesOfTypeLocs() const { return false; } |
| 40 | |
| 41 | bool VisitAttributedTypeLoc(AttributedTypeLoc TL) { |
| 42 | handleAttr(TL); |
| 43 | return true; |
| 44 | } |
| 45 | |
| 46 | bool TraverseDecl(Decl *D) { |
| 47 | if (!D || D->isImplicit()) |
| 48 | return true; |
| 49 | |
Argyrios Kyrtzidis | b0e1e12 | 2011-11-07 18:46:46 +0000 | [diff] [blame] | 50 | SaveAndRestore<bool> Save(FullyMigratable, isMigratable(D)); |
Argyrios Kyrtzidis | f38fa73 | 2011-11-06 18:58:03 +0000 | [diff] [blame] | 51 | |
Argyrios Kyrtzidis | b0e1e12 | 2011-11-07 18:46:46 +0000 | [diff] [blame] | 52 | if (ObjCPropertyDecl *PropD = dyn_cast<ObjCPropertyDecl>(D)) { |
Argyrios Kyrtzidis | f38fa73 | 2011-11-06 18:58:03 +0000 | [diff] [blame] | 53 | lookForAttribute(PropD, PropD->getTypeSourceInfo()); |
Argyrios Kyrtzidis | b0e1e12 | 2011-11-07 18:46:46 +0000 | [diff] [blame] | 54 | AllProps.push_back(PropD); |
| 55 | } else if (DeclaratorDecl *DD = dyn_cast<DeclaratorDecl>(D)) { |
| 56 | lookForAttribute(DD, DD->getTypeSourceInfo()); |
| 57 | } |
Argyrios Kyrtzidis | f38fa73 | 2011-11-06 18:58:03 +0000 | [diff] [blame] | 58 | return base::TraverseDecl(D); |
| 59 | } |
| 60 | |
| 61 | void lookForAttribute(Decl *D, TypeSourceInfo *TInfo) { |
| 62 | if (!TInfo) |
| 63 | return; |
| 64 | TypeLoc TL = TInfo->getTypeLoc(); |
| 65 | while (TL) { |
David Blaikie | 39e6ab4 | 2013-02-18 22:06:02 +0000 | [diff] [blame] | 66 | if (QualifiedTypeLoc QL = TL.getAs<QualifiedTypeLoc>()) { |
| 67 | TL = QL.getUnqualifiedLoc(); |
| 68 | } else if (AttributedTypeLoc Attr = TL.getAs<AttributedTypeLoc>()) { |
| 69 | if (handleAttr(Attr, D)) |
Argyrios Kyrtzidis | f38fa73 | 2011-11-06 18:58:03 +0000 | [diff] [blame] | 70 | break; |
David Blaikie | 39e6ab4 | 2013-02-18 22:06:02 +0000 | [diff] [blame] | 71 | TL = Attr.getModifiedLoc(); |
| 72 | } else if (ArrayTypeLoc Arr = TL.getAs<ArrayTypeLoc>()) { |
| 73 | TL = Arr.getElementLoc(); |
| 74 | } else if (PointerTypeLoc PT = TL.getAs<PointerTypeLoc>()) { |
| 75 | TL = PT.getPointeeLoc(); |
| 76 | } else if (ReferenceTypeLoc RT = TL.getAs<ReferenceTypeLoc>()) |
| 77 | TL = RT.getPointeeLoc(); |
Argyrios Kyrtzidis | f38fa73 | 2011-11-06 18:58:03 +0000 | [diff] [blame] | 78 | else |
| 79 | break; |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | bool handleAttr(AttributedTypeLoc TL, Decl *D = 0) { |
| 84 | if (TL.getAttrKind() != AttributedType::attr_objc_ownership) |
| 85 | return false; |
| 86 | |
| 87 | SourceLocation Loc = TL.getAttrNameLoc(); |
| 88 | unsigned RawLoc = Loc.getRawEncoding(); |
| 89 | if (MigrateCtx.AttrSet.count(RawLoc)) |
| 90 | return true; |
| 91 | |
| 92 | ASTContext &Ctx = MigrateCtx.Pass.Ctx; |
| 93 | SourceManager &SM = Ctx.getSourceManager(); |
Argyrios Kyrtzidis | 12192cf | 2011-11-07 18:40:29 +0000 | [diff] [blame] | 94 | if (Loc.isMacroID()) |
| 95 | Loc = SM.getImmediateExpansionRange(Loc).first; |
Dylan Noblesmith | f7ccbad | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 96 | SmallString<32> Buf; |
Argyrios Kyrtzidis | f38fa73 | 2011-11-06 18:58:03 +0000 | [diff] [blame] | 97 | bool Invalid = false; |
| 98 | StringRef Spell = Lexer::getSpelling( |
| 99 | SM.getSpellingLoc(TL.getAttrEnumOperandLoc()), |
David Blaikie | 4e4d084 | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 100 | Buf, SM, Ctx.getLangOpts(), &Invalid); |
Argyrios Kyrtzidis | f38fa73 | 2011-11-06 18:58:03 +0000 | [diff] [blame] | 101 | if (Invalid) |
| 102 | return false; |
| 103 | MigrationContext::GCAttrOccurrence::AttrKind Kind; |
| 104 | if (Spell == "strong") |
| 105 | Kind = MigrationContext::GCAttrOccurrence::Strong; |
| 106 | else if (Spell == "weak") |
| 107 | Kind = MigrationContext::GCAttrOccurrence::Weak; |
| 108 | else |
| 109 | return false; |
| 110 | |
| 111 | MigrateCtx.AttrSet.insert(RawLoc); |
| 112 | MigrateCtx.GCAttrs.push_back(MigrationContext::GCAttrOccurrence()); |
| 113 | MigrationContext::GCAttrOccurrence &Attr = MigrateCtx.GCAttrs.back(); |
| 114 | |
| 115 | Attr.Kind = Kind; |
Argyrios Kyrtzidis | 12192cf | 2011-11-07 18:40:29 +0000 | [diff] [blame] | 116 | Attr.Loc = Loc; |
Argyrios Kyrtzidis | f38fa73 | 2011-11-06 18:58:03 +0000 | [diff] [blame] | 117 | Attr.ModifiedType = TL.getModifiedLoc().getType(); |
| 118 | Attr.Dcl = D; |
| 119 | Attr.FullyMigratable = FullyMigratable; |
| 120 | return true; |
| 121 | } |
| 122 | |
| 123 | bool isMigratable(Decl *D) { |
| 124 | if (isa<TranslationUnitDecl>(D)) |
| 125 | return false; |
| 126 | |
| 127 | if (isInMainFile(D)) |
| 128 | return true; |
| 129 | |
| 130 | if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) |
| 131 | return FD->hasBody(); |
| 132 | |
Argyrios Kyrtzidis | b0e1e12 | 2011-11-07 18:46:46 +0000 | [diff] [blame] | 133 | if (ObjCContainerDecl *ContD = dyn_cast<ObjCContainerDecl>(D)) |
| 134 | return hasObjCImpl(ContD); |
Argyrios Kyrtzidis | f38fa73 | 2011-11-06 18:58:03 +0000 | [diff] [blame] | 135 | |
| 136 | if (CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(D)) { |
| 137 | for (CXXRecordDecl::method_iterator |
| 138 | MI = RD->method_begin(), ME = RD->method_end(); MI != ME; ++MI) { |
David Blaikie | 262bc18 | 2012-04-30 02:36:29 +0000 | [diff] [blame] | 139 | if (MI->isOutOfLine()) |
Argyrios Kyrtzidis | f38fa73 | 2011-11-06 18:58:03 +0000 | [diff] [blame] | 140 | return true; |
| 141 | } |
| 142 | return false; |
| 143 | } |
| 144 | |
| 145 | return isMigratable(cast<Decl>(D->getDeclContext())); |
| 146 | } |
| 147 | |
Argyrios Kyrtzidis | b0e1e12 | 2011-11-07 18:46:46 +0000 | [diff] [blame] | 148 | static bool hasObjCImpl(Decl *D) { |
| 149 | if (!D) |
| 150 | return false; |
| 151 | if (ObjCContainerDecl *ContD = dyn_cast<ObjCContainerDecl>(D)) { |
| 152 | if (ObjCInterfaceDecl *ID = dyn_cast<ObjCInterfaceDecl>(ContD)) |
| 153 | return ID->getImplementation() != 0; |
| 154 | if (ObjCCategoryDecl *CD = dyn_cast<ObjCCategoryDecl>(ContD)) |
| 155 | return CD->getImplementation() != 0; |
| 156 | if (isa<ObjCImplDecl>(ContD)) |
| 157 | return true; |
| 158 | return false; |
| 159 | } |
| 160 | return false; |
| 161 | } |
| 162 | |
Argyrios Kyrtzidis | f38fa73 | 2011-11-06 18:58:03 +0000 | [diff] [blame] | 163 | bool isInMainFile(Decl *D) { |
| 164 | if (!D) |
| 165 | return false; |
| 166 | |
| 167 | for (Decl::redecl_iterator |
| 168 | I = D->redecls_begin(), E = D->redecls_end(); I != E; ++I) |
David Blaikie | bd4fa45 | 2012-05-01 00:48:43 +0000 | [diff] [blame] | 169 | if (!isInMainFile(I->getLocation())) |
Argyrios Kyrtzidis | f38fa73 | 2011-11-06 18:58:03 +0000 | [diff] [blame] | 170 | return false; |
| 171 | |
| 172 | return true; |
| 173 | } |
| 174 | |
| 175 | bool isInMainFile(SourceLocation Loc) { |
| 176 | if (Loc.isInvalid()) |
| 177 | return false; |
| 178 | |
| 179 | SourceManager &SM = MigrateCtx.Pass.Ctx.getSourceManager(); |
| 180 | return SM.isInFileID(SM.getExpansionLoc(Loc), SM.getMainFileID()); |
| 181 | } |
| 182 | }; |
| 183 | |
| 184 | } // anonymous namespace |
| 185 | |
Argyrios Kyrtzidis | 280b4ad | 2011-11-06 18:58:23 +0000 | [diff] [blame] | 186 | static void errorForGCAttrsOnNonObjC(MigrationContext &MigrateCtx) { |
| 187 | TransformActions &TA = MigrateCtx.Pass.TA; |
| 188 | |
| 189 | for (unsigned i = 0, e = MigrateCtx.GCAttrs.size(); i != e; ++i) { |
| 190 | MigrationContext::GCAttrOccurrence &Attr = MigrateCtx.GCAttrs[i]; |
| 191 | if (Attr.FullyMigratable && Attr.Dcl) { |
| 192 | if (Attr.ModifiedType.isNull()) |
| 193 | continue; |
| 194 | if (!Attr.ModifiedType->isObjCRetainableType()) { |
| 195 | TA.reportError("GC managed memory will become unmanaged in ARC", |
| 196 | Attr.Loc); |
| 197 | } |
| 198 | } |
| 199 | } |
| 200 | } |
| 201 | |
Argyrios Kyrtzidis | 12192cf | 2011-11-07 18:40:29 +0000 | [diff] [blame] | 202 | static void checkWeakGCAttrs(MigrationContext &MigrateCtx) { |
| 203 | TransformActions &TA = MigrateCtx.Pass.TA; |
| 204 | |
| 205 | for (unsigned i = 0, e = MigrateCtx.GCAttrs.size(); i != e; ++i) { |
| 206 | MigrationContext::GCAttrOccurrence &Attr = MigrateCtx.GCAttrs[i]; |
Argyrios Kyrtzidis | b0e1e12 | 2011-11-07 18:46:46 +0000 | [diff] [blame] | 207 | if (Attr.Kind == MigrationContext::GCAttrOccurrence::Weak) { |
Argyrios Kyrtzidis | 12192cf | 2011-11-07 18:40:29 +0000 | [diff] [blame] | 208 | if (Attr.ModifiedType.isNull() || |
| 209 | !Attr.ModifiedType->isObjCRetainableType()) |
| 210 | continue; |
| 211 | if (!canApplyWeak(MigrateCtx.Pass.Ctx, Attr.ModifiedType, |
| 212 | /*AllowOnUnknownClass=*/true)) { |
| 213 | Transaction Trans(TA); |
Argyrios Kyrtzidis | 7cfd7fe | 2011-11-08 02:02:38 +0000 | [diff] [blame] | 214 | if (!MigrateCtx.RemovedAttrSet.count(Attr.Loc.getRawEncoding())) |
| 215 | TA.replaceText(Attr.Loc, "__weak", "__unsafe_unretained"); |
Argyrios Kyrtzidis | 12192cf | 2011-11-07 18:40:29 +0000 | [diff] [blame] | 216 | TA.clearDiagnostic(diag::err_arc_weak_no_runtime, |
| 217 | diag::err_arc_unsupported_weak_class, |
| 218 | Attr.Loc); |
| 219 | } |
| 220 | } |
| 221 | } |
| 222 | } |
| 223 | |
Argyrios Kyrtzidis | b0e1e12 | 2011-11-07 18:46:46 +0000 | [diff] [blame] | 224 | typedef llvm::TinyPtrVector<ObjCPropertyDecl *> IndivPropsTy; |
| 225 | |
| 226 | static void checkAllAtProps(MigrationContext &MigrateCtx, |
| 227 | SourceLocation AtLoc, |
| 228 | IndivPropsTy &IndProps) { |
| 229 | if (IndProps.empty()) |
| 230 | return; |
| 231 | |
| 232 | for (IndivPropsTy::iterator |
| 233 | PI = IndProps.begin(), PE = IndProps.end(); PI != PE; ++PI) { |
| 234 | QualType T = (*PI)->getType(); |
| 235 | if (T.isNull() || !T->isObjCRetainableType()) |
| 236 | return; |
| 237 | } |
| 238 | |
| 239 | SmallVector<std::pair<AttributedTypeLoc, ObjCPropertyDecl *>, 4> ATLs; |
| 240 | bool hasWeak = false, hasStrong = false; |
Argyrios Kyrtzidis | 6da4274 | 2011-11-28 02:04:36 +0000 | [diff] [blame] | 241 | ObjCPropertyDecl::PropertyAttributeKind |
| 242 | Attrs = ObjCPropertyDecl::OBJC_PR_noattr; |
Argyrios Kyrtzidis | b0e1e12 | 2011-11-07 18:46:46 +0000 | [diff] [blame] | 243 | for (IndivPropsTy::iterator |
| 244 | PI = IndProps.begin(), PE = IndProps.end(); PI != PE; ++PI) { |
| 245 | ObjCPropertyDecl *PD = *PI; |
Argyrios Kyrtzidis | 6da4274 | 2011-11-28 02:04:36 +0000 | [diff] [blame] | 246 | Attrs = PD->getPropertyAttributesAsWritten(); |
Argyrios Kyrtzidis | b0e1e12 | 2011-11-07 18:46:46 +0000 | [diff] [blame] | 247 | TypeSourceInfo *TInfo = PD->getTypeSourceInfo(); |
| 248 | if (!TInfo) |
| 249 | return; |
| 250 | TypeLoc TL = TInfo->getTypeLoc(); |
David Blaikie | 39e6ab4 | 2013-02-18 22:06:02 +0000 | [diff] [blame] | 251 | if (AttributedTypeLoc ATL = |
| 252 | TL.getAs<AttributedTypeLoc>()) { |
| 253 | ATLs.push_back(std::make_pair(ATL, PD)); |
Argyrios Kyrtzidis | b0e1e12 | 2011-11-07 18:46:46 +0000 | [diff] [blame] | 254 | if (TInfo->getType().getObjCLifetime() == Qualifiers::OCL_Weak) { |
| 255 | hasWeak = true; |
| 256 | } else if (TInfo->getType().getObjCLifetime() == Qualifiers::OCL_Strong) |
| 257 | hasStrong = true; |
| 258 | else |
| 259 | return; |
| 260 | } |
| 261 | } |
| 262 | if (ATLs.empty()) |
| 263 | return; |
| 264 | if (hasWeak && hasStrong) |
| 265 | return; |
| 266 | |
| 267 | TransformActions &TA = MigrateCtx.Pass.TA; |
| 268 | Transaction Trans(TA); |
| 269 | |
| 270 | if (GCAttrsCollector::hasObjCImpl( |
| 271 | cast<Decl>(IndProps.front()->getDeclContext()))) { |
| 272 | if (hasWeak) |
| 273 | MigrateCtx.AtPropsWeak.insert(AtLoc.getRawEncoding()); |
| 274 | |
| 275 | } else { |
| 276 | StringRef toAttr = "strong"; |
| 277 | if (hasWeak) { |
| 278 | if (canApplyWeak(MigrateCtx.Pass.Ctx, IndProps.front()->getType(), |
| 279 | /*AllowOnUnkwownClass=*/true)) |
| 280 | toAttr = "weak"; |
| 281 | else |
| 282 | toAttr = "unsafe_unretained"; |
| 283 | } |
Argyrios Kyrtzidis | 6da4274 | 2011-11-28 02:04:36 +0000 | [diff] [blame] | 284 | if (Attrs & ObjCPropertyDecl::OBJC_PR_assign) |
| 285 | MigrateCtx.rewritePropertyAttribute("assign", toAttr, AtLoc); |
| 286 | else |
| 287 | MigrateCtx.addPropertyAttribute(toAttr, AtLoc); |
Argyrios Kyrtzidis | b0e1e12 | 2011-11-07 18:46:46 +0000 | [diff] [blame] | 288 | } |
| 289 | |
| 290 | for (unsigned i = 0, e = ATLs.size(); i != e; ++i) { |
| 291 | SourceLocation Loc = ATLs[i].first.getAttrNameLoc(); |
| 292 | if (Loc.isMacroID()) |
| 293 | Loc = MigrateCtx.Pass.Ctx.getSourceManager() |
| 294 | .getImmediateExpansionRange(Loc).first; |
| 295 | TA.remove(Loc); |
| 296 | TA.clearDiagnostic(diag::err_objc_property_attr_mutually_exclusive, AtLoc); |
| 297 | TA.clearDiagnostic(diag::err_arc_inconsistent_property_ownership, |
| 298 | ATLs[i].second->getLocation()); |
Argyrios Kyrtzidis | 7cfd7fe | 2011-11-08 02:02:38 +0000 | [diff] [blame] | 299 | MigrateCtx.RemovedAttrSet.insert(Loc.getRawEncoding()); |
Argyrios Kyrtzidis | b0e1e12 | 2011-11-07 18:46:46 +0000 | [diff] [blame] | 300 | } |
| 301 | } |
| 302 | |
| 303 | static void checkAllProps(MigrationContext &MigrateCtx, |
| 304 | std::vector<ObjCPropertyDecl *> &AllProps) { |
| 305 | typedef llvm::TinyPtrVector<ObjCPropertyDecl *> IndivPropsTy; |
| 306 | llvm::DenseMap<unsigned, IndivPropsTy> AtProps; |
| 307 | |
| 308 | for (unsigned i = 0, e = AllProps.size(); i != e; ++i) { |
| 309 | ObjCPropertyDecl *PD = AllProps[i]; |
| 310 | if (PD->getPropertyAttributesAsWritten() & |
Argyrios Kyrtzidis | 6d7d16d | 2011-11-28 00:23:12 +0000 | [diff] [blame] | 311 | (ObjCPropertyDecl::OBJC_PR_assign | |
| 312 | ObjCPropertyDecl::OBJC_PR_readonly)) { |
Argyrios Kyrtzidis | b0e1e12 | 2011-11-07 18:46:46 +0000 | [diff] [blame] | 313 | SourceLocation AtLoc = PD->getAtLoc(); |
| 314 | if (AtLoc.isInvalid()) |
| 315 | continue; |
| 316 | unsigned RawAt = AtLoc.getRawEncoding(); |
| 317 | AtProps[RawAt].push_back(PD); |
| 318 | } |
| 319 | } |
| 320 | |
| 321 | for (llvm::DenseMap<unsigned, IndivPropsTy>::iterator |
| 322 | I = AtProps.begin(), E = AtProps.end(); I != E; ++I) { |
| 323 | SourceLocation AtLoc = SourceLocation::getFromRawEncoding(I->first); |
| 324 | IndivPropsTy &IndProps = I->second; |
| 325 | checkAllAtProps(MigrateCtx, AtLoc, IndProps); |
| 326 | } |
| 327 | } |
| 328 | |
Argyrios Kyrtzidis | f38fa73 | 2011-11-06 18:58:03 +0000 | [diff] [blame] | 329 | void GCAttrsTraverser::traverseTU(MigrationContext &MigrateCtx) { |
Argyrios Kyrtzidis | b0e1e12 | 2011-11-07 18:46:46 +0000 | [diff] [blame] | 330 | std::vector<ObjCPropertyDecl *> AllProps; |
| 331 | GCAttrsCollector(MigrateCtx, AllProps).TraverseDecl( |
Argyrios Kyrtzidis | f38fa73 | 2011-11-06 18:58:03 +0000 | [diff] [blame] | 332 | MigrateCtx.Pass.Ctx.getTranslationUnitDecl()); |
Argyrios Kyrtzidis | 280b4ad | 2011-11-06 18:58:23 +0000 | [diff] [blame] | 333 | |
Argyrios Kyrtzidis | 280b4ad | 2011-11-06 18:58:23 +0000 | [diff] [blame] | 334 | errorForGCAttrsOnNonObjC(MigrateCtx); |
Argyrios Kyrtzidis | b0e1e12 | 2011-11-07 18:46:46 +0000 | [diff] [blame] | 335 | checkAllProps(MigrateCtx, AllProps); |
Argyrios Kyrtzidis | 7cfd7fe | 2011-11-08 02:02:38 +0000 | [diff] [blame] | 336 | checkWeakGCAttrs(MigrateCtx); |
Argyrios Kyrtzidis | 17ac319 | 2011-11-06 18:58:17 +0000 | [diff] [blame] | 337 | } |
| 338 | |
| 339 | void MigrationContext::dumpGCAttrs() { |
Argyrios Kyrtzidis | f38fa73 | 2011-11-06 18:58:03 +0000 | [diff] [blame] | 340 | llvm::errs() << "\n################\n"; |
Argyrios Kyrtzidis | 17ac319 | 2011-11-06 18:58:17 +0000 | [diff] [blame] | 341 | for (unsigned i = 0, e = GCAttrs.size(); i != e; ++i) { |
| 342 | GCAttrOccurrence &Attr = GCAttrs[i]; |
Argyrios Kyrtzidis | f38fa73 | 2011-11-06 18:58:03 +0000 | [diff] [blame] | 343 | llvm::errs() << "KIND: " |
Argyrios Kyrtzidis | 17ac319 | 2011-11-06 18:58:17 +0000 | [diff] [blame] | 344 | << (Attr.Kind == GCAttrOccurrence::Strong ? "strong" : "weak"); |
Argyrios Kyrtzidis | f38fa73 | 2011-11-06 18:58:03 +0000 | [diff] [blame] | 345 | llvm::errs() << "\nLOC: "; |
Argyrios Kyrtzidis | 17ac319 | 2011-11-06 18:58:17 +0000 | [diff] [blame] | 346 | Attr.Loc.dump(Pass.Ctx.getSourceManager()); |
Argyrios Kyrtzidis | f38fa73 | 2011-11-06 18:58:03 +0000 | [diff] [blame] | 347 | llvm::errs() << "\nTYPE: "; |
| 348 | Attr.ModifiedType.dump(); |
| 349 | if (Attr.Dcl) { |
| 350 | llvm::errs() << "DECL:\n"; |
| 351 | Attr.Dcl->dump(); |
| 352 | } else { |
| 353 | llvm::errs() << "DECL: NONE"; |
| 354 | } |
| 355 | llvm::errs() << "\nMIGRATABLE: " << Attr.FullyMigratable; |
| 356 | llvm::errs() << "\n----------------\n"; |
| 357 | } |
| 358 | llvm::errs() << "\n################\n"; |
Argyrios Kyrtzidis | f38fa73 | 2011-11-06 18:58:03 +0000 | [diff] [blame] | 359 | } |