clang 10.0.0git

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
Diag
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.
Definition: LiteralSupport.cpp:77
llvm
Specialize PointerLikeTypeTraits to allow LazyGenerationalUpdatePtr to be placed into a PointerUnion...
Definition: Dominators.h:30
clang::CodeGen::clear
virtual void clear()
clang::PreprocessorOptions
PreprocessorOptions - This class is used for passing the various options used in preprocessor initial...
Definition: PreprocessorOptions.h:45
LLVM.h
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified...
clang::DiagnosticsEngine
Concrete class used by the front-end to report problems and issues.
Definition: Diagnostic.h:149
clang::arcmt::FileRemapper
Definition: FileRemapper.h:30
clang::FileEntry
Cached information about one file (either on disk or in the virtual file system). ...
Definition: FileManager.h:78
clang
Dataflow Directional Tag Classes.
Definition: CFGReachabilityAnalysis.h:21