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