ARCMT.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===-- ARCMT.h - ARC Migration Rewriter ------------------------*- C++ -*-===//
  7. //
  8. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  9. // See https://llvm.org/LICENSE.txt for license information.
  10. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  11. //
  12. //===----------------------------------------------------------------------===//
  13. #ifndef LLVM_CLANG_ARCMIGRATE_ARCMT_H
  14. #define LLVM_CLANG_ARCMIGRATE_ARCMT_H
  15. #include "clang/ARCMigrate/FileRemapper.h"
  16. #include "clang/Basic/SourceLocation.h"
  17. #include "clang/Frontend/CompilerInvocation.h"
  18. namespace clang {
  19. class ASTContext;
  20. class DiagnosticConsumer;
  21. class PCHContainerOperations;
  22. namespace arcmt {
  23. class MigrationPass;
  24. /// Creates an AST with the provided CompilerInvocation but with these
  25. /// changes:
  26. /// -if a PCH/PTH is set, the original header is used instead
  27. /// -Automatic Reference Counting mode is enabled
  28. ///
  29. /// It then checks the AST and produces errors/warning for ARC migration issues
  30. /// that the user needs to handle manually.
  31. ///
  32. /// \param emitPremigrationARCErrors if true all ARC errors will get emitted
  33. /// even if the migrator can fix them, but the function will still return false
  34. /// if all ARC errors can be fixed.
  35. ///
  36. /// \param plistOut if non-empty, it is the file path to store the plist with
  37. /// the pre-migration ARC diagnostics.
  38. ///
  39. /// \returns false if no error is produced, true otherwise.
  40. bool
  41. checkForManualIssues(CompilerInvocation &CI, const FrontendInputFile &Input,
  42. std::shared_ptr<PCHContainerOperations> PCHContainerOps,
  43. DiagnosticConsumer *DiagClient,
  44. bool emitPremigrationARCErrors = false,
  45. StringRef plistOut = StringRef());
  46. /// Works similar to checkForManualIssues but instead of checking, it
  47. /// applies automatic modifications to source files to conform to ARC.
  48. ///
  49. /// \returns false if no error is produced, true otherwise.
  50. bool
  51. applyTransformations(CompilerInvocation &origCI,
  52. const FrontendInputFile &Input,
  53. std::shared_ptr<PCHContainerOperations> PCHContainerOps,
  54. DiagnosticConsumer *DiagClient);
  55. /// Applies automatic modifications and produces temporary files
  56. /// and metadata into the \p outputDir path.
  57. ///
  58. /// \param emitPremigrationARCErrors if true all ARC errors will get emitted
  59. /// even if the migrator can fix them, but the function will still return false
  60. /// if all ARC errors can be fixed.
  61. ///
  62. /// \param plistOut if non-empty, it is the file path to store the plist with
  63. /// the pre-migration ARC diagnostics.
  64. ///
  65. /// \returns false if no error is produced, true otherwise.
  66. bool migrateWithTemporaryFiles(
  67. CompilerInvocation &origCI, const FrontendInputFile &Input,
  68. std::shared_ptr<PCHContainerOperations> PCHContainerOps,
  69. DiagnosticConsumer *DiagClient, StringRef outputDir,
  70. bool emitPremigrationARCErrors, StringRef plistOut);
  71. /// Get the set of file remappings from the \p outputDir path that
  72. /// migrateWithTemporaryFiles produced.
  73. ///
  74. /// \returns false if no error is produced, true otherwise.
  75. bool getFileRemappings(std::vector<std::pair<std::string,std::string> > &remap,
  76. StringRef outputDir,
  77. DiagnosticConsumer *DiagClient);
  78. /// Get the set of file remappings from a list of files with remapping
  79. /// info.
  80. ///
  81. /// \returns false if no error is produced, true otherwise.
  82. bool getFileRemappingsFromFileList(
  83. std::vector<std::pair<std::string,std::string> > &remap,
  84. ArrayRef<StringRef> remapFiles,
  85. DiagnosticConsumer *DiagClient);
  86. typedef void (*TransformFn)(MigrationPass &pass);
  87. std::vector<TransformFn> getAllTransformations(LangOptions::GCMode OrigGCMode,
  88. bool NoFinalizeRemoval);
  89. class MigrationProcess {
  90. CompilerInvocation OrigCI;
  91. std::shared_ptr<PCHContainerOperations> PCHContainerOps;
  92. DiagnosticConsumer *DiagClient;
  93. FileRemapper Remapper;
  94. public:
  95. bool HadARCErrors;
  96. MigrationProcess(const CompilerInvocation &CI,
  97. std::shared_ptr<PCHContainerOperations> PCHContainerOps,
  98. DiagnosticConsumer *diagClient,
  99. StringRef outputDir = StringRef());
  100. class RewriteListener {
  101. public:
  102. virtual ~RewriteListener();
  103. virtual void start(ASTContext &Ctx) { }
  104. virtual void finish() { }
  105. virtual void insert(SourceLocation loc, StringRef text) { }
  106. virtual void remove(CharSourceRange range) { }
  107. };
  108. bool applyTransform(TransformFn trans, RewriteListener *listener = nullptr);
  109. FileRemapper &getRemapper() { return Remapper; }
  110. };
  111. } // end namespace arcmt
  112. } // end namespace clang
  113. #endif
  114. #ifdef __GNUC__
  115. #pragma GCC diagnostic pop
  116. #endif