clang API Documentation
00001 //===-- ARCMT.h - ARC Migration Rewriter ------------------------*- C++ -*-===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 00010 #ifndef LLVM_CLANG_ARCMIGRATE_ARCMT_H 00011 #define LLVM_CLANG_ARCMIGRATE_ARCMT_H 00012 00013 #include "clang/ARCMigrate/FileRemapper.h" 00014 #include "clang/Basic/SourceLocation.h" 00015 #include "clang/Frontend/CompilerInvocation.h" 00016 00017 namespace clang { 00018 class ASTContext; 00019 class DiagnosticConsumer; 00020 00021 namespace arcmt { 00022 class MigrationPass; 00023 00024 /// \brief Creates an AST with the provided CompilerInvocation but with these 00025 /// changes: 00026 /// -if a PCH/PTH is set, the original header is used instead 00027 /// -Automatic Reference Counting mode is enabled 00028 /// 00029 /// It then checks the AST and produces errors/warning for ARC migration issues 00030 /// that the user needs to handle manually. 00031 /// 00032 /// \param emitPremigrationARCErrors if true all ARC errors will get emitted 00033 /// even if the migrator can fix them, but the function will still return false 00034 /// if all ARC errors can be fixed. 00035 /// 00036 /// \param plistOut if non-empty, it is the file path to store the plist with 00037 /// the pre-migration ARC diagnostics. 00038 /// 00039 /// \returns false if no error is produced, true otherwise. 00040 bool checkForManualIssues(CompilerInvocation &CI, 00041 const FrontendInputFile &Input, 00042 DiagnosticConsumer *DiagClient, 00043 bool emitPremigrationARCErrors = false, 00044 StringRef plistOut = StringRef()); 00045 00046 /// \brief Works similar to checkForManualIssues but instead of checking, it 00047 /// applies automatic modifications to source files to conform to ARC. 00048 /// 00049 /// \returns false if no error is produced, true otherwise. 00050 bool applyTransformations(CompilerInvocation &origCI, 00051 const FrontendInputFile &Input, 00052 DiagnosticConsumer *DiagClient); 00053 00054 /// \brief Applies automatic modifications and produces temporary files 00055 /// and metadata into the \p outputDir path. 00056 /// 00057 /// \param emitPremigrationARCErrors if true all ARC errors will get emitted 00058 /// even if the migrator can fix them, but the function will still return false 00059 /// if all ARC errors can be fixed. 00060 /// 00061 /// \param plistOut if non-empty, it is the file path to store the plist with 00062 /// the pre-migration ARC diagnostics. 00063 /// 00064 /// \returns false if no error is produced, true otherwise. 00065 bool migrateWithTemporaryFiles(CompilerInvocation &origCI, 00066 const FrontendInputFile &Input, 00067 DiagnosticConsumer *DiagClient, 00068 StringRef outputDir, 00069 bool emitPremigrationARCErrors, 00070 StringRef plistOut); 00071 00072 /// \brief Get the set of file remappings from the \p outputDir path that 00073 /// migrateWithTemporaryFiles produced. 00074 /// 00075 /// \returns false if no error is produced, true otherwise. 00076 bool getFileRemappings(std::vector<std::pair<std::string,std::string> > &remap, 00077 StringRef outputDir, 00078 DiagnosticConsumer *DiagClient); 00079 00080 /// \brief Get the set of file remappings from a list of files with remapping 00081 /// info. 00082 /// 00083 /// \returns false if no error is produced, true otherwise. 00084 bool getFileRemappingsFromFileList( 00085 std::vector<std::pair<std::string,std::string> > &remap, 00086 ArrayRef<StringRef> remapFiles, 00087 DiagnosticConsumer *DiagClient); 00088 00089 typedef void (*TransformFn)(MigrationPass &pass); 00090 00091 std::vector<TransformFn> getAllTransformations(LangOptions::GCMode OrigGCMode, 00092 bool NoFinalizeRemoval); 00093 00094 class MigrationProcess { 00095 CompilerInvocation OrigCI; 00096 DiagnosticConsumer *DiagClient; 00097 FileRemapper Remapper; 00098 00099 public: 00100 bool HadARCErrors; 00101 00102 MigrationProcess(const CompilerInvocation &CI, DiagnosticConsumer *diagClient, 00103 StringRef outputDir = StringRef()); 00104 00105 class RewriteListener { 00106 public: 00107 virtual ~RewriteListener(); 00108 00109 virtual void start(ASTContext &Ctx) { } 00110 virtual void finish() { } 00111 00112 virtual void insert(SourceLocation loc, StringRef text) { } 00113 virtual void remove(CharSourceRange range) { } 00114 }; 00115 00116 bool applyTransform(TransformFn trans, RewriteListener *listener = nullptr); 00117 00118 FileRemapper &getRemapper() { return Remapper; } 00119 }; 00120 00121 } // end namespace arcmt 00122 00123 } // end namespace clang 00124 00125 #endif