1//===-- FileRemapper.h - File Remapping Helper ------------------*- C++ -*-===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9 10#ifndef LLVM_CLANG_ARCMIGRATE_FILEREMAPPER_H 11#define LLVM_CLANG_ARCMIGRATE_FILEREMAPPER_H 12 13#include "clang/Basic/LLVM.h" 14#include "llvm/ADT/DenseMap.h" 15#include "llvm/ADT/OwningPtr.h" 16#include "llvm/ADT/PointerUnion.h" 17#include "llvm/ADT/StringRef.h" 18 19namespace llvm { 20 class MemoryBuffer; 21} 22 23namespace clang { 24 class FileManager; 25 class FileEntry; 26 class DiagnosticsEngine; 27 class PreprocessorOptions; 28 29namespace arcmt { 30 31class FileRemapper { 32 // FIXME: Reuse the same FileManager for multiple ASTContexts. 33 OwningPtr<FileManager> FileMgr; 34 35 typedef llvm::PointerUnion<const FileEntry *, llvm::MemoryBuffer *> Target; 36 typedef llvm::DenseMap<const FileEntry *, Target> MappingsTy; 37 MappingsTy FromToMappings; 38 39 llvm::DenseMap<const FileEntry *, const FileEntry *> ToFromMappings; 40 41public: 42 FileRemapper(); 43 ~FileRemapper(); 44 45 bool initFromDisk(StringRef outputDir, DiagnosticsEngine &Diag, 46 bool ignoreIfFilesChanged); 47 bool initFromFile(StringRef filePath, DiagnosticsEngine &Diag, 48 bool ignoreIfFilesChanged); 49 bool flushToDisk(StringRef outputDir, DiagnosticsEngine &Diag); 50 bool flushToFile(StringRef outputPath, DiagnosticsEngine &Diag); 51 52 bool overwriteOriginal(DiagnosticsEngine &Diag, 53 StringRef outputDir = StringRef()); 54 55 void remap(StringRef filePath, llvm::MemoryBuffer *memBuf); 56 57 void applyMappings(PreprocessorOptions &PPOpts) const; 58 59 void transferMappingsAndClear(PreprocessorOptions &PPOpts); 60 61 void clear(StringRef outputDir = StringRef()); 62 63private: 64 void remap(const FileEntry *file, llvm::MemoryBuffer *memBuf); 65 void remap(const FileEntry *file, const FileEntry *newfile); 66 67 const FileEntry *getOriginalFile(StringRef filePath); 68 void resetTarget(Target &targ); 69 70 bool report(const Twine &err, DiagnosticsEngine &Diag); 71 72 std::string getRemapInfoFile(StringRef outputDir); 73}; 74 75} // end namespace arcmt 76 77} // end namespace clang 78 79#endif 80