Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(149)

Unified Diff: tools/clang/rewrite_to_chrome_style/EditTracker.cpp

Issue 2597863002: rewrite_to_chrome_style: associate replacements with the affected file (Closed)
Patch Set: . Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: tools/clang/rewrite_to_chrome_style/EditTracker.cpp
diff --git a/tools/clang/rewrite_to_chrome_style/EditTracker.cpp b/tools/clang/rewrite_to_chrome_style/EditTracker.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..cd8228ebdf5844c6ba22c66f0e20b38226bfb3ee
--- /dev/null
+++ b/tools/clang/rewrite_to_chrome_style/EditTracker.cpp
@@ -0,0 +1,41 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "EditTracker.h"
+
+#include <assert.h>
+#include <stdio.h>
+#include "llvm/Support/Path.h"
+#include "llvm/Support/raw_ostream.h"
+
+void EditTracker::Add(const clang::SourceManager& source_manager,
+ clang::SourceLocation location,
+ llvm::StringRef original_text,
+ llvm::StringRef new_text) {
+ llvm::StringRef filename;
+ for (int i = 0; i < 10; i++) {
+ filename = source_manager.getFilename(location);
+ if (!filename.empty() || !location.isMacroID())
+ break;
+ // Otherwise, no filename and the SourceLocation is a macro ID. Look one
+ // level up the stack...
+ location = source_manager.getImmediateMacroCallerLoc(location);
+ }
+ assert(!filename.empty() && "Can't track edit with no filename!");
+ auto result = tracked_edits_.try_emplace(original_text);
+ if (result.second) {
+ result.first->getValue().new_text = new_text;
+ }
+ result.first->getValue().filenames.try_emplace(filename);
+}
+
+void EditTracker::SerializeTo(llvm::StringRef tag,
+ llvm::raw_ostream& output) const {
+ for (const auto& edit : tracked_edits_) {
+ for (const auto& filename : edit.getValue().filenames) {
+ output << filename.getKey() << ":" << tag << ":" << edit.getKey() << ":"
+ << edit.getValue().new_text << "\n";
+ }
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698