[PATCH] D90887: ARCMigrate: Stop abusing PreprocessorOptions for passing back file remappings, NFC

Duncan P. N. Exon Smith via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Nov 5 14:26:59 PST 2020


dexonsmith created this revision.
dexonsmith added reviewers: arphaman, JDevlieghere.
Herald added a subscriber: ributzka.
dexonsmith requested review of this revision.

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.


https://reviews.llvm.org/D90887

Files:
  clang/include/clang/ARCMigrate/FileRemapper.h
  clang/lib/ARCMigrate/ARCMT.cpp
  clang/lib/ARCMigrate/FileRemapper.cpp
  clang/tools/arcmt-test/arcmt-test.cpp


Index: clang/tools/arcmt-test/arcmt-test.cpp
===================================================================
--- clang/tools/arcmt-test/arcmt-test.cpp
+++ clang/tools/arcmt-test/arcmt-test.cpp
@@ -139,11 +139,10 @@
 }
 
 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,
Index: clang/lib/ARCMigrate/FileRemapper.cpp
===================================================================
--- clang/lib/ARCMigrate/FileRemapper.cpp
+++ clang/lib/ARCMigrate/FileRemapper.cpp
@@ -190,6 +190,21 @@
   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) {
Index: clang/lib/ARCMigrate/ARCMT.cpp
===================================================================
--- clang/lib/ARCMigrate/ARCMT.cpp
+++ clang/lib/ARCMigrate/ARCMT.cpp
@@ -416,9 +416,11 @@
   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;
 }
Index: clang/include/clang/ARCMigrate/FileRemapper.h
===================================================================
--- clang/include/clang/ARCMigrate/FileRemapper.h
+++ 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 @@
 
   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:


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D90887.303262.patch
Type: text/x-patch
Size: 3226 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20201105/fc3875e1/attachment.bin>


More information about the cfe-commits mailing list