blob: ab4aa0e08504964ba1a0457c963d639f8cc6ef1e [file] [log] [blame]
Ted Kremenekf7639e12012-03-06 20:06:33 +00001//===--- 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
10#include "clang/ARCMigrate/ARCMTActions.h"
Chandler Carruth3a022472012-12-04 09:13:33 +000011#include "clang/AST/ASTConsumer.h"
12#include "clang/AST/ASTContext.h"
13#include "clang/AST/NSAPI.h"
Argyrios Kyrtzidis6b4f3412013-01-16 23:54:48 +000014#include "clang/AST/ParentMap.h"
Chandler Carruth3a022472012-12-04 09:13:33 +000015#include "clang/AST/RecursiveASTVisitor.h"
16#include "clang/Basic/FileManager.h"
17#include "clang/Edit/Commit.h"
18#include "clang/Edit/EditedSource.h"
19#include "clang/Edit/EditsReceiver.h"
20#include "clang/Edit/Rewriters.h"
Ted Kremenekf7639e12012-03-06 20:06:33 +000021#include "clang/Frontend/CompilerInstance.h"
22#include "clang/Frontend/MultiplexConsumer.h"
Argyrios Kyrtzidisf3d587e2012-12-04 07:27:05 +000023#include "clang/Lex/PPConditionalDirectiveRecord.h"
Chandler Carruth3a022472012-12-04 09:13:33 +000024#include "clang/Lex/Preprocessor.h"
25#include "clang/Rewrite/Core/Rewriter.h"
Ted Kremenekf7639e12012-03-06 20:06:33 +000026#include "llvm/ADT/SmallString.h"
27
28using namespace clang;
29using namespace arcmt;
30
31namespace {
32
33class ObjCMigrateASTConsumer : public ASTConsumer {
34 void migrateDecl(Decl *D);
Fariborz Jahaniana7437f02013-07-03 23:05:00 +000035 void migrateObjCInterfaceDecl(ASTContext &Ctx, ObjCInterfaceDecl *D);
Fariborz Jahanian1be01532013-07-12 22:32:19 +000036 void migrateProtocolConformance(ASTContext &Ctx,
37 const ObjCImplementationDecl *ImpDecl);
Ted Kremenekf7639e12012-03-06 20:06:33 +000038
39public:
40 std::string MigrateDir;
41 bool MigrateLiterals;
42 bool MigrateSubscripting;
Fariborz Jahaniand83ef842013-07-09 16:59:14 +000043 bool MigrateProperty;
Dmitri Gribenkof8579502013-01-12 19:30:44 +000044 OwningPtr<NSAPI> NSAPIObj;
45 OwningPtr<edit::EditedSource> Editor;
Ted Kremenekf7639e12012-03-06 20:06:33 +000046 FileRemapper &Remapper;
47 FileManager &FileMgr;
Argyrios Kyrtzidisf3d587e2012-12-04 07:27:05 +000048 const PPConditionalDirectiveRecord *PPRec;
Fariborz Jahaniana7437f02013-07-03 23:05:00 +000049 Preprocessor &PP;
Ted Kremenekf7639e12012-03-06 20:06:33 +000050 bool IsOutputFile;
Fariborz Jahanian1be01532013-07-12 22:32:19 +000051 llvm::SmallPtrSet<ObjCProtocolDecl *, 32> ObjCProtocolDecls;
52
Ted Kremenekf7639e12012-03-06 20:06:33 +000053 ObjCMigrateASTConsumer(StringRef migrateDir,
54 bool migrateLiterals,
55 bool migrateSubscripting,
Fariborz Jahaniand83ef842013-07-09 16:59:14 +000056 bool migrateProperty,
Ted Kremenekf7639e12012-03-06 20:06:33 +000057 FileRemapper &remapper,
58 FileManager &fileMgr,
Argyrios Kyrtzidisf3d587e2012-12-04 07:27:05 +000059 const PPConditionalDirectiveRecord *PPRec,
Fariborz Jahaniana7437f02013-07-03 23:05:00 +000060 Preprocessor &PP,
Ted Kremenekf7639e12012-03-06 20:06:33 +000061 bool isOutputFile = false)
62 : MigrateDir(migrateDir),
63 MigrateLiterals(migrateLiterals),
64 MigrateSubscripting(migrateSubscripting),
Fariborz Jahaniand83ef842013-07-09 16:59:14 +000065 MigrateProperty(migrateProperty),
Fariborz Jahaniana7437f02013-07-03 23:05:00 +000066 Remapper(remapper), FileMgr(fileMgr), PPRec(PPRec), PP(PP),
Ted Kremenekf7639e12012-03-06 20:06:33 +000067 IsOutputFile(isOutputFile) { }
68
69protected:
70 virtual void Initialize(ASTContext &Context) {
71 NSAPIObj.reset(new NSAPI(Context));
72 Editor.reset(new edit::EditedSource(Context.getSourceManager(),
David Blaikiebbafb8a2012-03-11 07:00:24 +000073 Context.getLangOpts(),
Ted Kremenekf7639e12012-03-06 20:06:33 +000074 PPRec));
75 }
76
77 virtual bool HandleTopLevelDecl(DeclGroupRef DG) {
78 for (DeclGroupRef::iterator I = DG.begin(), E = DG.end(); I != E; ++I)
79 migrateDecl(*I);
80 return true;
81 }
82 virtual void HandleInterestingDecl(DeclGroupRef DG) {
83 // Ignore decls from the PCH.
84 }
85 virtual void HandleTopLevelDeclInObjCContainer(DeclGroupRef DG) {
86 ObjCMigrateASTConsumer::HandleTopLevelDecl(DG);
87 }
88
89 virtual void HandleTranslationUnit(ASTContext &Ctx);
90};
91
92}
93
94ObjCMigrateAction::ObjCMigrateAction(FrontendAction *WrappedAction,
95 StringRef migrateDir,
96 bool migrateLiterals,
Fariborz Jahaniand83ef842013-07-09 16:59:14 +000097 bool migrateSubscripting,
98 bool migrateProperty)
Ted Kremenekf7639e12012-03-06 20:06:33 +000099 : WrapperFrontendAction(WrappedAction), MigrateDir(migrateDir),
100 MigrateLiterals(migrateLiterals), MigrateSubscripting(migrateSubscripting),
Fariborz Jahaniand83ef842013-07-09 16:59:14 +0000101 MigrateProperty(migrateProperty),
Ted Kremenekf7639e12012-03-06 20:06:33 +0000102 CompInst(0) {
103 if (MigrateDir.empty())
104 MigrateDir = "."; // user current directory if none is given.
105}
106
107ASTConsumer *ObjCMigrateAction::CreateASTConsumer(CompilerInstance &CI,
108 StringRef InFile) {
Argyrios Kyrtzidisf3d587e2012-12-04 07:27:05 +0000109 PPConditionalDirectiveRecord *
110 PPRec = new PPConditionalDirectiveRecord(CompInst->getSourceManager());
111 CompInst->getPreprocessor().addPPCallbacks(PPRec);
Ted Kremenekf7639e12012-03-06 20:06:33 +0000112 ASTConsumer *
113 WrappedConsumer = WrapperFrontendAction::CreateASTConsumer(CI, InFile);
114 ASTConsumer *MTConsumer = new ObjCMigrateASTConsumer(MigrateDir,
115 MigrateLiterals,
116 MigrateSubscripting,
Fariborz Jahaniand83ef842013-07-09 16:59:14 +0000117 MigrateProperty,
Ted Kremenekf7639e12012-03-06 20:06:33 +0000118 Remapper,
119 CompInst->getFileManager(),
Fariborz Jahaniana7437f02013-07-03 23:05:00 +0000120 PPRec,
121 CompInst->getPreprocessor());
Ted Kremenekf7639e12012-03-06 20:06:33 +0000122 ASTConsumer *Consumers[] = { MTConsumer, WrappedConsumer };
123 return new MultiplexConsumer(Consumers);
124}
125
126bool ObjCMigrateAction::BeginInvocation(CompilerInstance &CI) {
127 Remapper.initFromDisk(MigrateDir, CI.getDiagnostics(),
128 /*ignoreIfFilesChanges=*/true);
129 CompInst = &CI;
130 CI.getDiagnostics().setIgnoreAllWarnings(true);
Ted Kremenekf7639e12012-03-06 20:06:33 +0000131 return true;
132}
133
134namespace {
135class ObjCMigrator : public RecursiveASTVisitor<ObjCMigrator> {
136 ObjCMigrateASTConsumer &Consumer;
Argyrios Kyrtzidis6b4f3412013-01-16 23:54:48 +0000137 ParentMap &PMap;
Ted Kremenekf7639e12012-03-06 20:06:33 +0000138
139public:
Argyrios Kyrtzidis6b4f3412013-01-16 23:54:48 +0000140 ObjCMigrator(ObjCMigrateASTConsumer &consumer, ParentMap &PMap)
141 : Consumer(consumer), PMap(PMap) { }
Ted Kremenekf7639e12012-03-06 20:06:33 +0000142
143 bool shouldVisitTemplateInstantiations() const { return false; }
144 bool shouldWalkTypesOfTypeLocs() const { return false; }
145
146 bool VisitObjCMessageExpr(ObjCMessageExpr *E) {
147 if (Consumer.MigrateLiterals) {
148 edit::Commit commit(*Consumer.Editor);
Argyrios Kyrtzidis6b4f3412013-01-16 23:54:48 +0000149 edit::rewriteToObjCLiteralSyntax(E, *Consumer.NSAPIObj, commit, &PMap);
Ted Kremenekf7639e12012-03-06 20:06:33 +0000150 Consumer.Editor->commit(commit);
151 }
152
153 if (Consumer.MigrateSubscripting) {
154 edit::Commit commit(*Consumer.Editor);
155 edit::rewriteToObjCSubscriptSyntax(E, *Consumer.NSAPIObj, commit);
156 Consumer.Editor->commit(commit);
157 }
158
159 return true;
160 }
161
162 bool TraverseObjCMessageExpr(ObjCMessageExpr *E) {
163 // Do depth first; we want to rewrite the subexpressions first so that if
164 // we have to move expressions we will move them already rewritten.
165 for (Stmt::child_range range = E->children(); range; ++range)
166 if (!TraverseStmt(*range))
167 return false;
168
169 return WalkUpFromObjCMessageExpr(E);
170 }
171};
Argyrios Kyrtzidis6b4f3412013-01-16 23:54:48 +0000172
173class BodyMigrator : public RecursiveASTVisitor<BodyMigrator> {
174 ObjCMigrateASTConsumer &Consumer;
175 OwningPtr<ParentMap> PMap;
176
177public:
178 BodyMigrator(ObjCMigrateASTConsumer &consumer) : Consumer(consumer) { }
179
180 bool shouldVisitTemplateInstantiations() const { return false; }
181 bool shouldWalkTypesOfTypeLocs() const { return false; }
182
183 bool TraverseStmt(Stmt *S) {
184 PMap.reset(new ParentMap(S));
185 ObjCMigrator(Consumer, *PMap).TraverseStmt(S);
186 return true;
187 }
188};
Ted Kremenekf7639e12012-03-06 20:06:33 +0000189}
190
191void ObjCMigrateASTConsumer::migrateDecl(Decl *D) {
192 if (!D)
193 return;
194 if (isa<ObjCMethodDecl>(D))
195 return; // Wait for the ObjC container declaration.
196
Argyrios Kyrtzidis6b4f3412013-01-16 23:54:48 +0000197 BodyMigrator(*this).TraverseDecl(D);
Ted Kremenekf7639e12012-03-06 20:06:33 +0000198}
199
Fariborz Jahaniana7437f02013-07-03 23:05:00 +0000200void ObjCMigrateASTConsumer::migrateObjCInterfaceDecl(ASTContext &Ctx,
201 ObjCInterfaceDecl *D) {
202 for (ObjCContainerDecl::method_iterator M = D->meth_begin(), MEnd = D->meth_end();
203 M != MEnd; ++M) {
204 ObjCMethodDecl *Method = (*M);
Fariborz Jahaniande661002013-07-03 23:44:11 +0000205 if (Method->isPropertyAccessor() || Method->param_size() != 0)
Fariborz Jahaniana7437f02013-07-03 23:05:00 +0000206 continue;
207 // Is this method candidate to be a getter?
Fariborz Jahaniande661002013-07-03 23:44:11 +0000208 QualType GRT = Method->getResultType();
209 if (GRT->isVoidType())
210 continue;
Fariborz Jahanian7ac20e12013-07-08 22:49:25 +0000211 // FIXME. Don't know what todo with attributes, skip for now.
212 if (Method->hasAttrs())
213 continue;
214
Fariborz Jahaniande661002013-07-03 23:44:11 +0000215 Selector GetterSelector = Method->getSelector();
216 IdentifierInfo *getterName = GetterSelector.getIdentifierInfoForSlot(0);
217 Selector SetterSelector =
218 SelectorTable::constructSetterSelector(PP.getIdentifierTable(),
219 PP.getSelectorTable(),
220 getterName);
221 if (ObjCMethodDecl *SetterMethod = D->lookupMethod(SetterSelector, true)) {
222 // Is this a valid setter, matching the target getter?
223 QualType SRT = SetterMethod->getResultType();
224 if (!SRT->isVoidType())
Fariborz Jahaniana7437f02013-07-03 23:05:00 +0000225 continue;
Fariborz Jahaniande661002013-07-03 23:44:11 +0000226 const ParmVarDecl *argDecl = *SetterMethod->param_begin();
Fariborz Jahanian43bbaac2013-07-04 00:24:32 +0000227 QualType ArgType = argDecl->getType();
Fariborz Jahanian7ac20e12013-07-08 22:49:25 +0000228 if (!Ctx.hasSameUnqualifiedType(ArgType, GRT) ||
229 SetterMethod->hasAttrs())
Fariborz Jahanian43bbaac2013-07-04 00:24:32 +0000230 continue;
Fariborz Jahanian266926d2013-07-05 20:46:03 +0000231 edit::Commit commit(*Editor);
232 edit::rewriteToObjCProperty(Method, SetterMethod, *NSAPIObj, commit);
233 Editor->commit(commit);
Fariborz Jahaniana7437f02013-07-03 23:05:00 +0000234 }
Fariborz Jahaniana7437f02013-07-03 23:05:00 +0000235 }
236}
237
Fariborz Jahanian9eabf452013-07-13 00:04:20 +0000238static bool
Fariborz Jahanian9a3512b2013-07-13 17:16:41 +0000239ClassImplementsAllMethodsAndProperties(ASTContext &Ctx,
Fariborz Jahanian9eabf452013-07-13 00:04:20 +0000240 const ObjCImplementationDecl *ImpDecl,
Fariborz Jahaniand36150d2013-07-15 21:22:08 +0000241 const ObjCInterfaceDecl *IDecl,
Fariborz Jahanian9eabf452013-07-13 00:04:20 +0000242 ObjCProtocolDecl *Protocol) {
Fariborz Jahaniand36150d2013-07-15 21:22:08 +0000243 // In auto-synthesis, protocol properties are not synthesized. So,
244 // a conforming protocol must have its required properties declared
245 // in class interface.
246 if (const ObjCProtocolDecl *PDecl = Protocol->getDefinition())
247 for (ObjCProtocolDecl::prop_iterator P = PDecl->prop_begin(),
248 E = PDecl->prop_end(); P != E; ++P) {
249 ObjCPropertyDecl *Property = *P;
250 if (Property->getPropertyImplementation() == ObjCPropertyDecl::Optional)
251 continue;
252 DeclContext::lookup_const_result R = IDecl->lookup(Property->getDeclName());
Fariborz Jahanian2bc3dda2013-07-16 21:59:42 +0000253 if (R.size() == 0) {
254 // Relax the rule and look into class's implementation for a synthesize
255 // or dynamic declaration. Class is implementing a property coming from
256 // another protocol. This still makes the target protocol as conforming.
257 if (!ImpDecl->FindPropertyImplDecl(
258 Property->getDeclName().getAsIdentifierInfo()))
259 return false;
Fariborz Jahaniand36150d2013-07-15 21:22:08 +0000260 }
Fariborz Jahanian2bc3dda2013-07-16 21:59:42 +0000261 else if (ObjCPropertyDecl *ClassProperty = dyn_cast<ObjCPropertyDecl>(R[0])) {
262 if ((ClassProperty->getPropertyAttributes()
263 != Property->getPropertyAttributes()) ||
264 !Ctx.hasSameType(ClassProperty->getType(), Property->getType()))
265 return false;
266 }
267 else
268 return false;
Fariborz Jahaniand36150d2013-07-15 21:22:08 +0000269 }
270 // At this point, all required properties in this protocol conform to those
271 // declared in the class.
272 // Check that class implements the required methods of the protocol too.
Fariborz Jahanian5bd5aff2013-07-16 00:20:21 +0000273 if (const ObjCProtocolDecl *PDecl = Protocol->getDefinition()) {
274 if (PDecl->meth_begin() == PDecl->meth_end())
275 return false;
Fariborz Jahaniand36150d2013-07-15 21:22:08 +0000276 for (ObjCContainerDecl::method_iterator M = PDecl->meth_begin(),
277 MEnd = PDecl->meth_end(); M != MEnd; ++M) {
278 ObjCMethodDecl *MD = (*M);
Fariborz Jahanian5bd5aff2013-07-16 00:20:21 +0000279 if (MD->isImplicit())
280 continue;
Fariborz Jahaniand36150d2013-07-15 21:22:08 +0000281 if (MD->getImplementationControl() == ObjCMethodDecl::Optional)
282 continue;
283 bool match = false;
284 DeclContext::lookup_const_result R = ImpDecl->lookup(MD->getDeclName());
Fariborz Jahanian5bd5aff2013-07-16 00:20:21 +0000285 if (R.size() == 0)
286 return false;
Fariborz Jahaniand36150d2013-07-15 21:22:08 +0000287 for (unsigned I = 0, N = R.size(); I != N; ++I)
288 if (ObjCMethodDecl *ImpMD = dyn_cast<ObjCMethodDecl>(R[0]))
289 if (Ctx.ObjCMethodsAreEqual(MD, ImpMD)) {
290 match = true;
291 break;
292 }
293 if (!match)
294 return false;
295 }
Fariborz Jahanian5bd5aff2013-07-16 00:20:21 +0000296 }
Fariborz Jahaniand36150d2013-07-15 21:22:08 +0000297
298 return true;
Fariborz Jahanian9eabf452013-07-13 00:04:20 +0000299}
300
Fariborz Jahanian1be01532013-07-12 22:32:19 +0000301void ObjCMigrateASTConsumer::migrateProtocolConformance(ASTContext &Ctx,
302 const ObjCImplementationDecl *ImpDecl) {
303 const ObjCInterfaceDecl *IDecl = ImpDecl->getClassInterface();
304 if (!IDecl || ObjCProtocolDecls.empty())
305 return;
306 // Find all implicit conforming protocols for this class
307 // and make them explicit.
308 llvm::SmallPtrSet<ObjCProtocolDecl *, 8> ExplicitProtocols;
309 Ctx.CollectInheritedProtocols(IDecl, ExplicitProtocols);
Fariborz Jahanian9eabf452013-07-13 00:04:20 +0000310 llvm::SmallVector<ObjCProtocolDecl *, 8> PotentialImplicitProtocols;
Fariborz Jahanian1be01532013-07-12 22:32:19 +0000311
Fariborz Jahanian9eabf452013-07-13 00:04:20 +0000312 for (llvm::SmallPtrSet<ObjCProtocolDecl*, 32>::iterator I =
Fariborz Jahanian1be01532013-07-12 22:32:19 +0000313 ObjCProtocolDecls.begin(),
314 E = ObjCProtocolDecls.end(); I != E; ++I)
315 if (!ExplicitProtocols.count(*I))
Fariborz Jahanian9eabf452013-07-13 00:04:20 +0000316 PotentialImplicitProtocols.push_back(*I);
Fariborz Jahanian1be01532013-07-12 22:32:19 +0000317
318 if (PotentialImplicitProtocols.empty())
319 return;
Fariborz Jahanian9eabf452013-07-13 00:04:20 +0000320
321 // go through list of non-optional methods and properties in each protocol
322 // in the PotentialImplicitProtocols list. If class implements every one of the
323 // methods and properties, then this class conforms to this protocol.
324 llvm::SmallVector<ObjCProtocolDecl*, 8> ConformingProtocols;
325 for (unsigned i = 0, e = PotentialImplicitProtocols.size(); i != e; i++)
Fariborz Jahaniand36150d2013-07-15 21:22:08 +0000326 if (ClassImplementsAllMethodsAndProperties(Ctx, ImpDecl, IDecl,
Fariborz Jahanian9eabf452013-07-13 00:04:20 +0000327 PotentialImplicitProtocols[i]))
328 ConformingProtocols.push_back(PotentialImplicitProtocols[i]);
Fariborz Jahanian5bd5aff2013-07-16 00:20:21 +0000329
330 if (ConformingProtocols.empty())
331 return;
332 edit::Commit commit(*Editor);
333 edit::rewriteToObjCInterfaceDecl(IDecl, ConformingProtocols, *NSAPIObj, commit);
334 Editor->commit(commit);
Fariborz Jahanian1be01532013-07-12 22:32:19 +0000335}
336
Ted Kremenekf7639e12012-03-06 20:06:33 +0000337namespace {
338
339class RewritesReceiver : public edit::EditsReceiver {
340 Rewriter &Rewrite;
341
342public:
343 RewritesReceiver(Rewriter &Rewrite) : Rewrite(Rewrite) { }
344
345 virtual void insert(SourceLocation loc, StringRef text) {
346 Rewrite.InsertText(loc, text);
347 }
348 virtual void replace(CharSourceRange range, StringRef text) {
349 Rewrite.ReplaceText(range.getBegin(), Rewrite.getRangeSize(range), text);
350 }
351};
352
353}
354
355void ObjCMigrateASTConsumer::HandleTranslationUnit(ASTContext &Ctx) {
Fariborz Jahaniana7437f02013-07-03 23:05:00 +0000356
357 TranslationUnitDecl *TU = Ctx.getTranslationUnitDecl();
Fariborz Jahaniand83ef842013-07-09 16:59:14 +0000358 if (MigrateProperty)
359 for (DeclContext::decl_iterator D = TU->decls_begin(), DEnd = TU->decls_end();
360 D != DEnd; ++D) {
361 if (ObjCInterfaceDecl *CDecl = dyn_cast<ObjCInterfaceDecl>(*D))
362 migrateObjCInterfaceDecl(Ctx, CDecl);
Fariborz Jahanian1be01532013-07-12 22:32:19 +0000363 else if (ObjCProtocolDecl *PDecl = dyn_cast<ObjCProtocolDecl>(*D))
364 ObjCProtocolDecls.insert(PDecl);
365 else if (const ObjCImplementationDecl *ImpDecl =
366 dyn_cast<ObjCImplementationDecl>(*D))
367 migrateProtocolConformance(Ctx, ImpDecl);
Fariborz Jahaniand83ef842013-07-09 16:59:14 +0000368 }
Fariborz Jahaniana7437f02013-07-03 23:05:00 +0000369
David Blaikiebbafb8a2012-03-11 07:00:24 +0000370 Rewriter rewriter(Ctx.getSourceManager(), Ctx.getLangOpts());
Ted Kremenekf7639e12012-03-06 20:06:33 +0000371 RewritesReceiver Rec(rewriter);
372 Editor->applyRewrites(Rec);
373
374 for (Rewriter::buffer_iterator
375 I = rewriter.buffer_begin(), E = rewriter.buffer_end(); I != E; ++I) {
376 FileID FID = I->first;
377 RewriteBuffer &buf = I->second;
378 const FileEntry *file = Ctx.getSourceManager().getFileEntryForID(FID);
379 assert(file);
Dmitri Gribenkof8579502013-01-12 19:30:44 +0000380 SmallString<512> newText;
Ted Kremenekf7639e12012-03-06 20:06:33 +0000381 llvm::raw_svector_ostream vecOS(newText);
382 buf.write(vecOS);
383 vecOS.flush();
384 llvm::MemoryBuffer *memBuf = llvm::MemoryBuffer::getMemBufferCopy(
385 StringRef(newText.data(), newText.size()), file->getName());
Dmitri Gribenkof8579502013-01-12 19:30:44 +0000386 SmallString<64> filePath(file->getName());
Ted Kremenekf7639e12012-03-06 20:06:33 +0000387 FileMgr.FixupRelativePath(filePath);
388 Remapper.remap(filePath.str(), memBuf);
389 }
390
391 if (IsOutputFile) {
392 Remapper.flushToFile(MigrateDir, Ctx.getDiagnostics());
393 } else {
394 Remapper.flushToDisk(MigrateDir, Ctx.getDiagnostics());
395 }
396}
397
398bool MigrateSourceAction::BeginInvocation(CompilerInstance &CI) {
Argyrios Kyrtzidisb4822602012-05-24 16:48:23 +0000399 CI.getDiagnostics().setIgnoreAllWarnings(true);
Ted Kremenekf7639e12012-03-06 20:06:33 +0000400 return true;
401}
402
403ASTConsumer *MigrateSourceAction::CreateASTConsumer(CompilerInstance &CI,
404 StringRef InFile) {
Argyrios Kyrtzidisf3d587e2012-12-04 07:27:05 +0000405 PPConditionalDirectiveRecord *
406 PPRec = new PPConditionalDirectiveRecord(CI.getSourceManager());
407 CI.getPreprocessor().addPPCallbacks(PPRec);
Ted Kremenekf7639e12012-03-06 20:06:33 +0000408 return new ObjCMigrateASTConsumer(CI.getFrontendOpts().OutputFile,
409 /*MigrateLiterals=*/true,
410 /*MigrateSubscripting=*/true,
Fariborz Jahaniand83ef842013-07-09 16:59:14 +0000411 /*MigrateProperty*/true,
Ted Kremenekf7639e12012-03-06 20:06:33 +0000412 Remapper,
413 CI.getFileManager(),
Argyrios Kyrtzidisf3d587e2012-12-04 07:27:05 +0000414 PPRec,
Fariborz Jahaniana7437f02013-07-03 23:05:00 +0000415 CI.getPreprocessor(),
Ted Kremenekf7639e12012-03-06 20:06:33 +0000416 /*isOutputFile=*/true);
417}