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/Frontend/ASTUnit.h"
12 #include "clang/Frontend/CompilerInstance.h"
13 #include "clang/Frontend/FrontendAction.h"
14 #include "clang/Frontend/TextDiagnosticPrinter.h"
15 #include "clang/Frontend/Utils.h"
16 #include "clang/AST/ASTConsumer.h"
17 #include "clang/Rewrite/Rewriter.h"
18 #include "clang/Sema/SemaDiagnostic.h"
19 #include "clang/Basic/DiagnosticCategories.h"
20 #include "clang/Lex/Preprocessor.h"
21 #include "llvm/Support/MemoryBuffer.h"
22 #include "llvm/ADT/Triple.h"
23 using namespace clang;
24 using namespace arcmt;
26 bool CapturedDiagList::clearDiagnostic(ArrayRef<unsigned> IDs,
28 if (range.isInvalid())
32 ListTy::iterator I = List.begin();
33 while (I != List.end()) {
34 FullSourceLoc diagLoc = I->getLocation();
35 if ((IDs.empty() || // empty means clear all diagnostics in the range.
36 std::find(IDs.begin(), IDs.end(), I->getID()) != IDs.end()) &&
37 !diagLoc.isBeforeInTranslationUnitThan(range.getBegin()) &&
38 (diagLoc == range.getEnd() ||
39 diagLoc.isBeforeInTranslationUnitThan(range.getEnd()))) {
41 ListTy::iterator eraseS = I++;
42 while (I != List.end() && I->getLevel() == DiagnosticsEngine::Note)
44 // Clear the diagnostic and any notes following it.
45 List.erase(eraseS, I);
55 bool CapturedDiagList::hasDiagnostic(ArrayRef<unsigned> IDs,
56 SourceRange range) const {
57 if (range.isInvalid())
60 ListTy::const_iterator I = List.begin();
61 while (I != List.end()) {
62 FullSourceLoc diagLoc = I->getLocation();
63 if ((IDs.empty() || // empty means any diagnostic in the range.
64 std::find(IDs.begin(), IDs.end(), I->getID()) != IDs.end()) &&
65 !diagLoc.isBeforeInTranslationUnitThan(range.getBegin()) &&
66 (diagLoc == range.getEnd() ||
67 diagLoc.isBeforeInTranslationUnitThan(range.getEnd()))) {
77 void CapturedDiagList::reportDiagnostics(DiagnosticsEngine &Diags) const {
78 for (ListTy::const_iterator I = List.begin(), E = List.end(); I != E; ++I)
82 bool CapturedDiagList::hasErrors() const {
83 for (ListTy::const_iterator I = List.begin(), E = List.end(); I != E; ++I)
84 if (I->getLevel() >= DiagnosticsEngine::Error)
92 class CaptureDiagnosticConsumer : public DiagnosticConsumer {
93 DiagnosticsEngine &Diags;
94 DiagnosticConsumer &DiagClient;
95 CapturedDiagList &CapturedDiags;
96 bool HasBegunSourceFile;
98 CaptureDiagnosticConsumer(DiagnosticsEngine &diags,
99 DiagnosticConsumer &client,
100 CapturedDiagList &capturedDiags)
101 : Diags(diags), DiagClient(client), CapturedDiags(capturedDiags),
102 HasBegunSourceFile(false) { }
104 virtual void BeginSourceFile(const LangOptions &Opts,
105 const Preprocessor *PP) {
106 // Pass BeginSourceFile message onto DiagClient on first call.
107 // The corresponding EndSourceFile call will be made from an
108 // explicit call to FinishCapture.
109 if (!HasBegunSourceFile) {
110 DiagClient.BeginSourceFile(Opts, PP);
111 HasBegunSourceFile = true;
115 void FinishCapture() {
116 // Call EndSourceFile on DiagClient on completion of capture to
117 // enable VerifyDiagnosticConsumer to check diagnostics *after*
118 // it has received the diagnostic list.
119 if (HasBegunSourceFile) {
120 DiagClient.EndSourceFile();
121 HasBegunSourceFile = false;
125 virtual ~CaptureDiagnosticConsumer() {
126 assert(!HasBegunSourceFile && "FinishCapture not called!");
129 virtual void HandleDiagnostic(DiagnosticsEngine::Level level,
130 const Diagnostic &Info) {
131 if (DiagnosticIDs::isARCDiagnostic(Info.getID()) ||
132 level >= DiagnosticsEngine::Error || level == DiagnosticsEngine::Note) {
133 CapturedDiags.push_back(StoredDiagnostic(level, Info));
137 // Non-ARC warnings are ignored.
138 Diags.setLastDiagnosticIgnored();
141 DiagnosticConsumer *clone(DiagnosticsEngine &Diags) const {
142 // Just drop any diagnostics that come from cloned consumers; they'll
143 // have different source managers anyway.
144 return new IgnoringDiagConsumer();
148 } // end anonymous namespace
150 static inline StringRef SimulatorVersionDefineName() {
151 return "__IPHONE_OS_VERSION_MIN_REQUIRED=";
154 /// \brief Parse the simulator version define:
155 /// __IPHONE_OS_VERSION_MIN_REQUIRED=([0-9])([0-9][0-9])([0-9][0-9])
156 // and return the grouped values as integers, e.g:
157 // __IPHONE_OS_VERSION_MIN_REQUIRED=40201
158 // will return Major=4, Minor=2, Micro=1.
159 static bool GetVersionFromSimulatorDefine(StringRef define,
160 unsigned &Major, unsigned &Minor,
162 assert(define.startswith(SimulatorVersionDefineName()));
163 StringRef name, version;
164 llvm::tie(name, version) = define.split('=');
167 std::string verstr = version.str();
169 unsigned num = (unsigned) strtol(verstr.c_str(), &end, 10);
179 static bool HasARCRuntime(CompilerInvocation &origCI) {
180 // This duplicates some functionality from Darwin::AddDeploymentTarget
181 // but this function is well defined, so keep it decoupled from the driver
182 // and avoid unrelated complications.
184 for (unsigned i = 0, e = origCI.getPreprocessorOpts().Macros.size();
186 StringRef define = origCI.getPreprocessorOpts().Macros[i].first;
187 bool isUndef = origCI.getPreprocessorOpts().Macros[i].second;
190 if (!define.startswith(SimulatorVersionDefineName()))
192 unsigned Major = 0, Minor = 0, Micro = 0;
193 if (GetVersionFromSimulatorDefine(define, Major, Minor, Micro) &&
194 Major < 10 && Minor < 100 && Micro < 100)
198 llvm::Triple triple(origCI.getTargetOpts().Triple);
200 if (triple.getOS() == llvm::Triple::IOS)
201 return triple.getOSMajorVersion() >= 5;
203 if (triple.getOS() == llvm::Triple::Darwin)
204 return triple.getOSMajorVersion() >= 11;
206 if (triple.getOS() == llvm::Triple::MacOSX) {
207 unsigned Major, Minor, Micro;
208 triple.getOSVersion(Major, Minor, Micro);
209 return Major > 10 || (Major == 10 && Minor >= 7);
215 static CompilerInvocation *
216 createInvocationForMigration(CompilerInvocation &origCI) {
217 OwningPtr<CompilerInvocation> CInvok;
218 CInvok.reset(new CompilerInvocation(origCI));
219 CInvok->getPreprocessorOpts().ImplicitPCHInclude = std::string();
220 CInvok->getPreprocessorOpts().ImplicitPTHInclude = std::string();
221 std::string define = getARCMTMacroName();
223 CInvok->getPreprocessorOpts().addMacroDef(define);
224 CInvok->getLangOpts()->ObjCAutoRefCount = true;
225 CInvok->getLangOpts()->setGC(LangOptions::NonGC);
226 CInvok->getDiagnosticOpts().ErrorLimit = 0;
227 CInvok->getDiagnosticOpts().PedanticErrors = 0;
229 // Ignore -Werror flags when migrating.
230 std::vector<std::string> WarnOpts;
231 for (std::vector<std::string>::iterator
232 I = CInvok->getDiagnosticOpts().Warnings.begin(),
233 E = CInvok->getDiagnosticOpts().Warnings.end(); I != E; ++I) {
234 if (!StringRef(*I).startswith("error"))
235 WarnOpts.push_back(*I);
237 WarnOpts.push_back("error=arc-unsafe-retained-assign");
238 CInvok->getDiagnosticOpts().Warnings = llvm_move(WarnOpts);
240 CInvok->getLangOpts()->ObjCRuntimeHasWeak = HasARCRuntime(origCI);
242 return CInvok.take();
245 static void emitPremigrationErrors(const CapturedDiagList &arcDiags,
246 const DiagnosticOptions &diagOpts,
248 TextDiagnosticPrinter printer(llvm::errs(), diagOpts);
249 IntrusiveRefCntPtr<DiagnosticIDs> DiagID(new DiagnosticIDs());
250 IntrusiveRefCntPtr<DiagnosticsEngine> Diags(
251 new DiagnosticsEngine(DiagID, &printer, /*ShouldOwnClient=*/false));
252 Diags->setSourceManager(&PP.getSourceManager());
254 printer.BeginSourceFile(PP.getLangOpts(), &PP);
255 arcDiags.reportDiagnostics(*Diags);
256 printer.EndSourceFile();
259 //===----------------------------------------------------------------------===//
260 // checkForManualIssues.
261 //===----------------------------------------------------------------------===//
263 bool arcmt::checkForManualIssues(CompilerInvocation &origCI,
264 const FrontendInputFile &Input,
265 DiagnosticConsumer *DiagClient,
266 bool emitPremigrationARCErrors,
267 StringRef plistOut) {
268 if (!origCI.getLangOpts()->ObjC1)
271 LangOptions::GCMode OrigGCMode = origCI.getLangOpts()->getGC();
272 bool NoNSAllocReallocError = origCI.getMigratorOpts().NoNSAllocReallocError;
273 bool NoFinalizeRemoval = origCI.getMigratorOpts().NoFinalizeRemoval;
275 std::vector<TransformFn> transforms = arcmt::getAllTransformations(OrigGCMode,
277 assert(!transforms.empty());
279 OwningPtr<CompilerInvocation> CInvok;
280 CInvok.reset(createInvocationForMigration(origCI));
281 CInvok->getFrontendOpts().Inputs.clear();
282 CInvok->getFrontendOpts().Inputs.push_back(Input);
284 CapturedDiagList capturedDiags;
287 IntrusiveRefCntPtr<DiagnosticIDs> DiagID(new DiagnosticIDs());
288 IntrusiveRefCntPtr<DiagnosticsEngine> Diags(
289 new DiagnosticsEngine(DiagID, DiagClient, /*ShouldOwnClient=*/false));
291 // Filter of all diagnostics.
292 CaptureDiagnosticConsumer errRec(*Diags, *DiagClient, capturedDiags);
293 Diags->setClient(&errRec, /*ShouldOwnClient=*/false);
295 OwningPtr<ASTUnit> Unit(
296 ASTUnit::LoadFromCompilerInvocationAction(CInvok.take(), Diags));
298 errRec.FinishCapture();
302 // Don't filter diagnostics anymore.
303 Diags->setClient(DiagClient, /*ShouldOwnClient=*/false);
305 ASTContext &Ctx = Unit->getASTContext();
307 if (Diags->hasFatalErrorOccurred()) {
309 DiagClient->BeginSourceFile(Ctx.getLangOpts(), &Unit->getPreprocessor());
310 capturedDiags.reportDiagnostics(*Diags);
311 DiagClient->EndSourceFile();
312 errRec.FinishCapture();
316 if (emitPremigrationARCErrors)
317 emitPremigrationErrors(capturedDiags, origCI.getDiagnosticOpts(),
318 Unit->getPreprocessor());
319 if (!plistOut.empty()) {
320 SmallVector<StoredDiagnostic, 8> arcDiags;
321 for (CapturedDiagList::iterator
322 I = capturedDiags.begin(), E = capturedDiags.end(); I != E; ++I)
323 arcDiags.push_back(*I);
324 writeARCDiagsToPlist(plistOut, arcDiags,
325 Ctx.getSourceManager(), Ctx.getLangOpts());
328 // After parsing of source files ended, we want to reuse the
329 // diagnostics objects to emit further diagnostics.
330 // We call BeginSourceFile because DiagnosticConsumer requires that
331 // diagnostics with source range information are emitted only in between
332 // BeginSourceFile() and EndSourceFile().
333 DiagClient->BeginSourceFile(Ctx.getLangOpts(), &Unit->getPreprocessor());
335 // No macros will be added since we are just checking and we won't modify
337 std::vector<SourceLocation> ARCMTMacroLocs;
339 TransformActions testAct(*Diags, capturedDiags, Ctx, Unit->getPreprocessor());
340 MigrationPass pass(Ctx, OrigGCMode, Unit->getSema(), testAct, ARCMTMacroLocs);
341 pass.setNSAllocReallocError(NoNSAllocReallocError);
342 pass.setNoFinalizeRemoval(NoFinalizeRemoval);
344 for (unsigned i=0, e = transforms.size(); i != e; ++i)
347 capturedDiags.reportDiagnostics(*Diags);
349 DiagClient->EndSourceFile();
350 errRec.FinishCapture();
352 // If we are migrating code that gets the '-fobjc-arc' flag, make sure
353 // to remove it so that we don't get errors from normal compilation.
354 origCI.getLangOpts()->ObjCAutoRefCount = false;
356 return capturedDiags.hasErrors() || testAct.hasReportedErrors();
359 //===----------------------------------------------------------------------===//
360 // applyTransformations.
361 //===----------------------------------------------------------------------===//
363 static bool applyTransforms(CompilerInvocation &origCI,
364 const FrontendInputFile &Input,
365 DiagnosticConsumer *DiagClient,
367 bool emitPremigrationARCErrors,
368 StringRef plistOut) {
369 if (!origCI.getLangOpts()->ObjC1)
372 LangOptions::GCMode OrigGCMode = origCI.getLangOpts()->getGC();
374 // Make sure checking is successful first.
375 CompilerInvocation CInvokForCheck(origCI);
376 if (arcmt::checkForManualIssues(CInvokForCheck, Input, DiagClient,
377 emitPremigrationARCErrors, plistOut))
380 CompilerInvocation CInvok(origCI);
381 CInvok.getFrontendOpts().Inputs.clear();
382 CInvok.getFrontendOpts().Inputs.push_back(Input);
384 MigrationProcess migration(CInvok, DiagClient, outputDir);
385 bool NoFinalizeRemoval = origCI.getMigratorOpts().NoFinalizeRemoval;
387 std::vector<TransformFn> transforms = arcmt::getAllTransformations(OrigGCMode,
389 assert(!transforms.empty());
391 for (unsigned i=0, e = transforms.size(); i != e; ++i) {
392 bool err = migration.applyTransform(transforms[i]);
393 if (err) return true;
396 IntrusiveRefCntPtr<DiagnosticIDs> DiagID(new DiagnosticIDs());
397 IntrusiveRefCntPtr<DiagnosticsEngine> Diags(
398 new DiagnosticsEngine(DiagID, DiagClient, /*ShouldOwnClient=*/false));
400 if (outputDir.empty()) {
401 origCI.getLangOpts()->ObjCAutoRefCount = true;
402 return migration.getRemapper().overwriteOriginal(*Diags);
404 // If we are migrating code that gets the '-fobjc-arc' flag, make sure
405 // to remove it so that we don't get errors from normal compilation.
406 origCI.getLangOpts()->ObjCAutoRefCount = false;
407 return migration.getRemapper().flushToDisk(outputDir, *Diags);
411 bool arcmt::applyTransformations(CompilerInvocation &origCI,
412 const FrontendInputFile &Input,
413 DiagnosticConsumer *DiagClient) {
414 return applyTransforms(origCI, Input, DiagClient,
415 StringRef(), false, StringRef());
418 bool arcmt::migrateWithTemporaryFiles(CompilerInvocation &origCI,
419 const FrontendInputFile &Input,
420 DiagnosticConsumer *DiagClient,
422 bool emitPremigrationARCErrors,
423 StringRef plistOut) {
424 assert(!outputDir.empty() && "Expected output directory path");
425 return applyTransforms(origCI, Input, DiagClient,
426 outputDir, emitPremigrationARCErrors, plistOut);
429 bool arcmt::getFileRemappings(std::vector<std::pair<std::string,std::string> > &
432 DiagnosticConsumer *DiagClient) {
433 assert(!outputDir.empty());
435 IntrusiveRefCntPtr<DiagnosticIDs> DiagID(new DiagnosticIDs());
436 IntrusiveRefCntPtr<DiagnosticsEngine> Diags(
437 new DiagnosticsEngine(DiagID, DiagClient, /*ShouldOwnClient=*/false));
439 FileRemapper remapper;
440 bool err = remapper.initFromDisk(outputDir, *Diags,
441 /*ignoreIfFilesChanged=*/true);
445 PreprocessorOptions PPOpts;
446 remapper.applyMappings(PPOpts);
447 remap = PPOpts.RemappedFiles;
452 bool arcmt::getFileRemappingsFromFileList(
453 std::vector<std::pair<std::string,std::string> > &remap,
454 ArrayRef<StringRef> remapFiles,
455 DiagnosticConsumer *DiagClient) {
456 bool hasErrorOccurred = false;
457 llvm::StringMap<bool> Uniquer;
459 llvm::IntrusiveRefCntPtr<DiagnosticIDs> DiagID(new DiagnosticIDs());
460 llvm::IntrusiveRefCntPtr<DiagnosticsEngine> Diags(
461 new DiagnosticsEngine(DiagID, DiagClient, /*ShouldOwnClient=*/false));
463 for (ArrayRef<StringRef>::iterator
464 I = remapFiles.begin(), E = remapFiles.end(); I != E; ++I) {
467 FileRemapper remapper;
468 bool err = remapper.initFromFile(file, *Diags,
469 /*ignoreIfFilesChanged=*/true);
470 hasErrorOccurred = hasErrorOccurred || err;
474 PreprocessorOptions PPOpts;
475 remapper.applyMappings(PPOpts);
476 for (PreprocessorOptions::remapped_file_iterator
477 RI = PPOpts.remapped_file_begin(), RE = PPOpts.remapped_file_end();
479 bool &inserted = Uniquer[RI->first];
483 remap.push_back(*RI);
487 return hasErrorOccurred;
490 //===----------------------------------------------------------------------===//
491 // CollectTransformActions.
492 //===----------------------------------------------------------------------===//
496 class ARCMTMacroTrackerPPCallbacks : public PPCallbacks {
497 std::vector<SourceLocation> &ARCMTMacroLocs;
500 ARCMTMacroTrackerPPCallbacks(std::vector<SourceLocation> &ARCMTMacroLocs)
501 : ARCMTMacroLocs(ARCMTMacroLocs) { }
503 virtual void MacroExpands(const Token &MacroNameTok, const MacroInfo *MI,
505 if (MacroNameTok.getIdentifierInfo()->getName() == getARCMTMacroName())
506 ARCMTMacroLocs.push_back(MacroNameTok.getLocation());
510 class ARCMTMacroTrackerAction : public ASTFrontendAction {
511 std::vector<SourceLocation> &ARCMTMacroLocs;
514 ARCMTMacroTrackerAction(std::vector<SourceLocation> &ARCMTMacroLocs)
515 : ARCMTMacroLocs(ARCMTMacroLocs) { }
517 virtual ASTConsumer *CreateASTConsumer(CompilerInstance &CI,
519 CI.getPreprocessor().addPPCallbacks(
520 new ARCMTMacroTrackerPPCallbacks(ARCMTMacroLocs));
521 return new ASTConsumer();
525 class RewritesApplicator : public TransformActions::RewriteReceiver {
527 MigrationProcess::RewriteListener *Listener;
530 RewritesApplicator(Rewriter &rewriter, ASTContext &ctx,
531 MigrationProcess::RewriteListener *listener)
532 : rewriter(rewriter), Listener(listener) {
534 Listener->start(ctx);
536 ~RewritesApplicator() {
541 virtual void insert(SourceLocation loc, StringRef text) {
542 bool err = rewriter.InsertText(loc, text, /*InsertAfter=*/true,
543 /*indentNewLines=*/true);
544 if (!err && Listener)
545 Listener->insert(loc, text);
548 virtual void remove(CharSourceRange range) {
549 Rewriter::RewriteOptions removeOpts;
550 removeOpts.IncludeInsertsAtBeginOfRange = false;
551 removeOpts.IncludeInsertsAtEndOfRange = false;
552 removeOpts.RemoveLineIfEmpty = true;
554 bool err = rewriter.RemoveText(range, removeOpts);
555 if (!err && Listener)
556 Listener->remove(range);
559 virtual void increaseIndentation(CharSourceRange range,
560 SourceLocation parentIndent) {
561 rewriter.IncreaseIndentation(range, parentIndent);
565 } // end anonymous namespace.
567 /// \brief Anchor for VTable.
568 MigrationProcess::RewriteListener::~RewriteListener() { }
570 MigrationProcess::MigrationProcess(const CompilerInvocation &CI,
571 DiagnosticConsumer *diagClient,
573 : OrigCI(CI), DiagClient(diagClient) {
574 if (!outputDir.empty()) {
575 IntrusiveRefCntPtr<DiagnosticIDs> DiagID(new DiagnosticIDs());
576 IntrusiveRefCntPtr<DiagnosticsEngine> Diags(
577 new DiagnosticsEngine(DiagID, DiagClient, /*ShouldOwnClient=*/false));
578 Remapper.initFromDisk(outputDir, *Diags, /*ignoreIfFilesChanges=*/true);
582 bool MigrationProcess::applyTransform(TransformFn trans,
583 RewriteListener *listener) {
584 OwningPtr<CompilerInvocation> CInvok;
585 CInvok.reset(createInvocationForMigration(OrigCI));
586 CInvok->getDiagnosticOpts().IgnoreWarnings = true;
588 Remapper.applyMappings(CInvok->getPreprocessorOpts());
590 CapturedDiagList capturedDiags;
591 std::vector<SourceLocation> ARCMTMacroLocs;
594 IntrusiveRefCntPtr<DiagnosticIDs> DiagID(new DiagnosticIDs());
595 IntrusiveRefCntPtr<DiagnosticsEngine> Diags(
596 new DiagnosticsEngine(DiagID, DiagClient, /*ShouldOwnClient=*/false));
598 // Filter of all diagnostics.
599 CaptureDiagnosticConsumer errRec(*Diags, *DiagClient, capturedDiags);
600 Diags->setClient(&errRec, /*ShouldOwnClient=*/false);
602 OwningPtr<ARCMTMacroTrackerAction> ASTAction;
603 ASTAction.reset(new ARCMTMacroTrackerAction(ARCMTMacroLocs));
605 OwningPtr<ASTUnit> Unit(
606 ASTUnit::LoadFromCompilerInvocationAction(CInvok.take(), Diags,
609 errRec.FinishCapture();
612 Unit->setOwnsRemappedFileBuffers(false); // FileRemapper manages that.
614 // Don't filter diagnostics anymore.
615 Diags->setClient(DiagClient, /*ShouldOwnClient=*/false);
617 ASTContext &Ctx = Unit->getASTContext();
619 if (Diags->hasFatalErrorOccurred()) {
621 DiagClient->BeginSourceFile(Ctx.getLangOpts(), &Unit->getPreprocessor());
622 capturedDiags.reportDiagnostics(*Diags);
623 DiagClient->EndSourceFile();
624 errRec.FinishCapture();
628 // After parsing of source files ended, we want to reuse the
629 // diagnostics objects to emit further diagnostics.
630 // We call BeginSourceFile because DiagnosticConsumer requires that
631 // diagnostics with source range information are emitted only in between
632 // BeginSourceFile() and EndSourceFile().
633 DiagClient->BeginSourceFile(Ctx.getLangOpts(), &Unit->getPreprocessor());
635 Rewriter rewriter(Ctx.getSourceManager(), Ctx.getLangOpts());
636 TransformActions TA(*Diags, capturedDiags, Ctx, Unit->getPreprocessor());
637 MigrationPass pass(Ctx, OrigCI.getLangOpts()->getGC(),
638 Unit->getSema(), TA, ARCMTMacroLocs);
643 RewritesApplicator applicator(rewriter, Ctx, listener);
644 TA.applyRewrites(applicator);
647 DiagClient->EndSourceFile();
648 errRec.FinishCapture();
650 if (DiagClient->getNumErrors())
653 for (Rewriter::buffer_iterator
654 I = rewriter.buffer_begin(), E = rewriter.buffer_end(); I != E; ++I) {
655 FileID FID = I->first;
656 RewriteBuffer &buf = I->second;
657 const FileEntry *file = Ctx.getSourceManager().getFileEntryForID(FID);
659 std::string newFname = file->getName();
660 newFname += "-trans";
661 SmallString<512> newText;
662 llvm::raw_svector_ostream vecOS(newText);
665 llvm::MemoryBuffer *memBuf = llvm::MemoryBuffer::getMemBufferCopy(
666 StringRef(newText.data(), newText.size()), newFname);
667 SmallString<64> filePath(file->getName());
668 Unit->getFileManager().FixupRelativePath(filePath);
669 Remapper.remap(filePath.str(), memBuf);