1 //===-- FileRemapper.h - File Remapping Helper ------------------*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #ifndef LLVM_CLANG_ARCMIGRATE_FILEREMAPPER_H
10 #define LLVM_CLANG_ARCMIGRATE_FILEREMAPPER_H
12 #include "clang/Basic/LLVM.h"
13 #include "llvm/ADT/DenseMap.h"
14 #include "llvm/ADT/PointerUnion.h"
15 #include "llvm/ADT/StringRef.h"
25 class DiagnosticsEngine;
26 class PreprocessorOptions;
31 // FIXME: Reuse the same FileManager for multiple ASTContexts.
32 std::unique_ptr<FileManager> FileMgr;
34 typedef llvm::PointerUnion<const FileEntry *, llvm::MemoryBuffer *> Target;
35 typedef llvm::DenseMap<const FileEntry *, Target> MappingsTy;
36 MappingsTy FromToMappings;
38 llvm::DenseMap<const FileEntry *, const FileEntry *> ToFromMappings;
44 bool initFromDisk(StringRef outputDir, DiagnosticsEngine &Diag,
45 bool ignoreIfFilesChanged);
46 bool initFromFile(StringRef filePath, DiagnosticsEngine &Diag,
47 bool ignoreIfFilesChanged);
48 bool flushToDisk(StringRef outputDir, DiagnosticsEngine &Diag);
49 bool flushToFile(StringRef outputPath, DiagnosticsEngine &Diag);
51 bool overwriteOriginal(DiagnosticsEngine &Diag,
52 StringRef outputDir = StringRef());
54 void remap(StringRef filePath, std::unique_ptr<llvm::MemoryBuffer> memBuf);
56 void applyMappings(PreprocessorOptions &PPOpts) const;
58 void clear(StringRef outputDir = StringRef());
61 void remap(const FileEntry *file, std::unique_ptr<llvm::MemoryBuffer> memBuf);
62 void remap(const FileEntry *file, const FileEntry *newfile);
64 const FileEntry *getOriginalFile(StringRef filePath);
65 void resetTarget(Target &targ);
67 bool report(const Twine &err, DiagnosticsEngine &Diag);
69 std::string getRemapInfoFile(StringRef outputDir);
72 } // end namespace arcmt
74 } // end namespace clang