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 | dfe6ed9 | 2013-08-12 23:17:13 +0000 | [diff] [blame] | 27 | #include "clang/AST/Attr.h" |
Ted Kremenek | f7639e1 | 2012-03-06 20:06:33 +0000 | [diff] [blame] | 28 | #include "llvm/ADT/SmallString.h" |
| 29 | |
| 30 | using namespace clang; |
| 31 | using namespace arcmt; |
| 32 | |
| 33 | namespace { |
| 34 | |
| 35 | class ObjCMigrateASTConsumer : public ASTConsumer { |
| 36 | void migrateDecl(Decl *D); |
Fariborz Jahanian | a7437f0 | 2013-07-03 23:05:00 +0000 | [diff] [blame] | 37 | void migrateObjCInterfaceDecl(ASTContext &Ctx, ObjCInterfaceDecl *D); |
Fariborz Jahanian | 1be0153 | 2013-07-12 22:32:19 +0000 | [diff] [blame] | 38 | void migrateProtocolConformance(ASTContext &Ctx, |
| 39 | const ObjCImplementationDecl *ImpDecl); |
Fariborz Jahanian | 9246327 | 2013-07-18 20:11:45 +0000 | [diff] [blame] | 40 | void migrateNSEnumDecl(ASTContext &Ctx, const EnumDecl *EnumDcl, |
| 41 | const TypedefDecl *TypedefDcl); |
Fariborz Jahanian | 7122135 | 2013-07-23 22:42:28 +0000 | [diff] [blame] | 42 | void migrateInstanceType(ASTContext &Ctx, ObjCContainerDecl *CDecl); |
Fariborz Jahanian | 670ef26 | 2013-07-23 23:34:42 +0000 | [diff] [blame] | 43 | void migrateMethodInstanceType(ASTContext &Ctx, ObjCContainerDecl *CDecl, |
| 44 | ObjCMethodDecl *OM); |
Fariborz Jahanian | c429185 | 2013-08-02 18:00:53 +0000 | [diff] [blame] | 45 | void migrateFactoryMethod(ASTContext &Ctx, ObjCContainerDecl *CDecl, |
Fariborz Jahanian | 9275c68 | 2013-08-02 20:54:18 +0000 | [diff] [blame] | 46 | ObjCMethodDecl *OM, |
| 47 | ObjCInstanceTypeFamily OIT_Family = OIT_None); |
Fariborz Jahanian | dfe6ed9 | 2013-08-12 23:17:13 +0000 | [diff] [blame] | 48 | |
Fariborz Jahanian | c13c1b0 | 2013-08-13 18:01:42 +0000 | [diff] [blame] | 49 | void migrateFunctionDeclAnnotation(ASTContext &Ctx, |
| 50 | const FunctionDecl *FuncDecl); |
Fariborz Jahanian | dfe6ed9 | 2013-08-12 23:17:13 +0000 | [diff] [blame] | 51 | |
Fariborz Jahanian | c13c1b0 | 2013-08-13 18:01:42 +0000 | [diff] [blame] | 52 | void migrateObjCMethodDeclAnnotation(ASTContext &Ctx, |
| 53 | const ObjCMethodDecl *MethodDecl); |
Ted Kremenek | f7639e1 | 2012-03-06 20:06:33 +0000 | [diff] [blame] | 54 | public: |
| 55 | std::string MigrateDir; |
| 56 | bool MigrateLiterals; |
| 57 | bool MigrateSubscripting; |
Fariborz Jahanian | d83ef84 | 2013-07-09 16:59:14 +0000 | [diff] [blame] | 58 | bool MigrateProperty; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 59 | OwningPtr<NSAPI> NSAPIObj; |
| 60 | OwningPtr<edit::EditedSource> Editor; |
Ted Kremenek | f7639e1 | 2012-03-06 20:06:33 +0000 | [diff] [blame] | 61 | FileRemapper &Remapper; |
| 62 | FileManager &FileMgr; |
Argyrios Kyrtzidis | f3d587e | 2012-12-04 07:27:05 +0000 | [diff] [blame] | 63 | const PPConditionalDirectiveRecord *PPRec; |
Fariborz Jahanian | a7437f0 | 2013-07-03 23:05:00 +0000 | [diff] [blame] | 64 | Preprocessor &PP; |
Ted Kremenek | f7639e1 | 2012-03-06 20:06:33 +0000 | [diff] [blame] | 65 | bool IsOutputFile; |
Fariborz Jahanian | 1be0153 | 2013-07-12 22:32:19 +0000 | [diff] [blame] | 66 | llvm::SmallPtrSet<ObjCProtocolDecl *, 32> ObjCProtocolDecls; |
| 67 | |
Ted Kremenek | f7639e1 | 2012-03-06 20:06:33 +0000 | [diff] [blame] | 68 | ObjCMigrateASTConsumer(StringRef migrateDir, |
| 69 | bool migrateLiterals, |
| 70 | bool migrateSubscripting, |
Fariborz Jahanian | d83ef84 | 2013-07-09 16:59:14 +0000 | [diff] [blame] | 71 | bool migrateProperty, |
Ted Kremenek | f7639e1 | 2012-03-06 20:06:33 +0000 | [diff] [blame] | 72 | FileRemapper &remapper, |
| 73 | FileManager &fileMgr, |
Argyrios Kyrtzidis | f3d587e | 2012-12-04 07:27:05 +0000 | [diff] [blame] | 74 | const PPConditionalDirectiveRecord *PPRec, |
Fariborz Jahanian | a7437f0 | 2013-07-03 23:05:00 +0000 | [diff] [blame] | 75 | Preprocessor &PP, |
Ted Kremenek | f7639e1 | 2012-03-06 20:06:33 +0000 | [diff] [blame] | 76 | bool isOutputFile = false) |
| 77 | : MigrateDir(migrateDir), |
| 78 | MigrateLiterals(migrateLiterals), |
| 79 | MigrateSubscripting(migrateSubscripting), |
Fariborz Jahanian | d83ef84 | 2013-07-09 16:59:14 +0000 | [diff] [blame] | 80 | MigrateProperty(migrateProperty), |
Fariborz Jahanian | a7437f0 | 2013-07-03 23:05:00 +0000 | [diff] [blame] | 81 | Remapper(remapper), FileMgr(fileMgr), PPRec(PPRec), PP(PP), |
Ted Kremenek | f7639e1 | 2012-03-06 20:06:33 +0000 | [diff] [blame] | 82 | IsOutputFile(isOutputFile) { } |
| 83 | |
| 84 | protected: |
| 85 | virtual void Initialize(ASTContext &Context) { |
| 86 | NSAPIObj.reset(new NSAPI(Context)); |
| 87 | Editor.reset(new edit::EditedSource(Context.getSourceManager(), |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 88 | Context.getLangOpts(), |
Ted Kremenek | f7639e1 | 2012-03-06 20:06:33 +0000 | [diff] [blame] | 89 | PPRec)); |
| 90 | } |
| 91 | |
| 92 | virtual bool HandleTopLevelDecl(DeclGroupRef DG) { |
| 93 | for (DeclGroupRef::iterator I = DG.begin(), E = DG.end(); I != E; ++I) |
| 94 | migrateDecl(*I); |
| 95 | return true; |
| 96 | } |
| 97 | virtual void HandleInterestingDecl(DeclGroupRef DG) { |
| 98 | // Ignore decls from the PCH. |
| 99 | } |
| 100 | virtual void HandleTopLevelDeclInObjCContainer(DeclGroupRef DG) { |
| 101 | ObjCMigrateASTConsumer::HandleTopLevelDecl(DG); |
| 102 | } |
| 103 | |
| 104 | virtual void HandleTranslationUnit(ASTContext &Ctx); |
| 105 | }; |
| 106 | |
| 107 | } |
| 108 | |
| 109 | ObjCMigrateAction::ObjCMigrateAction(FrontendAction *WrappedAction, |
| 110 | StringRef migrateDir, |
| 111 | bool migrateLiterals, |
Fariborz Jahanian | d83ef84 | 2013-07-09 16:59:14 +0000 | [diff] [blame] | 112 | bool migrateSubscripting, |
| 113 | bool migrateProperty) |
Ted Kremenek | f7639e1 | 2012-03-06 20:06:33 +0000 | [diff] [blame] | 114 | : WrapperFrontendAction(WrappedAction), MigrateDir(migrateDir), |
| 115 | MigrateLiterals(migrateLiterals), MigrateSubscripting(migrateSubscripting), |
Fariborz Jahanian | d83ef84 | 2013-07-09 16:59:14 +0000 | [diff] [blame] | 116 | MigrateProperty(migrateProperty), |
Ted Kremenek | f7639e1 | 2012-03-06 20:06:33 +0000 | [diff] [blame] | 117 | CompInst(0) { |
| 118 | if (MigrateDir.empty()) |
| 119 | MigrateDir = "."; // user current directory if none is given. |
| 120 | } |
| 121 | |
| 122 | ASTConsumer *ObjCMigrateAction::CreateASTConsumer(CompilerInstance &CI, |
| 123 | StringRef InFile) { |
Argyrios Kyrtzidis | f3d587e | 2012-12-04 07:27:05 +0000 | [diff] [blame] | 124 | PPConditionalDirectiveRecord * |
| 125 | PPRec = new PPConditionalDirectiveRecord(CompInst->getSourceManager()); |
| 126 | CompInst->getPreprocessor().addPPCallbacks(PPRec); |
Ted Kremenek | f7639e1 | 2012-03-06 20:06:33 +0000 | [diff] [blame] | 127 | ASTConsumer * |
| 128 | WrappedConsumer = WrapperFrontendAction::CreateASTConsumer(CI, InFile); |
| 129 | ASTConsumer *MTConsumer = new ObjCMigrateASTConsumer(MigrateDir, |
| 130 | MigrateLiterals, |
| 131 | MigrateSubscripting, |
Fariborz Jahanian | d83ef84 | 2013-07-09 16:59:14 +0000 | [diff] [blame] | 132 | MigrateProperty, |
Ted Kremenek | f7639e1 | 2012-03-06 20:06:33 +0000 | [diff] [blame] | 133 | Remapper, |
| 134 | CompInst->getFileManager(), |
Fariborz Jahanian | a7437f0 | 2013-07-03 23:05:00 +0000 | [diff] [blame] | 135 | PPRec, |
| 136 | CompInst->getPreprocessor()); |
Ted Kremenek | f7639e1 | 2012-03-06 20:06:33 +0000 | [diff] [blame] | 137 | ASTConsumer *Consumers[] = { MTConsumer, WrappedConsumer }; |
| 138 | return new MultiplexConsumer(Consumers); |
| 139 | } |
| 140 | |
| 141 | bool ObjCMigrateAction::BeginInvocation(CompilerInstance &CI) { |
| 142 | Remapper.initFromDisk(MigrateDir, CI.getDiagnostics(), |
| 143 | /*ignoreIfFilesChanges=*/true); |
| 144 | CompInst = &CI; |
| 145 | CI.getDiagnostics().setIgnoreAllWarnings(true); |
Ted Kremenek | f7639e1 | 2012-03-06 20:06:33 +0000 | [diff] [blame] | 146 | return true; |
| 147 | } |
| 148 | |
| 149 | namespace { |
| 150 | class ObjCMigrator : public RecursiveASTVisitor<ObjCMigrator> { |
| 151 | ObjCMigrateASTConsumer &Consumer; |
Argyrios Kyrtzidis | 6b4f341 | 2013-01-16 23:54:48 +0000 | [diff] [blame] | 152 | ParentMap &PMap; |
Ted Kremenek | f7639e1 | 2012-03-06 20:06:33 +0000 | [diff] [blame] | 153 | |
| 154 | public: |
Argyrios Kyrtzidis | 6b4f341 | 2013-01-16 23:54:48 +0000 | [diff] [blame] | 155 | ObjCMigrator(ObjCMigrateASTConsumer &consumer, ParentMap &PMap) |
| 156 | : Consumer(consumer), PMap(PMap) { } |
Ted Kremenek | f7639e1 | 2012-03-06 20:06:33 +0000 | [diff] [blame] | 157 | |
| 158 | bool shouldVisitTemplateInstantiations() const { return false; } |
| 159 | bool shouldWalkTypesOfTypeLocs() const { return false; } |
| 160 | |
| 161 | bool VisitObjCMessageExpr(ObjCMessageExpr *E) { |
| 162 | if (Consumer.MigrateLiterals) { |
| 163 | edit::Commit commit(*Consumer.Editor); |
Argyrios Kyrtzidis | 6b4f341 | 2013-01-16 23:54:48 +0000 | [diff] [blame] | 164 | edit::rewriteToObjCLiteralSyntax(E, *Consumer.NSAPIObj, commit, &PMap); |
Ted Kremenek | f7639e1 | 2012-03-06 20:06:33 +0000 | [diff] [blame] | 165 | Consumer.Editor->commit(commit); |
| 166 | } |
| 167 | |
| 168 | if (Consumer.MigrateSubscripting) { |
| 169 | edit::Commit commit(*Consumer.Editor); |
| 170 | edit::rewriteToObjCSubscriptSyntax(E, *Consumer.NSAPIObj, commit); |
| 171 | Consumer.Editor->commit(commit); |
| 172 | } |
| 173 | |
| 174 | return true; |
| 175 | } |
| 176 | |
| 177 | bool TraverseObjCMessageExpr(ObjCMessageExpr *E) { |
| 178 | // Do depth first; we want to rewrite the subexpressions first so that if |
| 179 | // we have to move expressions we will move them already rewritten. |
| 180 | for (Stmt::child_range range = E->children(); range; ++range) |
| 181 | if (!TraverseStmt(*range)) |
| 182 | return false; |
| 183 | |
| 184 | return WalkUpFromObjCMessageExpr(E); |
| 185 | } |
| 186 | }; |
Argyrios Kyrtzidis | 6b4f341 | 2013-01-16 23:54:48 +0000 | [diff] [blame] | 187 | |
| 188 | class BodyMigrator : public RecursiveASTVisitor<BodyMigrator> { |
| 189 | ObjCMigrateASTConsumer &Consumer; |
| 190 | OwningPtr<ParentMap> PMap; |
| 191 | |
| 192 | public: |
| 193 | BodyMigrator(ObjCMigrateASTConsumer &consumer) : Consumer(consumer) { } |
| 194 | |
| 195 | bool shouldVisitTemplateInstantiations() const { return false; } |
| 196 | bool shouldWalkTypesOfTypeLocs() const { return false; } |
| 197 | |
| 198 | bool TraverseStmt(Stmt *S) { |
| 199 | PMap.reset(new ParentMap(S)); |
| 200 | ObjCMigrator(Consumer, *PMap).TraverseStmt(S); |
| 201 | return true; |
| 202 | } |
| 203 | }; |
Ted Kremenek | f7639e1 | 2012-03-06 20:06:33 +0000 | [diff] [blame] | 204 | } |
| 205 | |
| 206 | void ObjCMigrateASTConsumer::migrateDecl(Decl *D) { |
| 207 | if (!D) |
| 208 | return; |
| 209 | if (isa<ObjCMethodDecl>(D)) |
| 210 | return; // Wait for the ObjC container declaration. |
| 211 | |
Argyrios Kyrtzidis | 6b4f341 | 2013-01-16 23:54:48 +0000 | [diff] [blame] | 212 | BodyMigrator(*this).TraverseDecl(D); |
Ted Kremenek | f7639e1 | 2012-03-06 20:06:33 +0000 | [diff] [blame] | 213 | } |
| 214 | |
Fariborz Jahanian | cf2ff9b | 2013-08-08 20:51:58 +0000 | [diff] [blame] | 215 | static void append_attr(std::string &PropertyString, const char *attr, |
| 216 | bool GetterHasIsPrefix) { |
| 217 | PropertyString += (GetterHasIsPrefix ? ", " : "("); |
| 218 | PropertyString += attr; |
| 219 | PropertyString += ')'; |
| 220 | } |
| 221 | |
Fariborz Jahanian | 85e988b | 2013-07-18 22:17:33 +0000 | [diff] [blame] | 222 | static bool rewriteToObjCProperty(const ObjCMethodDecl *Getter, |
| 223 | const ObjCMethodDecl *Setter, |
Fariborz Jahanian | cf2ff9b | 2013-08-08 20:51:58 +0000 | [diff] [blame] | 224 | const NSAPI &NS, edit::Commit &commit, |
| 225 | bool GetterHasIsPrefix) { |
Fariborz Jahanian | 85e988b | 2013-07-18 22:17:33 +0000 | [diff] [blame] | 226 | ASTContext &Context = NS.getASTContext(); |
| 227 | std::string PropertyString = "@property"; |
Fariborz Jahanian | cf387c6 | 2013-08-06 18:06:23 +0000 | [diff] [blame] | 228 | std::string PropertyNameString = Getter->getNameAsString(); |
| 229 | StringRef PropertyName(PropertyNameString); |
Fariborz Jahanian | cf2ff9b | 2013-08-08 20:51:58 +0000 | [diff] [blame] | 230 | if (GetterHasIsPrefix) { |
| 231 | PropertyString += "(getter="; |
| 232 | PropertyString += PropertyNameString; |
| 233 | } |
Fariborz Jahanian | cf387c6 | 2013-08-06 18:06:23 +0000 | [diff] [blame] | 234 | // Short circuit properties that contain the name "delegate" or "dataSource", |
| 235 | // or have exact name "target" to have unsafe_unretained attribute. |
| 236 | if (PropertyName.equals("target") || |
| 237 | (PropertyName.find("delegate") != StringRef::npos) || |
| 238 | (PropertyName.find("dataSource") != StringRef::npos)) |
Fariborz Jahanian | cf2ff9b | 2013-08-08 20:51:58 +0000 | [diff] [blame] | 239 | append_attr(PropertyString, "unsafe_unretained", GetterHasIsPrefix); |
Fariborz Jahanian | cf387c6 | 2013-08-06 18:06:23 +0000 | [diff] [blame] | 240 | else { |
| 241 | const ParmVarDecl *argDecl = *Setter->param_begin(); |
| 242 | QualType ArgType = Context.getCanonicalType(argDecl->getType()); |
| 243 | Qualifiers::ObjCLifetime propertyLifetime = ArgType.getObjCLifetime(); |
| 244 | bool RetainableObject = ArgType->isObjCRetainableType(); |
| 245 | if (RetainableObject && propertyLifetime == Qualifiers::OCL_Strong) { |
| 246 | if (const ObjCObjectPointerType *ObjPtrTy = |
| 247 | ArgType->getAs<ObjCObjectPointerType>()) { |
| 248 | ObjCInterfaceDecl *IDecl = ObjPtrTy->getObjectType()->getInterface(); |
| 249 | if (IDecl && |
| 250 | IDecl->lookupNestedProtocol(&Context.Idents.get("NSCopying"))) |
Fariborz Jahanian | cf2ff9b | 2013-08-08 20:51:58 +0000 | [diff] [blame] | 251 | append_attr(PropertyString, "copy", GetterHasIsPrefix); |
Fariborz Jahanian | cf387c6 | 2013-08-06 18:06:23 +0000 | [diff] [blame] | 252 | else |
Fariborz Jahanian | cf2ff9b | 2013-08-08 20:51:58 +0000 | [diff] [blame] | 253 | append_attr(PropertyString, "retain", GetterHasIsPrefix); |
| 254 | } else if (GetterHasIsPrefix) |
| 255 | PropertyString += ')'; |
Fariborz Jahanian | cf387c6 | 2013-08-06 18:06:23 +0000 | [diff] [blame] | 256 | } else if (propertyLifetime == Qualifiers::OCL_Weak) |
| 257 | // TODO. More precise determination of 'weak' attribute requires |
| 258 | // looking into setter's implementation for backing weak ivar. |
Fariborz Jahanian | cf2ff9b | 2013-08-08 20:51:58 +0000 | [diff] [blame] | 259 | append_attr(PropertyString, "weak", GetterHasIsPrefix); |
Fariborz Jahanian | cf387c6 | 2013-08-06 18:06:23 +0000 | [diff] [blame] | 260 | else if (RetainableObject) |
Fariborz Jahanian | cf2ff9b | 2013-08-08 20:51:58 +0000 | [diff] [blame] | 261 | append_attr(PropertyString, "retain", GetterHasIsPrefix); |
| 262 | else if (GetterHasIsPrefix) |
| 263 | PropertyString += ')'; |
Fariborz Jahanian | cf387c6 | 2013-08-06 18:06:23 +0000 | [diff] [blame] | 264 | } |
Fariborz Jahanian | 85e988b | 2013-07-18 22:17:33 +0000 | [diff] [blame] | 265 | |
Fariborz Jahanian | cf2ff9b | 2013-08-08 20:51:58 +0000 | [diff] [blame] | 266 | QualType RT = Getter->getResultType(); |
| 267 | if (!isa<TypedefType>(RT)) { |
| 268 | // strip off any ARC lifetime qualifier. |
| 269 | QualType CanResultTy = Context.getCanonicalType(RT); |
| 270 | if (CanResultTy.getQualifiers().hasObjCLifetime()) { |
| 271 | Qualifiers Qs = CanResultTy.getQualifiers(); |
| 272 | Qs.removeObjCLifetime(); |
| 273 | RT = Context.getQualifiedType(CanResultTy.getUnqualifiedType(), Qs); |
| 274 | } |
Fariborz Jahanian | 85e988b | 2013-07-18 22:17:33 +0000 | [diff] [blame] | 275 | } |
| 276 | PropertyString += " "; |
Fariborz Jahanian | cf2ff9b | 2013-08-08 20:51:58 +0000 | [diff] [blame] | 277 | PropertyString += RT.getAsString(Context.getPrintingPolicy()); |
Fariborz Jahanian | 85e988b | 2013-07-18 22:17:33 +0000 | [diff] [blame] | 278 | PropertyString += " "; |
Fariborz Jahanian | cf2ff9b | 2013-08-08 20:51:58 +0000 | [diff] [blame] | 279 | if (GetterHasIsPrefix) { |
| 280 | // property name must strip off "is" and lower case the first character |
| 281 | // after that; e.g. isContinuous will become continuous. |
| 282 | StringRef PropertyNameStringRef(PropertyNameString); |
| 283 | PropertyNameStringRef = PropertyNameStringRef.drop_front(2); |
| 284 | PropertyNameString = PropertyNameStringRef; |
| 285 | std::string NewPropertyNameString = PropertyNameString; |
Fariborz Jahanian | db8bf83 | 2013-08-08 21:51:06 +0000 | [diff] [blame] | 286 | NewPropertyNameString[0] = toLowercase(NewPropertyNameString[0]); |
Fariborz Jahanian | cf2ff9b | 2013-08-08 20:51:58 +0000 | [diff] [blame] | 287 | PropertyString += NewPropertyNameString; |
| 288 | } |
| 289 | else |
| 290 | PropertyString += PropertyNameString; |
Fariborz Jahanian | 85e988b | 2013-07-18 22:17:33 +0000 | [diff] [blame] | 291 | commit.replace(CharSourceRange::getCharRange(Getter->getLocStart(), |
| 292 | Getter->getDeclaratorEndLoc()), |
| 293 | PropertyString); |
| 294 | SourceLocation EndLoc = Setter->getDeclaratorEndLoc(); |
| 295 | // Get location past ';' |
| 296 | EndLoc = EndLoc.getLocWithOffset(1); |
| 297 | commit.remove(CharSourceRange::getCharRange(Setter->getLocStart(), EndLoc)); |
| 298 | return true; |
| 299 | } |
| 300 | |
Fariborz Jahanian | a7437f0 | 2013-07-03 23:05:00 +0000 | [diff] [blame] | 301 | void ObjCMigrateASTConsumer::migrateObjCInterfaceDecl(ASTContext &Ctx, |
| 302 | ObjCInterfaceDecl *D) { |
| 303 | for (ObjCContainerDecl::method_iterator M = D->meth_begin(), MEnd = D->meth_end(); |
| 304 | M != MEnd; ++M) { |
| 305 | ObjCMethodDecl *Method = (*M); |
Fariborz Jahanian | de66100 | 2013-07-03 23:44:11 +0000 | [diff] [blame] | 306 | if (Method->isPropertyAccessor() || Method->param_size() != 0) |
Fariborz Jahanian | a7437f0 | 2013-07-03 23:05:00 +0000 | [diff] [blame] | 307 | continue; |
| 308 | // Is this method candidate to be a getter? |
Fariborz Jahanian | de66100 | 2013-07-03 23:44:11 +0000 | [diff] [blame] | 309 | QualType GRT = Method->getResultType(); |
| 310 | if (GRT->isVoidType()) |
| 311 | continue; |
Fariborz Jahanian | 7ac20e1 | 2013-07-08 22:49:25 +0000 | [diff] [blame] | 312 | // FIXME. Don't know what todo with attributes, skip for now. |
| 313 | if (Method->hasAttrs()) |
| 314 | continue; |
| 315 | |
Fariborz Jahanian | de66100 | 2013-07-03 23:44:11 +0000 | [diff] [blame] | 316 | Selector GetterSelector = Method->getSelector(); |
| 317 | IdentifierInfo *getterName = GetterSelector.getIdentifierInfoForSlot(0); |
| 318 | Selector SetterSelector = |
| 319 | SelectorTable::constructSetterSelector(PP.getIdentifierTable(), |
| 320 | PP.getSelectorTable(), |
| 321 | getterName); |
Fariborz Jahanian | cf2ff9b | 2013-08-08 20:51:58 +0000 | [diff] [blame] | 322 | ObjCMethodDecl *SetterMethod = D->lookupMethod(SetterSelector, true); |
| 323 | bool GetterHasIsPrefix = false; |
| 324 | if (!SetterMethod) { |
| 325 | // try a different naming convention for getter: isXxxxx |
| 326 | StringRef getterNameString = getterName->getName(); |
Fariborz Jahanian | 261fdb7 | 2013-08-08 21:20:01 +0000 | [diff] [blame] | 327 | if (getterNameString.startswith("is") && !GRT->isObjCRetainableType()) { |
Fariborz Jahanian | cf2ff9b | 2013-08-08 20:51:58 +0000 | [diff] [blame] | 328 | GetterHasIsPrefix = true; |
| 329 | const char *CGetterName = getterNameString.data() + 2; |
Fariborz Jahanian | 261fdb7 | 2013-08-08 21:20:01 +0000 | [diff] [blame] | 330 | if (CGetterName[0] && isUppercase(CGetterName[0])) { |
Fariborz Jahanian | cf2ff9b | 2013-08-08 20:51:58 +0000 | [diff] [blame] | 331 | getterName = &Ctx.Idents.get(CGetterName); |
| 332 | SetterSelector = |
| 333 | SelectorTable::constructSetterSelector(PP.getIdentifierTable(), |
| 334 | PP.getSelectorTable(), |
| 335 | getterName); |
| 336 | SetterMethod = D->lookupMethod(SetterSelector, true); |
| 337 | } |
| 338 | } |
| 339 | } |
| 340 | if (SetterMethod) { |
Fariborz Jahanian | de66100 | 2013-07-03 23:44:11 +0000 | [diff] [blame] | 341 | // Is this a valid setter, matching the target getter? |
| 342 | QualType SRT = SetterMethod->getResultType(); |
| 343 | if (!SRT->isVoidType()) |
Fariborz Jahanian | a7437f0 | 2013-07-03 23:05:00 +0000 | [diff] [blame] | 344 | continue; |
Fariborz Jahanian | de66100 | 2013-07-03 23:44:11 +0000 | [diff] [blame] | 345 | const ParmVarDecl *argDecl = *SetterMethod->param_begin(); |
Fariborz Jahanian | 43bbaac | 2013-07-04 00:24:32 +0000 | [diff] [blame] | 346 | QualType ArgType = argDecl->getType(); |
Fariborz Jahanian | 7ac20e1 | 2013-07-08 22:49:25 +0000 | [diff] [blame] | 347 | if (!Ctx.hasSameUnqualifiedType(ArgType, GRT) || |
| 348 | SetterMethod->hasAttrs()) |
Fariborz Jahanian | 43bbaac | 2013-07-04 00:24:32 +0000 | [diff] [blame] | 349 | continue; |
Fariborz Jahanian | 266926d | 2013-07-05 20:46:03 +0000 | [diff] [blame] | 350 | edit::Commit commit(*Editor); |
Fariborz Jahanian | cf2ff9b | 2013-08-08 20:51:58 +0000 | [diff] [blame] | 351 | rewriteToObjCProperty(Method, SetterMethod, *NSAPIObj, commit, |
| 352 | GetterHasIsPrefix); |
Fariborz Jahanian | 266926d | 2013-07-05 20:46:03 +0000 | [diff] [blame] | 353 | Editor->commit(commit); |
Fariborz Jahanian | a7437f0 | 2013-07-03 23:05:00 +0000 | [diff] [blame] | 354 | } |
Fariborz Jahanian | a7437f0 | 2013-07-03 23:05:00 +0000 | [diff] [blame] | 355 | } |
| 356 | } |
| 357 | |
Fariborz Jahanian | 9eabf45 | 2013-07-13 00:04:20 +0000 | [diff] [blame] | 358 | static bool |
Fariborz Jahanian | 9a3512b | 2013-07-13 17:16:41 +0000 | [diff] [blame] | 359 | ClassImplementsAllMethodsAndProperties(ASTContext &Ctx, |
Fariborz Jahanian | 9eabf45 | 2013-07-13 00:04:20 +0000 | [diff] [blame] | 360 | const ObjCImplementationDecl *ImpDecl, |
Fariborz Jahanian | d36150d | 2013-07-15 21:22:08 +0000 | [diff] [blame] | 361 | const ObjCInterfaceDecl *IDecl, |
Fariborz Jahanian | 9eabf45 | 2013-07-13 00:04:20 +0000 | [diff] [blame] | 362 | ObjCProtocolDecl *Protocol) { |
Fariborz Jahanian | d36150d | 2013-07-15 21:22:08 +0000 | [diff] [blame] | 363 | // In auto-synthesis, protocol properties are not synthesized. So, |
| 364 | // a conforming protocol must have its required properties declared |
| 365 | // in class interface. |
Fariborz Jahanian | 9e543af | 2013-07-22 23:50:04 +0000 | [diff] [blame] | 366 | bool HasAtleastOneRequiredProperty = false; |
Fariborz Jahanian | d36150d | 2013-07-15 21:22:08 +0000 | [diff] [blame] | 367 | if (const ObjCProtocolDecl *PDecl = Protocol->getDefinition()) |
| 368 | for (ObjCProtocolDecl::prop_iterator P = PDecl->prop_begin(), |
| 369 | E = PDecl->prop_end(); P != E; ++P) { |
| 370 | ObjCPropertyDecl *Property = *P; |
| 371 | if (Property->getPropertyImplementation() == ObjCPropertyDecl::Optional) |
| 372 | continue; |
Fariborz Jahanian | 9e543af | 2013-07-22 23:50:04 +0000 | [diff] [blame] | 373 | HasAtleastOneRequiredProperty = true; |
Fariborz Jahanian | d36150d | 2013-07-15 21:22:08 +0000 | [diff] [blame] | 374 | DeclContext::lookup_const_result R = IDecl->lookup(Property->getDeclName()); |
Fariborz Jahanian | 2bc3dda | 2013-07-16 21:59:42 +0000 | [diff] [blame] | 375 | if (R.size() == 0) { |
| 376 | // Relax the rule and look into class's implementation for a synthesize |
| 377 | // or dynamic declaration. Class is implementing a property coming from |
| 378 | // another protocol. This still makes the target protocol as conforming. |
| 379 | if (!ImpDecl->FindPropertyImplDecl( |
| 380 | Property->getDeclName().getAsIdentifierInfo())) |
| 381 | return false; |
Fariborz Jahanian | d36150d | 2013-07-15 21:22:08 +0000 | [diff] [blame] | 382 | } |
Fariborz Jahanian | 2bc3dda | 2013-07-16 21:59:42 +0000 | [diff] [blame] | 383 | else if (ObjCPropertyDecl *ClassProperty = dyn_cast<ObjCPropertyDecl>(R[0])) { |
| 384 | if ((ClassProperty->getPropertyAttributes() |
| 385 | != Property->getPropertyAttributes()) || |
| 386 | !Ctx.hasSameType(ClassProperty->getType(), Property->getType())) |
| 387 | return false; |
| 388 | } |
| 389 | else |
| 390 | return false; |
Fariborz Jahanian | d36150d | 2013-07-15 21:22:08 +0000 | [diff] [blame] | 391 | } |
Fariborz Jahanian | 9e543af | 2013-07-22 23:50:04 +0000 | [diff] [blame] | 392 | |
Fariborz Jahanian | d36150d | 2013-07-15 21:22:08 +0000 | [diff] [blame] | 393 | // At this point, all required properties in this protocol conform to those |
| 394 | // declared in the class. |
| 395 | // Check that class implements the required methods of the protocol too. |
Fariborz Jahanian | 9e543af | 2013-07-22 23:50:04 +0000 | [diff] [blame] | 396 | bool HasAtleastOneRequiredMethod = false; |
Fariborz Jahanian | 5bd5aff | 2013-07-16 00:20:21 +0000 | [diff] [blame] | 397 | if (const ObjCProtocolDecl *PDecl = Protocol->getDefinition()) { |
| 398 | if (PDecl->meth_begin() == PDecl->meth_end()) |
Fariborz Jahanian | 9e543af | 2013-07-22 23:50:04 +0000 | [diff] [blame] | 399 | return HasAtleastOneRequiredProperty; |
Fariborz Jahanian | d36150d | 2013-07-15 21:22:08 +0000 | [diff] [blame] | 400 | for (ObjCContainerDecl::method_iterator M = PDecl->meth_begin(), |
| 401 | MEnd = PDecl->meth_end(); M != MEnd; ++M) { |
| 402 | ObjCMethodDecl *MD = (*M); |
Fariborz Jahanian | 5bd5aff | 2013-07-16 00:20:21 +0000 | [diff] [blame] | 403 | if (MD->isImplicit()) |
| 404 | continue; |
Fariborz Jahanian | d36150d | 2013-07-15 21:22:08 +0000 | [diff] [blame] | 405 | if (MD->getImplementationControl() == ObjCMethodDecl::Optional) |
| 406 | continue; |
Fariborz Jahanian | d36150d | 2013-07-15 21:22:08 +0000 | [diff] [blame] | 407 | DeclContext::lookup_const_result R = ImpDecl->lookup(MD->getDeclName()); |
Fariborz Jahanian | 5bd5aff | 2013-07-16 00:20:21 +0000 | [diff] [blame] | 408 | if (R.size() == 0) |
| 409 | return false; |
Fariborz Jahanian | 9e543af | 2013-07-22 23:50:04 +0000 | [diff] [blame] | 410 | bool match = false; |
| 411 | HasAtleastOneRequiredMethod = true; |
Fariborz Jahanian | d36150d | 2013-07-15 21:22:08 +0000 | [diff] [blame] | 412 | for (unsigned I = 0, N = R.size(); I != N; ++I) |
| 413 | if (ObjCMethodDecl *ImpMD = dyn_cast<ObjCMethodDecl>(R[0])) |
| 414 | if (Ctx.ObjCMethodsAreEqual(MD, ImpMD)) { |
| 415 | match = true; |
| 416 | break; |
| 417 | } |
| 418 | if (!match) |
| 419 | return false; |
| 420 | } |
Fariborz Jahanian | 5bd5aff | 2013-07-16 00:20:21 +0000 | [diff] [blame] | 421 | } |
Fariborz Jahanian | 9e543af | 2013-07-22 23:50:04 +0000 | [diff] [blame] | 422 | if (HasAtleastOneRequiredProperty || HasAtleastOneRequiredMethod) |
| 423 | return true; |
| 424 | return false; |
Fariborz Jahanian | 9eabf45 | 2013-07-13 00:04:20 +0000 | [diff] [blame] | 425 | } |
| 426 | |
Fariborz Jahanian | 85e988b | 2013-07-18 22:17:33 +0000 | [diff] [blame] | 427 | static bool rewriteToObjCInterfaceDecl(const ObjCInterfaceDecl *IDecl, |
| 428 | llvm::SmallVectorImpl<ObjCProtocolDecl*> &ConformingProtocols, |
| 429 | const NSAPI &NS, edit::Commit &commit) { |
| 430 | const ObjCList<ObjCProtocolDecl> &Protocols = IDecl->getReferencedProtocols(); |
| 431 | std::string ClassString; |
| 432 | SourceLocation EndLoc = |
| 433 | IDecl->getSuperClass() ? IDecl->getSuperClassLoc() : IDecl->getLocation(); |
| 434 | |
| 435 | if (Protocols.empty()) { |
| 436 | ClassString = '<'; |
| 437 | for (unsigned i = 0, e = ConformingProtocols.size(); i != e; i++) { |
| 438 | ClassString += ConformingProtocols[i]->getNameAsString(); |
| 439 | if (i != (e-1)) |
| 440 | ClassString += ", "; |
| 441 | } |
| 442 | ClassString += "> "; |
| 443 | } |
| 444 | else { |
| 445 | ClassString = ", "; |
| 446 | for (unsigned i = 0, e = ConformingProtocols.size(); i != e; i++) { |
| 447 | ClassString += ConformingProtocols[i]->getNameAsString(); |
| 448 | if (i != (e-1)) |
| 449 | ClassString += ", "; |
| 450 | } |
| 451 | ObjCInterfaceDecl::protocol_loc_iterator PL = IDecl->protocol_loc_end() - 1; |
| 452 | EndLoc = *PL; |
| 453 | } |
| 454 | |
| 455 | commit.insertAfterToken(EndLoc, ClassString); |
| 456 | return true; |
| 457 | } |
| 458 | |
| 459 | static bool rewriteToNSEnumDecl(const EnumDecl *EnumDcl, |
| 460 | const TypedefDecl *TypedefDcl, |
Fariborz Jahanian | b0057bb | 2013-07-19 01:05:49 +0000 | [diff] [blame] | 461 | const NSAPI &NS, edit::Commit &commit, |
| 462 | bool IsNSIntegerType) { |
Fariborz Jahanian | c1c44f6 | 2013-07-19 20:18:36 +0000 | [diff] [blame] | 463 | std::string ClassString = |
Fariborz Jahanian | b0057bb | 2013-07-19 01:05:49 +0000 | [diff] [blame] | 464 | IsNSIntegerType ? "typedef NS_ENUM(NSInteger, " : "typedef NS_OPTIONS(NSUInteger, "; |
Fariborz Jahanian | 85e988b | 2013-07-18 22:17:33 +0000 | [diff] [blame] | 465 | ClassString += TypedefDcl->getIdentifier()->getName(); |
| 466 | ClassString += ')'; |
| 467 | SourceRange R(EnumDcl->getLocStart(), EnumDcl->getLocStart()); |
| 468 | commit.replace(R, ClassString); |
| 469 | SourceLocation EndOfTypedefLoc = TypedefDcl->getLocEnd(); |
| 470 | EndOfTypedefLoc = trans::findLocationAfterSemi(EndOfTypedefLoc, NS.getASTContext()); |
| 471 | if (!EndOfTypedefLoc.isInvalid()) { |
| 472 | commit.remove(SourceRange(TypedefDcl->getLocStart(), EndOfTypedefLoc)); |
| 473 | return true; |
| 474 | } |
| 475 | return false; |
| 476 | } |
| 477 | |
Fariborz Jahanian | d0f6f79 | 2013-07-22 18:53:45 +0000 | [diff] [blame] | 478 | static bool rewriteToNSMacroDecl(const EnumDecl *EnumDcl, |
Fariborz Jahanian | c1c44f6 | 2013-07-19 20:18:36 +0000 | [diff] [blame] | 479 | const TypedefDecl *TypedefDcl, |
Fariborz Jahanian | d0f6f79 | 2013-07-22 18:53:45 +0000 | [diff] [blame] | 480 | const NSAPI &NS, edit::Commit &commit, |
| 481 | bool IsNSIntegerType) { |
| 482 | std::string ClassString = |
| 483 | IsNSIntegerType ? "NS_ENUM(NSInteger, " : "NS_OPTIONS(NSUInteger, "; |
Fariborz Jahanian | c1c44f6 | 2013-07-19 20:18:36 +0000 | [diff] [blame] | 484 | ClassString += TypedefDcl->getIdentifier()->getName(); |
| 485 | ClassString += ')'; |
| 486 | SourceRange R(EnumDcl->getLocStart(), EnumDcl->getLocStart()); |
| 487 | commit.replace(R, ClassString); |
| 488 | SourceLocation TypedefLoc = TypedefDcl->getLocEnd(); |
| 489 | commit.remove(SourceRange(TypedefLoc, TypedefLoc)); |
| 490 | return true; |
| 491 | } |
| 492 | |
Fariborz Jahanian | d0f6f79 | 2013-07-22 18:53:45 +0000 | [diff] [blame] | 493 | static bool UseNSOptionsMacro(ASTContext &Ctx, |
| 494 | const EnumDecl *EnumDcl) { |
| 495 | bool PowerOfTwo = true; |
| 496 | for (EnumDecl::enumerator_iterator EI = EnumDcl->enumerator_begin(), |
| 497 | EE = EnumDcl->enumerator_end(); EI != EE; ++EI) { |
| 498 | EnumConstantDecl *Enumerator = (*EI); |
| 499 | const Expr *InitExpr = Enumerator->getInitExpr(); |
| 500 | if (!InitExpr) { |
| 501 | PowerOfTwo = false; |
| 502 | continue; |
| 503 | } |
| 504 | InitExpr = InitExpr->IgnoreImpCasts(); |
| 505 | if (const BinaryOperator *BO = dyn_cast<BinaryOperator>(InitExpr)) |
| 506 | if (BO->isShiftOp() || BO->isBitwiseOp()) |
| 507 | return true; |
| 508 | |
| 509 | uint64_t EnumVal = Enumerator->getInitVal().getZExtValue(); |
| 510 | if (PowerOfTwo && EnumVal && !llvm::isPowerOf2_64(EnumVal)) |
| 511 | PowerOfTwo = false; |
| 512 | } |
| 513 | return PowerOfTwo; |
| 514 | } |
| 515 | |
Fariborz Jahanian | 008ef72 | 2013-07-19 17:44:32 +0000 | [diff] [blame] | 516 | void ObjCMigrateASTConsumer::migrateProtocolConformance(ASTContext &Ctx, |
Fariborz Jahanian | 1be0153 | 2013-07-12 22:32:19 +0000 | [diff] [blame] | 517 | const ObjCImplementationDecl *ImpDecl) { |
| 518 | const ObjCInterfaceDecl *IDecl = ImpDecl->getClassInterface(); |
| 519 | if (!IDecl || ObjCProtocolDecls.empty()) |
| 520 | return; |
| 521 | // Find all implicit conforming protocols for this class |
| 522 | // and make them explicit. |
| 523 | llvm::SmallPtrSet<ObjCProtocolDecl *, 8> ExplicitProtocols; |
| 524 | Ctx.CollectInheritedProtocols(IDecl, ExplicitProtocols); |
Fariborz Jahanian | 9eabf45 | 2013-07-13 00:04:20 +0000 | [diff] [blame] | 525 | llvm::SmallVector<ObjCProtocolDecl *, 8> PotentialImplicitProtocols; |
Fariborz Jahanian | 1be0153 | 2013-07-12 22:32:19 +0000 | [diff] [blame] | 526 | |
Fariborz Jahanian | 9eabf45 | 2013-07-13 00:04:20 +0000 | [diff] [blame] | 527 | for (llvm::SmallPtrSet<ObjCProtocolDecl*, 32>::iterator I = |
Fariborz Jahanian | 1be0153 | 2013-07-12 22:32:19 +0000 | [diff] [blame] | 528 | ObjCProtocolDecls.begin(), |
| 529 | E = ObjCProtocolDecls.end(); I != E; ++I) |
| 530 | if (!ExplicitProtocols.count(*I)) |
Fariborz Jahanian | 9eabf45 | 2013-07-13 00:04:20 +0000 | [diff] [blame] | 531 | PotentialImplicitProtocols.push_back(*I); |
Fariborz Jahanian | 1be0153 | 2013-07-12 22:32:19 +0000 | [diff] [blame] | 532 | |
| 533 | if (PotentialImplicitProtocols.empty()) |
| 534 | return; |
Fariborz Jahanian | 9eabf45 | 2013-07-13 00:04:20 +0000 | [diff] [blame] | 535 | |
| 536 | // go through list of non-optional methods and properties in each protocol |
| 537 | // in the PotentialImplicitProtocols list. If class implements every one of the |
| 538 | // methods and properties, then this class conforms to this protocol. |
| 539 | llvm::SmallVector<ObjCProtocolDecl*, 8> ConformingProtocols; |
| 540 | for (unsigned i = 0, e = PotentialImplicitProtocols.size(); i != e; i++) |
Fariborz Jahanian | d36150d | 2013-07-15 21:22:08 +0000 | [diff] [blame] | 541 | if (ClassImplementsAllMethodsAndProperties(Ctx, ImpDecl, IDecl, |
Fariborz Jahanian | 9eabf45 | 2013-07-13 00:04:20 +0000 | [diff] [blame] | 542 | PotentialImplicitProtocols[i])) |
| 543 | ConformingProtocols.push_back(PotentialImplicitProtocols[i]); |
Fariborz Jahanian | 5bd5aff | 2013-07-16 00:20:21 +0000 | [diff] [blame] | 544 | |
| 545 | if (ConformingProtocols.empty()) |
| 546 | return; |
Fariborz Jahanian | cb7b8de | 2013-07-17 00:02:22 +0000 | [diff] [blame] | 547 | |
| 548 | // Further reduce number of conforming protocols. If protocol P1 is in the list |
| 549 | // protocol P2 (P2<P1>), No need to include P1. |
| 550 | llvm::SmallVector<ObjCProtocolDecl*, 8> MinimalConformingProtocols; |
| 551 | for (unsigned i = 0, e = ConformingProtocols.size(); i != e; i++) { |
| 552 | bool DropIt = false; |
| 553 | ObjCProtocolDecl *TargetPDecl = ConformingProtocols[i]; |
| 554 | for (unsigned i1 = 0, e1 = ConformingProtocols.size(); i1 != e1; i1++) { |
| 555 | ObjCProtocolDecl *PDecl = ConformingProtocols[i1]; |
| 556 | if (PDecl == TargetPDecl) |
| 557 | continue; |
| 558 | if (PDecl->lookupProtocolNamed( |
| 559 | TargetPDecl->getDeclName().getAsIdentifierInfo())) { |
| 560 | DropIt = true; |
| 561 | break; |
| 562 | } |
| 563 | } |
| 564 | if (!DropIt) |
| 565 | MinimalConformingProtocols.push_back(TargetPDecl); |
| 566 | } |
Fariborz Jahanian | 5bd5aff | 2013-07-16 00:20:21 +0000 | [diff] [blame] | 567 | edit::Commit commit(*Editor); |
Fariborz Jahanian | 85e988b | 2013-07-18 22:17:33 +0000 | [diff] [blame] | 568 | rewriteToObjCInterfaceDecl(IDecl, MinimalConformingProtocols, |
| 569 | *NSAPIObj, commit); |
Fariborz Jahanian | 5bd5aff | 2013-07-16 00:20:21 +0000 | [diff] [blame] | 570 | Editor->commit(commit); |
Fariborz Jahanian | 1be0153 | 2013-07-12 22:32:19 +0000 | [diff] [blame] | 571 | } |
| 572 | |
Fariborz Jahanian | 9246327 | 2013-07-18 20:11:45 +0000 | [diff] [blame] | 573 | void ObjCMigrateASTConsumer::migrateNSEnumDecl(ASTContext &Ctx, |
| 574 | const EnumDecl *EnumDcl, |
| 575 | const TypedefDecl *TypedefDcl) { |
| 576 | if (!EnumDcl->isCompleteDefinition() || EnumDcl->getIdentifier() || |
| 577 | !TypedefDcl->getIdentifier()) |
| 578 | return; |
| 579 | |
| 580 | QualType qt = TypedefDcl->getTypeSourceInfo()->getType(); |
Fariborz Jahanian | b0057bb | 2013-07-19 01:05:49 +0000 | [diff] [blame] | 581 | bool IsNSIntegerType = NSAPIObj->isObjCNSIntegerType(qt); |
| 582 | bool IsNSUIntegerType = !IsNSIntegerType && NSAPIObj->isObjCNSUIntegerType(qt); |
Fariborz Jahanian | d0f6f79 | 2013-07-22 18:53:45 +0000 | [diff] [blame] | 583 | |
Fariborz Jahanian | c1c44f6 | 2013-07-19 20:18:36 +0000 | [diff] [blame] | 584 | if (!IsNSIntegerType && !IsNSUIntegerType) { |
| 585 | // Also check for typedef enum {...} TD; |
| 586 | if (const EnumType *EnumTy = qt->getAs<EnumType>()) { |
| 587 | if (EnumTy->getDecl() == EnumDcl) { |
Fariborz Jahanian | d0f6f79 | 2013-07-22 18:53:45 +0000 | [diff] [blame] | 588 | bool NSOptions = UseNSOptionsMacro(Ctx, EnumDcl); |
| 589 | if (NSOptions) { |
| 590 | if (!Ctx.Idents.get("NS_OPTIONS").hasMacroDefinition()) |
| 591 | return; |
| 592 | } |
| 593 | else if (!Ctx.Idents.get("NS_ENUM").hasMacroDefinition()) |
Fariborz Jahanian | c1c44f6 | 2013-07-19 20:18:36 +0000 | [diff] [blame] | 594 | return; |
| 595 | edit::Commit commit(*Editor); |
Fariborz Jahanian | d0f6f79 | 2013-07-22 18:53:45 +0000 | [diff] [blame] | 596 | rewriteToNSMacroDecl(EnumDcl, TypedefDcl, *NSAPIObj, commit, !NSOptions); |
Fariborz Jahanian | c1c44f6 | 2013-07-19 20:18:36 +0000 | [diff] [blame] | 597 | Editor->commit(commit); |
Fariborz Jahanian | c1c44f6 | 2013-07-19 20:18:36 +0000 | [diff] [blame] | 598 | } |
Fariborz Jahanian | c1c44f6 | 2013-07-19 20:18:36 +0000 | [diff] [blame] | 599 | } |
Fariborz Jahanian | d0f6f79 | 2013-07-22 18:53:45 +0000 | [diff] [blame] | 600 | return; |
| 601 | } |
| 602 | if (IsNSIntegerType && UseNSOptionsMacro(Ctx, EnumDcl)) { |
| 603 | // We may still use NS_OPTIONS based on what we find in the enumertor list. |
| 604 | IsNSIntegerType = false; |
| 605 | IsNSUIntegerType = true; |
Fariborz Jahanian | c1c44f6 | 2013-07-19 20:18:36 +0000 | [diff] [blame] | 606 | } |
Fariborz Jahanian | 9246327 | 2013-07-18 20:11:45 +0000 | [diff] [blame] | 607 | |
| 608 | // NS_ENUM must be available. |
Fariborz Jahanian | b0057bb | 2013-07-19 01:05:49 +0000 | [diff] [blame] | 609 | if (IsNSIntegerType && !Ctx.Idents.get("NS_ENUM").hasMacroDefinition()) |
| 610 | return; |
| 611 | // NS_OPTIONS must be available. |
| 612 | if (IsNSUIntegerType && !Ctx.Idents.get("NS_OPTIONS").hasMacroDefinition()) |
Fariborz Jahanian | 9246327 | 2013-07-18 20:11:45 +0000 | [diff] [blame] | 613 | return; |
| 614 | edit::Commit commit(*Editor); |
Fariborz Jahanian | b0057bb | 2013-07-19 01:05:49 +0000 | [diff] [blame] | 615 | rewriteToNSEnumDecl(EnumDcl, TypedefDcl, *NSAPIObj, commit, IsNSIntegerType); |
Fariborz Jahanian | 9246327 | 2013-07-18 20:11:45 +0000 | [diff] [blame] | 616 | Editor->commit(commit); |
| 617 | } |
| 618 | |
Fariborz Jahanian | c429185 | 2013-08-02 18:00:53 +0000 | [diff] [blame] | 619 | static void ReplaceWithInstancetype(const ObjCMigrateASTConsumer &ASTC, |
| 620 | ObjCMethodDecl *OM) { |
| 621 | SourceRange R; |
| 622 | std::string ClassString; |
| 623 | if (TypeSourceInfo *TSInfo = OM->getResultTypeSourceInfo()) { |
| 624 | TypeLoc TL = TSInfo->getTypeLoc(); |
| 625 | R = SourceRange(TL.getBeginLoc(), TL.getEndLoc()); |
| 626 | ClassString = "instancetype"; |
| 627 | } |
| 628 | else { |
| 629 | R = SourceRange(OM->getLocStart(), OM->getLocStart()); |
| 630 | ClassString = OM->isInstanceMethod() ? '-' : '+'; |
| 631 | ClassString += " (instancetype)"; |
| 632 | } |
| 633 | edit::Commit commit(*ASTC.Editor); |
| 634 | commit.replace(R, ClassString); |
| 635 | ASTC.Editor->commit(commit); |
| 636 | } |
| 637 | |
Fariborz Jahanian | 670ef26 | 2013-07-23 23:34:42 +0000 | [diff] [blame] | 638 | void ObjCMigrateASTConsumer::migrateMethodInstanceType(ASTContext &Ctx, |
| 639 | ObjCContainerDecl *CDecl, |
| 640 | ObjCMethodDecl *OM) { |
Fariborz Jahanian | 7122135 | 2013-07-23 22:42:28 +0000 | [diff] [blame] | 641 | ObjCInstanceTypeFamily OIT_Family = |
| 642 | Selector::getInstTypeMethodFamily(OM->getSelector()); |
Fariborz Jahanian | 9275c68 | 2013-08-02 20:54:18 +0000 | [diff] [blame] | 643 | |
Fariborz Jahanian | 267bae3 | 2013-07-24 19:18:37 +0000 | [diff] [blame] | 644 | std::string ClassName; |
Fariborz Jahanian | 631925f | 2013-07-23 23:55:55 +0000 | [diff] [blame] | 645 | switch (OIT_Family) { |
Fariborz Jahanian | 9275c68 | 2013-08-02 20:54:18 +0000 | [diff] [blame] | 646 | case OIT_None: |
| 647 | migrateFactoryMethod(Ctx, CDecl, OM); |
| 648 | return; |
Fariborz Jahanian | 631925f | 2013-07-23 23:55:55 +0000 | [diff] [blame] | 649 | case OIT_Array: |
Fariborz Jahanian | 267bae3 | 2013-07-24 19:18:37 +0000 | [diff] [blame] | 650 | ClassName = "NSArray"; |
Fariborz Jahanian | 631925f | 2013-07-23 23:55:55 +0000 | [diff] [blame] | 651 | break; |
| 652 | case OIT_Dictionary: |
Fariborz Jahanian | 267bae3 | 2013-07-24 19:18:37 +0000 | [diff] [blame] | 653 | ClassName = "NSDictionary"; |
| 654 | break; |
| 655 | case OIT_MemManage: |
| 656 | ClassName = "NSObject"; |
Fariborz Jahanian | 631925f | 2013-07-23 23:55:55 +0000 | [diff] [blame] | 657 | break; |
Fariborz Jahanian | 9275c68 | 2013-08-02 20:54:18 +0000 | [diff] [blame] | 658 | case OIT_Singleton: |
| 659 | migrateFactoryMethod(Ctx, CDecl, OM, OIT_Singleton); |
Fariborz Jahanian | 631925f | 2013-07-23 23:55:55 +0000 | [diff] [blame] | 660 | return; |
| 661 | } |
Fariborz Jahanian | 7122135 | 2013-07-23 22:42:28 +0000 | [diff] [blame] | 662 | if (!OM->getResultType()->isObjCIdType()) |
| 663 | return; |
| 664 | |
| 665 | ObjCInterfaceDecl *IDecl = dyn_cast<ObjCInterfaceDecl>(CDecl); |
| 666 | if (!IDecl) { |
| 667 | if (ObjCCategoryDecl *CatDecl = dyn_cast<ObjCCategoryDecl>(CDecl)) |
| 668 | IDecl = CatDecl->getClassInterface(); |
| 669 | else if (ObjCImplDecl *ImpDecl = dyn_cast<ObjCImplDecl>(CDecl)) |
| 670 | IDecl = ImpDecl->getClassInterface(); |
| 671 | } |
Fariborz Jahanian | 267bae3 | 2013-07-24 19:18:37 +0000 | [diff] [blame] | 672 | if (!IDecl || |
Fariborz Jahanian | c429185 | 2013-08-02 18:00:53 +0000 | [diff] [blame] | 673 | !IDecl->lookupInheritedClass(&Ctx.Idents.get(ClassName))) { |
| 674 | migrateFactoryMethod(Ctx, CDecl, OM); |
Fariborz Jahanian | 7122135 | 2013-07-23 22:42:28 +0000 | [diff] [blame] | 675 | return; |
Fariborz Jahanian | 280954a | 2013-07-24 18:31:42 +0000 | [diff] [blame] | 676 | } |
Fariborz Jahanian | c429185 | 2013-08-02 18:00:53 +0000 | [diff] [blame] | 677 | ReplaceWithInstancetype(*this, OM); |
Fariborz Jahanian | 7122135 | 2013-07-23 22:42:28 +0000 | [diff] [blame] | 678 | } |
| 679 | |
| 680 | void ObjCMigrateASTConsumer::migrateInstanceType(ASTContext &Ctx, |
| 681 | ObjCContainerDecl *CDecl) { |
| 682 | // migrate methods which can have instancetype as their result type. |
| 683 | for (ObjCContainerDecl::method_iterator M = CDecl->meth_begin(), |
| 684 | MEnd = CDecl->meth_end(); |
| 685 | M != MEnd; ++M) { |
| 686 | ObjCMethodDecl *Method = (*M); |
| 687 | migrateMethodInstanceType(Ctx, CDecl, Method); |
| 688 | } |
| 689 | } |
| 690 | |
Fariborz Jahanian | c429185 | 2013-08-02 18:00:53 +0000 | [diff] [blame] | 691 | void ObjCMigrateASTConsumer::migrateFactoryMethod(ASTContext &Ctx, |
| 692 | ObjCContainerDecl *CDecl, |
Fariborz Jahanian | 9275c68 | 2013-08-02 20:54:18 +0000 | [diff] [blame] | 693 | ObjCMethodDecl *OM, |
| 694 | ObjCInstanceTypeFamily OIT_Family) { |
Fariborz Jahanian | 3bfc35e | 2013-08-02 22:34:18 +0000 | [diff] [blame] | 695 | if (OM->isInstanceMethod() || |
| 696 | OM->getResultType() == Ctx.getObjCInstanceType() || |
| 697 | !OM->getResultType()->isObjCIdType()) |
Fariborz Jahanian | c429185 | 2013-08-02 18:00:53 +0000 | [diff] [blame] | 698 | return; |
| 699 | |
| 700 | // Candidate factory methods are + (id) NaMeXXX : ... which belong to a class |
| 701 | // NSYYYNamE with matching names be at least 3 characters long. |
| 702 | ObjCInterfaceDecl *IDecl = dyn_cast<ObjCInterfaceDecl>(CDecl); |
| 703 | if (!IDecl) { |
| 704 | if (ObjCCategoryDecl *CatDecl = dyn_cast<ObjCCategoryDecl>(CDecl)) |
| 705 | IDecl = CatDecl->getClassInterface(); |
| 706 | else if (ObjCImplDecl *ImpDecl = dyn_cast<ObjCImplDecl>(CDecl)) |
| 707 | IDecl = ImpDecl->getClassInterface(); |
| 708 | } |
| 709 | if (!IDecl) |
| 710 | return; |
| 711 | |
| 712 | std::string StringClassName = IDecl->getName(); |
| 713 | StringRef LoweredClassName(StringClassName); |
| 714 | std::string StringLoweredClassName = LoweredClassName.lower(); |
| 715 | LoweredClassName = StringLoweredClassName; |
| 716 | |
| 717 | IdentifierInfo *MethodIdName = OM->getSelector().getIdentifierInfoForSlot(0); |
Fariborz Jahanian | c13c1b0 | 2013-08-13 18:01:42 +0000 | [diff] [blame] | 718 | // Handle method with no name at its first selector slot; e.g. + (id):(int)x. |
| 719 | if (!MethodIdName) |
| 720 | return; |
| 721 | |
Fariborz Jahanian | c429185 | 2013-08-02 18:00:53 +0000 | [diff] [blame] | 722 | std::string MethodName = MethodIdName->getName(); |
Fariborz Jahanian | 9275c68 | 2013-08-02 20:54:18 +0000 | [diff] [blame] | 723 | if (OIT_Family == OIT_Singleton) { |
| 724 | StringRef STRefMethodName(MethodName); |
| 725 | size_t len = 0; |
| 726 | if (STRefMethodName.startswith("standard")) |
| 727 | len = strlen("standard"); |
| 728 | else if (STRefMethodName.startswith("shared")) |
| 729 | len = strlen("shared"); |
| 730 | else if (STRefMethodName.startswith("default")) |
| 731 | len = strlen("default"); |
| 732 | else |
| 733 | return; |
| 734 | MethodName = STRefMethodName.substr(len); |
| 735 | } |
Fariborz Jahanian | c429185 | 2013-08-02 18:00:53 +0000 | [diff] [blame] | 736 | std::string MethodNameSubStr = MethodName.substr(0, 3); |
| 737 | StringRef MethodNamePrefix(MethodNameSubStr); |
| 738 | std::string StringLoweredMethodNamePrefix = MethodNamePrefix.lower(); |
| 739 | MethodNamePrefix = StringLoweredMethodNamePrefix; |
| 740 | size_t Ix = LoweredClassName.rfind(MethodNamePrefix); |
| 741 | if (Ix == StringRef::npos) |
| 742 | return; |
| 743 | std::string ClassNamePostfix = LoweredClassName.substr(Ix); |
| 744 | StringRef LoweredMethodName(MethodName); |
| 745 | std::string StringLoweredMethodName = LoweredMethodName.lower(); |
| 746 | LoweredMethodName = StringLoweredMethodName; |
| 747 | if (!LoweredMethodName.startswith(ClassNamePostfix)) |
| 748 | return; |
| 749 | ReplaceWithInstancetype(*this, OM); |
| 750 | } |
| 751 | |
Fariborz Jahanian | dfe6ed9 | 2013-08-12 23:17:13 +0000 | [diff] [blame] | 752 | void ObjCMigrateASTConsumer::migrateFunctionDeclAnnotation( |
| 753 | ASTContext &Ctx, |
Fariborz Jahanian | c13c1b0 | 2013-08-13 18:01:42 +0000 | [diff] [blame] | 754 | const FunctionDecl *FuncDecl) { |
Fariborz Jahanian | dfe6ed9 | 2013-08-12 23:17:13 +0000 | [diff] [blame] | 755 | if (FuncDecl->hasAttr<CFAuditedTransferAttr>() || |
| 756 | FuncDecl->getAttr<CFReturnsRetainedAttr>() || |
Fariborz Jahanian | c13c1b0 | 2013-08-13 18:01:42 +0000 | [diff] [blame] | 757 | FuncDecl->getAttr<CFReturnsNotRetainedAttr>() || |
| 758 | FuncDecl->hasBody()) |
Fariborz Jahanian | dfe6ed9 | 2013-08-12 23:17:13 +0000 | [diff] [blame] | 759 | return; |
| 760 | } |
| 761 | |
| 762 | void ObjCMigrateASTConsumer::migrateObjCMethodDeclAnnotation( |
| 763 | ASTContext &Ctx, |
Fariborz Jahanian | c13c1b0 | 2013-08-13 18:01:42 +0000 | [diff] [blame] | 764 | const ObjCMethodDecl *MethodDecl) { |
Fariborz Jahanian | dfe6ed9 | 2013-08-12 23:17:13 +0000 | [diff] [blame] | 765 | if (MethodDecl->hasAttr<CFAuditedTransferAttr>() || |
| 766 | MethodDecl->getAttr<CFReturnsRetainedAttr>() || |
Fariborz Jahanian | c13c1b0 | 2013-08-13 18:01:42 +0000 | [diff] [blame] | 767 | MethodDecl->getAttr<CFReturnsNotRetainedAttr>() || |
| 768 | MethodDecl->hasBody()) |
Fariborz Jahanian | dfe6ed9 | 2013-08-12 23:17:13 +0000 | [diff] [blame] | 769 | return; |
| 770 | } |
| 771 | |
Ted Kremenek | f7639e1 | 2012-03-06 20:06:33 +0000 | [diff] [blame] | 772 | namespace { |
| 773 | |
| 774 | class RewritesReceiver : public edit::EditsReceiver { |
| 775 | Rewriter &Rewrite; |
| 776 | |
| 777 | public: |
| 778 | RewritesReceiver(Rewriter &Rewrite) : Rewrite(Rewrite) { } |
| 779 | |
| 780 | virtual void insert(SourceLocation loc, StringRef text) { |
| 781 | Rewrite.InsertText(loc, text); |
| 782 | } |
| 783 | virtual void replace(CharSourceRange range, StringRef text) { |
| 784 | Rewrite.ReplaceText(range.getBegin(), Rewrite.getRangeSize(range), text); |
| 785 | } |
| 786 | }; |
| 787 | |
| 788 | } |
| 789 | |
| 790 | void ObjCMigrateASTConsumer::HandleTranslationUnit(ASTContext &Ctx) { |
Fariborz Jahanian | a7437f0 | 2013-07-03 23:05:00 +0000 | [diff] [blame] | 791 | |
| 792 | TranslationUnitDecl *TU = Ctx.getTranslationUnitDecl(); |
Fariborz Jahanian | d83ef84 | 2013-07-09 16:59:14 +0000 | [diff] [blame] | 793 | if (MigrateProperty) |
| 794 | for (DeclContext::decl_iterator D = TU->decls_begin(), DEnd = TU->decls_end(); |
| 795 | D != DEnd; ++D) { |
| 796 | if (ObjCInterfaceDecl *CDecl = dyn_cast<ObjCInterfaceDecl>(*D)) |
| 797 | migrateObjCInterfaceDecl(Ctx, CDecl); |
Fariborz Jahanian | 1be0153 | 2013-07-12 22:32:19 +0000 | [diff] [blame] | 798 | else if (ObjCProtocolDecl *PDecl = dyn_cast<ObjCProtocolDecl>(*D)) |
| 799 | ObjCProtocolDecls.insert(PDecl); |
| 800 | else if (const ObjCImplementationDecl *ImpDecl = |
| 801 | dyn_cast<ObjCImplementationDecl>(*D)) |
| 802 | migrateProtocolConformance(Ctx, ImpDecl); |
Fariborz Jahanian | 9246327 | 2013-07-18 20:11:45 +0000 | [diff] [blame] | 803 | else if (const EnumDecl *ED = dyn_cast<EnumDecl>(*D)) { |
| 804 | DeclContext::decl_iterator N = D; |
| 805 | ++N; |
Fariborz Jahanian | 008ef72 | 2013-07-19 17:44:32 +0000 | [diff] [blame] | 806 | if (N != DEnd) |
| 807 | if (const TypedefDecl *TD = dyn_cast<TypedefDecl>(*N)) |
| 808 | migrateNSEnumDecl(Ctx, ED, TD); |
Fariborz Jahanian | 9246327 | 2013-07-18 20:11:45 +0000 | [diff] [blame] | 809 | } |
Fariborz Jahanian | c13c1b0 | 2013-08-13 18:01:42 +0000 | [diff] [blame] | 810 | else if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(*D)) |
| 811 | migrateFunctionDeclAnnotation(Ctx, FD); |
| 812 | else if (const ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(*D)) |
| 813 | migrateObjCMethodDeclAnnotation(Ctx, MD); |
| 814 | |
Fariborz Jahanian | 7122135 | 2013-07-23 22:42:28 +0000 | [diff] [blame] | 815 | // migrate methods which can have instancetype as their result type. |
| 816 | if (ObjCContainerDecl *CDecl = dyn_cast<ObjCContainerDecl>(*D)) |
| 817 | migrateInstanceType(Ctx, CDecl); |
Fariborz Jahanian | d83ef84 | 2013-07-09 16:59:14 +0000 | [diff] [blame] | 818 | } |
Fariborz Jahanian | a7437f0 | 2013-07-03 23:05:00 +0000 | [diff] [blame] | 819 | |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 820 | Rewriter rewriter(Ctx.getSourceManager(), Ctx.getLangOpts()); |
Ted Kremenek | f7639e1 | 2012-03-06 20:06:33 +0000 | [diff] [blame] | 821 | RewritesReceiver Rec(rewriter); |
| 822 | Editor->applyRewrites(Rec); |
| 823 | |
| 824 | for (Rewriter::buffer_iterator |
| 825 | I = rewriter.buffer_begin(), E = rewriter.buffer_end(); I != E; ++I) { |
| 826 | FileID FID = I->first; |
| 827 | RewriteBuffer &buf = I->second; |
| 828 | const FileEntry *file = Ctx.getSourceManager().getFileEntryForID(FID); |
| 829 | assert(file); |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 830 | SmallString<512> newText; |
Ted Kremenek | f7639e1 | 2012-03-06 20:06:33 +0000 | [diff] [blame] | 831 | llvm::raw_svector_ostream vecOS(newText); |
| 832 | buf.write(vecOS); |
| 833 | vecOS.flush(); |
| 834 | llvm::MemoryBuffer *memBuf = llvm::MemoryBuffer::getMemBufferCopy( |
| 835 | StringRef(newText.data(), newText.size()), file->getName()); |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 836 | SmallString<64> filePath(file->getName()); |
Ted Kremenek | f7639e1 | 2012-03-06 20:06:33 +0000 | [diff] [blame] | 837 | FileMgr.FixupRelativePath(filePath); |
| 838 | Remapper.remap(filePath.str(), memBuf); |
| 839 | } |
| 840 | |
| 841 | if (IsOutputFile) { |
| 842 | Remapper.flushToFile(MigrateDir, Ctx.getDiagnostics()); |
| 843 | } else { |
| 844 | Remapper.flushToDisk(MigrateDir, Ctx.getDiagnostics()); |
| 845 | } |
| 846 | } |
| 847 | |
| 848 | bool MigrateSourceAction::BeginInvocation(CompilerInstance &CI) { |
Argyrios Kyrtzidis | b482260 | 2012-05-24 16:48:23 +0000 | [diff] [blame] | 849 | CI.getDiagnostics().setIgnoreAllWarnings(true); |
Ted Kremenek | f7639e1 | 2012-03-06 20:06:33 +0000 | [diff] [blame] | 850 | return true; |
| 851 | } |
| 852 | |
| 853 | ASTConsumer *MigrateSourceAction::CreateASTConsumer(CompilerInstance &CI, |
| 854 | StringRef InFile) { |
Argyrios Kyrtzidis | f3d587e | 2012-12-04 07:27:05 +0000 | [diff] [blame] | 855 | PPConditionalDirectiveRecord * |
| 856 | PPRec = new PPConditionalDirectiveRecord(CI.getSourceManager()); |
| 857 | CI.getPreprocessor().addPPCallbacks(PPRec); |
Ted Kremenek | f7639e1 | 2012-03-06 20:06:33 +0000 | [diff] [blame] | 858 | return new ObjCMigrateASTConsumer(CI.getFrontendOpts().OutputFile, |
| 859 | /*MigrateLiterals=*/true, |
| 860 | /*MigrateSubscripting=*/true, |
Fariborz Jahanian | d83ef84 | 2013-07-09 16:59:14 +0000 | [diff] [blame] | 861 | /*MigrateProperty*/true, |
Ted Kremenek | f7639e1 | 2012-03-06 20:06:33 +0000 | [diff] [blame] | 862 | Remapper, |
| 863 | CI.getFileManager(), |
Argyrios Kyrtzidis | f3d587e | 2012-12-04 07:27:05 +0000 | [diff] [blame] | 864 | PPRec, |
Fariborz Jahanian | a7437f0 | 2013-07-03 23:05:00 +0000 | [diff] [blame] | 865 | CI.getPreprocessor(), |
Ted Kremenek | f7639e1 | 2012-03-06 20:06:33 +0000 | [diff] [blame] | 866 | /*isOutputFile=*/true); |
| 867 | } |