Home | History | Annotate | Download | only in ARCMigrate
      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 "llvm/ADT/OwningPtr.h"
     14 #include "llvm/ADT/PointerUnion.h"
     15 #include "llvm/ADT/DenseMap.h"
     16 #include "llvm/ADT/StringRef.h"
     17 
     18 namespace llvm {
     19   class MemoryBuffer;
     20 }
     21 
     22 namespace clang {
     23   class FileManager;
     24   class FileEntry;
     25   class Diagnostic;
     26   class CompilerInvocation;
     27 
     28 namespace arcmt {
     29 
     30 class FileRemapper {
     31   // FIXME: Reuse the same FileManager for multiple ASTContexts.
     32   llvm::OwningPtr<FileManager> FileMgr;
     33 
     34   typedef llvm::PointerUnion<const FileEntry *, llvm::MemoryBuffer *> Target;
     35   typedef llvm::DenseMap<const FileEntry *, Target> MappingsTy;
     36   MappingsTy FromToMappings;
     37 
     38   llvm::DenseMap<const FileEntry *, const FileEntry *> ToFromMappings;
     39 
     40 public:
     41   FileRemapper();
     42   ~FileRemapper();
     43 
     44   bool initFromDisk(llvm::StringRef outputDir, Diagnostic &Diag,
     45                     bool ignoreIfFilesChanged);
     46   bool flushToDisk(llvm::StringRef outputDir, Diagnostic &Diag);
     47 
     48   bool overwriteOriginal(Diagnostic &Diag,
     49                          llvm::StringRef outputDir = llvm::StringRef());
     50 
     51   void remap(llvm::StringRef filePath, llvm::MemoryBuffer *memBuf);
     52   void remap(llvm::StringRef filePath, llvm::StringRef newPath);
     53 
     54   void applyMappings(CompilerInvocation &CI) const;
     55 
     56   void transferMappingsAndClear(CompilerInvocation &CI);
     57 
     58   void clear(llvm::StringRef outputDir = llvm::StringRef());
     59 
     60 private:
     61   void remap(const FileEntry *file, llvm::MemoryBuffer *memBuf);
     62   void remap(const FileEntry *file, const FileEntry *newfile);
     63 
     64   const FileEntry *getOriginalFile(llvm::StringRef filePath);
     65   void resetTarget(Target &targ);
     66 
     67   bool report(const std::string &err, Diagnostic &Diag);
     68 
     69   std::string getRemapInfoFile(llvm::StringRef outputDir);
     70 };
     71 
     72 } // end namespace arcmt
     73 
     74 }  // end namespace clang
     75 
     76 #endif
     77