1 //===--- ARCMT.cpp - Migration to ARC mode --------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "Internals.h"
11 #include "clang/AST/ASTConsumer.h"
12 #include "clang/Basic/DiagnosticCategories.h"
13 #include "clang/Frontend/ASTUnit.h"
14 #include "clang/Frontend/CompilerInstance.h"
15 #include "clang/Frontend/FrontendAction.h"
16 #include "clang/Frontend/TextDiagnosticPrinter.h"
17 #include "clang/Frontend/Utils.h"
18 #include "clang/Lex/Preprocessor.h"
19 #include "clang/Rewrite/Core/Rewriter.h"
20 #include "clang/Sema/SemaDiagnostic.h"
21 #include "clang/Serialization/ASTReader.h"
22 #include "llvm/ADT/Triple.h"
23 #include "llvm/Support/MemoryBuffer.h"
24 using namespace clang;
25 using namespace arcmt;
27 bool CapturedDiagList::clearDiagnostic(ArrayRef<unsigned> IDs,
29 if (range.isInvalid())
33 ListTy::iterator I = List.begin();
34 while (I != List.end()) {
35 FullSourceLoc diagLoc = I->getLocation();
36 if ((IDs.empty() || // empty means clear all diagnostics in the range.
37 std::find(IDs.begin(), IDs.end(), I->getID()) != IDs.end()) &&
38 !diagLoc.isBeforeInTranslationUnitThan(range.getBegin()) &&
39 (diagLoc == range.getEnd() ||
40 diagLoc.isBeforeInTranslationUnitThan(range.getEnd()))) {
42 ListTy::iterator eraseS = I++;
43 if (eraseS->getLevel() != DiagnosticsEngine::Note)
44 while (I != List.end() && I->getLevel() == DiagnosticsEngine::Note)
46 // Clear the diagnostic and any notes following it.
47 I = List.erase(eraseS, I);
57 bool CapturedDiagList::hasDiagnostic(ArrayRef<unsigned> IDs,
58 SourceRange range) const {
59 if (range.isInvalid())
62 ListTy::const_iterator I = List.begin();
63 while (I != List.end()) {
64 FullSourceLoc diagLoc = I->getLocation();
65 if ((IDs.empty() || // empty means any diagnostic in the range.
66 std::find(IDs.begin(), IDs.end(), I->getID()) != IDs.end()) &&
67 !diagLoc.isBeforeInTranslationUnitThan(range.getBegin()) &&
68 (diagLoc == range.getEnd() ||
69 diagLoc.isBeforeInTranslationUnitThan(range.getEnd()))) {
79 void CapturedDiagList::reportDiagnostics(DiagnosticsEngine &Diags) const {
80 for (ListTy::const_iterator I = List.begin(), E = List.end(); I != E; ++I)
84 bool CapturedDiagList::hasErrors() const {
85 for (ListTy::const_iterator I = List.begin(), E = List.end(); I != E; ++I)
86 if (I->getLevel() >= DiagnosticsEngine::Error)
94 class CaptureDiagnosticConsumer : public DiagnosticConsumer {
95 DiagnosticsEngine &Diags;
96 DiagnosticConsumer &DiagClient;
97 CapturedDiagList &CapturedDiags;
98 bool HasBegunSourceFile;
100 CaptureDiagnosticConsumer(DiagnosticsEngine &diags,
101 DiagnosticConsumer &client,
102 CapturedDiagList &capturedDiags)
103 : Diags(diags), DiagClient(client), CapturedDiags(capturedDiags),
104 HasBegunSourceFile(false) { }
106 virtual void BeginSourceFile(const LangOptions &Opts,
107 const Preprocessor *PP) {
108 // Pass BeginSourceFile message onto DiagClient on first call.
109 // The corresponding EndSourceFile call will be made from an
110 // explicit call to FinishCapture.
111 if (!HasBegunSourceFile) {
112 DiagClient.BeginSourceFile(Opts, PP);
113 HasBegunSourceFile = true;
117 void FinishCapture() {
118 // Call EndSourceFile on DiagClient on completion of capture to
119 // enable VerifyDiagnosticConsumer to check diagnostics *after*
120 // it has received the diagnostic list.
121 if (HasBegunSourceFile) {
122 DiagClient.EndSourceFile();
123 HasBegunSourceFile = false;
127 virtual ~CaptureDiagnosticConsumer() {
128 assert(!HasBegunSourceFile && "FinishCapture not called!");
131 virtual void HandleDiagnostic(DiagnosticsEngine::Level level,
132 const Diagnostic &Info) {
133 if (DiagnosticIDs::isARCDiagnostic(Info.getID()) ||
134 level >= DiagnosticsEngine::Error || level == DiagnosticsEngine::Note) {
135 if (Info.getLocation().isValid())
136 CapturedDiags.push_back(StoredDiagnostic(level, Info));
140 // Non-ARC warnings are ignored.
141 Diags.setLastDiagnosticIgnored();
144 DiagnosticConsumer *clone(DiagnosticsEngine &Diags) const {
145 // Just drop any diagnostics that come from cloned consumers; they'll
146 // have different source managers anyway.
147 return new IgnoringDiagConsumer();
151 } // end anonymous namespace
153 static bool HasARCRuntime(CompilerInvocation &origCI) {
154 // This duplicates some functionality from Darwin::AddDeploymentTarget
155 // but this function is well defined, so keep it decoupled from the driver
156 // and avoid unrelated complications.
157 llvm::Triple triple(origCI.getTargetOpts().Triple);
159 if (triple.getOS() == llvm::Triple::IOS)
160 return triple.getOSMajorVersion() >= 5;
162 if (triple.getOS() == llvm::Triple::Darwin)
163 return triple.getOSMajorVersion() >= 11;
165 if (triple.getOS() == llvm::Triple::MacOSX) {
166 unsigned Major, Minor, Micro;
167 triple.getOSVersion(Major, Minor, Micro);
168 return Major > 10 || (Major == 10 && Minor >= 7);
174 static CompilerInvocation *
175 createInvocationForMigration(CompilerInvocation &origCI) {
176 OwningPtr<CompilerInvocation> CInvok;
177 CInvok.reset(new CompilerInvocation(origCI));
178 PreprocessorOptions &PPOpts = CInvok->getPreprocessorOpts();
179 if (!PPOpts.ImplicitPCHInclude.empty()) {
180 // We can't use a PCH because it was likely built in non-ARC mode and we
181 // want to parse in ARC. Include the original header.
182 FileManager FileMgr(origCI.getFileSystemOpts());
183 IntrusiveRefCntPtr<DiagnosticIDs> DiagID(new DiagnosticIDs());
184 IntrusiveRefCntPtr<DiagnosticsEngine> Diags(
185 new DiagnosticsEngine(DiagID, &origCI.getDiagnosticOpts(),
186 new IgnoringDiagConsumer()));
187 std::string OriginalFile =
188 ASTReader::getOriginalSourceFile(PPOpts.ImplicitPCHInclude,
190 if (!OriginalFile.empty())
191 PPOpts.Includes.insert(PPOpts.Includes.begin(), OriginalFile);
192 PPOpts.ImplicitPCHInclude.clear();
194 // FIXME: Get the original header of a PTH as well.
195 CInvok->getPreprocessorOpts().ImplicitPTHInclude.clear();
196 std::string define = getARCMTMacroName();
198 CInvok->getPreprocessorOpts().addMacroDef(define);
199 CInvok->getLangOpts()->ObjCAutoRefCount = true;
200 CInvok->getLangOpts()->setGC(LangOptions::NonGC);
201 CInvok->getDiagnosticOpts().ErrorLimit = 0;
202 CInvok->getDiagnosticOpts().PedanticErrors = 0;
204 // Ignore -Werror flags when migrating.
205 std::vector<std::string> WarnOpts;
206 for (std::vector<std::string>::iterator
207 I = CInvok->getDiagnosticOpts().Warnings.begin(),
208 E = CInvok->getDiagnosticOpts().Warnings.end(); I != E; ++I) {
209 if (!StringRef(*I).startswith("error"))
210 WarnOpts.push_back(*I);
212 WarnOpts.push_back("error=arc-unsafe-retained-assign");
213 CInvok->getDiagnosticOpts().Warnings = llvm_move(WarnOpts);
215 CInvok->getLangOpts()->ObjCARCWeak = HasARCRuntime(origCI);
217 return CInvok.take();
220 static void emitPremigrationErrors(const CapturedDiagList &arcDiags,
221 DiagnosticOptions *diagOpts,
223 TextDiagnosticPrinter printer(llvm::errs(), diagOpts);
224 IntrusiveRefCntPtr<DiagnosticIDs> DiagID(new DiagnosticIDs());
225 IntrusiveRefCntPtr<DiagnosticsEngine> Diags(
226 new DiagnosticsEngine(DiagID, diagOpts, &printer,
227 /*ShouldOwnClient=*/false));
228 Diags->setSourceManager(&PP.getSourceManager());
230 printer.BeginSourceFile(PP.getLangOpts(), &PP);
231 arcDiags.reportDiagnostics(*Diags);
232 printer.EndSourceFile();
235 //===----------------------------------------------------------------------===//
236 // checkForManualIssues.
237 //===----------------------------------------------------------------------===//
239 bool arcmt::checkForManualIssues(CompilerInvocation &origCI,
240 const FrontendInputFile &Input,
241 DiagnosticConsumer *DiagClient,
242 bool emitPremigrationARCErrors,
243 StringRef plistOut) {
244 if (!origCI.getLangOpts()->ObjC1)
247 LangOptions::GCMode OrigGCMode = origCI.getLangOpts()->getGC();
248 bool NoNSAllocReallocError = origCI.getMigratorOpts().NoNSAllocReallocError;
249 bool NoFinalizeRemoval = origCI.getMigratorOpts().NoFinalizeRemoval;
251 std::vector<TransformFn> transforms = arcmt::getAllTransformations(OrigGCMode,
253 assert(!transforms.empty());
255 OwningPtr<CompilerInvocation> CInvok;
256 CInvok.reset(createInvocationForMigration(origCI));
257 CInvok->getFrontendOpts().Inputs.clear();
258 CInvok->getFrontendOpts().Inputs.push_back(Input);
260 CapturedDiagList capturedDiags;
263 IntrusiveRefCntPtr<DiagnosticIDs> DiagID(new DiagnosticIDs());
264 IntrusiveRefCntPtr<DiagnosticsEngine> Diags(
265 new DiagnosticsEngine(DiagID, &origCI.getDiagnosticOpts(),
266 DiagClient, /*ShouldOwnClient=*/false));
268 // Filter of all diagnostics.
269 CaptureDiagnosticConsumer errRec(*Diags, *DiagClient, capturedDiags);
270 Diags->setClient(&errRec, /*ShouldOwnClient=*/false);
272 OwningPtr<ASTUnit> Unit(
273 ASTUnit::LoadFromCompilerInvocationAction(CInvok.take(), Diags));
275 errRec.FinishCapture();
279 // Don't filter diagnostics anymore.
280 Diags->setClient(DiagClient, /*ShouldOwnClient=*/false);
282 ASTContext &Ctx = Unit->getASTContext();
284 if (Diags->hasFatalErrorOccurred()) {
286 DiagClient->BeginSourceFile(Ctx.getLangOpts(), &Unit->getPreprocessor());
287 capturedDiags.reportDiagnostics(*Diags);
288 DiagClient->EndSourceFile();
289 errRec.FinishCapture();
293 if (emitPremigrationARCErrors)
294 emitPremigrationErrors(capturedDiags, &origCI.getDiagnosticOpts(),
295 Unit->getPreprocessor());
296 if (!plistOut.empty()) {
297 SmallVector<StoredDiagnostic, 8> arcDiags;
298 for (CapturedDiagList::iterator
299 I = capturedDiags.begin(), E = capturedDiags.end(); I != E; ++I)
300 arcDiags.push_back(*I);
301 writeARCDiagsToPlist(plistOut, arcDiags,
302 Ctx.getSourceManager(), Ctx.getLangOpts());
305 // After parsing of source files ended, we want to reuse the
306 // diagnostics objects to emit further diagnostics.
307 // We call BeginSourceFile because DiagnosticConsumer requires that
308 // diagnostics with source range information are emitted only in between
309 // BeginSourceFile() and EndSourceFile().
310 DiagClient->BeginSourceFile(Ctx.getLangOpts(), &Unit->getPreprocessor());
312 // No macros will be added since we are just checking and we won't modify
314 std::vector<SourceLocation> ARCMTMacroLocs;
316 TransformActions testAct(*Diags, capturedDiags, Ctx, Unit->getPreprocessor());
317 MigrationPass pass(Ctx, OrigGCMode, Unit->getSema(), testAct, capturedDiags,
319 pass.setNSAllocReallocError(NoNSAllocReallocError);
320 pass.setNoFinalizeRemoval(NoFinalizeRemoval);
322 for (unsigned i=0, e = transforms.size(); i != e; ++i)
325 capturedDiags.reportDiagnostics(*Diags);
327 DiagClient->EndSourceFile();
328 errRec.FinishCapture();
330 // If we are migrating code that gets the '-fobjc-arc' flag, make sure
331 // to remove it so that we don't get errors from normal compilation.
332 origCI.getLangOpts()->ObjCAutoRefCount = false;
334 return capturedDiags.hasErrors() || testAct.hasReportedErrors();
337 //===----------------------------------------------------------------------===//
338 // applyTransformations.
339 //===----------------------------------------------------------------------===//
341 static bool applyTransforms(CompilerInvocation &origCI,
342 const FrontendInputFile &Input,
343 DiagnosticConsumer *DiagClient,
345 bool emitPremigrationARCErrors,
346 StringRef plistOut) {
347 if (!origCI.getLangOpts()->ObjC1)
350 LangOptions::GCMode OrigGCMode = origCI.getLangOpts()->getGC();
352 // Make sure checking is successful first.
353 CompilerInvocation CInvokForCheck(origCI);
354 if (arcmt::checkForManualIssues(CInvokForCheck, Input, DiagClient,
355 emitPremigrationARCErrors, plistOut))
358 CompilerInvocation CInvok(origCI);
359 CInvok.getFrontendOpts().Inputs.clear();
360 CInvok.getFrontendOpts().Inputs.push_back(Input);
362 MigrationProcess migration(CInvok, DiagClient, outputDir);
363 bool NoFinalizeRemoval = origCI.getMigratorOpts().NoFinalizeRemoval;
365 std::vector<TransformFn> transforms = arcmt::getAllTransformations(OrigGCMode,
367 assert(!transforms.empty());
369 for (unsigned i=0, e = transforms.size(); i != e; ++i) {
370 bool err = migration.applyTransform(transforms[i]);
371 if (err) return true;
374 IntrusiveRefCntPtr<DiagnosticIDs> DiagID(new DiagnosticIDs());
375 IntrusiveRefCntPtr<DiagnosticsEngine> Diags(
376 new DiagnosticsEngine(DiagID, &origCI.getDiagnosticOpts(),
377 DiagClient, /*ShouldOwnClient=*/false));
379 if (outputDir.empty()) {
380 origCI.getLangOpts()->ObjCAutoRefCount = true;
381 return migration.getRemapper().overwriteOriginal(*Diags);
383 // If we are migrating code that gets the '-fobjc-arc' flag, make sure
384 // to remove it so that we don't get errors from normal compilation.
385 origCI.getLangOpts()->ObjCAutoRefCount = false;
386 return migration.getRemapper().flushToDisk(outputDir, *Diags);
390 bool arcmt::applyTransformations(CompilerInvocation &origCI,
391 const FrontendInputFile &Input,
392 DiagnosticConsumer *DiagClient) {
393 return applyTransforms(origCI, Input, DiagClient,
394 StringRef(), false, StringRef());
397 bool arcmt::migrateWithTemporaryFiles(CompilerInvocation &origCI,
398 const FrontendInputFile &Input,
399 DiagnosticConsumer *DiagClient,
401 bool emitPremigrationARCErrors,
402 StringRef plistOut) {
403 assert(!outputDir.empty() && "Expected output directory path");
404 return applyTransforms(origCI, Input, DiagClient,
405 outputDir, emitPremigrationARCErrors, plistOut);
408 bool arcmt::getFileRemappings(std::vector<std::pair<std::string,std::string> > &
411 DiagnosticConsumer *DiagClient) {
412 assert(!outputDir.empty());
414 IntrusiveRefCntPtr<DiagnosticIDs> DiagID(new DiagnosticIDs());
415 IntrusiveRefCntPtr<DiagnosticsEngine> Diags(
416 new DiagnosticsEngine(DiagID, new DiagnosticOptions,
417 DiagClient, /*ShouldOwnClient=*/false));
419 FileRemapper remapper;
420 bool err = remapper.initFromDisk(outputDir, *Diags,
421 /*ignoreIfFilesChanged=*/true);
425 PreprocessorOptions PPOpts;
426 remapper.applyMappings(PPOpts);
427 remap = PPOpts.RemappedFiles;
432 bool arcmt::getFileRemappingsFromFileList(
433 std::vector<std::pair<std::string,std::string> > &remap,
434 ArrayRef<StringRef> remapFiles,
435 DiagnosticConsumer *DiagClient) {
436 bool hasErrorOccurred = false;
437 llvm::StringMap<bool> Uniquer;
439 IntrusiveRefCntPtr<DiagnosticIDs> DiagID(new DiagnosticIDs());
440 IntrusiveRefCntPtr<DiagnosticsEngine> Diags(
441 new DiagnosticsEngine(DiagID, new DiagnosticOptions,
442 DiagClient, /*ShouldOwnClient=*/false));
444 for (ArrayRef<StringRef>::iterator
445 I = remapFiles.begin(), E = remapFiles.end(); I != E; ++I) {
448 FileRemapper remapper;
449 bool err = remapper.initFromFile(file, *Diags,
450 /*ignoreIfFilesChanged=*/true);
451 hasErrorOccurred = hasErrorOccurred || err;
455 PreprocessorOptions PPOpts;
456 remapper.applyMappings(PPOpts);
457 for (PreprocessorOptions::remapped_file_iterator
458 RI = PPOpts.remapped_file_begin(), RE = PPOpts.remapped_file_end();
460 bool &inserted = Uniquer[RI->first];
464 remap.push_back(*RI);
468 return hasErrorOccurred;
471 //===----------------------------------------------------------------------===//
472 // CollectTransformActions.
473 //===----------------------------------------------------------------------===//
477 class ARCMTMacroTrackerPPCallbacks : public PPCallbacks {
478 std::vector<SourceLocation> &ARCMTMacroLocs;
481 ARCMTMacroTrackerPPCallbacks(std::vector<SourceLocation> &ARCMTMacroLocs)
482 : ARCMTMacroLocs(ARCMTMacroLocs) { }
484 virtual void MacroExpands(const Token &MacroNameTok, const MacroDirective *MD,
486 if (MacroNameTok.getIdentifierInfo()->getName() == getARCMTMacroName())
487 ARCMTMacroLocs.push_back(MacroNameTok.getLocation());
491 class ARCMTMacroTrackerAction : public ASTFrontendAction {
492 std::vector<SourceLocation> &ARCMTMacroLocs;
495 ARCMTMacroTrackerAction(std::vector<SourceLocation> &ARCMTMacroLocs)
496 : ARCMTMacroLocs(ARCMTMacroLocs) { }
498 virtual ASTConsumer *CreateASTConsumer(CompilerInstance &CI,
500 CI.getPreprocessor().addPPCallbacks(
501 new ARCMTMacroTrackerPPCallbacks(ARCMTMacroLocs));
502 return new ASTConsumer();
506 class RewritesApplicator : public TransformActions::RewriteReceiver {
508 MigrationProcess::RewriteListener *Listener;
511 RewritesApplicator(Rewriter &rewriter, ASTContext &ctx,
512 MigrationProcess::RewriteListener *listener)
513 : rewriter(rewriter), Listener(listener) {
515 Listener->start(ctx);
517 ~RewritesApplicator() {
522 virtual void insert(SourceLocation loc, StringRef text) {
523 bool err = rewriter.InsertText(loc, text, /*InsertAfter=*/true,
524 /*indentNewLines=*/true);
525 if (!err && Listener)
526 Listener->insert(loc, text);
529 virtual void remove(CharSourceRange range) {
530 Rewriter::RewriteOptions removeOpts;
531 removeOpts.IncludeInsertsAtBeginOfRange = false;
532 removeOpts.IncludeInsertsAtEndOfRange = false;
533 removeOpts.RemoveLineIfEmpty = true;
535 bool err = rewriter.RemoveText(range, removeOpts);
536 if (!err && Listener)
537 Listener->remove(range);
540 virtual void increaseIndentation(CharSourceRange range,
541 SourceLocation parentIndent) {
542 rewriter.IncreaseIndentation(range, parentIndent);
546 } // end anonymous namespace.
548 /// \brief Anchor for VTable.
549 MigrationProcess::RewriteListener::~RewriteListener() { }
551 MigrationProcess::MigrationProcess(const CompilerInvocation &CI,
552 DiagnosticConsumer *diagClient,
554 : OrigCI(CI), DiagClient(diagClient) {
555 if (!outputDir.empty()) {
556 IntrusiveRefCntPtr<DiagnosticIDs> DiagID(new DiagnosticIDs());
557 IntrusiveRefCntPtr<DiagnosticsEngine> Diags(
558 new DiagnosticsEngine(DiagID, &CI.getDiagnosticOpts(),
559 DiagClient, /*ShouldOwnClient=*/false));
560 Remapper.initFromDisk(outputDir, *Diags, /*ignoreIfFilesChanges=*/true);
564 bool MigrationProcess::applyTransform(TransformFn trans,
565 RewriteListener *listener) {
566 OwningPtr<CompilerInvocation> CInvok;
567 CInvok.reset(createInvocationForMigration(OrigCI));
568 CInvok->getDiagnosticOpts().IgnoreWarnings = true;
570 Remapper.applyMappings(CInvok->getPreprocessorOpts());
572 CapturedDiagList capturedDiags;
573 std::vector<SourceLocation> ARCMTMacroLocs;
576 IntrusiveRefCntPtr<DiagnosticIDs> DiagID(new DiagnosticIDs());
577 IntrusiveRefCntPtr<DiagnosticsEngine> Diags(
578 new DiagnosticsEngine(DiagID, new DiagnosticOptions,
579 DiagClient, /*ShouldOwnClient=*/false));
581 // Filter of all diagnostics.
582 CaptureDiagnosticConsumer errRec(*Diags, *DiagClient, capturedDiags);
583 Diags->setClient(&errRec, /*ShouldOwnClient=*/false);
585 OwningPtr<ARCMTMacroTrackerAction> ASTAction;
586 ASTAction.reset(new ARCMTMacroTrackerAction(ARCMTMacroLocs));
588 OwningPtr<ASTUnit> Unit(
589 ASTUnit::LoadFromCompilerInvocationAction(CInvok.take(), Diags,
592 errRec.FinishCapture();
595 Unit->setOwnsRemappedFileBuffers(false); // FileRemapper manages that.
597 // Don't filter diagnostics anymore.
598 Diags->setClient(DiagClient, /*ShouldOwnClient=*/false);
600 ASTContext &Ctx = Unit->getASTContext();
602 if (Diags->hasFatalErrorOccurred()) {
604 DiagClient->BeginSourceFile(Ctx.getLangOpts(), &Unit->getPreprocessor());
605 capturedDiags.reportDiagnostics(*Diags);
606 DiagClient->EndSourceFile();
607 errRec.FinishCapture();
611 // After parsing of source files ended, we want to reuse the
612 // diagnostics objects to emit further diagnostics.
613 // We call BeginSourceFile because DiagnosticConsumer requires that
614 // diagnostics with source range information are emitted only in between
615 // BeginSourceFile() and EndSourceFile().
616 DiagClient->BeginSourceFile(Ctx.getLangOpts(), &Unit->getPreprocessor());
618 Rewriter rewriter(Ctx.getSourceManager(), Ctx.getLangOpts());
619 TransformActions TA(*Diags, capturedDiags, Ctx, Unit->getPreprocessor());
620 MigrationPass pass(Ctx, OrigCI.getLangOpts()->getGC(),
621 Unit->getSema(), TA, capturedDiags, ARCMTMacroLocs);
626 RewritesApplicator applicator(rewriter, Ctx, listener);
627 TA.applyRewrites(applicator);
630 DiagClient->EndSourceFile();
631 errRec.FinishCapture();
633 if (DiagClient->getNumErrors())
636 for (Rewriter::buffer_iterator
637 I = rewriter.buffer_begin(), E = rewriter.buffer_end(); I != E; ++I) {
638 FileID FID = I->first;
639 RewriteBuffer &buf = I->second;
640 const FileEntry *file = Ctx.getSourceManager().getFileEntryForID(FID);
642 std::string newFname = file->getName();
643 newFname += "-trans";
644 SmallString<512> newText;
645 llvm::raw_svector_ostream vecOS(newText);
648 llvm::MemoryBuffer *memBuf = llvm::MemoryBuffer::getMemBufferCopy(
649 StringRef(newText.data(), newText.size()), newFname);
650 SmallString<64> filePath(file->getName());
651 Unit->getFileManager().FixupRelativePath(filePath);
652 Remapper.remap(filePath.str(), memBuf);