clang  10.0.0svn
FileRemapper.h
Go to the documentation of this file.
1 //===-- FileRemapper.h - File Remapping Helper ------------------*- C++ -*-===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #ifndef LLVM_CLANG_ARCMIGRATE_FILEREMAPPER_H
10 #define LLVM_CLANG_ARCMIGRATE_FILEREMAPPER_H
11 
12 #include "clang/Basic/LLVM.h"
13 #include "llvm/ADT/DenseMap.h"
14 #include "llvm/ADT/PointerUnion.h"
15 #include "llvm/ADT/StringRef.h"
16 #include <memory>
17 
18 namespace llvm {
19  class MemoryBuffer;
20 }
21 
22 namespace clang {
23  class FileManager;
24  class FileEntry;
25  class DiagnosticsEngine;
26  class PreprocessorOptions;
27 
28 namespace arcmt {
29 
30 class FileRemapper {
31  // FIXME: Reuse the same FileManager for multiple ASTContexts.
32  std::unique_ptr<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(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);
50 
51  bool overwriteOriginal(DiagnosticsEngine &Diag,
52  StringRef outputDir = StringRef());
53 
54  void remap(StringRef filePath, std::unique_ptr<llvm::MemoryBuffer> memBuf);
55 
56  void applyMappings(PreprocessorOptions &PPOpts) const;
57 
58  void clear(StringRef outputDir = StringRef());
59 
60 private:
61  void remap(const FileEntry *file, std::unique_ptr<llvm::MemoryBuffer> memBuf);
62  void remap(const FileEntry *file, const FileEntry *newfile);
63 
64  const FileEntry *getOriginalFile(StringRef filePath);
65  void resetTarget(Target &targ);
66 
67  bool report(const Twine &err, DiagnosticsEngine &Diag);
68 
69  std::string getRemapInfoFile(StringRef outputDir);
70 };
71 
72 } // end namespace arcmt
73 
74 } // end namespace clang
75 
76 #endif
static DiagnosticBuilder Diag(DiagnosticsEngine *Diags, const LangOptions &Features, FullSourceLoc TokLoc, const char *TokBegin, const char *TokRangeBegin, const char *TokRangeEnd, unsigned DiagID)
Produce a diagnostic highlighting some portion of a literal.
Specialize PointerLikeTypeTraits to allow LazyGenerationalUpdatePtr to be placed into a PointerUnion...
Definition: Dominators.h:30
virtual void clear()
PreprocessorOptions - This class is used for passing the various options used in preprocessor initial...
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified...
Concrete class used by the front-end to report problems and issues.
Definition: Diagnostic.h:149
Cached information about one file (either on disk or in the virtual file system). ...
Definition: FileManager.h:78
Dataflow Directional Tag Classes.