clang API Documentation
00001 //===-- FileRemapper.h - File Remapping Helper ------------------*- 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_FILEREMAPPER_H 00011 #define LLVM_CLANG_ARCMIGRATE_FILEREMAPPER_H 00012 00013 #include "clang/Basic/LLVM.h" 00014 #include "llvm/ADT/OwningPtr.h" 00015 #include "llvm/ADT/PointerUnion.h" 00016 #include "llvm/ADT/DenseMap.h" 00017 #include "llvm/ADT/StringRef.h" 00018 00019 namespace llvm { 00020 class MemoryBuffer; 00021 } 00022 00023 namespace clang { 00024 class FileManager; 00025 class FileEntry; 00026 class DiagnosticsEngine; 00027 class PreprocessorOptions; 00028 00029 namespace arcmt { 00030 00031 class FileRemapper { 00032 // FIXME: Reuse the same FileManager for multiple ASTContexts. 00033 OwningPtr<FileManager> FileMgr; 00034 00035 typedef llvm::PointerUnion<const FileEntry *, llvm::MemoryBuffer *> Target; 00036 typedef llvm::DenseMap<const FileEntry *, Target> MappingsTy; 00037 MappingsTy FromToMappings; 00038 00039 llvm::DenseMap<const FileEntry *, const FileEntry *> ToFromMappings; 00040 00041 public: 00042 FileRemapper(); 00043 ~FileRemapper(); 00044 00045 bool initFromDisk(StringRef outputDir, DiagnosticsEngine &Diag, 00046 bool ignoreIfFilesChanged); 00047 bool initFromFile(StringRef filePath, DiagnosticsEngine &Diag, 00048 bool ignoreIfFilesChanged); 00049 bool flushToDisk(StringRef outputDir, DiagnosticsEngine &Diag); 00050 bool flushToFile(StringRef outputPath, DiagnosticsEngine &Diag); 00051 00052 bool overwriteOriginal(DiagnosticsEngine &Diag, 00053 StringRef outputDir = StringRef()); 00054 00055 void remap(StringRef filePath, llvm::MemoryBuffer *memBuf); 00056 void remap(StringRef filePath, StringRef newPath); 00057 00058 void applyMappings(PreprocessorOptions &PPOpts) const; 00059 00060 void transferMappingsAndClear(PreprocessorOptions &PPOpts); 00061 00062 void clear(StringRef outputDir = StringRef()); 00063 00064 private: 00065 void remap(const FileEntry *file, llvm::MemoryBuffer *memBuf); 00066 void remap(const FileEntry *file, const FileEntry *newfile); 00067 00068 const FileEntry *getOriginalFile(StringRef filePath); 00069 void resetTarget(Target &targ); 00070 00071 bool report(const Twine &err, DiagnosticsEngine &Diag); 00072 00073 std::string getRemapInfoFile(StringRef outputDir); 00074 }; 00075 00076 } // end namespace arcmt 00077 00078 } // end namespace clang 00079 00080 #endif