Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:36:27

0001 //===-- ARCMT.h - ARC Migration Rewriter ------------------------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 
0009 #ifndef LLVM_CLANG_ARCMIGRATE_ARCMT_H
0010 #define LLVM_CLANG_ARCMIGRATE_ARCMT_H
0011 
0012 #include "clang/ARCMigrate/FileRemapper.h"
0013 #include "clang/Basic/SourceLocation.h"
0014 #include "clang/Frontend/CompilerInvocation.h"
0015 
0016 namespace clang {
0017   class ASTContext;
0018   class DiagnosticConsumer;
0019   class PCHContainerOperations;
0020 
0021 namespace arcmt {
0022   class MigrationPass;
0023 
0024 /// Creates an AST with the provided CompilerInvocation but with these
0025 /// changes:
0026 ///   -if a PCH/PTH is set, the original header is used instead
0027 ///   -Automatic Reference Counting mode is enabled
0028 ///
0029 /// It then checks the AST and produces errors/warning for ARC migration issues
0030 /// that the user needs to handle manually.
0031 ///
0032 /// \param emitPremigrationARCErrors if true all ARC errors will get emitted
0033 /// even if the migrator can fix them, but the function will still return false
0034 /// if all ARC errors can be fixed.
0035 ///
0036 /// \param plistOut if non-empty, it is the file path to store the plist with
0037 /// the pre-migration ARC diagnostics.
0038 ///
0039 /// \returns false if no error is produced, true otherwise.
0040 bool
0041 checkForManualIssues(CompilerInvocation &CI, const FrontendInputFile &Input,
0042                      std::shared_ptr<PCHContainerOperations> PCHContainerOps,
0043                      DiagnosticConsumer *DiagClient,
0044                      bool emitPremigrationARCErrors = false,
0045                      StringRef plistOut = StringRef());
0046 
0047 /// Works similar to checkForManualIssues but instead of checking, it
0048 /// applies automatic modifications to source files to conform to ARC.
0049 ///
0050 /// \returns false if no error is produced, true otherwise.
0051 bool
0052 applyTransformations(CompilerInvocation &origCI,
0053                      const FrontendInputFile &Input,
0054                      std::shared_ptr<PCHContainerOperations> PCHContainerOps,
0055                      DiagnosticConsumer *DiagClient);
0056 
0057 /// Applies automatic modifications and produces temporary files
0058 /// and metadata into the \p outputDir path.
0059 ///
0060 /// \param emitPremigrationARCErrors if true all ARC errors will get emitted
0061 /// even if the migrator can fix them, but the function will still return false
0062 /// if all ARC errors can be fixed.
0063 ///
0064 /// \param plistOut if non-empty, it is the file path to store the plist with
0065 /// the pre-migration ARC diagnostics.
0066 ///
0067 /// \returns false if no error is produced, true otherwise.
0068 bool migrateWithTemporaryFiles(
0069     CompilerInvocation &origCI, const FrontendInputFile &Input,
0070     std::shared_ptr<PCHContainerOperations> PCHContainerOps,
0071     DiagnosticConsumer *DiagClient, StringRef outputDir,
0072     bool emitPremigrationARCErrors, StringRef plistOut);
0073 
0074 /// Get the set of file remappings from the \p outputDir path that
0075 /// migrateWithTemporaryFiles produced.
0076 ///
0077 /// \returns false if no error is produced, true otherwise.
0078 bool getFileRemappings(std::vector<std::pair<std::string,std::string> > &remap,
0079                        StringRef outputDir,
0080                        DiagnosticConsumer *DiagClient);
0081 
0082 /// Get the set of file remappings from a list of files with remapping
0083 /// info.
0084 ///
0085 /// \returns false if no error is produced, true otherwise.
0086 bool getFileRemappingsFromFileList(
0087                         std::vector<std::pair<std::string,std::string> > &remap,
0088                         ArrayRef<StringRef> remapFiles,
0089                         DiagnosticConsumer *DiagClient);
0090 
0091 typedef void (*TransformFn)(MigrationPass &pass);
0092 
0093 std::vector<TransformFn> getAllTransformations(LangOptions::GCMode OrigGCMode,
0094                                                bool NoFinalizeRemoval);
0095 
0096 class MigrationProcess {
0097   CompilerInvocation OrigCI;
0098   std::shared_ptr<PCHContainerOperations> PCHContainerOps;
0099   DiagnosticConsumer *DiagClient;
0100   FileRemapper Remapper;
0101 
0102 public:
0103   bool HadARCErrors;
0104 
0105   MigrationProcess(CompilerInvocation &CI,
0106                    std::shared_ptr<PCHContainerOperations> PCHContainerOps,
0107                    DiagnosticConsumer *diagClient,
0108                    StringRef outputDir = StringRef());
0109 
0110   class RewriteListener {
0111   public:
0112     virtual ~RewriteListener();
0113 
0114     virtual void start(ASTContext &Ctx) { }
0115     virtual void finish() { }
0116 
0117     virtual void insert(SourceLocation loc, StringRef text) { }
0118     virtual void remove(CharSourceRange range) { }
0119   };
0120 
0121   bool applyTransform(TransformFn trans, RewriteListener *listener = nullptr);
0122 
0123   FileRemapper &getRemapper() { return Remapper; }
0124 };
0125 
0126 } // end namespace arcmt
0127 
0128 }  // end namespace clang
0129 
0130 #endif