Ted Kremenek | f7639e1 | 2012-03-06 20:06:33 +0000 | [diff] [blame] | 1 | //===--- ObjCMT.cpp - ObjC Migrate Tool -----------------------------------===// |
| 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 | |
Fariborz Jahanian | 85e988b | 2013-07-18 22:17:33 +0000 | [diff] [blame] | 10 | #include "Transforms.h" |
Ted Kremenek | f7639e1 | 2012-03-06 20:06:33 +0000 | [diff] [blame] | 11 | #include "clang/ARCMigrate/ARCMTActions.h" |
Chandler Carruth | 3a02247 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 12 | #include "clang/AST/ASTConsumer.h" |
| 13 | #include "clang/AST/ASTContext.h" |
| 14 | #include "clang/AST/NSAPI.h" |
Argyrios Kyrtzidis | 6b4f341 | 2013-01-16 23:54:48 +0000 | [diff] [blame] | 15 | #include "clang/AST/ParentMap.h" |
Chandler Carruth | 3a02247 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 16 | #include "clang/AST/RecursiveASTVisitor.h" |
| 17 | #include "clang/Basic/FileManager.h" |
| 18 | #include "clang/Edit/Commit.h" |
| 19 | #include "clang/Edit/EditedSource.h" |
| 20 | #include "clang/Edit/EditsReceiver.h" |
| 21 | #include "clang/Edit/Rewriters.h" |
Ted Kremenek | f7639e1 | 2012-03-06 20:06:33 +0000 | [diff] [blame] | 22 | #include "clang/Frontend/CompilerInstance.h" |
| 23 | #include "clang/Frontend/MultiplexConsumer.h" |
Argyrios Kyrtzidis | f3d587e | 2012-12-04 07:27:05 +0000 | [diff] [blame] | 24 | #include "clang/Lex/PPConditionalDirectiveRecord.h" |
Chandler Carruth | 3a02247 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 25 | #include "clang/Lex/Preprocessor.h" |
| 26 | #include "clang/Rewrite/Core/Rewriter.h" |
Fariborz Jahanian | 9ef4a26 | 2013-08-19 19:13:34 +0000 | [diff] [blame] | 27 | #include "clang/Analysis/DomainSpecific/CocoaConventions.h" |
Fariborz Jahanian | 84ac1de | 2013-08-15 21:44:38 +0000 | [diff] [blame] | 28 | #include "clang/StaticAnalyzer/Checkers/ObjCRetainCount.h" |
Fariborz Jahanian | dfe6ed9 | 2013-08-12 23:17:13 +0000 | [diff] [blame] | 29 | #include "clang/AST/Attr.h" |
Ted Kremenek | f7639e1 | 2012-03-06 20:06:33 +0000 | [diff] [blame] | 30 | #include "llvm/ADT/SmallString.h" |
| 31 | |
| 32 | using namespace clang; |
| 33 | using namespace arcmt; |
Fariborz Jahanian | 84ac1de | 2013-08-15 21:44:38 +0000 | [diff] [blame] | 34 | using namespace ento::objc_retain; |
Ted Kremenek | f7639e1 | 2012-03-06 20:06:33 +0000 | [diff] [blame] | 35 | |
| 36 | namespace { |
| 37 | |
| 38 | class ObjCMigrateASTConsumer : public ASTConsumer { |
Fariborz Jahanian | 63ffce2 | 2013-08-27 22:42:30 +0000 | [diff] [blame] | 39 | enum CF_BRIDGING_KIND { |
| 40 | CF_BRIDGING_NONE, |
| 41 | CF_BRIDGING_ENABLE, |
| 42 | CF_BRIDGING_MAY_INCLUDE |
| 43 | }; |
| 44 | |
Ted Kremenek | f7639e1 | 2012-03-06 20:06:33 +0000 | [diff] [blame] | 45 | void migrateDecl(Decl *D); |
Fariborz Jahanian | 92f7242 | 2013-09-17 19:00:30 +0000 | [diff] [blame] | 46 | void migrateObjCInterfaceDecl(ASTContext &Ctx, ObjCContainerDecl *D); |
Fariborz Jahanian | 1be0153 | 2013-07-12 22:32:19 +0000 | [diff] [blame] | 47 | void migrateProtocolConformance(ASTContext &Ctx, |
| 48 | const ObjCImplementationDecl *ImpDecl); |
Fariborz Jahanian | 9246327 | 2013-07-18 20:11:45 +0000 | [diff] [blame] | 49 | void migrateNSEnumDecl(ASTContext &Ctx, const EnumDecl *EnumDcl, |
| 50 | const TypedefDecl *TypedefDcl); |
Fariborz Jahanian | d0fbf6c | 2013-08-30 23:52:08 +0000 | [diff] [blame] | 51 | void migrateMethods(ASTContext &Ctx, ObjCContainerDecl *CDecl); |
Fariborz Jahanian | 670ef26 | 2013-07-23 23:34:42 +0000 | [diff] [blame] | 52 | void migrateMethodInstanceType(ASTContext &Ctx, ObjCContainerDecl *CDecl, |
| 53 | ObjCMethodDecl *OM); |
Fariborz Jahanian | 92f7242 | 2013-09-17 19:00:30 +0000 | [diff] [blame] | 54 | bool migrateProperty(ASTContext &Ctx, ObjCContainerDecl *D, ObjCMethodDecl *OM); |
Fariborz Jahanian | d0fbf6c | 2013-08-30 23:52:08 +0000 | [diff] [blame] | 55 | void migrateNsReturnsInnerPointer(ASTContext &Ctx, ObjCMethodDecl *OM); |
Fariborz Jahanian | c429185 | 2013-08-02 18:00:53 +0000 | [diff] [blame] | 56 | void migrateFactoryMethod(ASTContext &Ctx, ObjCContainerDecl *CDecl, |
Fariborz Jahanian | 9275c68 | 2013-08-02 20:54:18 +0000 | [diff] [blame] | 57 | ObjCMethodDecl *OM, |
| 58 | ObjCInstanceTypeFamily OIT_Family = OIT_None); |
Fariborz Jahanian | dfe6ed9 | 2013-08-12 23:17:13 +0000 | [diff] [blame] | 59 | |
Fariborz Jahanian | 4f64dd2 | 2013-08-22 21:40:15 +0000 | [diff] [blame] | 60 | void migrateCFAnnotation(ASTContext &Ctx, const Decl *Decl); |
Fariborz Jahanian | 63ffce2 | 2013-08-27 22:42:30 +0000 | [diff] [blame] | 61 | void AddCFAnnotations(ASTContext &Ctx, const CallEffects &CE, |
Fariborz Jahanian | 7ca1d30 | 2013-08-27 23:56:54 +0000 | [diff] [blame] | 62 | const FunctionDecl *FuncDecl, bool ResultAnnotated); |
Fariborz Jahanian | 63ffce2 | 2013-08-27 22:42:30 +0000 | [diff] [blame] | 63 | void AddCFAnnotations(ASTContext &Ctx, const CallEffects &CE, |
Fariborz Jahanian | 7ca1d30 | 2013-08-27 23:56:54 +0000 | [diff] [blame] | 64 | const ObjCMethodDecl *MethodDecl, bool ResultAnnotated); |
Fariborz Jahanian | 2ec4d7b | 2013-08-16 23:35:05 +0000 | [diff] [blame] | 65 | |
Fariborz Jahanian | 301b521 | 2013-08-20 22:42:13 +0000 | [diff] [blame] | 66 | void AnnotateImplicitBridging(ASTContext &Ctx); |
| 67 | |
Fariborz Jahanian | 63ffce2 | 2013-08-27 22:42:30 +0000 | [diff] [blame] | 68 | CF_BRIDGING_KIND migrateAddFunctionAnnotation(ASTContext &Ctx, |
| 69 | const FunctionDecl *FuncDecl); |
Fariborz Jahanian | dfe6ed9 | 2013-08-12 23:17:13 +0000 | [diff] [blame] | 70 | |
Fariborz Jahanian | 926fafb | 2013-08-22 18:35:27 +0000 | [diff] [blame] | 71 | void migrateARCSafeAnnotation(ASTContext &Ctx, ObjCContainerDecl *CDecl); |
| 72 | |
Fariborz Jahanian | 89f6d10 | 2013-09-04 00:10:06 +0000 | [diff] [blame] | 73 | void migrateAddMethodAnnotation(ASTContext &Ctx, |
| 74 | const ObjCMethodDecl *MethodDecl); |
Ted Kremenek | f7639e1 | 2012-03-06 20:06:33 +0000 | [diff] [blame] | 75 | public: |
| 76 | std::string MigrateDir; |
| 77 | bool MigrateLiterals; |
| 78 | bool MigrateSubscripting; |
Fariborz Jahanian | d83ef84 | 2013-07-09 16:59:14 +0000 | [diff] [blame] | 79 | bool MigrateProperty; |
Fariborz Jahanian | 55d6e6c | 2013-08-28 23:22:46 +0000 | [diff] [blame] | 80 | bool MigrateReadonlyProperty; |
Fariborz Jahanian | b834352 | 2013-08-20 23:35:26 +0000 | [diff] [blame] | 81 | unsigned FileId; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 82 | OwningPtr<NSAPI> NSAPIObj; |
| 83 | OwningPtr<edit::EditedSource> Editor; |
Ted Kremenek | f7639e1 | 2012-03-06 20:06:33 +0000 | [diff] [blame] | 84 | FileRemapper &Remapper; |
| 85 | FileManager &FileMgr; |
Argyrios Kyrtzidis | f3d587e | 2012-12-04 07:27:05 +0000 | [diff] [blame] | 86 | const PPConditionalDirectiveRecord *PPRec; |
Fariborz Jahanian | a7437f0 | 2013-07-03 23:05:00 +0000 | [diff] [blame] | 87 | Preprocessor &PP; |
Ted Kremenek | f7639e1 | 2012-03-06 20:06:33 +0000 | [diff] [blame] | 88 | bool IsOutputFile; |
Fariborz Jahanian | 1be0153 | 2013-07-12 22:32:19 +0000 | [diff] [blame] | 89 | llvm::SmallPtrSet<ObjCProtocolDecl *, 32> ObjCProtocolDecls; |
Fariborz Jahanian | 926fafb | 2013-08-22 18:35:27 +0000 | [diff] [blame] | 90 | llvm::SmallVector<const Decl *, 8> CFFunctionIBCandidates; |
Fariborz Jahanian | 1be0153 | 2013-07-12 22:32:19 +0000 | [diff] [blame] | 91 | |
Ted Kremenek | f7639e1 | 2012-03-06 20:06:33 +0000 | [diff] [blame] | 92 | ObjCMigrateASTConsumer(StringRef migrateDir, |
| 93 | bool migrateLiterals, |
| 94 | bool migrateSubscripting, |
Fariborz Jahanian | d83ef84 | 2013-07-09 16:59:14 +0000 | [diff] [blame] | 95 | bool migrateProperty, |
Fariborz Jahanian | 55d6e6c | 2013-08-28 23:22:46 +0000 | [diff] [blame] | 96 | bool migrateReadonlyProperty, |
Ted Kremenek | f7639e1 | 2012-03-06 20:06:33 +0000 | [diff] [blame] | 97 | FileRemapper &remapper, |
| 98 | FileManager &fileMgr, |
Argyrios Kyrtzidis | f3d587e | 2012-12-04 07:27:05 +0000 | [diff] [blame] | 99 | const PPConditionalDirectiveRecord *PPRec, |
Fariborz Jahanian | a7437f0 | 2013-07-03 23:05:00 +0000 | [diff] [blame] | 100 | Preprocessor &PP, |
Ted Kremenek | f7639e1 | 2012-03-06 20:06:33 +0000 | [diff] [blame] | 101 | bool isOutputFile = false) |
| 102 | : MigrateDir(migrateDir), |
| 103 | MigrateLiterals(migrateLiterals), |
| 104 | MigrateSubscripting(migrateSubscripting), |
Fariborz Jahanian | 55d6e6c | 2013-08-28 23:22:46 +0000 | [diff] [blame] | 105 | MigrateProperty(migrateProperty), |
| 106 | MigrateReadonlyProperty(migrateReadonlyProperty), |
| 107 | FileId(0), Remapper(remapper), FileMgr(fileMgr), PPRec(PPRec), PP(PP), |
Ted Kremenek | f7639e1 | 2012-03-06 20:06:33 +0000 | [diff] [blame] | 108 | IsOutputFile(isOutputFile) { } |
| 109 | |
| 110 | protected: |
| 111 | virtual void Initialize(ASTContext &Context) { |
| 112 | NSAPIObj.reset(new NSAPI(Context)); |
| 113 | Editor.reset(new edit::EditedSource(Context.getSourceManager(), |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 114 | Context.getLangOpts(), |
Ted Kremenek | f7639e1 | 2012-03-06 20:06:33 +0000 | [diff] [blame] | 115 | PPRec)); |
| 116 | } |
| 117 | |
| 118 | virtual bool HandleTopLevelDecl(DeclGroupRef DG) { |
| 119 | for (DeclGroupRef::iterator I = DG.begin(), E = DG.end(); I != E; ++I) |
| 120 | migrateDecl(*I); |
| 121 | return true; |
| 122 | } |
| 123 | virtual void HandleInterestingDecl(DeclGroupRef DG) { |
| 124 | // Ignore decls from the PCH. |
| 125 | } |
| 126 | virtual void HandleTopLevelDeclInObjCContainer(DeclGroupRef DG) { |
| 127 | ObjCMigrateASTConsumer::HandleTopLevelDecl(DG); |
| 128 | } |
| 129 | |
| 130 | virtual void HandleTranslationUnit(ASTContext &Ctx); |
| 131 | }; |
| 132 | |
| 133 | } |
| 134 | |
| 135 | ObjCMigrateAction::ObjCMigrateAction(FrontendAction *WrappedAction, |
| 136 | StringRef migrateDir, |
| 137 | bool migrateLiterals, |
Fariborz Jahanian | d83ef84 | 2013-07-09 16:59:14 +0000 | [diff] [blame] | 138 | bool migrateSubscripting, |
Fariborz Jahanian | 55d6e6c | 2013-08-28 23:22:46 +0000 | [diff] [blame] | 139 | bool migrateProperty, |
| 140 | bool migrateReadonlyProperty) |
Ted Kremenek | f7639e1 | 2012-03-06 20:06:33 +0000 | [diff] [blame] | 141 | : WrapperFrontendAction(WrappedAction), MigrateDir(migrateDir), |
| 142 | MigrateLiterals(migrateLiterals), MigrateSubscripting(migrateSubscripting), |
Fariborz Jahanian | d83ef84 | 2013-07-09 16:59:14 +0000 | [diff] [blame] | 143 | MigrateProperty(migrateProperty), |
Fariborz Jahanian | 55d6e6c | 2013-08-28 23:22:46 +0000 | [diff] [blame] | 144 | MigrateReadonlyProperty(migrateReadonlyProperty), |
Ted Kremenek | f7639e1 | 2012-03-06 20:06:33 +0000 | [diff] [blame] | 145 | CompInst(0) { |
| 146 | if (MigrateDir.empty()) |
| 147 | MigrateDir = "."; // user current directory if none is given. |
| 148 | } |
| 149 | |
| 150 | ASTConsumer *ObjCMigrateAction::CreateASTConsumer(CompilerInstance &CI, |
| 151 | StringRef InFile) { |
Argyrios Kyrtzidis | f3d587e | 2012-12-04 07:27:05 +0000 | [diff] [blame] | 152 | PPConditionalDirectiveRecord * |
| 153 | PPRec = new PPConditionalDirectiveRecord(CompInst->getSourceManager()); |
| 154 | CompInst->getPreprocessor().addPPCallbacks(PPRec); |
Ted Kremenek | f7639e1 | 2012-03-06 20:06:33 +0000 | [diff] [blame] | 155 | ASTConsumer * |
| 156 | WrappedConsumer = WrapperFrontendAction::CreateASTConsumer(CI, InFile); |
| 157 | ASTConsumer *MTConsumer = new ObjCMigrateASTConsumer(MigrateDir, |
| 158 | MigrateLiterals, |
| 159 | MigrateSubscripting, |
Fariborz Jahanian | d83ef84 | 2013-07-09 16:59:14 +0000 | [diff] [blame] | 160 | MigrateProperty, |
Fariborz Jahanian | 55d6e6c | 2013-08-28 23:22:46 +0000 | [diff] [blame] | 161 | MigrateReadonlyProperty, |
Ted Kremenek | f7639e1 | 2012-03-06 20:06:33 +0000 | [diff] [blame] | 162 | Remapper, |
| 163 | CompInst->getFileManager(), |
Fariborz Jahanian | a7437f0 | 2013-07-03 23:05:00 +0000 | [diff] [blame] | 164 | PPRec, |
| 165 | CompInst->getPreprocessor()); |
Ted Kremenek | f7639e1 | 2012-03-06 20:06:33 +0000 | [diff] [blame] | 166 | ASTConsumer *Consumers[] = { MTConsumer, WrappedConsumer }; |
| 167 | return new MultiplexConsumer(Consumers); |
| 168 | } |
| 169 | |
| 170 | bool ObjCMigrateAction::BeginInvocation(CompilerInstance &CI) { |
| 171 | Remapper.initFromDisk(MigrateDir, CI.getDiagnostics(), |
| 172 | /*ignoreIfFilesChanges=*/true); |
| 173 | CompInst = &CI; |
| 174 | CI.getDiagnostics().setIgnoreAllWarnings(true); |
Ted Kremenek | f7639e1 | 2012-03-06 20:06:33 +0000 | [diff] [blame] | 175 | return true; |
| 176 | } |
| 177 | |
| 178 | namespace { |
| 179 | class ObjCMigrator : public RecursiveASTVisitor<ObjCMigrator> { |
| 180 | ObjCMigrateASTConsumer &Consumer; |
Argyrios Kyrtzidis | 6b4f341 | 2013-01-16 23:54:48 +0000 | [diff] [blame] | 181 | ParentMap &PMap; |
Ted Kremenek | f7639e1 | 2012-03-06 20:06:33 +0000 | [diff] [blame] | 182 | |
| 183 | public: |
Argyrios Kyrtzidis | 6b4f341 | 2013-01-16 23:54:48 +0000 | [diff] [blame] | 184 | ObjCMigrator(ObjCMigrateASTConsumer &consumer, ParentMap &PMap) |
| 185 | : Consumer(consumer), PMap(PMap) { } |
Ted Kremenek | f7639e1 | 2012-03-06 20:06:33 +0000 | [diff] [blame] | 186 | |
| 187 | bool shouldVisitTemplateInstantiations() const { return false; } |
| 188 | bool shouldWalkTypesOfTypeLocs() const { return false; } |
| 189 | |
| 190 | bool VisitObjCMessageExpr(ObjCMessageExpr *E) { |
| 191 | if (Consumer.MigrateLiterals) { |
| 192 | edit::Commit commit(*Consumer.Editor); |
Argyrios Kyrtzidis | 6b4f341 | 2013-01-16 23:54:48 +0000 | [diff] [blame] | 193 | edit::rewriteToObjCLiteralSyntax(E, *Consumer.NSAPIObj, commit, &PMap); |
Ted Kremenek | f7639e1 | 2012-03-06 20:06:33 +0000 | [diff] [blame] | 194 | Consumer.Editor->commit(commit); |
| 195 | } |
| 196 | |
| 197 | if (Consumer.MigrateSubscripting) { |
| 198 | edit::Commit commit(*Consumer.Editor); |
| 199 | edit::rewriteToObjCSubscriptSyntax(E, *Consumer.NSAPIObj, commit); |
| 200 | Consumer.Editor->commit(commit); |
| 201 | } |
| 202 | |
| 203 | return true; |
| 204 | } |
| 205 | |
| 206 | bool TraverseObjCMessageExpr(ObjCMessageExpr *E) { |
| 207 | // Do depth first; we want to rewrite the subexpressions first so that if |
| 208 | // we have to move expressions we will move them already rewritten. |
| 209 | for (Stmt::child_range range = E->children(); range; ++range) |
| 210 | if (!TraverseStmt(*range)) |
| 211 | return false; |
| 212 | |
| 213 | return WalkUpFromObjCMessageExpr(E); |
| 214 | } |
| 215 | }; |
Argyrios Kyrtzidis | 6b4f341 | 2013-01-16 23:54:48 +0000 | [diff] [blame] | 216 | |
| 217 | class BodyMigrator : public RecursiveASTVisitor<BodyMigrator> { |
| 218 | ObjCMigrateASTConsumer &Consumer; |
| 219 | OwningPtr<ParentMap> PMap; |
| 220 | |
| 221 | public: |
| 222 | BodyMigrator(ObjCMigrateASTConsumer &consumer) : Consumer(consumer) { } |
| 223 | |
| 224 | bool shouldVisitTemplateInstantiations() const { return false; } |
| 225 | bool shouldWalkTypesOfTypeLocs() const { return false; } |
| 226 | |
| 227 | bool TraverseStmt(Stmt *S) { |
| 228 | PMap.reset(new ParentMap(S)); |
| 229 | ObjCMigrator(Consumer, *PMap).TraverseStmt(S); |
| 230 | return true; |
| 231 | } |
| 232 | }; |
Ted Kremenek | f7639e1 | 2012-03-06 20:06:33 +0000 | [diff] [blame] | 233 | } |
| 234 | |
| 235 | void ObjCMigrateASTConsumer::migrateDecl(Decl *D) { |
| 236 | if (!D) |
| 237 | return; |
| 238 | if (isa<ObjCMethodDecl>(D)) |
| 239 | return; // Wait for the ObjC container declaration. |
| 240 | |
Argyrios Kyrtzidis | 6b4f341 | 2013-01-16 23:54:48 +0000 | [diff] [blame] | 241 | BodyMigrator(*this).TraverseDecl(D); |
Ted Kremenek | f7639e1 | 2012-03-06 20:06:33 +0000 | [diff] [blame] | 242 | } |
| 243 | |
Fariborz Jahanian | 447b15e | 2013-08-21 18:49:03 +0000 | [diff] [blame] | 244 | static void append_attr(std::string &PropertyString, const char *attr) { |
| 245 | PropertyString += ", "; |
Fariborz Jahanian | cf2ff9b | 2013-08-08 20:51:58 +0000 | [diff] [blame] | 246 | PropertyString += attr; |
Fariborz Jahanian | cf2ff9b | 2013-08-08 20:51:58 +0000 | [diff] [blame] | 247 | } |
| 248 | |
Fariborz Jahanian | 85e988b | 2013-07-18 22:17:33 +0000 | [diff] [blame] | 249 | static bool rewriteToObjCProperty(const ObjCMethodDecl *Getter, |
| 250 | const ObjCMethodDecl *Setter, |
Fariborz Jahanian | cf2ff9b | 2013-08-08 20:51:58 +0000 | [diff] [blame] | 251 | const NSAPI &NS, edit::Commit &commit, |
Fariborz Jahanian | ca39960 | 2013-09-11 17:05:15 +0000 | [diff] [blame] | 252 | unsigned LengthOfPrefix) { |
Fariborz Jahanian | 85e988b | 2013-07-18 22:17:33 +0000 | [diff] [blame] | 253 | ASTContext &Context = NS.getASTContext(); |
Fariborz Jahanian | 447b15e | 2013-08-21 18:49:03 +0000 | [diff] [blame] | 254 | std::string PropertyString = "@property(nonatomic"; |
Fariborz Jahanian | cf387c6 | 2013-08-06 18:06:23 +0000 | [diff] [blame] | 255 | std::string PropertyNameString = Getter->getNameAsString(); |
| 256 | StringRef PropertyName(PropertyNameString); |
Fariborz Jahanian | ca39960 | 2013-09-11 17:05:15 +0000 | [diff] [blame] | 257 | if (LengthOfPrefix > 0) { |
Fariborz Jahanian | 447b15e | 2013-08-21 18:49:03 +0000 | [diff] [blame] | 258 | PropertyString += ", getter="; |
Fariborz Jahanian | cf2ff9b | 2013-08-08 20:51:58 +0000 | [diff] [blame] | 259 | PropertyString += PropertyNameString; |
| 260 | } |
Fariborz Jahanian | 55d6e6c | 2013-08-28 23:22:46 +0000 | [diff] [blame] | 261 | // Property with no setter may be suggested as a 'readonly' property. |
| 262 | if (!Setter) |
| 263 | append_attr(PropertyString, "readonly"); |
| 264 | |
Fariborz Jahanian | cf387c6 | 2013-08-06 18:06:23 +0000 | [diff] [blame] | 265 | // Short circuit properties that contain the name "delegate" or "dataSource", |
| 266 | // or have exact name "target" to have unsafe_unretained attribute. |
| 267 | if (PropertyName.equals("target") || |
| 268 | (PropertyName.find("delegate") != StringRef::npos) || |
| 269 | (PropertyName.find("dataSource") != StringRef::npos)) |
Fariborz Jahanian | 447b15e | 2013-08-21 18:49:03 +0000 | [diff] [blame] | 270 | append_attr(PropertyString, "unsafe_unretained"); |
Fariborz Jahanian | 55d6e6c | 2013-08-28 23:22:46 +0000 | [diff] [blame] | 271 | else if (Setter) { |
Fariborz Jahanian | cf387c6 | 2013-08-06 18:06:23 +0000 | [diff] [blame] | 272 | const ParmVarDecl *argDecl = *Setter->param_begin(); |
| 273 | QualType ArgType = Context.getCanonicalType(argDecl->getType()); |
| 274 | Qualifiers::ObjCLifetime propertyLifetime = ArgType.getObjCLifetime(); |
| 275 | bool RetainableObject = ArgType->isObjCRetainableType(); |
| 276 | if (RetainableObject && propertyLifetime == Qualifiers::OCL_Strong) { |
| 277 | if (const ObjCObjectPointerType *ObjPtrTy = |
| 278 | ArgType->getAs<ObjCObjectPointerType>()) { |
| 279 | ObjCInterfaceDecl *IDecl = ObjPtrTy->getObjectType()->getInterface(); |
| 280 | if (IDecl && |
| 281 | IDecl->lookupNestedProtocol(&Context.Idents.get("NSCopying"))) |
Fariborz Jahanian | 447b15e | 2013-08-21 18:49:03 +0000 | [diff] [blame] | 282 | append_attr(PropertyString, "copy"); |
Fariborz Jahanian | cf387c6 | 2013-08-06 18:06:23 +0000 | [diff] [blame] | 283 | else |
Fariborz Jahanian | 447b15e | 2013-08-21 18:49:03 +0000 | [diff] [blame] | 284 | append_attr(PropertyString, "retain"); |
| 285 | } |
Fariborz Jahanian | cf387c6 | 2013-08-06 18:06:23 +0000 | [diff] [blame] | 286 | } else if (propertyLifetime == Qualifiers::OCL_Weak) |
| 287 | // TODO. More precise determination of 'weak' attribute requires |
| 288 | // looking into setter's implementation for backing weak ivar. |
Fariborz Jahanian | 447b15e | 2013-08-21 18:49:03 +0000 | [diff] [blame] | 289 | append_attr(PropertyString, "weak"); |
Fariborz Jahanian | cf387c6 | 2013-08-06 18:06:23 +0000 | [diff] [blame] | 290 | else if (RetainableObject) |
Fariborz Jahanian | 447b15e | 2013-08-21 18:49:03 +0000 | [diff] [blame] | 291 | append_attr(PropertyString, "retain"); |
Fariborz Jahanian | cf387c6 | 2013-08-06 18:06:23 +0000 | [diff] [blame] | 292 | } |
Fariborz Jahanian | 447b15e | 2013-08-21 18:49:03 +0000 | [diff] [blame] | 293 | PropertyString += ')'; |
Fariborz Jahanian | 85e988b | 2013-07-18 22:17:33 +0000 | [diff] [blame] | 294 | |
Fariborz Jahanian | cf2ff9b | 2013-08-08 20:51:58 +0000 | [diff] [blame] | 295 | QualType RT = Getter->getResultType(); |
| 296 | if (!isa<TypedefType>(RT)) { |
| 297 | // strip off any ARC lifetime qualifier. |
| 298 | QualType CanResultTy = Context.getCanonicalType(RT); |
| 299 | if (CanResultTy.getQualifiers().hasObjCLifetime()) { |
| 300 | Qualifiers Qs = CanResultTy.getQualifiers(); |
| 301 | Qs.removeObjCLifetime(); |
| 302 | RT = Context.getQualifiedType(CanResultTy.getUnqualifiedType(), Qs); |
| 303 | } |
Fariborz Jahanian | 85e988b | 2013-07-18 22:17:33 +0000 | [diff] [blame] | 304 | } |
| 305 | PropertyString += " "; |
Fariborz Jahanian | cf2ff9b | 2013-08-08 20:51:58 +0000 | [diff] [blame] | 306 | PropertyString += RT.getAsString(Context.getPrintingPolicy()); |
Fariborz Jahanian | 85e988b | 2013-07-18 22:17:33 +0000 | [diff] [blame] | 307 | PropertyString += " "; |
Fariborz Jahanian | ca39960 | 2013-09-11 17:05:15 +0000 | [diff] [blame] | 308 | if (LengthOfPrefix > 0) { |
Fariborz Jahanian | cf2ff9b | 2013-08-08 20:51:58 +0000 | [diff] [blame] | 309 | // property name must strip off "is" and lower case the first character |
| 310 | // after that; e.g. isContinuous will become continuous. |
| 311 | StringRef PropertyNameStringRef(PropertyNameString); |
Fariborz Jahanian | ca39960 | 2013-09-11 17:05:15 +0000 | [diff] [blame] | 312 | PropertyNameStringRef = PropertyNameStringRef.drop_front(LengthOfPrefix); |
Fariborz Jahanian | cf2ff9b | 2013-08-08 20:51:58 +0000 | [diff] [blame] | 313 | PropertyNameString = PropertyNameStringRef; |
| 314 | std::string NewPropertyNameString = PropertyNameString; |
Fariborz Jahanian | 34fea36 | 2013-09-11 18:27:16 +0000 | [diff] [blame] | 315 | bool NoLowering = (isUppercase(NewPropertyNameString[0]) && |
| 316 | NewPropertyNameString.size() > 1 && |
| 317 | isUppercase(NewPropertyNameString[1])); |
| 318 | if (!NoLowering) |
| 319 | NewPropertyNameString[0] = toLowercase(NewPropertyNameString[0]); |
Fariborz Jahanian | cf2ff9b | 2013-08-08 20:51:58 +0000 | [diff] [blame] | 320 | PropertyString += NewPropertyNameString; |
| 321 | } |
| 322 | else |
| 323 | PropertyString += PropertyNameString; |
Fariborz Jahanian | 215f96c | 2013-09-06 23:45:20 +0000 | [diff] [blame] | 324 | SourceLocation StartGetterSelectorLoc = Getter->getSelectorStartLoc(); |
| 325 | Selector GetterSelector = Getter->getSelector(); |
| 326 | |
| 327 | SourceLocation EndGetterSelectorLoc = |
| 328 | StartGetterSelectorLoc.getLocWithOffset(GetterSelector.getNameForSlot(0).size()); |
Fariborz Jahanian | 85e988b | 2013-07-18 22:17:33 +0000 | [diff] [blame] | 329 | commit.replace(CharSourceRange::getCharRange(Getter->getLocStart(), |
Fariborz Jahanian | 215f96c | 2013-09-06 23:45:20 +0000 | [diff] [blame] | 330 | EndGetterSelectorLoc), |
Fariborz Jahanian | 85e988b | 2013-07-18 22:17:33 +0000 | [diff] [blame] | 331 | PropertyString); |
Fariborz Jahanian | 55d6e6c | 2013-08-28 23:22:46 +0000 | [diff] [blame] | 332 | if (Setter) { |
| 333 | SourceLocation EndLoc = Setter->getDeclaratorEndLoc(); |
| 334 | // Get location past ';' |
| 335 | EndLoc = EndLoc.getLocWithOffset(1); |
| 336 | commit.remove(CharSourceRange::getCharRange(Setter->getLocStart(), EndLoc)); |
| 337 | } |
Fariborz Jahanian | 85e988b | 2013-07-18 22:17:33 +0000 | [diff] [blame] | 338 | return true; |
| 339 | } |
| 340 | |
Fariborz Jahanian | a7437f0 | 2013-07-03 23:05:00 +0000 | [diff] [blame] | 341 | void ObjCMigrateASTConsumer::migrateObjCInterfaceDecl(ASTContext &Ctx, |
Fariborz Jahanian | 92f7242 | 2013-09-17 19:00:30 +0000 | [diff] [blame] | 342 | ObjCContainerDecl *D) { |
Fariborz Jahanian | 75226d5 | 2013-09-17 21:56:04 +0000 | [diff] [blame] | 343 | if (D->isDeprecated()) |
| 344 | return; |
| 345 | |
Fariborz Jahanian | a7437f0 | 2013-07-03 23:05:00 +0000 | [diff] [blame] | 346 | for (ObjCContainerDecl::method_iterator M = D->meth_begin(), MEnd = D->meth_end(); |
| 347 | M != MEnd; ++M) { |
| 348 | ObjCMethodDecl *Method = (*M); |
Fariborz Jahanian | 75226d5 | 2013-09-17 21:56:04 +0000 | [diff] [blame] | 349 | if (Method->isDeprecated()) |
| 350 | continue; |
Fariborz Jahanian | 215f96c | 2013-09-06 23:45:20 +0000 | [diff] [blame] | 351 | if (!migrateProperty(Ctx, D, Method)) |
| 352 | migrateNsReturnsInnerPointer(Ctx, Method); |
Fariborz Jahanian | a7437f0 | 2013-07-03 23:05:00 +0000 | [diff] [blame] | 353 | } |
| 354 | } |
| 355 | |
Fariborz Jahanian | 9eabf45 | 2013-07-13 00:04:20 +0000 | [diff] [blame] | 356 | static bool |
Fariborz Jahanian | 9a3512b | 2013-07-13 17:16:41 +0000 | [diff] [blame] | 357 | ClassImplementsAllMethodsAndProperties(ASTContext &Ctx, |
Fariborz Jahanian | 9eabf45 | 2013-07-13 00:04:20 +0000 | [diff] [blame] | 358 | const ObjCImplementationDecl *ImpDecl, |
Fariborz Jahanian | d36150d | 2013-07-15 21:22:08 +0000 | [diff] [blame] | 359 | const ObjCInterfaceDecl *IDecl, |
Fariborz Jahanian | 9eabf45 | 2013-07-13 00:04:20 +0000 | [diff] [blame] | 360 | ObjCProtocolDecl *Protocol) { |
Fariborz Jahanian | d36150d | 2013-07-15 21:22:08 +0000 | [diff] [blame] | 361 | // In auto-synthesis, protocol properties are not synthesized. So, |
| 362 | // a conforming protocol must have its required properties declared |
| 363 | // in class interface. |
Fariborz Jahanian | 9e543af | 2013-07-22 23:50:04 +0000 | [diff] [blame] | 364 | bool HasAtleastOneRequiredProperty = false; |
Fariborz Jahanian | d36150d | 2013-07-15 21:22:08 +0000 | [diff] [blame] | 365 | if (const ObjCProtocolDecl *PDecl = Protocol->getDefinition()) |
| 366 | for (ObjCProtocolDecl::prop_iterator P = PDecl->prop_begin(), |
| 367 | E = PDecl->prop_end(); P != E; ++P) { |
| 368 | ObjCPropertyDecl *Property = *P; |
| 369 | if (Property->getPropertyImplementation() == ObjCPropertyDecl::Optional) |
| 370 | continue; |
Fariborz Jahanian | 9e543af | 2013-07-22 23:50:04 +0000 | [diff] [blame] | 371 | HasAtleastOneRequiredProperty = true; |
Fariborz Jahanian | d36150d | 2013-07-15 21:22:08 +0000 | [diff] [blame] | 372 | DeclContext::lookup_const_result R = IDecl->lookup(Property->getDeclName()); |
Fariborz Jahanian | 2bc3dda | 2013-07-16 21:59:42 +0000 | [diff] [blame] | 373 | if (R.size() == 0) { |
| 374 | // Relax the rule and look into class's implementation for a synthesize |
| 375 | // or dynamic declaration. Class is implementing a property coming from |
| 376 | // another protocol. This still makes the target protocol as conforming. |
| 377 | if (!ImpDecl->FindPropertyImplDecl( |
| 378 | Property->getDeclName().getAsIdentifierInfo())) |
| 379 | return false; |
Fariborz Jahanian | d36150d | 2013-07-15 21:22:08 +0000 | [diff] [blame] | 380 | } |
Fariborz Jahanian | 2bc3dda | 2013-07-16 21:59:42 +0000 | [diff] [blame] | 381 | else if (ObjCPropertyDecl *ClassProperty = dyn_cast<ObjCPropertyDecl>(R[0])) { |
| 382 | if ((ClassProperty->getPropertyAttributes() |
| 383 | != Property->getPropertyAttributes()) || |
| 384 | !Ctx.hasSameType(ClassProperty->getType(), Property->getType())) |
| 385 | return false; |
| 386 | } |
| 387 | else |
| 388 | return false; |
Fariborz Jahanian | d36150d | 2013-07-15 21:22:08 +0000 | [diff] [blame] | 389 | } |
Fariborz Jahanian | 9e543af | 2013-07-22 23:50:04 +0000 | [diff] [blame] | 390 | |
Fariborz Jahanian | d36150d | 2013-07-15 21:22:08 +0000 | [diff] [blame] | 391 | // At this point, all required properties in this protocol conform to those |
| 392 | // declared in the class. |
| 393 | // Check that class implements the required methods of the protocol too. |
Fariborz Jahanian | 9e543af | 2013-07-22 23:50:04 +0000 | [diff] [blame] | 394 | bool HasAtleastOneRequiredMethod = false; |
Fariborz Jahanian | 5bd5aff | 2013-07-16 00:20:21 +0000 | [diff] [blame] | 395 | if (const ObjCProtocolDecl *PDecl = Protocol->getDefinition()) { |
| 396 | if (PDecl->meth_begin() == PDecl->meth_end()) |
Fariborz Jahanian | 9e543af | 2013-07-22 23:50:04 +0000 | [diff] [blame] | 397 | return HasAtleastOneRequiredProperty; |
Fariborz Jahanian | d36150d | 2013-07-15 21:22:08 +0000 | [diff] [blame] | 398 | for (ObjCContainerDecl::method_iterator M = PDecl->meth_begin(), |
| 399 | MEnd = PDecl->meth_end(); M != MEnd; ++M) { |
| 400 | ObjCMethodDecl *MD = (*M); |
Fariborz Jahanian | 5bd5aff | 2013-07-16 00:20:21 +0000 | [diff] [blame] | 401 | if (MD->isImplicit()) |
| 402 | continue; |
Fariborz Jahanian | d36150d | 2013-07-15 21:22:08 +0000 | [diff] [blame] | 403 | if (MD->getImplementationControl() == ObjCMethodDecl::Optional) |
| 404 | continue; |
Fariborz Jahanian | d36150d | 2013-07-15 21:22:08 +0000 | [diff] [blame] | 405 | DeclContext::lookup_const_result R = ImpDecl->lookup(MD->getDeclName()); |
Fariborz Jahanian | 5bd5aff | 2013-07-16 00:20:21 +0000 | [diff] [blame] | 406 | if (R.size() == 0) |
| 407 | return false; |
Fariborz Jahanian | 9e543af | 2013-07-22 23:50:04 +0000 | [diff] [blame] | 408 | bool match = false; |
| 409 | HasAtleastOneRequiredMethod = true; |
Fariborz Jahanian | d36150d | 2013-07-15 21:22:08 +0000 | [diff] [blame] | 410 | for (unsigned I = 0, N = R.size(); I != N; ++I) |
| 411 | if (ObjCMethodDecl *ImpMD = dyn_cast<ObjCMethodDecl>(R[0])) |
| 412 | if (Ctx.ObjCMethodsAreEqual(MD, ImpMD)) { |
| 413 | match = true; |
| 414 | break; |
| 415 | } |
| 416 | if (!match) |
| 417 | return false; |
| 418 | } |
Fariborz Jahanian | 5bd5aff | 2013-07-16 00:20:21 +0000 | [diff] [blame] | 419 | } |
Fariborz Jahanian | 9e543af | 2013-07-22 23:50:04 +0000 | [diff] [blame] | 420 | if (HasAtleastOneRequiredProperty || HasAtleastOneRequiredMethod) |
| 421 | return true; |
| 422 | return false; |
Fariborz Jahanian | 9eabf45 | 2013-07-13 00:04:20 +0000 | [diff] [blame] | 423 | } |
| 424 | |
Fariborz Jahanian | 85e988b | 2013-07-18 22:17:33 +0000 | [diff] [blame] | 425 | static bool rewriteToObjCInterfaceDecl(const ObjCInterfaceDecl *IDecl, |
| 426 | llvm::SmallVectorImpl<ObjCProtocolDecl*> &ConformingProtocols, |
| 427 | const NSAPI &NS, edit::Commit &commit) { |
| 428 | const ObjCList<ObjCProtocolDecl> &Protocols = IDecl->getReferencedProtocols(); |
| 429 | std::string ClassString; |
| 430 | SourceLocation EndLoc = |
| 431 | IDecl->getSuperClass() ? IDecl->getSuperClassLoc() : IDecl->getLocation(); |
| 432 | |
| 433 | if (Protocols.empty()) { |
| 434 | ClassString = '<'; |
| 435 | for (unsigned i = 0, e = ConformingProtocols.size(); i != e; i++) { |
| 436 | ClassString += ConformingProtocols[i]->getNameAsString(); |
| 437 | if (i != (e-1)) |
| 438 | ClassString += ", "; |
| 439 | } |
| 440 | ClassString += "> "; |
| 441 | } |
| 442 | else { |
| 443 | ClassString = ", "; |
| 444 | for (unsigned i = 0, e = ConformingProtocols.size(); i != e; i++) { |
| 445 | ClassString += ConformingProtocols[i]->getNameAsString(); |
| 446 | if (i != (e-1)) |
| 447 | ClassString += ", "; |
| 448 | } |
| 449 | ObjCInterfaceDecl::protocol_loc_iterator PL = IDecl->protocol_loc_end() - 1; |
| 450 | EndLoc = *PL; |
| 451 | } |
| 452 | |
| 453 | commit.insertAfterToken(EndLoc, ClassString); |
| 454 | return true; |
| 455 | } |
| 456 | |
| 457 | static bool rewriteToNSEnumDecl(const EnumDecl *EnumDcl, |
| 458 | const TypedefDecl *TypedefDcl, |
Fariborz Jahanian | b0057bb | 2013-07-19 01:05:49 +0000 | [diff] [blame] | 459 | const NSAPI &NS, edit::Commit &commit, |
Fariborz Jahanian | ff3476e | 2013-08-30 17:46:01 +0000 | [diff] [blame] | 460 | bool IsNSIntegerType, |
| 461 | bool NSOptions) { |
| 462 | std::string ClassString; |
| 463 | if (NSOptions) |
| 464 | ClassString = "typedef NS_OPTIONS(NSUInteger, "; |
| 465 | else |
| 466 | ClassString = |
| 467 | IsNSIntegerType ? "typedef NS_ENUM(NSInteger, " |
| 468 | : "typedef NS_ENUM(NSUInteger, "; |
| 469 | |
Fariborz Jahanian | 85e988b | 2013-07-18 22:17:33 +0000 | [diff] [blame] | 470 | ClassString += TypedefDcl->getIdentifier()->getName(); |
| 471 | ClassString += ')'; |
| 472 | SourceRange R(EnumDcl->getLocStart(), EnumDcl->getLocStart()); |
| 473 | commit.replace(R, ClassString); |
| 474 | SourceLocation EndOfTypedefLoc = TypedefDcl->getLocEnd(); |
| 475 | EndOfTypedefLoc = trans::findLocationAfterSemi(EndOfTypedefLoc, NS.getASTContext()); |
| 476 | if (!EndOfTypedefLoc.isInvalid()) { |
| 477 | commit.remove(SourceRange(TypedefDcl->getLocStart(), EndOfTypedefLoc)); |
| 478 | return true; |
| 479 | } |
| 480 | return false; |
| 481 | } |
| 482 | |
Fariborz Jahanian | d0f6f79 | 2013-07-22 18:53:45 +0000 | [diff] [blame] | 483 | static bool rewriteToNSMacroDecl(const EnumDecl *EnumDcl, |
Fariborz Jahanian | c1c44f6 | 2013-07-19 20:18:36 +0000 | [diff] [blame] | 484 | const TypedefDecl *TypedefDcl, |
Fariborz Jahanian | d0f6f79 | 2013-07-22 18:53:45 +0000 | [diff] [blame] | 485 | const NSAPI &NS, edit::Commit &commit, |
| 486 | bool IsNSIntegerType) { |
| 487 | std::string ClassString = |
| 488 | IsNSIntegerType ? "NS_ENUM(NSInteger, " : "NS_OPTIONS(NSUInteger, "; |
Fariborz Jahanian | c1c44f6 | 2013-07-19 20:18:36 +0000 | [diff] [blame] | 489 | ClassString += TypedefDcl->getIdentifier()->getName(); |
| 490 | ClassString += ')'; |
| 491 | SourceRange R(EnumDcl->getLocStart(), EnumDcl->getLocStart()); |
| 492 | commit.replace(R, ClassString); |
| 493 | SourceLocation TypedefLoc = TypedefDcl->getLocEnd(); |
| 494 | commit.remove(SourceRange(TypedefLoc, TypedefLoc)); |
| 495 | return true; |
| 496 | } |
| 497 | |
Fariborz Jahanian | a23f4fb | 2013-08-30 00:10:37 +0000 | [diff] [blame] | 498 | static bool UseNSOptionsMacro(Preprocessor &PP, ASTContext &Ctx, |
Fariborz Jahanian | d0f6f79 | 2013-07-22 18:53:45 +0000 | [diff] [blame] | 499 | const EnumDecl *EnumDcl) { |
| 500 | bool PowerOfTwo = true; |
Fariborz Jahanian | 02bdb16 | 2013-09-23 20:27:06 +0000 | [diff] [blame^] | 501 | bool AllHexdecimalEnumerator = true; |
Fariborz Jahanian | be7bc11 | 2013-08-15 18:46:37 +0000 | [diff] [blame] | 502 | uint64_t MaxPowerOfTwoVal = 0; |
Fariborz Jahanian | d0f6f79 | 2013-07-22 18:53:45 +0000 | [diff] [blame] | 503 | for (EnumDecl::enumerator_iterator EI = EnumDcl->enumerator_begin(), |
| 504 | EE = EnumDcl->enumerator_end(); EI != EE; ++EI) { |
| 505 | EnumConstantDecl *Enumerator = (*EI); |
| 506 | const Expr *InitExpr = Enumerator->getInitExpr(); |
| 507 | if (!InitExpr) { |
| 508 | PowerOfTwo = false; |
Fariborz Jahanian | 02bdb16 | 2013-09-23 20:27:06 +0000 | [diff] [blame^] | 509 | AllHexdecimalEnumerator = false; |
Fariborz Jahanian | d0f6f79 | 2013-07-22 18:53:45 +0000 | [diff] [blame] | 510 | continue; |
| 511 | } |
Fariborz Jahanian | 6e1798e | 2013-09-17 23:32:51 +0000 | [diff] [blame] | 512 | InitExpr = InitExpr->IgnoreParenCasts(); |
Fariborz Jahanian | d0f6f79 | 2013-07-22 18:53:45 +0000 | [diff] [blame] | 513 | if (const BinaryOperator *BO = dyn_cast<BinaryOperator>(InitExpr)) |
| 514 | if (BO->isShiftOp() || BO->isBitwiseOp()) |
| 515 | return true; |
| 516 | |
| 517 | uint64_t EnumVal = Enumerator->getInitVal().getZExtValue(); |
Fariborz Jahanian | be7bc11 | 2013-08-15 18:46:37 +0000 | [diff] [blame] | 518 | if (PowerOfTwo && EnumVal) { |
| 519 | if (!llvm::isPowerOf2_64(EnumVal)) |
| 520 | PowerOfTwo = false; |
| 521 | else if (EnumVal > MaxPowerOfTwoVal) |
| 522 | MaxPowerOfTwoVal = EnumVal; |
| 523 | } |
Fariborz Jahanian | 02bdb16 | 2013-09-23 20:27:06 +0000 | [diff] [blame^] | 524 | if (AllHexdecimalEnumerator && EnumVal) { |
| 525 | bool FoundHexdecimalEnumerator = false; |
Fariborz Jahanian | a23f4fb | 2013-08-30 00:10:37 +0000 | [diff] [blame] | 526 | SourceLocation EndLoc = Enumerator->getLocEnd(); |
| 527 | Token Tok; |
| 528 | if (!PP.getRawToken(EndLoc, Tok, /*IgnoreWhiteSpace=*/true)) |
| 529 | if (Tok.isLiteral() && Tok.getLength() > 2) { |
| 530 | if (const char *StringLit = Tok.getLiteralData()) |
| 531 | FoundHexdecimalEnumerator = |
| 532 | (StringLit[0] == '0' && (toLowercase(StringLit[1]) == 'x')); |
| 533 | } |
Fariborz Jahanian | 02bdb16 | 2013-09-23 20:27:06 +0000 | [diff] [blame^] | 534 | if (!FoundHexdecimalEnumerator) |
| 535 | AllHexdecimalEnumerator = false; |
Fariborz Jahanian | a23f4fb | 2013-08-30 00:10:37 +0000 | [diff] [blame] | 536 | } |
Fariborz Jahanian | d0f6f79 | 2013-07-22 18:53:45 +0000 | [diff] [blame] | 537 | } |
Fariborz Jahanian | 02bdb16 | 2013-09-23 20:27:06 +0000 | [diff] [blame^] | 538 | return AllHexdecimalEnumerator || (PowerOfTwo && (MaxPowerOfTwoVal > 2)); |
Fariborz Jahanian | d0f6f79 | 2013-07-22 18:53:45 +0000 | [diff] [blame] | 539 | } |
| 540 | |
Fariborz Jahanian | 008ef72 | 2013-07-19 17:44:32 +0000 | [diff] [blame] | 541 | void ObjCMigrateASTConsumer::migrateProtocolConformance(ASTContext &Ctx, |
Fariborz Jahanian | 1be0153 | 2013-07-12 22:32:19 +0000 | [diff] [blame] | 542 | const ObjCImplementationDecl *ImpDecl) { |
| 543 | const ObjCInterfaceDecl *IDecl = ImpDecl->getClassInterface(); |
Fariborz Jahanian | 75226d5 | 2013-09-17 21:56:04 +0000 | [diff] [blame] | 544 | if (!IDecl || ObjCProtocolDecls.empty() || IDecl->isDeprecated()) |
Fariborz Jahanian | 1be0153 | 2013-07-12 22:32:19 +0000 | [diff] [blame] | 545 | return; |
| 546 | // Find all implicit conforming protocols for this class |
| 547 | // and make them explicit. |
| 548 | llvm::SmallPtrSet<ObjCProtocolDecl *, 8> ExplicitProtocols; |
| 549 | Ctx.CollectInheritedProtocols(IDecl, ExplicitProtocols); |
Fariborz Jahanian | 9eabf45 | 2013-07-13 00:04:20 +0000 | [diff] [blame] | 550 | llvm::SmallVector<ObjCProtocolDecl *, 8> PotentialImplicitProtocols; |
Fariborz Jahanian | 1be0153 | 2013-07-12 22:32:19 +0000 | [diff] [blame] | 551 | |
Fariborz Jahanian | 9eabf45 | 2013-07-13 00:04:20 +0000 | [diff] [blame] | 552 | for (llvm::SmallPtrSet<ObjCProtocolDecl*, 32>::iterator I = |
Fariborz Jahanian | 1be0153 | 2013-07-12 22:32:19 +0000 | [diff] [blame] | 553 | ObjCProtocolDecls.begin(), |
| 554 | E = ObjCProtocolDecls.end(); I != E; ++I) |
| 555 | if (!ExplicitProtocols.count(*I)) |
Fariborz Jahanian | 9eabf45 | 2013-07-13 00:04:20 +0000 | [diff] [blame] | 556 | PotentialImplicitProtocols.push_back(*I); |
Fariborz Jahanian | 1be0153 | 2013-07-12 22:32:19 +0000 | [diff] [blame] | 557 | |
| 558 | if (PotentialImplicitProtocols.empty()) |
| 559 | return; |
Fariborz Jahanian | 9eabf45 | 2013-07-13 00:04:20 +0000 | [diff] [blame] | 560 | |
| 561 | // go through list of non-optional methods and properties in each protocol |
| 562 | // in the PotentialImplicitProtocols list. If class implements every one of the |
| 563 | // methods and properties, then this class conforms to this protocol. |
| 564 | llvm::SmallVector<ObjCProtocolDecl*, 8> ConformingProtocols; |
| 565 | for (unsigned i = 0, e = PotentialImplicitProtocols.size(); i != e; i++) |
Fariborz Jahanian | d36150d | 2013-07-15 21:22:08 +0000 | [diff] [blame] | 566 | if (ClassImplementsAllMethodsAndProperties(Ctx, ImpDecl, IDecl, |
Fariborz Jahanian | 9eabf45 | 2013-07-13 00:04:20 +0000 | [diff] [blame] | 567 | PotentialImplicitProtocols[i])) |
| 568 | ConformingProtocols.push_back(PotentialImplicitProtocols[i]); |
Fariborz Jahanian | 5bd5aff | 2013-07-16 00:20:21 +0000 | [diff] [blame] | 569 | |
| 570 | if (ConformingProtocols.empty()) |
| 571 | return; |
Fariborz Jahanian | cb7b8de | 2013-07-17 00:02:22 +0000 | [diff] [blame] | 572 | |
| 573 | // Further reduce number of conforming protocols. If protocol P1 is in the list |
| 574 | // protocol P2 (P2<P1>), No need to include P1. |
| 575 | llvm::SmallVector<ObjCProtocolDecl*, 8> MinimalConformingProtocols; |
| 576 | for (unsigned i = 0, e = ConformingProtocols.size(); i != e; i++) { |
| 577 | bool DropIt = false; |
| 578 | ObjCProtocolDecl *TargetPDecl = ConformingProtocols[i]; |
| 579 | for (unsigned i1 = 0, e1 = ConformingProtocols.size(); i1 != e1; i1++) { |
| 580 | ObjCProtocolDecl *PDecl = ConformingProtocols[i1]; |
| 581 | if (PDecl == TargetPDecl) |
| 582 | continue; |
| 583 | if (PDecl->lookupProtocolNamed( |
| 584 | TargetPDecl->getDeclName().getAsIdentifierInfo())) { |
| 585 | DropIt = true; |
| 586 | break; |
| 587 | } |
| 588 | } |
| 589 | if (!DropIt) |
| 590 | MinimalConformingProtocols.push_back(TargetPDecl); |
| 591 | } |
Fariborz Jahanian | 5bd5aff | 2013-07-16 00:20:21 +0000 | [diff] [blame] | 592 | edit::Commit commit(*Editor); |
Fariborz Jahanian | 85e988b | 2013-07-18 22:17:33 +0000 | [diff] [blame] | 593 | rewriteToObjCInterfaceDecl(IDecl, MinimalConformingProtocols, |
| 594 | *NSAPIObj, commit); |
Fariborz Jahanian | 5bd5aff | 2013-07-16 00:20:21 +0000 | [diff] [blame] | 595 | Editor->commit(commit); |
Fariborz Jahanian | 1be0153 | 2013-07-12 22:32:19 +0000 | [diff] [blame] | 596 | } |
| 597 | |
Fariborz Jahanian | 9246327 | 2013-07-18 20:11:45 +0000 | [diff] [blame] | 598 | void ObjCMigrateASTConsumer::migrateNSEnumDecl(ASTContext &Ctx, |
| 599 | const EnumDecl *EnumDcl, |
| 600 | const TypedefDecl *TypedefDcl) { |
| 601 | if (!EnumDcl->isCompleteDefinition() || EnumDcl->getIdentifier() || |
Fariborz Jahanian | 75226d5 | 2013-09-17 21:56:04 +0000 | [diff] [blame] | 602 | !TypedefDcl->getIdentifier() || |
| 603 | EnumDcl->isDeprecated() || TypedefDcl->isDeprecated()) |
Fariborz Jahanian | 9246327 | 2013-07-18 20:11:45 +0000 | [diff] [blame] | 604 | return; |
| 605 | |
| 606 | QualType qt = TypedefDcl->getTypeSourceInfo()->getType(); |
Fariborz Jahanian | b0057bb | 2013-07-19 01:05:49 +0000 | [diff] [blame] | 607 | bool IsNSIntegerType = NSAPIObj->isObjCNSIntegerType(qt); |
| 608 | bool IsNSUIntegerType = !IsNSIntegerType && NSAPIObj->isObjCNSUIntegerType(qt); |
Fariborz Jahanian | d0f6f79 | 2013-07-22 18:53:45 +0000 | [diff] [blame] | 609 | |
Fariborz Jahanian | c1c44f6 | 2013-07-19 20:18:36 +0000 | [diff] [blame] | 610 | if (!IsNSIntegerType && !IsNSUIntegerType) { |
| 611 | // Also check for typedef enum {...} TD; |
| 612 | if (const EnumType *EnumTy = qt->getAs<EnumType>()) { |
| 613 | if (EnumTy->getDecl() == EnumDcl) { |
Fariborz Jahanian | a23f4fb | 2013-08-30 00:10:37 +0000 | [diff] [blame] | 614 | bool NSOptions = UseNSOptionsMacro(PP, Ctx, EnumDcl); |
Fariborz Jahanian | d0f6f79 | 2013-07-22 18:53:45 +0000 | [diff] [blame] | 615 | if (NSOptions) { |
| 616 | if (!Ctx.Idents.get("NS_OPTIONS").hasMacroDefinition()) |
| 617 | return; |
| 618 | } |
| 619 | else if (!Ctx.Idents.get("NS_ENUM").hasMacroDefinition()) |
Fariborz Jahanian | c1c44f6 | 2013-07-19 20:18:36 +0000 | [diff] [blame] | 620 | return; |
| 621 | edit::Commit commit(*Editor); |
Fariborz Jahanian | d0f6f79 | 2013-07-22 18:53:45 +0000 | [diff] [blame] | 622 | rewriteToNSMacroDecl(EnumDcl, TypedefDcl, *NSAPIObj, commit, !NSOptions); |
Fariborz Jahanian | c1c44f6 | 2013-07-19 20:18:36 +0000 | [diff] [blame] | 623 | Editor->commit(commit); |
Fariborz Jahanian | c1c44f6 | 2013-07-19 20:18:36 +0000 | [diff] [blame] | 624 | } |
Fariborz Jahanian | c1c44f6 | 2013-07-19 20:18:36 +0000 | [diff] [blame] | 625 | } |
Fariborz Jahanian | d0f6f79 | 2013-07-22 18:53:45 +0000 | [diff] [blame] | 626 | return; |
| 627 | } |
Fariborz Jahanian | 9246327 | 2013-07-18 20:11:45 +0000 | [diff] [blame] | 628 | |
Fariborz Jahanian | ff3476e | 2013-08-30 17:46:01 +0000 | [diff] [blame] | 629 | // We may still use NS_OPTIONS based on what we find in the enumertor list. |
| 630 | bool NSOptions = UseNSOptionsMacro(PP, Ctx, EnumDcl); |
Fariborz Jahanian | 9246327 | 2013-07-18 20:11:45 +0000 | [diff] [blame] | 631 | // NS_ENUM must be available. |
Fariborz Jahanian | b0057bb | 2013-07-19 01:05:49 +0000 | [diff] [blame] | 632 | if (IsNSIntegerType && !Ctx.Idents.get("NS_ENUM").hasMacroDefinition()) |
| 633 | return; |
| 634 | // NS_OPTIONS must be available. |
| 635 | if (IsNSUIntegerType && !Ctx.Idents.get("NS_OPTIONS").hasMacroDefinition()) |
Fariborz Jahanian | 9246327 | 2013-07-18 20:11:45 +0000 | [diff] [blame] | 636 | return; |
| 637 | edit::Commit commit(*Editor); |
Fariborz Jahanian | ff3476e | 2013-08-30 17:46:01 +0000 | [diff] [blame] | 638 | rewriteToNSEnumDecl(EnumDcl, TypedefDcl, *NSAPIObj, commit, IsNSIntegerType, NSOptions); |
Fariborz Jahanian | 9246327 | 2013-07-18 20:11:45 +0000 | [diff] [blame] | 639 | Editor->commit(commit); |
| 640 | } |
| 641 | |
Fariborz Jahanian | c429185 | 2013-08-02 18:00:53 +0000 | [diff] [blame] | 642 | static void ReplaceWithInstancetype(const ObjCMigrateASTConsumer &ASTC, |
| 643 | ObjCMethodDecl *OM) { |
| 644 | SourceRange R; |
| 645 | std::string ClassString; |
| 646 | if (TypeSourceInfo *TSInfo = OM->getResultTypeSourceInfo()) { |
| 647 | TypeLoc TL = TSInfo->getTypeLoc(); |
| 648 | R = SourceRange(TL.getBeginLoc(), TL.getEndLoc()); |
| 649 | ClassString = "instancetype"; |
| 650 | } |
| 651 | else { |
| 652 | R = SourceRange(OM->getLocStart(), OM->getLocStart()); |
| 653 | ClassString = OM->isInstanceMethod() ? '-' : '+'; |
| 654 | ClassString += " (instancetype)"; |
| 655 | } |
| 656 | edit::Commit commit(*ASTC.Editor); |
| 657 | commit.replace(R, ClassString); |
| 658 | ASTC.Editor->commit(commit); |
| 659 | } |
| 660 | |
Fariborz Jahanian | 670ef26 | 2013-07-23 23:34:42 +0000 | [diff] [blame] | 661 | void ObjCMigrateASTConsumer::migrateMethodInstanceType(ASTContext &Ctx, |
| 662 | ObjCContainerDecl *CDecl, |
| 663 | ObjCMethodDecl *OM) { |
Fariborz Jahanian | 7122135 | 2013-07-23 22:42:28 +0000 | [diff] [blame] | 664 | ObjCInstanceTypeFamily OIT_Family = |
| 665 | Selector::getInstTypeMethodFamily(OM->getSelector()); |
Fariborz Jahanian | 9275c68 | 2013-08-02 20:54:18 +0000 | [diff] [blame] | 666 | |
Fariborz Jahanian | 267bae3 | 2013-07-24 19:18:37 +0000 | [diff] [blame] | 667 | std::string ClassName; |
Fariborz Jahanian | 631925f | 2013-07-23 23:55:55 +0000 | [diff] [blame] | 668 | switch (OIT_Family) { |
Fariborz Jahanian | 9275c68 | 2013-08-02 20:54:18 +0000 | [diff] [blame] | 669 | case OIT_None: |
| 670 | migrateFactoryMethod(Ctx, CDecl, OM); |
| 671 | return; |
Fariborz Jahanian | 7dd7143 | 2013-08-28 21:23:00 +0000 | [diff] [blame] | 672 | case OIT_Array: |
| 673 | ClassName = "NSArray"; |
| 674 | break; |
| 675 | case OIT_Dictionary: |
| 676 | ClassName = "NSDictionary"; |
| 677 | break; |
Fariborz Jahanian | 9275c68 | 2013-08-02 20:54:18 +0000 | [diff] [blame] | 678 | case OIT_Singleton: |
| 679 | migrateFactoryMethod(Ctx, CDecl, OM, OIT_Singleton); |
Fariborz Jahanian | 631925f | 2013-07-23 23:55:55 +0000 | [diff] [blame] | 680 | return; |
Fariborz Jahanian | 1c900bc | 2013-09-18 20:35:47 +0000 | [diff] [blame] | 681 | case OIT_Init: |
| 682 | if (OM->getResultType()->isObjCIdType()) |
| 683 | ReplaceWithInstancetype(*this, OM); |
| 684 | return; |
Fariborz Jahanian | 631925f | 2013-07-23 23:55:55 +0000 | [diff] [blame] | 685 | } |
Fariborz Jahanian | 7122135 | 2013-07-23 22:42:28 +0000 | [diff] [blame] | 686 | if (!OM->getResultType()->isObjCIdType()) |
| 687 | return; |
| 688 | |
| 689 | ObjCInterfaceDecl *IDecl = dyn_cast<ObjCInterfaceDecl>(CDecl); |
| 690 | if (!IDecl) { |
| 691 | if (ObjCCategoryDecl *CatDecl = dyn_cast<ObjCCategoryDecl>(CDecl)) |
| 692 | IDecl = CatDecl->getClassInterface(); |
| 693 | else if (ObjCImplDecl *ImpDecl = dyn_cast<ObjCImplDecl>(CDecl)) |
| 694 | IDecl = ImpDecl->getClassInterface(); |
| 695 | } |
Fariborz Jahanian | 267bae3 | 2013-07-24 19:18:37 +0000 | [diff] [blame] | 696 | if (!IDecl || |
Fariborz Jahanian | c429185 | 2013-08-02 18:00:53 +0000 | [diff] [blame] | 697 | !IDecl->lookupInheritedClass(&Ctx.Idents.get(ClassName))) { |
| 698 | migrateFactoryMethod(Ctx, CDecl, OM); |
Fariborz Jahanian | 7122135 | 2013-07-23 22:42:28 +0000 | [diff] [blame] | 699 | return; |
Fariborz Jahanian | 280954a | 2013-07-24 18:31:42 +0000 | [diff] [blame] | 700 | } |
Fariborz Jahanian | c429185 | 2013-08-02 18:00:53 +0000 | [diff] [blame] | 701 | ReplaceWithInstancetype(*this, OM); |
Fariborz Jahanian | 7122135 | 2013-07-23 22:42:28 +0000 | [diff] [blame] | 702 | } |
| 703 | |
Fariborz Jahanian | d0fbf6c | 2013-08-30 23:52:08 +0000 | [diff] [blame] | 704 | static bool TypeIsInnerPointer(QualType T) { |
| 705 | if (!T->isAnyPointerType()) |
| 706 | return false; |
| 707 | if (T->isObjCObjectPointerType() || T->isObjCBuiltinType() || |
| 708 | T->isBlockPointerType() || ento::coreFoundation::isCFObjectRef(T)) |
| 709 | return false; |
Fariborz Jahanian | 9d5fffb | 2013-09-09 23:56:14 +0000 | [diff] [blame] | 710 | // Also, typedef-of-pointer-to-incomplete-struct is something that we assume |
| 711 | // is not an innter pointer type. |
| 712 | QualType OrigT = T; |
| 713 | while (const TypedefType *TD = dyn_cast<TypedefType>(T.getTypePtr())) |
| 714 | T = TD->getDecl()->getUnderlyingType(); |
| 715 | if (OrigT == T || !T->isPointerType()) |
| 716 | return true; |
| 717 | const PointerType* PT = T->getAs<PointerType>(); |
| 718 | QualType UPointeeT = PT->getPointeeType().getUnqualifiedType(); |
| 719 | if (UPointeeT->isRecordType()) { |
| 720 | const RecordType *RecordTy = UPointeeT->getAs<RecordType>(); |
| 721 | if (!RecordTy->getDecl()->isCompleteDefinition()) |
| 722 | return false; |
| 723 | } |
Fariborz Jahanian | d0fbf6c | 2013-08-30 23:52:08 +0000 | [diff] [blame] | 724 | return true; |
| 725 | } |
| 726 | |
Fariborz Jahanian | 2ba62a7 | 2013-09-18 17:22:25 +0000 | [diff] [blame] | 727 | static bool AttributesMatch(const Decl *Decl1, const Decl *Decl2) { |
| 728 | if (Decl1->hasAttrs() != Decl2->hasAttrs()) |
| 729 | return false; |
| 730 | |
| 731 | if (!Decl1->hasAttrs()) |
| 732 | return true; |
| 733 | |
| 734 | const AttrVec &Attrs1 = Decl1->getAttrs(); |
| 735 | const AttrVec &Attrs2 = Decl2->getAttrs(); |
| 736 | // This list is very small, so this need not be optimized. |
| 737 | for (unsigned i = 0, e = Attrs1.size(); i != e; i++) { |
| 738 | bool match = false; |
| 739 | for (unsigned j = 0, f = Attrs2.size(); j != f; j++) { |
| 740 | // Matching attribute kind only. We are not getting into |
| 741 | // details of the attributes. For all practical purposes |
| 742 | // this is sufficient. |
| 743 | if (Attrs1[i]->getKind() == Attrs2[j]->getKind()) { |
| 744 | match = true; |
| 745 | break; |
| 746 | } |
| 747 | } |
| 748 | if (!match) |
| 749 | return false; |
| 750 | } |
| 751 | return true; |
| 752 | } |
| 753 | |
Fariborz Jahanian | 215f96c | 2013-09-06 23:45:20 +0000 | [diff] [blame] | 754 | bool ObjCMigrateASTConsumer::migrateProperty(ASTContext &Ctx, |
Fariborz Jahanian | 92f7242 | 2013-09-17 19:00:30 +0000 | [diff] [blame] | 755 | ObjCContainerDecl *D, |
Fariborz Jahanian | 215f96c | 2013-09-06 23:45:20 +0000 | [diff] [blame] | 756 | ObjCMethodDecl *Method) { |
| 757 | if (Method->isPropertyAccessor() || !Method->isInstanceMethod() || |
| 758 | Method->param_size() != 0) |
| 759 | return false; |
| 760 | // Is this method candidate to be a getter? |
| 761 | QualType GRT = Method->getResultType(); |
| 762 | if (GRT->isVoidType()) |
| 763 | return false; |
Fariborz Jahanian | 215f96c | 2013-09-06 23:45:20 +0000 | [diff] [blame] | 764 | |
| 765 | Selector GetterSelector = Method->getSelector(); |
| 766 | IdentifierInfo *getterName = GetterSelector.getIdentifierInfoForSlot(0); |
| 767 | Selector SetterSelector = |
| 768 | SelectorTable::constructSetterSelector(PP.getIdentifierTable(), |
| 769 | PP.getSelectorTable(), |
| 770 | getterName); |
Fariborz Jahanian | 92f7242 | 2013-09-17 19:00:30 +0000 | [diff] [blame] | 771 | ObjCMethodDecl *SetterMethod = D->getInstanceMethod(SetterSelector); |
Fariborz Jahanian | ca39960 | 2013-09-11 17:05:15 +0000 | [diff] [blame] | 772 | unsigned LengthOfPrefix = 0; |
Fariborz Jahanian | 215f96c | 2013-09-06 23:45:20 +0000 | [diff] [blame] | 773 | if (!SetterMethod) { |
| 774 | // try a different naming convention for getter: isXxxxx |
| 775 | StringRef getterNameString = getterName->getName(); |
Fariborz Jahanian | ca39960 | 2013-09-11 17:05:15 +0000 | [diff] [blame] | 776 | bool IsPrefix = getterNameString.startswith("is"); |
Fariborz Jahanian | 4c3d9c5 | 2013-09-17 19:38:55 +0000 | [diff] [blame] | 777 | // Note that we don't want to change an isXXX method of retainable object |
| 778 | // type to property (readonly or otherwise). |
| 779 | if (IsPrefix && GRT->isObjCRetainableType()) |
| 780 | return false; |
| 781 | if (IsPrefix || getterNameString.startswith("get")) { |
Fariborz Jahanian | ca39960 | 2013-09-11 17:05:15 +0000 | [diff] [blame] | 782 | LengthOfPrefix = (IsPrefix ? 2 : 3); |
| 783 | const char *CGetterName = getterNameString.data() + LengthOfPrefix; |
| 784 | // Make sure that first character after "is" or "get" prefix can |
| 785 | // start an identifier. |
| 786 | if (!isIdentifierHead(CGetterName[0])) |
| 787 | return false; |
Fariborz Jahanian | 215f96c | 2013-09-06 23:45:20 +0000 | [diff] [blame] | 788 | if (CGetterName[0] && isUppercase(CGetterName[0])) { |
| 789 | getterName = &Ctx.Idents.get(CGetterName); |
| 790 | SetterSelector = |
| 791 | SelectorTable::constructSetterSelector(PP.getIdentifierTable(), |
| 792 | PP.getSelectorTable(), |
| 793 | getterName); |
Fariborz Jahanian | 92f7242 | 2013-09-17 19:00:30 +0000 | [diff] [blame] | 794 | SetterMethod = D->getInstanceMethod(SetterSelector); |
Fariborz Jahanian | 215f96c | 2013-09-06 23:45:20 +0000 | [diff] [blame] | 795 | } |
| 796 | } |
| 797 | } |
Fariborz Jahanian | 4c3d9c5 | 2013-09-17 19:38:55 +0000 | [diff] [blame] | 798 | |
Fariborz Jahanian | 215f96c | 2013-09-06 23:45:20 +0000 | [diff] [blame] | 799 | if (SetterMethod) { |
Fariborz Jahanian | 2ba62a7 | 2013-09-18 17:22:25 +0000 | [diff] [blame] | 800 | if (SetterMethod->isDeprecated() || |
| 801 | !AttributesMatch(Method, SetterMethod)) |
Fariborz Jahanian | f6c6505 | 2013-09-17 22:41:25 +0000 | [diff] [blame] | 802 | return false; |
Fariborz Jahanian | 2ba62a7 | 2013-09-18 17:22:25 +0000 | [diff] [blame] | 803 | |
Fariborz Jahanian | 215f96c | 2013-09-06 23:45:20 +0000 | [diff] [blame] | 804 | // Is this a valid setter, matching the target getter? |
| 805 | QualType SRT = SetterMethod->getResultType(); |
| 806 | if (!SRT->isVoidType()) |
| 807 | return false; |
| 808 | const ParmVarDecl *argDecl = *SetterMethod->param_begin(); |
| 809 | QualType ArgType = argDecl->getType(); |
Fariborz Jahanian | 2ba62a7 | 2013-09-18 17:22:25 +0000 | [diff] [blame] | 810 | if (!Ctx.hasSameUnqualifiedType(ArgType, GRT)) |
Fariborz Jahanian | 215f96c | 2013-09-06 23:45:20 +0000 | [diff] [blame] | 811 | return false; |
| 812 | edit::Commit commit(*Editor); |
| 813 | rewriteToObjCProperty(Method, SetterMethod, *NSAPIObj, commit, |
Fariborz Jahanian | ca39960 | 2013-09-11 17:05:15 +0000 | [diff] [blame] | 814 | LengthOfPrefix); |
Fariborz Jahanian | 215f96c | 2013-09-06 23:45:20 +0000 | [diff] [blame] | 815 | Editor->commit(commit); |
| 816 | return true; |
| 817 | } |
| 818 | else if (MigrateReadonlyProperty) { |
| 819 | // Try a non-void method with no argument (and no setter or property of same name |
| 820 | // as a 'readonly' property. |
| 821 | edit::Commit commit(*Editor); |
| 822 | rewriteToObjCProperty(Method, 0 /*SetterMethod*/, *NSAPIObj, commit, |
Fariborz Jahanian | ca39960 | 2013-09-11 17:05:15 +0000 | [diff] [blame] | 823 | LengthOfPrefix); |
Fariborz Jahanian | 215f96c | 2013-09-06 23:45:20 +0000 | [diff] [blame] | 824 | Editor->commit(commit); |
| 825 | return true; |
| 826 | } |
| 827 | return false; |
| 828 | } |
| 829 | |
Fariborz Jahanian | d0fbf6c | 2013-08-30 23:52:08 +0000 | [diff] [blame] | 830 | void ObjCMigrateASTConsumer::migrateNsReturnsInnerPointer(ASTContext &Ctx, |
| 831 | ObjCMethodDecl *OM) { |
| 832 | if (OM->hasAttr<ObjCReturnsInnerPointerAttr>()) |
| 833 | return; |
| 834 | |
| 835 | QualType RT = OM->getResultType(); |
| 836 | if (!TypeIsInnerPointer(RT) || |
| 837 | !Ctx.Idents.get("NS_RETURNS_INNER_POINTER").hasMacroDefinition()) |
| 838 | return; |
| 839 | |
| 840 | edit::Commit commit(*Editor); |
| 841 | commit.insertBefore(OM->getLocEnd(), " NS_RETURNS_INNER_POINTER"); |
| 842 | Editor->commit(commit); |
| 843 | } |
| 844 | |
| 845 | void ObjCMigrateASTConsumer::migrateMethods(ASTContext &Ctx, |
Fariborz Jahanian | 7122135 | 2013-07-23 22:42:28 +0000 | [diff] [blame] | 846 | ObjCContainerDecl *CDecl) { |
Fariborz Jahanian | e47a14a | 2013-09-18 15:43:52 +0000 | [diff] [blame] | 847 | if (CDecl->isDeprecated()) |
| 848 | return; |
| 849 | |
Fariborz Jahanian | 7122135 | 2013-07-23 22:42:28 +0000 | [diff] [blame] | 850 | // migrate methods which can have instancetype as their result type. |
| 851 | for (ObjCContainerDecl::method_iterator M = CDecl->meth_begin(), |
| 852 | MEnd = CDecl->meth_end(); |
| 853 | M != MEnd; ++M) { |
| 854 | ObjCMethodDecl *Method = (*M); |
Fariborz Jahanian | 75226d5 | 2013-09-17 21:56:04 +0000 | [diff] [blame] | 855 | if (Method->isDeprecated()) |
| 856 | continue; |
Fariborz Jahanian | 7122135 | 2013-07-23 22:42:28 +0000 | [diff] [blame] | 857 | migrateMethodInstanceType(Ctx, CDecl, Method); |
| 858 | } |
| 859 | } |
| 860 | |
Fariborz Jahanian | c429185 | 2013-08-02 18:00:53 +0000 | [diff] [blame] | 861 | void ObjCMigrateASTConsumer::migrateFactoryMethod(ASTContext &Ctx, |
| 862 | ObjCContainerDecl *CDecl, |
Fariborz Jahanian | 9275c68 | 2013-08-02 20:54:18 +0000 | [diff] [blame] | 863 | ObjCMethodDecl *OM, |
| 864 | ObjCInstanceTypeFamily OIT_Family) { |
Fariborz Jahanian | 3bfc35e | 2013-08-02 22:34:18 +0000 | [diff] [blame] | 865 | if (OM->isInstanceMethod() || |
| 866 | OM->getResultType() == Ctx.getObjCInstanceType() || |
| 867 | !OM->getResultType()->isObjCIdType()) |
Fariborz Jahanian | c429185 | 2013-08-02 18:00:53 +0000 | [diff] [blame] | 868 | return; |
| 869 | |
| 870 | // Candidate factory methods are + (id) NaMeXXX : ... which belong to a class |
| 871 | // NSYYYNamE with matching names be at least 3 characters long. |
| 872 | ObjCInterfaceDecl *IDecl = dyn_cast<ObjCInterfaceDecl>(CDecl); |
| 873 | if (!IDecl) { |
| 874 | if (ObjCCategoryDecl *CatDecl = dyn_cast<ObjCCategoryDecl>(CDecl)) |
| 875 | IDecl = CatDecl->getClassInterface(); |
| 876 | else if (ObjCImplDecl *ImpDecl = dyn_cast<ObjCImplDecl>(CDecl)) |
| 877 | IDecl = ImpDecl->getClassInterface(); |
| 878 | } |
| 879 | if (!IDecl) |
| 880 | return; |
| 881 | |
| 882 | std::string StringClassName = IDecl->getName(); |
| 883 | StringRef LoweredClassName(StringClassName); |
| 884 | std::string StringLoweredClassName = LoweredClassName.lower(); |
| 885 | LoweredClassName = StringLoweredClassName; |
| 886 | |
| 887 | IdentifierInfo *MethodIdName = OM->getSelector().getIdentifierInfoForSlot(0); |
Fariborz Jahanian | c13c1b0 | 2013-08-13 18:01:42 +0000 | [diff] [blame] | 888 | // Handle method with no name at its first selector slot; e.g. + (id):(int)x. |
| 889 | if (!MethodIdName) |
| 890 | return; |
| 891 | |
Fariborz Jahanian | c429185 | 2013-08-02 18:00:53 +0000 | [diff] [blame] | 892 | std::string MethodName = MethodIdName->getName(); |
Fariborz Jahanian | 9275c68 | 2013-08-02 20:54:18 +0000 | [diff] [blame] | 893 | if (OIT_Family == OIT_Singleton) { |
| 894 | StringRef STRefMethodName(MethodName); |
| 895 | size_t len = 0; |
| 896 | if (STRefMethodName.startswith("standard")) |
| 897 | len = strlen("standard"); |
| 898 | else if (STRefMethodName.startswith("shared")) |
| 899 | len = strlen("shared"); |
| 900 | else if (STRefMethodName.startswith("default")) |
| 901 | len = strlen("default"); |
| 902 | else |
| 903 | return; |
| 904 | MethodName = STRefMethodName.substr(len); |
| 905 | } |
Fariborz Jahanian | c429185 | 2013-08-02 18:00:53 +0000 | [diff] [blame] | 906 | std::string MethodNameSubStr = MethodName.substr(0, 3); |
| 907 | StringRef MethodNamePrefix(MethodNameSubStr); |
| 908 | std::string StringLoweredMethodNamePrefix = MethodNamePrefix.lower(); |
| 909 | MethodNamePrefix = StringLoweredMethodNamePrefix; |
| 910 | size_t Ix = LoweredClassName.rfind(MethodNamePrefix); |
| 911 | if (Ix == StringRef::npos) |
| 912 | return; |
| 913 | std::string ClassNamePostfix = LoweredClassName.substr(Ix); |
| 914 | StringRef LoweredMethodName(MethodName); |
| 915 | std::string StringLoweredMethodName = LoweredMethodName.lower(); |
| 916 | LoweredMethodName = StringLoweredMethodName; |
| 917 | if (!LoweredMethodName.startswith(ClassNamePostfix)) |
| 918 | return; |
| 919 | ReplaceWithInstancetype(*this, OM); |
| 920 | } |
| 921 | |
Fariborz Jahanian | 2ec4d7b | 2013-08-16 23:35:05 +0000 | [diff] [blame] | 922 | static bool IsVoidStarType(QualType Ty) { |
| 923 | if (!Ty->isPointerType()) |
| 924 | return false; |
| 925 | |
| 926 | while (const TypedefType *TD = dyn_cast<TypedefType>(Ty.getTypePtr())) |
| 927 | Ty = TD->getDecl()->getUnderlyingType(); |
| 928 | |
| 929 | // Is the type void*? |
| 930 | const PointerType* PT = Ty->getAs<PointerType>(); |
| 931 | if (PT->getPointeeType().getUnqualifiedType()->isVoidType()) |
| 932 | return true; |
| 933 | return IsVoidStarType(PT->getPointeeType()); |
| 934 | } |
| 935 | |
Fariborz Jahanian | 9427939 | 2013-08-20 18:54:39 +0000 | [diff] [blame] | 936 | /// AuditedType - This routine audits the type AT and returns false if it is one of known |
| 937 | /// CF object types or of the "void *" variety. It returns true if we don't care about the type |
| 938 | /// such as a non-pointer or pointers which have no ownership issues (such as "int *"). |
Fariborz Jahanian | 63ffce2 | 2013-08-27 22:42:30 +0000 | [diff] [blame] | 939 | static bool AuditedType (QualType AT) { |
| 940 | if (!AT->isAnyPointerType() && !AT->isBlockPointerType()) |
Fariborz Jahanian | 9ef4a26 | 2013-08-19 19:13:34 +0000 | [diff] [blame] | 941 | return true; |
Fariborz Jahanian | 9ef4a26 | 2013-08-19 19:13:34 +0000 | [diff] [blame] | 942 | // FIXME. There isn't much we can say about CF pointer type; or is there? |
Fariborz Jahanian | 9427939 | 2013-08-20 18:54:39 +0000 | [diff] [blame] | 943 | if (ento::coreFoundation::isCFObjectRef(AT) || |
| 944 | IsVoidStarType(AT) || |
| 945 | // If an ObjC object is type, assuming that it is not a CF function and |
| 946 | // that it is an un-audited function. |
Fariborz Jahanian | 2e9c19c | 2013-08-22 22:27:36 +0000 | [diff] [blame] | 947 | AT->isObjCObjectPointerType() || AT->isObjCBuiltinType()) |
Fariborz Jahanian | 9ef4a26 | 2013-08-19 19:13:34 +0000 | [diff] [blame] | 948 | return false; |
Fariborz Jahanian | 9427939 | 2013-08-20 18:54:39 +0000 | [diff] [blame] | 949 | // All other pointers are assumed audited as harmless. |
Fariborz Jahanian | 9ef4a26 | 2013-08-19 19:13:34 +0000 | [diff] [blame] | 950 | return true; |
Fariborz Jahanian | 2ec4d7b | 2013-08-16 23:35:05 +0000 | [diff] [blame] | 951 | } |
| 952 | |
Fariborz Jahanian | 301b521 | 2013-08-20 22:42:13 +0000 | [diff] [blame] | 953 | void ObjCMigrateASTConsumer::AnnotateImplicitBridging(ASTContext &Ctx) { |
Fariborz Jahanian | 926fafb | 2013-08-22 18:35:27 +0000 | [diff] [blame] | 954 | if (CFFunctionIBCandidates.empty()) |
| 955 | return; |
Fariborz Jahanian | 301b521 | 2013-08-20 22:42:13 +0000 | [diff] [blame] | 956 | if (!Ctx.Idents.get("CF_IMPLICIT_BRIDGING_ENABLED").hasMacroDefinition()) { |
| 957 | CFFunctionIBCandidates.clear(); |
Fariborz Jahanian | b834352 | 2013-08-20 23:35:26 +0000 | [diff] [blame] | 958 | FileId = 0; |
Fariborz Jahanian | 301b521 | 2013-08-20 22:42:13 +0000 | [diff] [blame] | 959 | return; |
| 960 | } |
| 961 | // Insert CF_IMPLICIT_BRIDGING_ENABLE/CF_IMPLICIT_BRIDGING_DISABLED |
Fariborz Jahanian | 926fafb | 2013-08-22 18:35:27 +0000 | [diff] [blame] | 962 | const Decl *FirstFD = CFFunctionIBCandidates[0]; |
| 963 | const Decl *LastFD = |
| 964 | CFFunctionIBCandidates[CFFunctionIBCandidates.size()-1]; |
Fariborz Jahanian | 301b521 | 2013-08-20 22:42:13 +0000 | [diff] [blame] | 965 | const char *PragmaString = "\nCF_IMPLICIT_BRIDGING_ENABLED\n\n"; |
| 966 | edit::Commit commit(*Editor); |
| 967 | commit.insertBefore(FirstFD->getLocStart(), PragmaString); |
| 968 | PragmaString = "\n\nCF_IMPLICIT_BRIDGING_DISABLED\n"; |
| 969 | SourceLocation EndLoc = LastFD->getLocEnd(); |
| 970 | // get location just past end of function location. |
| 971 | EndLoc = PP.getLocForEndOfToken(EndLoc); |
Fariborz Jahanian | 926fafb | 2013-08-22 18:35:27 +0000 | [diff] [blame] | 972 | if (isa<FunctionDecl>(LastFD)) { |
| 973 | // For Methods, EndLoc points to the ending semcolon. So, |
| 974 | // not of these extra work is needed. |
| 975 | Token Tok; |
| 976 | // get locaiton of token that comes after end of function. |
| 977 | bool Failed = PP.getRawToken(EndLoc, Tok, /*IgnoreWhiteSpace=*/true); |
| 978 | if (!Failed) |
| 979 | EndLoc = Tok.getLocation(); |
| 980 | } |
Fariborz Jahanian | 301b521 | 2013-08-20 22:42:13 +0000 | [diff] [blame] | 981 | commit.insertAfterToken(EndLoc, PragmaString); |
| 982 | Editor->commit(commit); |
Fariborz Jahanian | b834352 | 2013-08-20 23:35:26 +0000 | [diff] [blame] | 983 | FileId = 0; |
Fariborz Jahanian | 301b521 | 2013-08-20 22:42:13 +0000 | [diff] [blame] | 984 | CFFunctionIBCandidates.clear(); |
| 985 | } |
| 986 | |
Fariborz Jahanian | 4f64dd2 | 2013-08-22 21:40:15 +0000 | [diff] [blame] | 987 | void ObjCMigrateASTConsumer::migrateCFAnnotation(ASTContext &Ctx, const Decl *Decl) { |
Fariborz Jahanian | 75226d5 | 2013-09-17 21:56:04 +0000 | [diff] [blame] | 988 | if (Decl->isDeprecated()) |
| 989 | return; |
| 990 | |
Fariborz Jahanian | 4f64dd2 | 2013-08-22 21:40:15 +0000 | [diff] [blame] | 991 | if (Decl->hasAttr<CFAuditedTransferAttr>()) { |
Fariborz Jahanian | c6dfd3f | 2013-08-19 22:00:50 +0000 | [diff] [blame] | 992 | assert(CFFunctionIBCandidates.empty() && |
Fariborz Jahanian | 4f64dd2 | 2013-08-22 21:40:15 +0000 | [diff] [blame] | 993 | "Cannot have audited functions/methods inside user " |
Fariborz Jahanian | c6dfd3f | 2013-08-19 22:00:50 +0000 | [diff] [blame] | 994 | "provided CF_IMPLICIT_BRIDGING_ENABLE"); |
| 995 | return; |
| 996 | } |
| 997 | |
Fariborz Jahanian | 2ec4d7b | 2013-08-16 23:35:05 +0000 | [diff] [blame] | 998 | // Finction must be annotated first. |
Fariborz Jahanian | 89f6d10 | 2013-09-04 00:10:06 +0000 | [diff] [blame] | 999 | if (const FunctionDecl *FuncDecl = dyn_cast<FunctionDecl>(Decl)) { |
| 1000 | CF_BRIDGING_KIND AuditKind = migrateAddFunctionAnnotation(Ctx, FuncDecl); |
| 1001 | if (AuditKind == CF_BRIDGING_ENABLE) { |
Fariborz Jahanian | 63ffce2 | 2013-08-27 22:42:30 +0000 | [diff] [blame] | 1002 | CFFunctionIBCandidates.push_back(Decl); |
| 1003 | if (!FileId) |
| 1004 | FileId = PP.getSourceManager().getFileID(Decl->getLocation()).getHashValue(); |
| 1005 | } |
Fariborz Jahanian | 89f6d10 | 2013-09-04 00:10:06 +0000 | [diff] [blame] | 1006 | else if (AuditKind == CF_BRIDGING_MAY_INCLUDE) { |
| 1007 | if (!CFFunctionIBCandidates.empty()) { |
| 1008 | CFFunctionIBCandidates.push_back(Decl); |
| 1009 | if (!FileId) |
| 1010 | FileId = PP.getSourceManager().getFileID(Decl->getLocation()).getHashValue(); |
| 1011 | } |
| 1012 | } |
| 1013 | else |
| 1014 | AnnotateImplicitBridging(Ctx); |
Fariborz Jahanian | 63ffce2 | 2013-08-27 22:42:30 +0000 | [diff] [blame] | 1015 | } |
Fariborz Jahanian | 89f6d10 | 2013-09-04 00:10:06 +0000 | [diff] [blame] | 1016 | else { |
| 1017 | migrateAddMethodAnnotation(Ctx, cast<ObjCMethodDecl>(Decl)); |
Fariborz Jahanian | 301b521 | 2013-08-20 22:42:13 +0000 | [diff] [blame] | 1018 | AnnotateImplicitBridging(Ctx); |
Fariborz Jahanian | 89f6d10 | 2013-09-04 00:10:06 +0000 | [diff] [blame] | 1019 | } |
Fariborz Jahanian | 2ec4d7b | 2013-08-16 23:35:05 +0000 | [diff] [blame] | 1020 | } |
| 1021 | |
Fariborz Jahanian | 63ffce2 | 2013-08-27 22:42:30 +0000 | [diff] [blame] | 1022 | void ObjCMigrateASTConsumer::AddCFAnnotations(ASTContext &Ctx, |
| 1023 | const CallEffects &CE, |
Fariborz Jahanian | 7ca1d30 | 2013-08-27 23:56:54 +0000 | [diff] [blame] | 1024 | const FunctionDecl *FuncDecl, |
| 1025 | bool ResultAnnotated) { |
Fariborz Jahanian | 63ffce2 | 2013-08-27 22:42:30 +0000 | [diff] [blame] | 1026 | // Annotate function. |
Fariborz Jahanian | 7ca1d30 | 2013-08-27 23:56:54 +0000 | [diff] [blame] | 1027 | if (!ResultAnnotated) { |
Fariborz Jahanian | 9ef4a26 | 2013-08-19 19:13:34 +0000 | [diff] [blame] | 1028 | RetEffect Ret = CE.getReturnValue(); |
| 1029 | const char *AnnotationString = 0; |
Fariborz Jahanian | 1a26927 | 2013-09-04 22:49:19 +0000 | [diff] [blame] | 1030 | if (Ret.getObjKind() == RetEffect::CF) { |
| 1031 | if (Ret.isOwned() && |
| 1032 | Ctx.Idents.get("CF_RETURNS_RETAINED").hasMacroDefinition()) |
Fariborz Jahanian | 9ef4a26 | 2013-08-19 19:13:34 +0000 | [diff] [blame] | 1033 | AnnotationString = " CF_RETURNS_RETAINED"; |
Fariborz Jahanian | 1a26927 | 2013-09-04 22:49:19 +0000 | [diff] [blame] | 1034 | else if (Ret.notOwned() && |
| 1035 | Ctx.Idents.get("CF_RETURNS_NOT_RETAINED").hasMacroDefinition()) |
Fariborz Jahanian | 9ef4a26 | 2013-08-19 19:13:34 +0000 | [diff] [blame] | 1036 | AnnotationString = " CF_RETURNS_NOT_RETAINED"; |
| 1037 | } |
Fariborz Jahanian | 1a26927 | 2013-09-04 22:49:19 +0000 | [diff] [blame] | 1038 | else if (Ret.getObjKind() == RetEffect::ObjC) { |
| 1039 | if (Ret.isOwned() && |
| 1040 | Ctx.Idents.get("NS_RETURNS_RETAINED").hasMacroDefinition()) |
| 1041 | AnnotationString = " NS_RETURNS_RETAINED"; |
Fariborz Jahanian | 1a26927 | 2013-09-04 22:49:19 +0000 | [diff] [blame] | 1042 | } |
| 1043 | |
Fariborz Jahanian | 9ef4a26 | 2013-08-19 19:13:34 +0000 | [diff] [blame] | 1044 | if (AnnotationString) { |
| 1045 | edit::Commit commit(*Editor); |
| 1046 | commit.insertAfterToken(FuncDecl->getLocEnd(), AnnotationString); |
| 1047 | Editor->commit(commit); |
| 1048 | } |
Fariborz Jahanian | 84ac1de | 2013-08-15 21:44:38 +0000 | [diff] [blame] | 1049 | } |
Fariborz Jahanian | 9ef4a26 | 2013-08-19 19:13:34 +0000 | [diff] [blame] | 1050 | llvm::ArrayRef<ArgEffect> AEArgs = CE.getArgs(); |
| 1051 | unsigned i = 0; |
| 1052 | for (FunctionDecl::param_const_iterator pi = FuncDecl->param_begin(), |
| 1053 | pe = FuncDecl->param_end(); pi != pe; ++pi, ++i) { |
Fariborz Jahanian | b918d7a | 2013-08-21 19:37:47 +0000 | [diff] [blame] | 1054 | const ParmVarDecl *pd = *pi; |
Fariborz Jahanian | 9ef4a26 | 2013-08-19 19:13:34 +0000 | [diff] [blame] | 1055 | ArgEffect AE = AEArgs[i]; |
Fariborz Jahanian | 63ffce2 | 2013-08-27 22:42:30 +0000 | [diff] [blame] | 1056 | if (AE == DecRef && !pd->getAttr<CFConsumedAttr>() && |
| 1057 | Ctx.Idents.get("CF_CONSUMED").hasMacroDefinition()) { |
| 1058 | edit::Commit commit(*Editor); |
| 1059 | commit.insertBefore(pd->getLocation(), "CF_CONSUMED "); |
| 1060 | Editor->commit(commit); |
Fariborz Jahanian | 9427939 | 2013-08-20 18:54:39 +0000 | [diff] [blame] | 1061 | } |
Fariborz Jahanian | 1a26927 | 2013-09-04 22:49:19 +0000 | [diff] [blame] | 1062 | else if (AE == DecRefMsg && !pd->getAttr<NSConsumedAttr>() && |
| 1063 | Ctx.Idents.get("NS_CONSUMED").hasMacroDefinition()) { |
| 1064 | edit::Commit commit(*Editor); |
| 1065 | commit.insertBefore(pd->getLocation(), "NS_CONSUMED "); |
| 1066 | Editor->commit(commit); |
| 1067 | } |
Fariborz Jahanian | 84ac1de | 2013-08-15 21:44:38 +0000 | [diff] [blame] | 1068 | } |
Fariborz Jahanian | 63ffce2 | 2013-08-27 22:42:30 +0000 | [diff] [blame] | 1069 | } |
| 1070 | |
| 1071 | |
| 1072 | ObjCMigrateASTConsumer::CF_BRIDGING_KIND |
| 1073 | ObjCMigrateASTConsumer::migrateAddFunctionAnnotation( |
| 1074 | ASTContext &Ctx, |
| 1075 | const FunctionDecl *FuncDecl) { |
| 1076 | if (FuncDecl->hasBody()) |
| 1077 | return CF_BRIDGING_NONE; |
| 1078 | |
| 1079 | CallEffects CE = CallEffects::getEffect(FuncDecl); |
| 1080 | bool FuncIsReturnAnnotated = (FuncDecl->getAttr<CFReturnsRetainedAttr>() || |
Fariborz Jahanian | 1a26927 | 2013-09-04 22:49:19 +0000 | [diff] [blame] | 1081 | FuncDecl->getAttr<CFReturnsNotRetainedAttr>() || |
| 1082 | FuncDecl->getAttr<NSReturnsRetainedAttr>() || |
Fariborz Jahanian | c24879e | 2013-09-05 23:04:33 +0000 | [diff] [blame] | 1083 | FuncDecl->getAttr<NSReturnsNotRetainedAttr>() || |
| 1084 | FuncDecl->getAttr<NSReturnsAutoreleasedAttr>()); |
Fariborz Jahanian | 63ffce2 | 2013-08-27 22:42:30 +0000 | [diff] [blame] | 1085 | |
| 1086 | // Trivial case of when funciton is annotated and has no argument. |
| 1087 | if (FuncIsReturnAnnotated && FuncDecl->getNumParams() == 0) |
| 1088 | return CF_BRIDGING_NONE; |
| 1089 | |
| 1090 | bool ReturnCFAudited = false; |
| 1091 | if (!FuncIsReturnAnnotated) { |
| 1092 | RetEffect Ret = CE.getReturnValue(); |
| 1093 | if (Ret.getObjKind() == RetEffect::CF && |
Fariborz Jahanian | 89f6d10 | 2013-09-04 00:10:06 +0000 | [diff] [blame] | 1094 | (Ret.isOwned() || Ret.notOwned())) |
Fariborz Jahanian | 63ffce2 | 2013-08-27 22:42:30 +0000 | [diff] [blame] | 1095 | ReturnCFAudited = true; |
| 1096 | else if (!AuditedType(FuncDecl->getResultType())) |
| 1097 | return CF_BRIDGING_NONE; |
| 1098 | } |
| 1099 | |
| 1100 | // At this point result type is audited for potential inclusion. |
| 1101 | // Now, how about argument types. |
| 1102 | llvm::ArrayRef<ArgEffect> AEArgs = CE.getArgs(); |
| 1103 | unsigned i = 0; |
| 1104 | bool ArgCFAudited = false; |
| 1105 | for (FunctionDecl::param_const_iterator pi = FuncDecl->param_begin(), |
| 1106 | pe = FuncDecl->param_end(); pi != pe; ++pi, ++i) { |
| 1107 | const ParmVarDecl *pd = *pi; |
| 1108 | ArgEffect AE = AEArgs[i]; |
| 1109 | if (AE == DecRef /*CFConsumed annotated*/ || AE == IncRef) { |
| 1110 | if (AE == DecRef && !pd->getAttr<CFConsumedAttr>()) |
| 1111 | ArgCFAudited = true; |
| 1112 | else if (AE == IncRef) |
| 1113 | ArgCFAudited = true; |
| 1114 | } |
| 1115 | else { |
| 1116 | QualType AT = pd->getType(); |
| 1117 | if (!AuditedType(AT)) { |
Fariborz Jahanian | 7ca1d30 | 2013-08-27 23:56:54 +0000 | [diff] [blame] | 1118 | AddCFAnnotations(Ctx, CE, FuncDecl, FuncIsReturnAnnotated); |
Fariborz Jahanian | 63ffce2 | 2013-08-27 22:42:30 +0000 | [diff] [blame] | 1119 | return CF_BRIDGING_NONE; |
| 1120 | } |
| 1121 | } |
| 1122 | } |
| 1123 | if (ReturnCFAudited || ArgCFAudited) |
| 1124 | return CF_BRIDGING_ENABLE; |
| 1125 | |
| 1126 | return CF_BRIDGING_MAY_INCLUDE; |
Fariborz Jahanian | dfe6ed9 | 2013-08-12 23:17:13 +0000 | [diff] [blame] | 1127 | } |
| 1128 | |
Fariborz Jahanian | 926fafb | 2013-08-22 18:35:27 +0000 | [diff] [blame] | 1129 | void ObjCMigrateASTConsumer::migrateARCSafeAnnotation(ASTContext &Ctx, |
| 1130 | ObjCContainerDecl *CDecl) { |
Fariborz Jahanian | 75226d5 | 2013-09-17 21:56:04 +0000 | [diff] [blame] | 1131 | if (!isa<ObjCInterfaceDecl>(CDecl) || CDecl->isDeprecated()) |
Fariborz Jahanian | 926fafb | 2013-08-22 18:35:27 +0000 | [diff] [blame] | 1132 | return; |
| 1133 | |
| 1134 | // migrate methods which can have instancetype as their result type. |
| 1135 | for (ObjCContainerDecl::method_iterator M = CDecl->meth_begin(), |
| 1136 | MEnd = CDecl->meth_end(); |
| 1137 | M != MEnd; ++M) { |
| 1138 | ObjCMethodDecl *Method = (*M); |
Fariborz Jahanian | 4f64dd2 | 2013-08-22 21:40:15 +0000 | [diff] [blame] | 1139 | migrateCFAnnotation(Ctx, Method); |
Fariborz Jahanian | 926fafb | 2013-08-22 18:35:27 +0000 | [diff] [blame] | 1140 | } |
| 1141 | } |
| 1142 | |
Fariborz Jahanian | 63ffce2 | 2013-08-27 22:42:30 +0000 | [diff] [blame] | 1143 | void ObjCMigrateASTConsumer::AddCFAnnotations(ASTContext &Ctx, |
| 1144 | const CallEffects &CE, |
Fariborz Jahanian | 7ca1d30 | 2013-08-27 23:56:54 +0000 | [diff] [blame] | 1145 | const ObjCMethodDecl *MethodDecl, |
| 1146 | bool ResultAnnotated) { |
Fariborz Jahanian | 63ffce2 | 2013-08-27 22:42:30 +0000 | [diff] [blame] | 1147 | // Annotate function. |
Fariborz Jahanian | 7ca1d30 | 2013-08-27 23:56:54 +0000 | [diff] [blame] | 1148 | if (!ResultAnnotated) { |
Fariborz Jahanian | 926fafb | 2013-08-22 18:35:27 +0000 | [diff] [blame] | 1149 | RetEffect Ret = CE.getReturnValue(); |
| 1150 | const char *AnnotationString = 0; |
Fariborz Jahanian | 1a26927 | 2013-09-04 22:49:19 +0000 | [diff] [blame] | 1151 | if (Ret.getObjKind() == RetEffect::CF) { |
| 1152 | if (Ret.isOwned() && |
| 1153 | Ctx.Idents.get("CF_RETURNS_RETAINED").hasMacroDefinition()) |
Fariborz Jahanian | 926fafb | 2013-08-22 18:35:27 +0000 | [diff] [blame] | 1154 | AnnotationString = " CF_RETURNS_RETAINED"; |
Fariborz Jahanian | 1a26927 | 2013-09-04 22:49:19 +0000 | [diff] [blame] | 1155 | else if (Ret.notOwned() && |
| 1156 | Ctx.Idents.get("CF_RETURNS_NOT_RETAINED").hasMacroDefinition()) |
Fariborz Jahanian | 926fafb | 2013-08-22 18:35:27 +0000 | [diff] [blame] | 1157 | AnnotationString = " CF_RETURNS_NOT_RETAINED"; |
| 1158 | } |
Fariborz Jahanian | 1a26927 | 2013-09-04 22:49:19 +0000 | [diff] [blame] | 1159 | else if (Ret.getObjKind() == RetEffect::ObjC) { |
Fariborz Jahanian | c24879e | 2013-09-05 23:04:33 +0000 | [diff] [blame] | 1160 | ObjCMethodFamily OMF = MethodDecl->getMethodFamily(); |
| 1161 | switch (OMF) { |
| 1162 | case clang::OMF_alloc: |
| 1163 | case clang::OMF_new: |
| 1164 | case clang::OMF_copy: |
| 1165 | case clang::OMF_init: |
| 1166 | case clang::OMF_mutableCopy: |
| 1167 | break; |
| 1168 | |
| 1169 | default: |
| 1170 | if (Ret.isOwned() && |
| 1171 | Ctx.Idents.get("NS_RETURNS_RETAINED").hasMacroDefinition()) |
| 1172 | AnnotationString = " NS_RETURNS_RETAINED"; |
Fariborz Jahanian | c24879e | 2013-09-05 23:04:33 +0000 | [diff] [blame] | 1173 | break; |
| 1174 | } |
Fariborz Jahanian | 1a26927 | 2013-09-04 22:49:19 +0000 | [diff] [blame] | 1175 | } |
| 1176 | |
Fariborz Jahanian | 926fafb | 2013-08-22 18:35:27 +0000 | [diff] [blame] | 1177 | if (AnnotationString) { |
| 1178 | edit::Commit commit(*Editor); |
| 1179 | commit.insertBefore(MethodDecl->getLocEnd(), AnnotationString); |
| 1180 | Editor->commit(commit); |
Fariborz Jahanian | 926fafb | 2013-08-22 18:35:27 +0000 | [diff] [blame] | 1181 | } |
Fariborz Jahanian | 926fafb | 2013-08-22 18:35:27 +0000 | [diff] [blame] | 1182 | } |
Fariborz Jahanian | 926fafb | 2013-08-22 18:35:27 +0000 | [diff] [blame] | 1183 | llvm::ArrayRef<ArgEffect> AEArgs = CE.getArgs(); |
| 1184 | unsigned i = 0; |
| 1185 | for (ObjCMethodDecl::param_const_iterator pi = MethodDecl->param_begin(), |
| 1186 | pe = MethodDecl->param_end(); pi != pe; ++pi, ++i) { |
| 1187 | const ParmVarDecl *pd = *pi; |
| 1188 | ArgEffect AE = AEArgs[i]; |
Fariborz Jahanian | 63ffce2 | 2013-08-27 22:42:30 +0000 | [diff] [blame] | 1189 | if (AE == DecRef && !pd->getAttr<CFConsumedAttr>() && |
| 1190 | Ctx.Idents.get("CF_CONSUMED").hasMacroDefinition()) { |
| 1191 | edit::Commit commit(*Editor); |
| 1192 | commit.insertBefore(pd->getLocation(), "CF_CONSUMED "); |
| 1193 | Editor->commit(commit); |
Fariborz Jahanian | 926fafb | 2013-08-22 18:35:27 +0000 | [diff] [blame] | 1194 | } |
Fariborz Jahanian | 926fafb | 2013-08-22 18:35:27 +0000 | [diff] [blame] | 1195 | } |
Fariborz Jahanian | 63ffce2 | 2013-08-27 22:42:30 +0000 | [diff] [blame] | 1196 | } |
| 1197 | |
Fariborz Jahanian | 89f6d10 | 2013-09-04 00:10:06 +0000 | [diff] [blame] | 1198 | void ObjCMigrateASTConsumer::migrateAddMethodAnnotation( |
Fariborz Jahanian | 63ffce2 | 2013-08-27 22:42:30 +0000 | [diff] [blame] | 1199 | ASTContext &Ctx, |
| 1200 | const ObjCMethodDecl *MethodDecl) { |
Fariborz Jahanian | 1a26927 | 2013-09-04 22:49:19 +0000 | [diff] [blame] | 1201 | if (MethodDecl->hasBody() || MethodDecl->isImplicit()) |
Fariborz Jahanian | 89f6d10 | 2013-09-04 00:10:06 +0000 | [diff] [blame] | 1202 | return; |
Fariborz Jahanian | 63ffce2 | 2013-08-27 22:42:30 +0000 | [diff] [blame] | 1203 | |
| 1204 | CallEffects CE = CallEffects::getEffect(MethodDecl); |
| 1205 | bool MethodIsReturnAnnotated = (MethodDecl->getAttr<CFReturnsRetainedAttr>() || |
Fariborz Jahanian | 1a26927 | 2013-09-04 22:49:19 +0000 | [diff] [blame] | 1206 | MethodDecl->getAttr<CFReturnsNotRetainedAttr>() || |
| 1207 | MethodDecl->getAttr<NSReturnsRetainedAttr>() || |
Fariborz Jahanian | c24879e | 2013-09-05 23:04:33 +0000 | [diff] [blame] | 1208 | MethodDecl->getAttr<NSReturnsNotRetainedAttr>() || |
| 1209 | MethodDecl->getAttr<NSReturnsAutoreleasedAttr>()); |
| 1210 | |
| 1211 | if (CE.getReceiver() == DecRefMsg && |
| 1212 | !MethodDecl->getAttr<NSConsumesSelfAttr>() && |
| 1213 | MethodDecl->getMethodFamily() != OMF_init && |
| 1214 | MethodDecl->getMethodFamily() != OMF_release && |
| 1215 | Ctx.Idents.get("NS_CONSUMES_SELF").hasMacroDefinition()) { |
| 1216 | edit::Commit commit(*Editor); |
| 1217 | commit.insertBefore(MethodDecl->getLocEnd(), " NS_CONSUMES_SELF"); |
| 1218 | Editor->commit(commit); |
| 1219 | } |
Fariborz Jahanian | 63ffce2 | 2013-08-27 22:42:30 +0000 | [diff] [blame] | 1220 | |
| 1221 | // Trivial case of when funciton is annotated and has no argument. |
| 1222 | if (MethodIsReturnAnnotated && |
| 1223 | (MethodDecl->param_begin() == MethodDecl->param_end())) |
Fariborz Jahanian | 89f6d10 | 2013-09-04 00:10:06 +0000 | [diff] [blame] | 1224 | return; |
Fariborz Jahanian | 63ffce2 | 2013-08-27 22:42:30 +0000 | [diff] [blame] | 1225 | |
Fariborz Jahanian | 63ffce2 | 2013-08-27 22:42:30 +0000 | [diff] [blame] | 1226 | if (!MethodIsReturnAnnotated) { |
| 1227 | RetEffect Ret = CE.getReturnValue(); |
Fariborz Jahanian | 1a26927 | 2013-09-04 22:49:19 +0000 | [diff] [blame] | 1228 | if ((Ret.getObjKind() == RetEffect::CF || |
| 1229 | Ret.getObjKind() == RetEffect::ObjC) && |
| 1230 | (Ret.isOwned() || Ret.notOwned())) { |
Fariborz Jahanian | 8b10230 | 2013-09-04 16:43:57 +0000 | [diff] [blame] | 1231 | AddCFAnnotations(Ctx, CE, MethodDecl, false); |
| 1232 | return; |
| 1233 | } |
Fariborz Jahanian | 63ffce2 | 2013-08-27 22:42:30 +0000 | [diff] [blame] | 1234 | else if (!AuditedType(MethodDecl->getResultType())) |
Fariborz Jahanian | 89f6d10 | 2013-09-04 00:10:06 +0000 | [diff] [blame] | 1235 | return; |
Fariborz Jahanian | 63ffce2 | 2013-08-27 22:42:30 +0000 | [diff] [blame] | 1236 | } |
| 1237 | |
| 1238 | // At this point result type is either annotated or audited. |
| 1239 | // Now, how about argument types. |
| 1240 | llvm::ArrayRef<ArgEffect> AEArgs = CE.getArgs(); |
| 1241 | unsigned i = 0; |
Fariborz Jahanian | 63ffce2 | 2013-08-27 22:42:30 +0000 | [diff] [blame] | 1242 | for (ObjCMethodDecl::param_const_iterator pi = MethodDecl->param_begin(), |
| 1243 | pe = MethodDecl->param_end(); pi != pe; ++pi, ++i) { |
| 1244 | const ParmVarDecl *pd = *pi; |
| 1245 | ArgEffect AE = AEArgs[i]; |
Fariborz Jahanian | 8b10230 | 2013-09-04 16:43:57 +0000 | [diff] [blame] | 1246 | if ((AE == DecRef && !pd->getAttr<CFConsumedAttr>()) || AE == IncRef || |
| 1247 | !AuditedType(pd->getType())) { |
| 1248 | AddCFAnnotations(Ctx, CE, MethodDecl, MethodIsReturnAnnotated); |
| 1249 | return; |
Fariborz Jahanian | 63ffce2 | 2013-08-27 22:42:30 +0000 | [diff] [blame] | 1250 | } |
| 1251 | } |
Fariborz Jahanian | 89f6d10 | 2013-09-04 00:10:06 +0000 | [diff] [blame] | 1252 | return; |
Fariborz Jahanian | dfe6ed9 | 2013-08-12 23:17:13 +0000 | [diff] [blame] | 1253 | } |
| 1254 | |
Ted Kremenek | f7639e1 | 2012-03-06 20:06:33 +0000 | [diff] [blame] | 1255 | namespace { |
| 1256 | |
| 1257 | class RewritesReceiver : public edit::EditsReceiver { |
| 1258 | Rewriter &Rewrite; |
| 1259 | |
| 1260 | public: |
| 1261 | RewritesReceiver(Rewriter &Rewrite) : Rewrite(Rewrite) { } |
| 1262 | |
| 1263 | virtual void insert(SourceLocation loc, StringRef text) { |
| 1264 | Rewrite.InsertText(loc, text); |
| 1265 | } |
| 1266 | virtual void replace(CharSourceRange range, StringRef text) { |
| 1267 | Rewrite.ReplaceText(range.getBegin(), Rewrite.getRangeSize(range), text); |
| 1268 | } |
| 1269 | }; |
| 1270 | |
| 1271 | } |
| 1272 | |
| 1273 | void ObjCMigrateASTConsumer::HandleTranslationUnit(ASTContext &Ctx) { |
Fariborz Jahanian | a7437f0 | 2013-07-03 23:05:00 +0000 | [diff] [blame] | 1274 | |
| 1275 | TranslationUnitDecl *TU = Ctx.getTranslationUnitDecl(); |
Fariborz Jahanian | 301b521 | 2013-08-20 22:42:13 +0000 | [diff] [blame] | 1276 | if (MigrateProperty) { |
Fariborz Jahanian | d83ef84 | 2013-07-09 16:59:14 +0000 | [diff] [blame] | 1277 | for (DeclContext::decl_iterator D = TU->decls_begin(), DEnd = TU->decls_end(); |
| 1278 | D != DEnd; ++D) { |
Fariborz Jahanian | b834352 | 2013-08-20 23:35:26 +0000 | [diff] [blame] | 1279 | if (unsigned FID = |
| 1280 | PP.getSourceManager().getFileID((*D)->getLocation()).getHashValue()) |
Fariborz Jahanian | 75226d5 | 2013-09-17 21:56:04 +0000 | [diff] [blame] | 1281 | if (FileId && FileId != FID) |
Fariborz Jahanian | b834352 | 2013-08-20 23:35:26 +0000 | [diff] [blame] | 1282 | AnnotateImplicitBridging(Ctx); |
Fariborz Jahanian | b834352 | 2013-08-20 23:35:26 +0000 | [diff] [blame] | 1283 | |
Fariborz Jahanian | d83ef84 | 2013-07-09 16:59:14 +0000 | [diff] [blame] | 1284 | if (ObjCInterfaceDecl *CDecl = dyn_cast<ObjCInterfaceDecl>(*D)) |
| 1285 | migrateObjCInterfaceDecl(Ctx, CDecl); |
Fariborz Jahanian | 92f7242 | 2013-09-17 19:00:30 +0000 | [diff] [blame] | 1286 | if (ObjCCategoryDecl *CatDecl = dyn_cast<ObjCCategoryDecl>(*D)) |
| 1287 | migrateObjCInterfaceDecl(Ctx, CatDecl); |
Fariborz Jahanian | 1be0153 | 2013-07-12 22:32:19 +0000 | [diff] [blame] | 1288 | else if (ObjCProtocolDecl *PDecl = dyn_cast<ObjCProtocolDecl>(*D)) |
| 1289 | ObjCProtocolDecls.insert(PDecl); |
| 1290 | else if (const ObjCImplementationDecl *ImpDecl = |
| 1291 | dyn_cast<ObjCImplementationDecl>(*D)) |
| 1292 | migrateProtocolConformance(Ctx, ImpDecl); |
Fariborz Jahanian | 9246327 | 2013-07-18 20:11:45 +0000 | [diff] [blame] | 1293 | else if (const EnumDecl *ED = dyn_cast<EnumDecl>(*D)) { |
| 1294 | DeclContext::decl_iterator N = D; |
| 1295 | ++N; |
Fariborz Jahanian | 008ef72 | 2013-07-19 17:44:32 +0000 | [diff] [blame] | 1296 | if (N != DEnd) |
| 1297 | if (const TypedefDecl *TD = dyn_cast<TypedefDecl>(*N)) |
| 1298 | migrateNSEnumDecl(Ctx, ED, TD); |
Fariborz Jahanian | 9246327 | 2013-07-18 20:11:45 +0000 | [diff] [blame] | 1299 | } |
Fariborz Jahanian | c13c1b0 | 2013-08-13 18:01:42 +0000 | [diff] [blame] | 1300 | else if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(*D)) |
Fariborz Jahanian | 4f64dd2 | 2013-08-22 21:40:15 +0000 | [diff] [blame] | 1301 | migrateCFAnnotation(Ctx, FD); |
Fariborz Jahanian | c13c1b0 | 2013-08-13 18:01:42 +0000 | [diff] [blame] | 1302 | |
Fariborz Jahanian | 926fafb | 2013-08-22 18:35:27 +0000 | [diff] [blame] | 1303 | if (ObjCContainerDecl *CDecl = dyn_cast<ObjCContainerDecl>(*D)) { |
| 1304 | // migrate methods which can have instancetype as their result type. |
Fariborz Jahanian | d0fbf6c | 2013-08-30 23:52:08 +0000 | [diff] [blame] | 1305 | migrateMethods(Ctx, CDecl); |
Fariborz Jahanian | 926fafb | 2013-08-22 18:35:27 +0000 | [diff] [blame] | 1306 | // annotate methods with CF annotations. |
| 1307 | migrateARCSafeAnnotation(Ctx, CDecl); |
| 1308 | } |
Fariborz Jahanian | d83ef84 | 2013-07-09 16:59:14 +0000 | [diff] [blame] | 1309 | } |
Fariborz Jahanian | 926fafb | 2013-08-22 18:35:27 +0000 | [diff] [blame] | 1310 | AnnotateImplicitBridging(Ctx); |
Fariborz Jahanian | 301b521 | 2013-08-20 22:42:13 +0000 | [diff] [blame] | 1311 | } |
Fariborz Jahanian | a7437f0 | 2013-07-03 23:05:00 +0000 | [diff] [blame] | 1312 | |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 1313 | Rewriter rewriter(Ctx.getSourceManager(), Ctx.getLangOpts()); |
Ted Kremenek | f7639e1 | 2012-03-06 20:06:33 +0000 | [diff] [blame] | 1314 | RewritesReceiver Rec(rewriter); |
| 1315 | Editor->applyRewrites(Rec); |
| 1316 | |
| 1317 | for (Rewriter::buffer_iterator |
| 1318 | I = rewriter.buffer_begin(), E = rewriter.buffer_end(); I != E; ++I) { |
| 1319 | FileID FID = I->first; |
| 1320 | RewriteBuffer &buf = I->second; |
| 1321 | const FileEntry *file = Ctx.getSourceManager().getFileEntryForID(FID); |
| 1322 | assert(file); |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 1323 | SmallString<512> newText; |
Ted Kremenek | f7639e1 | 2012-03-06 20:06:33 +0000 | [diff] [blame] | 1324 | llvm::raw_svector_ostream vecOS(newText); |
| 1325 | buf.write(vecOS); |
| 1326 | vecOS.flush(); |
| 1327 | llvm::MemoryBuffer *memBuf = llvm::MemoryBuffer::getMemBufferCopy( |
| 1328 | StringRef(newText.data(), newText.size()), file->getName()); |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 1329 | SmallString<64> filePath(file->getName()); |
Ted Kremenek | f7639e1 | 2012-03-06 20:06:33 +0000 | [diff] [blame] | 1330 | FileMgr.FixupRelativePath(filePath); |
| 1331 | Remapper.remap(filePath.str(), memBuf); |
| 1332 | } |
| 1333 | |
| 1334 | if (IsOutputFile) { |
| 1335 | Remapper.flushToFile(MigrateDir, Ctx.getDiagnostics()); |
| 1336 | } else { |
| 1337 | Remapper.flushToDisk(MigrateDir, Ctx.getDiagnostics()); |
| 1338 | } |
| 1339 | } |
| 1340 | |
| 1341 | bool MigrateSourceAction::BeginInvocation(CompilerInstance &CI) { |
Argyrios Kyrtzidis | b482260 | 2012-05-24 16:48:23 +0000 | [diff] [blame] | 1342 | CI.getDiagnostics().setIgnoreAllWarnings(true); |
Ted Kremenek | f7639e1 | 2012-03-06 20:06:33 +0000 | [diff] [blame] | 1343 | return true; |
| 1344 | } |
| 1345 | |
| 1346 | ASTConsumer *MigrateSourceAction::CreateASTConsumer(CompilerInstance &CI, |
| 1347 | StringRef InFile) { |
Argyrios Kyrtzidis | f3d587e | 2012-12-04 07:27:05 +0000 | [diff] [blame] | 1348 | PPConditionalDirectiveRecord * |
| 1349 | PPRec = new PPConditionalDirectiveRecord(CI.getSourceManager()); |
| 1350 | CI.getPreprocessor().addPPCallbacks(PPRec); |
Ted Kremenek | f7639e1 | 2012-03-06 20:06:33 +0000 | [diff] [blame] | 1351 | return new ObjCMigrateASTConsumer(CI.getFrontendOpts().OutputFile, |
| 1352 | /*MigrateLiterals=*/true, |
| 1353 | /*MigrateSubscripting=*/true, |
Fariborz Jahanian | d83ef84 | 2013-07-09 16:59:14 +0000 | [diff] [blame] | 1354 | /*MigrateProperty*/true, |
Fariborz Jahanian | 55d6e6c | 2013-08-28 23:22:46 +0000 | [diff] [blame] | 1355 | /*MigrateReadonlyProperty*/true, |
Ted Kremenek | f7639e1 | 2012-03-06 20:06:33 +0000 | [diff] [blame] | 1356 | Remapper, |
| 1357 | CI.getFileManager(), |
Argyrios Kyrtzidis | f3d587e | 2012-12-04 07:27:05 +0000 | [diff] [blame] | 1358 | PPRec, |
Fariborz Jahanian | a7437f0 | 2013-07-03 23:05:00 +0000 | [diff] [blame] | 1359 | CI.getPreprocessor(), |
Ted Kremenek | f7639e1 | 2012-03-06 20:06:33 +0000 | [diff] [blame] | 1360 | /*isOutputFile=*/true); |
| 1361 | } |