blob: dd210264582e5d2b9707bbb50bcdf69ffd5a6c3f [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 Jahanian5bd5aff2013-07-16 00:20:21 +0000253 if (R.size() == 0)
254 return false;
Fariborz Jahaniand36150d2013-07-15 21:22:08 +0000255 for (unsigned I = 0, N = R.size(); I != N; ++I) {
256 if (ObjCPropertyDecl *ClassProperty = dyn_cast<ObjCPropertyDecl>(R[0])) {
257 if (ClassProperty->getPropertyAttributes()
258 != Property->getPropertyAttributes())
259 return false;
260 if (!Ctx.hasSameType(ClassProperty->getType(), Property->getType()))
261 return false;
262 }
263 }
264 }
265 // At this point, all required properties in this protocol conform to those
266 // declared in the class.
267 // Check that class implements the required methods of the protocol too.
Fariborz Jahanian5bd5aff2013-07-16 00:20:21 +0000268 if (const ObjCProtocolDecl *PDecl = Protocol->getDefinition()) {
269 if (PDecl->meth_begin() == PDecl->meth_end())
270 return false;
Fariborz Jahaniand36150d2013-07-15 21:22:08 +0000271 for (ObjCContainerDecl::method_iterator M = PDecl->meth_begin(),
272 MEnd = PDecl->meth_end(); M != MEnd; ++M) {
273 ObjCMethodDecl *MD = (*M);
Fariborz Jahanian5bd5aff2013-07-16 00:20:21 +0000274 if (MD->isImplicit())
275 continue;
Fariborz Jahaniand36150d2013-07-15 21:22:08 +0000276 if (MD->getImplementationControl() == ObjCMethodDecl::Optional)
277 continue;
278 bool match = false;
279 DeclContext::lookup_const_result R = ImpDecl->lookup(MD->getDeclName());
Fariborz Jahanian5bd5aff2013-07-16 00:20:21 +0000280 if (R.size() == 0)
281 return false;
Fariborz Jahaniand36150d2013-07-15 21:22:08 +0000282 for (unsigned I = 0, N = R.size(); I != N; ++I)
283 if (ObjCMethodDecl *ImpMD = dyn_cast<ObjCMethodDecl>(R[0]))
284 if (Ctx.ObjCMethodsAreEqual(MD, ImpMD)) {
285 match = true;
286 break;
287 }
288 if (!match)
289 return false;
290 }
Fariborz Jahanian5bd5aff2013-07-16 00:20:21 +0000291 }
Fariborz Jahaniand36150d2013-07-15 21:22:08 +0000292
293 return true;
Fariborz Jahanian9eabf452013-07-13 00:04:20 +0000294}
295
Fariborz Jahanian1be01532013-07-12 22:32:19 +0000296void ObjCMigrateASTConsumer::migrateProtocolConformance(ASTContext &Ctx,
297 const ObjCImplementationDecl *ImpDecl) {
298 const ObjCInterfaceDecl *IDecl = ImpDecl->getClassInterface();
299 if (!IDecl || ObjCProtocolDecls.empty())
300 return;
301 // Find all implicit conforming protocols for this class
302 // and make them explicit.
303 llvm::SmallPtrSet<ObjCProtocolDecl *, 8> ExplicitProtocols;
304 Ctx.CollectInheritedProtocols(IDecl, ExplicitProtocols);
Fariborz Jahanian9eabf452013-07-13 00:04:20 +0000305 llvm::SmallVector<ObjCProtocolDecl *, 8> PotentialImplicitProtocols;
Fariborz Jahanian1be01532013-07-12 22:32:19 +0000306
Fariborz Jahanian9eabf452013-07-13 00:04:20 +0000307 for (llvm::SmallPtrSet<ObjCProtocolDecl*, 32>::iterator I =
Fariborz Jahanian1be01532013-07-12 22:32:19 +0000308 ObjCProtocolDecls.begin(),
309 E = ObjCProtocolDecls.end(); I != E; ++I)
310 if (!ExplicitProtocols.count(*I))
Fariborz Jahanian9eabf452013-07-13 00:04:20 +0000311 PotentialImplicitProtocols.push_back(*I);
Fariborz Jahanian1be01532013-07-12 22:32:19 +0000312
313 if (PotentialImplicitProtocols.empty())
314 return;
Fariborz Jahanian9eabf452013-07-13 00:04:20 +0000315
316 // go through list of non-optional methods and properties in each protocol
317 // in the PotentialImplicitProtocols list. If class implements every one of the
318 // methods and properties, then this class conforms to this protocol.
319 llvm::SmallVector<ObjCProtocolDecl*, 8> ConformingProtocols;
320 for (unsigned i = 0, e = PotentialImplicitProtocols.size(); i != e; i++)
Fariborz Jahaniand36150d2013-07-15 21:22:08 +0000321 if (ClassImplementsAllMethodsAndProperties(Ctx, ImpDecl, IDecl,
Fariborz Jahanian9eabf452013-07-13 00:04:20 +0000322 PotentialImplicitProtocols[i]))
323 ConformingProtocols.push_back(PotentialImplicitProtocols[i]);
Fariborz Jahanian5bd5aff2013-07-16 00:20:21 +0000324
325 if (ConformingProtocols.empty())
326 return;
327 edit::Commit commit(*Editor);
328 edit::rewriteToObjCInterfaceDecl(IDecl, ConformingProtocols, *NSAPIObj, commit);
329 Editor->commit(commit);
Fariborz Jahanian1be01532013-07-12 22:32:19 +0000330}
331
Ted Kremenekf7639e12012-03-06 20:06:33 +0000332namespace {
333
334class RewritesReceiver : public edit::EditsReceiver {
335 Rewriter &Rewrite;
336
337public:
338 RewritesReceiver(Rewriter &Rewrite) : Rewrite(Rewrite) { }
339
340 virtual void insert(SourceLocation loc, StringRef text) {
341 Rewrite.InsertText(loc, text);
342 }
343 virtual void replace(CharSourceRange range, StringRef text) {
344 Rewrite.ReplaceText(range.getBegin(), Rewrite.getRangeSize(range), text);
345 }
346};
347
348}
349
350void ObjCMigrateASTConsumer::HandleTranslationUnit(ASTContext &Ctx) {
Fariborz Jahaniana7437f02013-07-03 23:05:00 +0000351
352 TranslationUnitDecl *TU = Ctx.getTranslationUnitDecl();
Fariborz Jahaniand83ef842013-07-09 16:59:14 +0000353 if (MigrateProperty)
354 for (DeclContext::decl_iterator D = TU->decls_begin(), DEnd = TU->decls_end();
355 D != DEnd; ++D) {
356 if (ObjCInterfaceDecl *CDecl = dyn_cast<ObjCInterfaceDecl>(*D))
357 migrateObjCInterfaceDecl(Ctx, CDecl);
Fariborz Jahanian1be01532013-07-12 22:32:19 +0000358 else if (ObjCProtocolDecl *PDecl = dyn_cast<ObjCProtocolDecl>(*D))
359 ObjCProtocolDecls.insert(PDecl);
360 else if (const ObjCImplementationDecl *ImpDecl =
361 dyn_cast<ObjCImplementationDecl>(*D))
362 migrateProtocolConformance(Ctx, ImpDecl);
Fariborz Jahaniand83ef842013-07-09 16:59:14 +0000363 }
Fariborz Jahaniana7437f02013-07-03 23:05:00 +0000364
David Blaikiebbafb8a2012-03-11 07:00:24 +0000365 Rewriter rewriter(Ctx.getSourceManager(), Ctx.getLangOpts());
Ted Kremenekf7639e12012-03-06 20:06:33 +0000366 RewritesReceiver Rec(rewriter);
367 Editor->applyRewrites(Rec);
368
369 for (Rewriter::buffer_iterator
370 I = rewriter.buffer_begin(), E = rewriter.buffer_end(); I != E; ++I) {
371 FileID FID = I->first;
372 RewriteBuffer &buf = I->second;
373 const FileEntry *file = Ctx.getSourceManager().getFileEntryForID(FID);
374 assert(file);
Dmitri Gribenkof8579502013-01-12 19:30:44 +0000375 SmallString<512> newText;
Ted Kremenekf7639e12012-03-06 20:06:33 +0000376 llvm::raw_svector_ostream vecOS(newText);
377 buf.write(vecOS);
378 vecOS.flush();
379 llvm::MemoryBuffer *memBuf = llvm::MemoryBuffer::getMemBufferCopy(
380 StringRef(newText.data(), newText.size()), file->getName());
Dmitri Gribenkof8579502013-01-12 19:30:44 +0000381 SmallString<64> filePath(file->getName());
Ted Kremenekf7639e12012-03-06 20:06:33 +0000382 FileMgr.FixupRelativePath(filePath);
383 Remapper.remap(filePath.str(), memBuf);
384 }
385
386 if (IsOutputFile) {
387 Remapper.flushToFile(MigrateDir, Ctx.getDiagnostics());
388 } else {
389 Remapper.flushToDisk(MigrateDir, Ctx.getDiagnostics());
390 }
391}
392
393bool MigrateSourceAction::BeginInvocation(CompilerInstance &CI) {
Argyrios Kyrtzidisb4822602012-05-24 16:48:23 +0000394 CI.getDiagnostics().setIgnoreAllWarnings(true);
Ted Kremenekf7639e12012-03-06 20:06:33 +0000395 return true;
396}
397
398ASTConsumer *MigrateSourceAction::CreateASTConsumer(CompilerInstance &CI,
399 StringRef InFile) {
Argyrios Kyrtzidisf3d587e2012-12-04 07:27:05 +0000400 PPConditionalDirectiveRecord *
401 PPRec = new PPConditionalDirectiveRecord(CI.getSourceManager());
402 CI.getPreprocessor().addPPCallbacks(PPRec);
Ted Kremenekf7639e12012-03-06 20:06:33 +0000403 return new ObjCMigrateASTConsumer(CI.getFrontendOpts().OutputFile,
404 /*MigrateLiterals=*/true,
405 /*MigrateSubscripting=*/true,
Fariborz Jahaniand83ef842013-07-09 16:59:14 +0000406 /*MigrateProperty*/true,
Ted Kremenekf7639e12012-03-06 20:06:33 +0000407 Remapper,
408 CI.getFileManager(),
Argyrios Kyrtzidisf3d587e2012-12-04 07:27:05 +0000409 PPRec,
Fariborz Jahaniana7437f02013-07-03 23:05:00 +0000410 CI.getPreprocessor(),
Ted Kremenekf7639e12012-03-06 20:06:33 +0000411 /*isOutputFile=*/true);
412}