summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/cpp11-migrate/Transform.cpp
diff options
context:
space:
mode:
authorEdwin Vane <edwin.vane@intel.com>2013-01-16 21:11:50 +0000
committerEdwin Vane <edwin.vane@intel.com>2013-01-16 21:11:50 +0000
commit862fec88356614724510b9b14d422015103bc9b1 (patch)
tree928c30bc0bd7a932a4520c7388450cd419b18280 /clang-tools-extra/cpp11-migrate/Transform.cpp
parent00dfc68c2d04ffed2e452860cbcd57d50dbe3b86 (diff)
downloadbcm5719-llvm-862fec88356614724510b9b14d422015103bc9b1.tar.gz
bcm5719-llvm-862fec88356614724510b9b14d422015103bc9b1.zip
Write transform results to disk only once
Instead of writing the result of each transform to disk for every transform, write the results to buffers in memory and pass those buffers to the next transform as input. Only write the buffers to disk if the final syntax check passes. Reviewers: klimek llvm-svn: 172657
Diffstat (limited to 'clang-tools-extra/cpp11-migrate/Transform.cpp')
-rw-r--r--clang-tools-extra/cpp11-migrate/Transform.cpp35
1 files changed, 35 insertions, 0 deletions
diff --git a/clang-tools-extra/cpp11-migrate/Transform.cpp b/clang-tools-extra/cpp11-migrate/Transform.cpp
new file mode 100644
index 00000000000..c3203793fe8
--- /dev/null
+++ b/clang-tools-extra/cpp11-migrate/Transform.cpp
@@ -0,0 +1,35 @@
+#include "Transform.h"
+#include "clang/Rewrite/Core/Rewriter.h"
+#include "clang/Basic/FileManager.h"
+#include "clang/Basic/SourceManager.h"
+#include "llvm/Support/raw_ostream.h"
+
+using namespace clang;
+
+void collectResults(clang::Rewriter &Rewrite,
+ FileContentsByPath &Results) {
+ for (Rewriter::buffer_iterator I = Rewrite.buffer_begin(),
+ E = Rewrite.buffer_end();
+ I != E; ++I) {
+ const FileEntry *Entry = Rewrite.getSourceMgr().getFileEntryForID(I->first);
+ assert(Entry != 0 && "Expected a FileEntry");
+ assert(Entry->getName() != 0 &&
+ "Unexpected NULL return from FileEntry::getName()");
+
+ FileContentsByPath::value_type ResultEntry;
+
+ ResultEntry.first = Entry->getName();
+
+ // Get a copy of the rewritten buffer from the Rewriter.
+ llvm::raw_string_ostream StringStream(ResultEntry.second);
+ I->second.write(StringStream);
+
+ // Cause results to be written to ResultEntry.second.
+ StringStream.str();
+
+ // FIXME: Use move semantics to avoid copies of the buffer contents if
+ // benchmarking shows the copies are expensive, especially for large source
+ // files.
+ Results.push_back(ResultEntry);
+ }
+}
OpenPOWER on IntegriCloud