clang API Documentation

FileRemapper.h
Go to the documentation of this file.
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/DenseMap.h"
00015 #include "llvm/ADT/PointerUnion.h"
00016 #include "llvm/ADT/StringRef.h"
00017 #include <memory>
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   std::unique_ptr<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, std::unique_ptr<llvm::MemoryBuffer> memBuf);
00056 
00057   void applyMappings(PreprocessorOptions &PPOpts) const;
00058 
00059   void clear(StringRef outputDir = StringRef());
00060 
00061 private:
00062   void remap(const FileEntry *file, std::unique_ptr<llvm::MemoryBuffer> memBuf);
00063   void remap(const FileEntry *file, const FileEntry *newfile);
00064 
00065   const FileEntry *getOriginalFile(StringRef filePath);
00066   void resetTarget(Target &targ);
00067 
00068   bool report(const Twine &err, DiagnosticsEngine &Diag);
00069 
00070   std::string getRemapInfoFile(StringRef outputDir);
00071 };
00072 
00073 } // end namespace arcmt
00074 
00075 }  // end namespace clang
00076 
00077 #endif