clang  3.8.0
ARCMT.cpp
Go to the documentation of this file.
1 //===--- ARCMT.cpp - Migration to ARC mode --------------------------------===//
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 "Internals.h"
11 #include "clang/AST/ASTConsumer.h"
13 #include "clang/Frontend/ASTUnit.h"
17 #include "clang/Frontend/Utils.h"
18 #include "clang/Lex/Preprocessor.h"
22 #include "llvm/ADT/Triple.h"
23 #include "llvm/Support/MemoryBuffer.h"
24 using namespace clang;
25 using namespace arcmt;
26 
28  SourceRange range) {
29  if (range.isInvalid())
30  return false;
31 
32  bool cleared = false;
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()))) {
41  cleared = true;
42  ListTy::iterator eraseS = I++;
43  if (eraseS->getLevel() != DiagnosticsEngine::Note)
44  while (I != List.end() && I->getLevel() == DiagnosticsEngine::Note)
45  ++I;
46  // Clear the diagnostic and any notes following it.
47  I = List.erase(eraseS, I);
48  continue;
49  }
50 
51  ++I;
52  }
53 
54  return cleared;
55 }
56 
58  SourceRange range) const {
59  if (range.isInvalid())
60  return false;
61 
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()))) {
70  return true;
71  }
72 
73  ++I;
74  }
75 
76  return false;
77 }
78 
80  for (ListTy::const_iterator I = List.begin(), E = List.end(); I != E; ++I)
81  Diags.Report(*I);
82 }
83 
85  for (ListTy::const_iterator I = List.begin(), E = List.end(); I != E; ++I)
86  if (I->getLevel() >= DiagnosticsEngine::Error)
87  return true;
88 
89  return false;
90 }
91 
92 namespace {
93 
94 class CaptureDiagnosticConsumer : public DiagnosticConsumer {
95  DiagnosticsEngine &Diags;
96  DiagnosticConsumer &DiagClient;
97  CapturedDiagList &CapturedDiags;
98  bool HasBegunSourceFile;
99 public:
100  CaptureDiagnosticConsumer(DiagnosticsEngine &diags,
101  DiagnosticConsumer &client,
102  CapturedDiagList &capturedDiags)
103  : Diags(diags), DiagClient(client), CapturedDiags(capturedDiags),
104  HasBegunSourceFile(false) { }
105 
106  void BeginSourceFile(const LangOptions &Opts,
107  const Preprocessor *PP) override {
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;
114  }
115  }
116 
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;
124  }
125  }
126 
127  ~CaptureDiagnosticConsumer() override {
128  assert(!HasBegunSourceFile && "FinishCapture not called!");
129  }
130 
131  void HandleDiagnostic(DiagnosticsEngine::Level level,
132  const Diagnostic &Info) override {
134  level >= DiagnosticsEngine::Error || level == DiagnosticsEngine::Note) {
135  if (Info.getLocation().isValid())
136  CapturedDiags.push_back(StoredDiagnostic(level, Info));
137  return;
138  }
139 
140  // Non-ARC warnings are ignored.
141  Diags.setLastDiagnosticIgnored();
142  }
143 };
144 
145 } // end anonymous namespace
146 
147 static bool HasARCRuntime(CompilerInvocation &origCI) {
148  // This duplicates some functionality from Darwin::AddDeploymentTarget
149  // but this function is well defined, so keep it decoupled from the driver
150  // and avoid unrelated complications.
151  llvm::Triple triple(origCI.getTargetOpts().Triple);
152 
153  if (triple.isiOS())
154  return triple.getOSMajorVersion() >= 5;
155 
156  if (triple.isWatchOS())
157  return true;
158 
159  if (triple.getOS() == llvm::Triple::Darwin)
160  return triple.getOSMajorVersion() >= 11;
161 
162  if (triple.getOS() == llvm::Triple::MacOSX) {
163  unsigned Major, Minor, Micro;
164  triple.getOSVersion(Major, Minor, Micro);
165  return Major > 10 || (Major == 10 && Minor >= 7);
166  }
167 
168  return false;
169 }
170 
171 static CompilerInvocation *
173  const PCHContainerReader &PCHContainerRdr) {
174  std::unique_ptr<CompilerInvocation> CInvok;
175  CInvok.reset(new CompilerInvocation(origCI));
176  PreprocessorOptions &PPOpts = CInvok->getPreprocessorOpts();
177  if (!PPOpts.ImplicitPCHInclude.empty()) {
178  // We can't use a PCH because it was likely built in non-ARC mode and we
179  // want to parse in ARC. Include the original header.
180  FileManager FileMgr(origCI.getFileSystemOpts());
183  new DiagnosticsEngine(DiagID, &origCI.getDiagnosticOpts(),
184  new IgnoringDiagConsumer()));
185  std::string OriginalFile = ASTReader::getOriginalSourceFile(
186  PPOpts.ImplicitPCHInclude, FileMgr, PCHContainerRdr, *Diags);
187  if (!OriginalFile.empty())
188  PPOpts.Includes.insert(PPOpts.Includes.begin(), OriginalFile);
189  PPOpts.ImplicitPCHInclude.clear();
190  }
191  // FIXME: Get the original header of a PTH as well.
192  CInvok->getPreprocessorOpts().ImplicitPTHInclude.clear();
193  std::string define = getARCMTMacroName();
194  define += '=';
195  CInvok->getPreprocessorOpts().addMacroDef(define);
196  CInvok->getLangOpts()->ObjCAutoRefCount = true;
197  CInvok->getLangOpts()->setGC(LangOptions::NonGC);
198  CInvok->getDiagnosticOpts().ErrorLimit = 0;
199  CInvok->getDiagnosticOpts().PedanticErrors = 0;
200 
201  // Ignore -Werror flags when migrating.
202  std::vector<std::string> WarnOpts;
204  I = CInvok->getDiagnosticOpts().Warnings.begin(),
205  E = CInvok->getDiagnosticOpts().Warnings.end(); I != E; ++I) {
206  if (!StringRef(*I).startswith("error"))
207  WarnOpts.push_back(*I);
208  }
209  WarnOpts.push_back("error=arc-unsafe-retained-assign");
210  CInvok->getDiagnosticOpts().Warnings = std::move(WarnOpts);
211 
212  CInvok->getLangOpts()->ObjCWeakRuntime = HasARCRuntime(origCI);
213  CInvok->getLangOpts()->ObjCWeak = CInvok->getLangOpts()->ObjCWeakRuntime;
214 
215  return CInvok.release();
216 }
217 
218 static void emitPremigrationErrors(const CapturedDiagList &arcDiags,
219  DiagnosticOptions *diagOpts,
220  Preprocessor &PP) {
221  TextDiagnosticPrinter printer(llvm::errs(), diagOpts);
224  new DiagnosticsEngine(DiagID, diagOpts, &printer,
225  /*ShouldOwnClient=*/false));
226  Diags->setSourceManager(&PP.getSourceManager());
227 
228  printer.BeginSourceFile(PP.getLangOpts(), &PP);
229  arcDiags.reportDiagnostics(*Diags);
230  printer.EndSourceFile();
231 }
232 
233 //===----------------------------------------------------------------------===//
234 // checkForManualIssues.
235 //===----------------------------------------------------------------------===//
236 
239  std::shared_ptr<PCHContainerOperations> PCHContainerOps,
240  DiagnosticConsumer *DiagClient, bool emitPremigrationARCErrors,
241  StringRef plistOut) {
242  if (!origCI.getLangOpts()->ObjC1)
243  return false;
244 
245  LangOptions::GCMode OrigGCMode = origCI.getLangOpts()->getGC();
246  bool NoNSAllocReallocError = origCI.getMigratorOpts().NoNSAllocReallocError;
247  bool NoFinalizeRemoval = origCI.getMigratorOpts().NoFinalizeRemoval;
248 
249  std::vector<TransformFn> transforms = arcmt::getAllTransformations(OrigGCMode,
250  NoFinalizeRemoval);
251  assert(!transforms.empty());
252 
253  std::unique_ptr<CompilerInvocation> CInvok;
254  CInvok.reset(
255  createInvocationForMigration(origCI, PCHContainerOps->getRawReader()));
256  CInvok->getFrontendOpts().Inputs.clear();
257  CInvok->getFrontendOpts().Inputs.push_back(Input);
258 
259  CapturedDiagList capturedDiags;
260 
261  assert(DiagClient);
264  new DiagnosticsEngine(DiagID, &origCI.getDiagnosticOpts(),
265  DiagClient, /*ShouldOwnClient=*/false));
266 
267  // Filter of all diagnostics.
268  CaptureDiagnosticConsumer errRec(*Diags, *DiagClient, capturedDiags);
269  Diags->setClient(&errRec, /*ShouldOwnClient=*/false);
270 
271  std::unique_ptr<ASTUnit> Unit(ASTUnit::LoadFromCompilerInvocationAction(
272  CInvok.release(), PCHContainerOps, Diags));
273  if (!Unit) {
274  errRec.FinishCapture();
275  return true;
276  }
277 
278  // Don't filter diagnostics anymore.
279  Diags->setClient(DiagClient, /*ShouldOwnClient=*/false);
280 
281  ASTContext &Ctx = Unit->getASTContext();
282 
283  if (Diags->hasFatalErrorOccurred()) {
284  Diags->Reset();
285  DiagClient->BeginSourceFile(Ctx.getLangOpts(), &Unit->getPreprocessor());
286  capturedDiags.reportDiagnostics(*Diags);
287  DiagClient->EndSourceFile();
288  errRec.FinishCapture();
289  return true;
290  }
291 
292  if (emitPremigrationARCErrors)
293  emitPremigrationErrors(capturedDiags, &origCI.getDiagnosticOpts(),
294  Unit->getPreprocessor());
295  if (!plistOut.empty()) {
298  I = capturedDiags.begin(), E = capturedDiags.end(); I != E; ++I)
299  arcDiags.push_back(*I);
300  writeARCDiagsToPlist(plistOut, arcDiags,
301  Ctx.getSourceManager(), Ctx.getLangOpts());
302  }
303 
304  // After parsing of source files ended, we want to reuse the
305  // diagnostics objects to emit further diagnostics.
306  // We call BeginSourceFile because DiagnosticConsumer requires that
307  // diagnostics with source range information are emitted only in between
308  // BeginSourceFile() and EndSourceFile().
309  DiagClient->BeginSourceFile(Ctx.getLangOpts(), &Unit->getPreprocessor());
310 
311  // No macros will be added since we are just checking and we won't modify
312  // source code.
313  std::vector<SourceLocation> ARCMTMacroLocs;
314 
315  TransformActions testAct(*Diags, capturedDiags, Ctx, Unit->getPreprocessor());
316  MigrationPass pass(Ctx, OrigGCMode, Unit->getSema(), testAct, capturedDiags,
317  ARCMTMacroLocs);
318  pass.setNoFinalizeRemoval(NoFinalizeRemoval);
319  if (!NoNSAllocReallocError)
320  Diags->setSeverity(diag::warn_arcmt_nsalloc_realloc, diag::Severity::Error,
321  SourceLocation());
322 
323  for (unsigned i=0, e = transforms.size(); i != e; ++i)
324  transforms[i](pass);
325 
326  capturedDiags.reportDiagnostics(*Diags);
327 
328  DiagClient->EndSourceFile();
329  errRec.FinishCapture();
330 
331  return capturedDiags.hasErrors() || testAct.hasReportedErrors();
332 }
333 
334 //===----------------------------------------------------------------------===//
335 // applyTransformations.
336 //===----------------------------------------------------------------------===//
337 
338 static bool
340  std::shared_ptr<PCHContainerOperations> PCHContainerOps,
341  DiagnosticConsumer *DiagClient, StringRef outputDir,
342  bool emitPremigrationARCErrors, StringRef plistOut) {
343  if (!origCI.getLangOpts()->ObjC1)
344  return false;
345 
346  LangOptions::GCMode OrigGCMode = origCI.getLangOpts()->getGC();
347 
348  // Make sure checking is successful first.
349  CompilerInvocation CInvokForCheck(origCI);
350  if (arcmt::checkForManualIssues(CInvokForCheck, Input, PCHContainerOps,
351  DiagClient, emitPremigrationARCErrors,
352  plistOut))
353  return true;
354 
355  CompilerInvocation CInvok(origCI);
356  CInvok.getFrontendOpts().Inputs.clear();
357  CInvok.getFrontendOpts().Inputs.push_back(Input);
358 
359  MigrationProcess migration(CInvok, PCHContainerOps, DiagClient, outputDir);
360  bool NoFinalizeRemoval = origCI.getMigratorOpts().NoFinalizeRemoval;
361 
362  std::vector<TransformFn> transforms = arcmt::getAllTransformations(OrigGCMode,
363  NoFinalizeRemoval);
364  assert(!transforms.empty());
365 
366  for (unsigned i=0, e = transforms.size(); i != e; ++i) {
367  bool err = migration.applyTransform(transforms[i]);
368  if (err) return true;
369  }
370 
373  new DiagnosticsEngine(DiagID, &origCI.getDiagnosticOpts(),
374  DiagClient, /*ShouldOwnClient=*/false));
375 
376  if (outputDir.empty()) {
377  origCI.getLangOpts()->ObjCAutoRefCount = true;
378  return migration.getRemapper().overwriteOriginal(*Diags);
379  } else {
380  return migration.getRemapper().flushToDisk(outputDir, *Diags);
381  }
382 }
383 
386  std::shared_ptr<PCHContainerOperations> PCHContainerOps,
387  DiagnosticConsumer *DiagClient) {
388  return applyTransforms(origCI, Input, PCHContainerOps, DiagClient,
389  StringRef(), false, StringRef());
390 }
391 
394  std::shared_ptr<PCHContainerOperations> PCHContainerOps,
395  DiagnosticConsumer *DiagClient, StringRef outputDir,
396  bool emitPremigrationARCErrors, StringRef plistOut) {
397  assert(!outputDir.empty() && "Expected output directory path");
398  return applyTransforms(origCI, Input, PCHContainerOps, DiagClient, outputDir,
399  emitPremigrationARCErrors, plistOut);
400 }
401 
402 bool arcmt::getFileRemappings(std::vector<std::pair<std::string,std::string> > &
403  remap,
404  StringRef outputDir,
405  DiagnosticConsumer *DiagClient) {
406  assert(!outputDir.empty());
407 
410  new DiagnosticsEngine(DiagID, new DiagnosticOptions,
411  DiagClient, /*ShouldOwnClient=*/false));
412 
413  FileRemapper remapper;
414  bool err = remapper.initFromDisk(outputDir, *Diags,
415  /*ignoreIfFilesChanged=*/true);
416  if (err)
417  return true;
418 
419  PreprocessorOptions PPOpts;
420  remapper.applyMappings(PPOpts);
421  remap = PPOpts.RemappedFiles;
422 
423  return false;
424 }
425 
426 
427 //===----------------------------------------------------------------------===//
428 // CollectTransformActions.
429 //===----------------------------------------------------------------------===//
430 
431 namespace {
432 
433 class ARCMTMacroTrackerPPCallbacks : public PPCallbacks {
434  std::vector<SourceLocation> &ARCMTMacroLocs;
435 
436 public:
437  ARCMTMacroTrackerPPCallbacks(std::vector<SourceLocation> &ARCMTMacroLocs)
438  : ARCMTMacroLocs(ARCMTMacroLocs) { }
439 
440  void MacroExpands(const Token &MacroNameTok, const MacroDefinition &MD,
441  SourceRange Range, const MacroArgs *Args) override {
442  if (MacroNameTok.getIdentifierInfo()->getName() == getARCMTMacroName())
443  ARCMTMacroLocs.push_back(MacroNameTok.getLocation());
444  }
445 };
446 
447 class ARCMTMacroTrackerAction : public ASTFrontendAction {
448  std::vector<SourceLocation> &ARCMTMacroLocs;
449 
450 public:
451  ARCMTMacroTrackerAction(std::vector<SourceLocation> &ARCMTMacroLocs)
452  : ARCMTMacroLocs(ARCMTMacroLocs) { }
453 
454  std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
455  StringRef InFile) override {
457  llvm::make_unique<ARCMTMacroTrackerPPCallbacks>(ARCMTMacroLocs));
458  return llvm::make_unique<ASTConsumer>();
459  }
460 };
461 
462 class RewritesApplicator : public TransformActions::RewriteReceiver {
463  Rewriter &rewriter;
465 
466 public:
467  RewritesApplicator(Rewriter &rewriter, ASTContext &ctx,
469  : rewriter(rewriter), Listener(listener) {
470  if (Listener)
471  Listener->start(ctx);
472  }
473  ~RewritesApplicator() override {
474  if (Listener)
475  Listener->finish();
476  }
477 
478  void insert(SourceLocation loc, StringRef text) override {
479  bool err = rewriter.InsertText(loc, text, /*InsertAfter=*/true,
480  /*indentNewLines=*/true);
481  if (!err && Listener)
482  Listener->insert(loc, text);
483  }
484 
485  void remove(CharSourceRange range) override {
486  Rewriter::RewriteOptions removeOpts;
487  removeOpts.IncludeInsertsAtBeginOfRange = false;
488  removeOpts.IncludeInsertsAtEndOfRange = false;
489  removeOpts.RemoveLineIfEmpty = true;
490 
491  bool err = rewriter.RemoveText(range, removeOpts);
492  if (!err && Listener)
493  Listener->remove(range);
494  }
495 
496  void increaseIndentation(CharSourceRange range,
497  SourceLocation parentIndent) override {
498  rewriter.IncreaseIndentation(range, parentIndent);
499  }
500 };
501 
502 } // end anonymous namespace.
503 
504 /// \brief Anchor for VTable.
506 
508  const CompilerInvocation &CI,
509  std::shared_ptr<PCHContainerOperations> PCHContainerOps,
510  DiagnosticConsumer *diagClient, StringRef outputDir)
511  : OrigCI(CI), PCHContainerOps(PCHContainerOps), DiagClient(diagClient),
513  if (!outputDir.empty()) {
516  new DiagnosticsEngine(DiagID, &CI.getDiagnosticOpts(),
517  DiagClient, /*ShouldOwnClient=*/false));
518  Remapper.initFromDisk(outputDir, *Diags, /*ignoreIfFilesChanges=*/true);
519  }
520 }
521 
523  RewriteListener *listener) {
524  std::unique_ptr<CompilerInvocation> CInvok;
525  CInvok.reset(
526  createInvocationForMigration(OrigCI, PCHContainerOps->getRawReader()));
527  CInvok->getDiagnosticOpts().IgnoreWarnings = true;
528 
529  Remapper.applyMappings(CInvok->getPreprocessorOpts());
530 
531  CapturedDiagList capturedDiags;
532  std::vector<SourceLocation> ARCMTMacroLocs;
533 
534  assert(DiagClient);
537  new DiagnosticsEngine(DiagID, new DiagnosticOptions,
538  DiagClient, /*ShouldOwnClient=*/false));
539 
540  // Filter of all diagnostics.
541  CaptureDiagnosticConsumer errRec(*Diags, *DiagClient, capturedDiags);
542  Diags->setClient(&errRec, /*ShouldOwnClient=*/false);
543 
544  std::unique_ptr<ARCMTMacroTrackerAction> ASTAction;
545  ASTAction.reset(new ARCMTMacroTrackerAction(ARCMTMacroLocs));
546 
547  std::unique_ptr<ASTUnit> Unit(ASTUnit::LoadFromCompilerInvocationAction(
548  CInvok.release(), PCHContainerOps, Diags, ASTAction.get()));
549  if (!Unit) {
550  errRec.FinishCapture();
551  return true;
552  }
553  Unit->setOwnsRemappedFileBuffers(false); // FileRemapper manages that.
554 
555  HadARCErrors = HadARCErrors || capturedDiags.hasErrors();
556 
557  // Don't filter diagnostics anymore.
558  Diags->setClient(DiagClient, /*ShouldOwnClient=*/false);
559 
560  ASTContext &Ctx = Unit->getASTContext();
561 
562  if (Diags->hasFatalErrorOccurred()) {
563  Diags->Reset();
564  DiagClient->BeginSourceFile(Ctx.getLangOpts(), &Unit->getPreprocessor());
565  capturedDiags.reportDiagnostics(*Diags);
566  DiagClient->EndSourceFile();
567  errRec.FinishCapture();
568  return true;
569  }
570 
571  // After parsing of source files ended, we want to reuse the
572  // diagnostics objects to emit further diagnostics.
573  // We call BeginSourceFile because DiagnosticConsumer requires that
574  // diagnostics with source range information are emitted only in between
575  // BeginSourceFile() and EndSourceFile().
576  DiagClient->BeginSourceFile(Ctx.getLangOpts(), &Unit->getPreprocessor());
577 
578  Rewriter rewriter(Ctx.getSourceManager(), Ctx.getLangOpts());
579  TransformActions TA(*Diags, capturedDiags, Ctx, Unit->getPreprocessor());
580  MigrationPass pass(Ctx, OrigCI.getLangOpts()->getGC(),
581  Unit->getSema(), TA, capturedDiags, ARCMTMacroLocs);
582 
583  trans(pass);
584 
585  {
586  RewritesApplicator applicator(rewriter, Ctx, listener);
587  TA.applyRewrites(applicator);
588  }
589 
590  DiagClient->EndSourceFile();
591  errRec.FinishCapture();
592 
593  if (DiagClient->getNumErrors())
594  return true;
595 
597  I = rewriter.buffer_begin(), E = rewriter.buffer_end(); I != E; ++I) {
598  FileID FID = I->first;
599  RewriteBuffer &buf = I->second;
600  const FileEntry *file = Ctx.getSourceManager().getFileEntryForID(FID);
601  assert(file);
602  std::string newFname = file->getName();
603  newFname += "-trans";
604  SmallString<512> newText;
605  llvm::raw_svector_ostream vecOS(newText);
606  buf.write(vecOS);
607  std::unique_ptr<llvm::MemoryBuffer> memBuf(
608  llvm::MemoryBuffer::getMemBufferCopy(
609  StringRef(newText.data(), newText.size()), newFname));
610  SmallString<64> filePath(file->getName());
611  Unit->getFileManager().FixupRelativePath(filePath);
612  Remapper.remap(filePath.str(), std::move(memBuf));
613  }
614 
615  return false;
616 }
SourceManager & getSourceManager() const
Definition: Preprocessor.h:687
SourceLocation getEnd() const
void(* TransformFn)(MigrationPass &pass)
Definition: ARCMT.h:92
void reportDiagnostics(DiagnosticsEngine &diags) const
Definition: ARCMT.cpp:79
bool IncreaseIndentation(CharSourceRange range, SourceLocation parentIndent)
Increase indentation for the lines between the given source range.
Definition: Rewriter.cpp:327
Implements support for file system lookup, file system caching, and directory search management...
Definition: FileManager.h:115
ListTy::const_iterator iterator
Definition: Internals.h:39
static StringRef getARCMTMacroName()
Definition: Internals.h:173
Represents a diagnostic in a form that can be retained until its corresponding source manager is dest...
Definition: Diagnostic.h:1257
bool applyTransformations(CompilerInvocation &origCI, const FrontendInputFile &Input, std::shared_ptr< PCHContainerOperations > PCHContainerOps, DiagnosticConsumer *DiagClient)
Works similar to checkForManualIssues but instead of checking, it applies automatic modifications to ...
Definition: ARCMT.cpp:384
std::vector< std::string > Includes
A description of the current definition of a macro.
Definition: MacroInfo.h:563
StringRef getOriginalSourceFile()
Retrieve the name of the original source file name for the primary module file.
Definition: ASTReader.h:1480
DiagnosticBuilder Report(SourceLocation Loc, unsigned DiagID)
Issue the message to the client.
Definition: Diagnostic.h:1117
unsigned getID() const
Definition: Diagnostic.h:1146
PreprocessorOptions - This class is used for passing the various options used in preprocessor initial...
bool RemoveText(SourceLocation Start, unsigned Length, RewriteOptions opts=RewriteOptions())
RemoveText - Remove the specified text region.
Definition: Rewriter.cpp:291
virtual void EndSourceFile()
Callback to inform the diagnostic client that processing of a source file has ended.
Definition: Diagnostic.h:1340
Abstract interface, implemented by clients of the front-end, which formats and prints fully processed...
Definition: Diagnostic.h:1307
RewriteBuffer - As code is rewritten, SourceBuffer's from the original input with modifications get a...
Definition: RewriteBuffer.h:27
This interface provides a way to observe the actions of the preprocessor as it does its thing...
Definition: PPCallbacks.h:38
void setNoFinalizeRemoval(bool val)
Definition: Internals.h:168
virtual ~RewriteListener()
Anchor for VTable.
Definition: ARCMT.cpp:505
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:91
const LangOptions & getLangOpts() const
Definition: Preprocessor.h:683
Token - This structure provides full information about a lexed token.
Definition: Token.h:37
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Definition: LangOptions.h:48
bool clearDiagnostic(ArrayRef< unsigned > IDs, SourceRange range)
Definition: ARCMT.cpp:27
const LangOptions & getLangOpts() const
Definition: ASTContext.h:596
const SourceLocation & getLocation() const
Definition: Diagnostic.h:1147
void remap(StringRef filePath, std::unique_ptr< llvm::MemoryBuffer > memBuf)
void BeginSourceFile(const LangOptions &LO, const Preprocessor *PP) override
Callback to inform the diagnostic client that processing of a source file is beginning.
Concrete class used by the front-end to report problems and issues.
Definition: Diagnostic.h:135
static void emitPremigrationErrors(const CapturedDiagList &arcDiags, DiagnosticOptions *diagOpts, Preprocessor &PP)
Definition: ARCMT.cpp:218
Present this diagnostic as an error.
bool hasDiagnostic(ArrayRef< unsigned > IDs, SourceRange range) const
Definition: ARCMT.cpp:57
iterator begin() const
Definition: Internals.h:40
This abstract interface provides operations for unwrapping containers for serialized ASTs (precompile...
detail::InMemoryDirectory::const_iterator I
Preprocessor & getPreprocessor() const
Return the current preprocessor.
buffer_iterator buffer_end()
Definition: Rewriter.h:178
FrontendOptions & getFrontendOpts()
MigratorOptions & getMigratorOpts()
const FileEntry * getFileEntryForID(FileID FID) const
Returns the FileEntry record for the provided FileID.
static ASTUnit * LoadFromCompilerInvocationAction(CompilerInvocation *CI, std::shared_ptr< PCHContainerOperations > PCHContainerOps, IntrusiveRefCntPtr< DiagnosticsEngine > Diags, ASTFrontendAction *Action=nullptr, ASTUnit *Unit=nullptr, bool Persistent=true, StringRef ResourceFilesPath=StringRef(), bool OnlyLocalDecls=false, bool CaptureDiagnostics=false, unsigned PrecompilePreambleAfterNParses=0, bool CacheCodeCompletionResults=false, bool IncludeBriefCommentsInCodeCompletion=false, bool UserFilesAreVolatile=false, std::unique_ptr< ASTUnit > *ErrAST=nullptr)
Create an ASTUnit from a source file, via a CompilerInvocation object, by invoking the optionally pro...
Definition: ASTUnit.cpp:1723
StringRef getName() const
Return the actual identifier string.
Represents a character-granular source range.
MacroArgs - An instance of this class captures information about the formal arguments specified to a ...
Definition: MacroArgs.h:29
Defines the clang::Preprocessor interface.
void writeARCDiagsToPlist(const std::string &outPath, ArrayRef< StoredDiagnostic > diags, SourceManager &SM, const LangOptions &LangOpts)
SourceLocation getLocation() const
Return a source location identifier for the specified offset in the current file. ...
Definition: Token.h:124
static bool applyTransforms(CompilerInvocation &origCI, const FrontendInputFile &Input, std::shared_ptr< PCHContainerOperations > PCHContainerOps, DiagnosticConsumer *DiagClient, StringRef outputDir, bool emitPremigrationARCErrors, StringRef plistOut)
Definition: ARCMT.cpp:339
bool checkForManualIssues(CompilerInvocation &CI, const FrontendInputFile &Input, std::shared_ptr< PCHContainerOperations > PCHContainerOps, DiagnosticConsumer *DiagClient, bool emitPremigrationARCErrors=false, StringRef plistOut=StringRef())
Creates an AST with the provided CompilerInvocation but with these changes: -if a PCH/PTH is set...
Definition: ARCMT.cpp:237
static bool HasARCRuntime(CompilerInvocation &origCI)
Definition: ARCMT.cpp:147
void EndSourceFile() override
Callback to inform the diagnostic client that processing of a source file has ended.
void applyMappings(PreprocessorOptions &PPOpts) const
MigrationProcess(const CompilerInvocation &CI, std::shared_ptr< PCHContainerOperations > PCHContainerOps, DiagnosticConsumer *diagClient, StringRef outputDir=StringRef())
Definition: ARCMT.cpp:507
An input file for the front end.
static CompilerInvocation * createInvocationForMigration(CompilerInvocation &origCI, const PCHContainerReader &PCHContainerRdr)
Definition: ARCMT.cpp:172
#define false
Definition: stdbool.h:33
bool overwriteOriginal(DiagnosticsEngine &Diag, StringRef outputDir=StringRef())
const char * getName() const
Definition: FileManager.h:84
CompilerInstance - Helper class for managing a single instance of the Clang compiler.
Encodes a location in the source.
const TemplateArgument * iterator
Definition: Type.h:4070
std::string ImplicitPCHInclude
The implicit PCH included at the start of the translation unit, or empty.
bool flushToDisk(StringRef outputDir, DiagnosticsEngine &Diag)
bool isValid() const
Return true if this is a valid SourceLocation object.
Options for controlling the compiler diagnostics engine.
std::vector< FrontendInputFile > Inputs
The input files and their types.
Cached information about one file (either on disk or in the virtual file system). ...
Definition: FileManager.h:53
bool InsertText(SourceLocation Loc, StringRef Str, bool InsertAfter=true, bool indentNewLines=false)
InsertText - Insert the specified string at the specified location in the original buffer...
Definition: Rewriter.cpp:238
Abstract base class to use for AST consumer-based frontend actions.
bool RemoveLineIfEmpty
If true and removing some text leaves a blank line also remove the empty line (false by default)...
Definition: Rewriter.h:45
SourceLocation getBegin() const
bool migrateWithTemporaryFiles(CompilerInvocation &origCI, const FrontendInputFile &Input, std::shared_ptr< PCHContainerOperations > PCHContainerOps, DiagnosticConsumer *DiagClient, StringRef outputDir, bool emitPremigrationARCErrors, StringRef plistOut)
Applies automatic modifications and produces temporary files and metadata into the outputDir path...
Definition: ARCMT.cpp:392
An opaque identifier used by SourceManager which refers to a source file (MemoryBuffer) along with it...
A diagnostic client that ignores all diagnostics.
Definition: Diagnostic.h:1363
std::vector< TransformFn > getAllTransformations(LangOptions::GCMode OrigGCMode, bool NoFinalizeRemoval)
Definition: Transforms.cpp:587
Used for handling and querying diagnostic IDs.
Helper class for holding the data necessary to invoke the compiler.
DiagnosticOptions & getDiagnosticOpts() const
detail::InMemoryDirectory::const_iterator E
raw_ostream & write(raw_ostream &Stream) const
Write to Stream the result of applying all changes to the original buffer.
Definition: Rewriter.cpp:25
bool IncludeInsertsAtBeginOfRange
Given a source range, true to include previous inserts at the beginning of the range as part of the r...
Definition: Rewriter.h:39
std::map< FileID, RewriteBuffer >::iterator buffer_iterator
Definition: Rewriter.h:53
iterator end() const
Definition: Internals.h:41
bool isInvalid() const
buffer_iterator buffer_begin()
Definition: Rewriter.h:177
SourceManager & getSourceManager()
Definition: ASTContext.h:553
bool initFromDisk(StringRef outputDir, DiagnosticsEngine &Diag, bool ignoreIfFilesChanged)
Rewriter - This is the main interface to the rewrite buffers.
Definition: Rewriter.h:31
static bool isARCDiagnostic(unsigned DiagID)
Return true if a given diagnostic falls into an ARC diagnostic category.
bool isBeforeInTranslationUnitThan(SourceLocation Loc) const
Determines the order of 2 source locations in the translation unit.
Level
The level of the diagnostic, after it has been through mapping.
Definition: Diagnostic.h:141
FileSystemOptions & getFileSystemOpts()
std::vector< std::pair< std::string, std::string > > RemappedFiles
The set of file remappings, which take existing files on the system (the first part of each pair) and...
const StringRef Input
A little helper class (which is basically a smart pointer that forwards info from DiagnosticsEngine) ...
Definition: Diagnostic.h:1137
FileRemapper & getRemapper()
Definition: ARCMT.h:124
A SourceLocation and its associated SourceManager.
Defines the clang::FrontendAction interface and various convenience abstract classes (clang::ASTFront...
unsigned getNumErrors() const
Definition: Diagnostic.h:1315
bool applyTransform(TransformFn trans, RewriteListener *listener=nullptr)
Definition: ARCMT.cpp:522
A trivial tuple used to represent a source range.
virtual void BeginSourceFile(const LangOptions &LangOpts, const Preprocessor *PP=nullptr)
Callback to inform the diagnostic client that processing of a source file is beginning.
Definition: Diagnostic.h:1332
std::string Triple
If given, the name of the target triple to compile for.
Definition: TargetOptions.h:28
bool getFileRemappings(std::vector< std::pair< std::string, std::string > > &remap, StringRef outputDir, DiagnosticConsumer *DiagClient)
Get the set of file remappings from the outputDir path that migrateWithTemporaryFiles produced...
Definition: ARCMT.cpp:402
void addPPCallbacks(std::unique_ptr< PPCallbacks > C)
Definition: Preprocessor.h:778
Engages in a tight little dance with the lexer to efficiently preprocess tokens.
Definition: Preprocessor.h:96
bool IncludeInsertsAtEndOfRange
Given a source range, true to include previous inserts at the end of the range as part of the range i...
Definition: Rewriter.h:42
IdentifierInfo * getIdentifierInfo() const
Definition: Token.h:177