[llvm-branch-commits] [clang] dcc4f7f - ARCMigrate: Stop abusing PreprocessorOptions for passing back file remappings, NFC
Duncan P. N. Exon Smith via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Wed Dec 2 16:33:34 PST 2020
Author: Duncan P. N. Exon Smith
Date: 2020-12-02T16:28:33-08:00
New Revision: dcc4f7f3c4b4442710ae73d6f73cded665426678
URL: https://github.com/llvm/llvm-project/commit/dcc4f7f3c4b4442710ae73d6f73cded665426678
DIFF: https://github.com/llvm/llvm-project/commit/dcc4f7f3c4b4442710ae73d6f73cded665426678.diff
LOG: ARCMigrate: Stop abusing PreprocessorOptions for passing back file remappings, NFC
As part of reducing use of PreprocessorOptions::RemappedFileBuffers,
stop abusing it to pass information around remapped files in
`ARCMigrate`. This simplifies an eventual follow-up to switch to using
an `InMemoryFileSystem` for this.
Differential Revision: https://reviews.llvm.org/D90887
Added:
Modified:
clang/include/clang/ARCMigrate/FileRemapper.h
clang/lib/ARCMigrate/ARCMT.cpp
clang/lib/ARCMigrate/FileRemapper.cpp
clang/tools/arcmt-test/arcmt-test.cpp
Removed:
################################################################################
diff --git a/clang/include/clang/ARCMigrate/FileRemapper.h b/clang/include/clang/ARCMigrate/FileRemapper.h
index 76b65b2f6884..4da68a678be2 100644
--- a/clang/include/clang/ARCMigrate/FileRemapper.h
+++ b/clang/include/clang/ARCMigrate/FileRemapper.h
@@ -12,11 +12,13 @@
#include "clang/Basic/LLVM.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/PointerUnion.h"
+#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/StringRef.h"
#include <memory>
namespace llvm {
class MemoryBuffer;
+ class MemoryBufferRef;
}
namespace clang {
@@ -55,6 +57,12 @@ class FileRemapper {
void applyMappings(PreprocessorOptions &PPOpts) const;
+ /// Iterate through all the mappings.
+ void forEachMapping(
+ llvm::function_ref<void(StringRef, StringRef)> CaptureFile,
+ llvm::function_ref<void(StringRef, const llvm::MemoryBufferRef &)>
+ CaptureBuffer) const;
+
void clear(StringRef outputDir = StringRef());
private:
diff --git a/clang/lib/ARCMigrate/ARCMT.cpp b/clang/lib/ARCMigrate/ARCMT.cpp
index e18def8a0b19..36fbe90e1e3a 100644
--- a/clang/lib/ARCMigrate/ARCMT.cpp
+++ b/clang/lib/ARCMigrate/ARCMT.cpp
@@ -416,9 +416,11 @@ bool arcmt::getFileRemappings(std::vector<std::pair<std::string,std::string> > &
if (err)
return true;
- PreprocessorOptions PPOpts;
- remapper.applyMappings(PPOpts);
- remap = PPOpts.RemappedFiles;
+ remapper.forEachMapping(
+ [&](StringRef From, StringRef To) {
+ remap.push_back(std::make_pair(From.str(), To.str()));
+ },
+ [](StringRef, const llvm::MemoryBufferRef &) {});
return false;
}
diff --git a/clang/lib/ARCMigrate/FileRemapper.cpp b/clang/lib/ARCMigrate/FileRemapper.cpp
index 0222583c015b..f536af1795ed 100644
--- a/clang/lib/ARCMigrate/FileRemapper.cpp
+++ b/clang/lib/ARCMigrate/FileRemapper.cpp
@@ -190,6 +190,21 @@ bool FileRemapper::overwriteOriginal(DiagnosticsEngine &Diag,
return false;
}
+void FileRemapper::forEachMapping(
+ llvm::function_ref<void(StringRef, StringRef)> CaptureFile,
+ llvm::function_ref<void(StringRef, const llvm::MemoryBufferRef &)>
+ CaptureBuffer) const {
+ for (auto &Mapping : FromToMappings) {
+ if (const FileEntry *FE = Mapping.second.dyn_cast<const FileEntry *>()) {
+ CaptureFile(Mapping.first->getName(), FE->getName());
+ continue;
+ }
+ CaptureBuffer(
+ Mapping.first->getName(),
+ Mapping.second.get<llvm::MemoryBuffer *>()->getMemBufferRef());
+ }
+}
+
void FileRemapper::applyMappings(PreprocessorOptions &PPOpts) const {
for (MappingsTy::const_iterator
I = FromToMappings.begin(), E = FromToMappings.end(); I != E; ++I) {
diff --git a/clang/tools/arcmt-test/arcmt-test.cpp b/clang/tools/arcmt-test/arcmt-test.cpp
index c4ba12d4f7cf..940e622b8a68 100644
--- a/clang/tools/arcmt-test/arcmt-test.cpp
+++ b/clang/tools/arcmt-test/arcmt-test.cpp
@@ -139,11 +139,10 @@ static bool checkForMigration(StringRef resourcesPath,
}
static void printResult(FileRemapper &remapper, raw_ostream &OS) {
- PreprocessorOptions PPOpts;
- remapper.applyMappings(PPOpts);
- // The changed files will be in memory buffers, print them.
- for (const auto &RB : PPOpts.RemappedFileBuffers)
- OS << RB.second->getBuffer();
+ remapper.forEachMapping([](StringRef, StringRef) {},
+ [&](StringRef, const llvm::MemoryBufferRef &Buffer) {
+ OS << Buffer.getBuffer();
+ });
}
static bool performTransformations(StringRef resourcesPath,
More information about the llvm-branch-commits
mailing list