18f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall//===-- FileRemapper.h - File Remapping Helper ------------------*- C++ -*-===//
28f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall//
38f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall//                     The LLVM Compiler Infrastructure
48f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall//
58f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall// This file is distributed under the University of Illinois Open Source
68f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall// License. See LICENSE.TXT for details.
78f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall//
88f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall//===----------------------------------------------------------------------===//
98f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall
108f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall#ifndef LLVM_CLANG_ARCMIGRATE_FILEREMAPPER_H
118f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall#define LLVM_CLANG_ARCMIGRATE_FILEREMAPPER_H
128f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall
13686775deca8b8685eb90801495880e3abdd844c2Chris Lattner#include "clang/Basic/LLVM.h"
1430a2e16f6c27f888dd11eba6bbbae1e980078fcbChandler Carruth#include "llvm/ADT/DenseMap.h"
158f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall#include "llvm/ADT/PointerUnion.h"
168f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall#include "llvm/ADT/StringRef.h"
17651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines#include <memory>
188f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall
198f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCallnamespace llvm {
208f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall  class MemoryBuffer;
218f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall}
228f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall
238f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCallnamespace clang {
248f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall  class FileManager;
258f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall  class FileEntry;
26d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie  class DiagnosticsEngine;
2730660a898545416f0fea2d717f16f75640001e38Ted Kremenek  class PreprocessorOptions;
288f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall
298f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCallnamespace arcmt {
308f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall
318f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCallclass FileRemapper {
328f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall  // FIXME: Reuse the same FileManager for multiple ASTContexts.
33651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines  std::unique_ptr<FileManager> FileMgr;
348f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall
358f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall  typedef llvm::PointerUnion<const FileEntry *, llvm::MemoryBuffer *> Target;
368f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall  typedef llvm::DenseMap<const FileEntry *, Target> MappingsTy;
378f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall  MappingsTy FromToMappings;
388f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall
398f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall  llvm::DenseMap<const FileEntry *, const FileEntry *> ToFromMappings;
408f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall
418f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCallpublic:
428f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall  FileRemapper();
438f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall  ~FileRemapper();
448f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall
45d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie  bool initFromDisk(StringRef outputDir, DiagnosticsEngine &Diag,
468f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall                    bool ignoreIfFilesChanged);
4730660a898545416f0fea2d717f16f75640001e38Ted Kremenek  bool initFromFile(StringRef filePath, DiagnosticsEngine &Diag,
4830660a898545416f0fea2d717f16f75640001e38Ted Kremenek                    bool ignoreIfFilesChanged);
49d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie  bool flushToDisk(StringRef outputDir, DiagnosticsEngine &Diag);
5030660a898545416f0fea2d717f16f75640001e38Ted Kremenek  bool flushToFile(StringRef outputPath, DiagnosticsEngine &Diag);
518f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall
52d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie  bool overwriteOriginal(DiagnosticsEngine &Diag,
53686775deca8b8685eb90801495880e3abdd844c2Chris Lattner                         StringRef outputDir = StringRef());
548f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall
55686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  void remap(StringRef filePath, llvm::MemoryBuffer *memBuf);
568f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall
5730660a898545416f0fea2d717f16f75640001e38Ted Kremenek  void applyMappings(PreprocessorOptions &PPOpts) const;
588f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall
59686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  void clear(StringRef outputDir = StringRef());
608f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall
618f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCallprivate:
628f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall  void remap(const FileEntry *file, llvm::MemoryBuffer *memBuf);
638f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall  void remap(const FileEntry *file, const FileEntry *newfile);
648f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall
65686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  const FileEntry *getOriginalFile(StringRef filePath);
668f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall  void resetTarget(Target &targ);
678f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall
68d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie  bool report(const Twine &err, DiagnosticsEngine &Diag);
698f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall
70686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  std::string getRemapInfoFile(StringRef outputDir);
718f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall};
728f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall
738f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall} // end namespace arcmt
748f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall
758f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall}  // end namespace clang
768f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall
778f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall#endif
78