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

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: actually implement stuff 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..2764d8a0dd863df00cfcfd4c1b758d4bf94033dc
--- /dev/null
+++ b/tools/clang/rewrite_to_chrome_style/EditTracker.cpp
@@ -0,0 +1,44 @@
+// 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) {
+ // TODO(dcheng): Can we assume filenames in Chrome are unique? I recall some
+ // bugs in the past when this wasn't true.
dcheng 2016/12/22 20:49:40 I just dump the entire path now; it's easy enough
+ 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);
Łukasz Anforowicz 2016/12/22 17:34:36 I don't understand why we want to do that here. W
dcheng 2016/12/22 20:49:40 Without this logic to trace upwards, functions tha
+ }
+ assert(!filename.empty() && "Can't track edit with no filename!");
dcheng 2016/12/22 10:26:22 For now, I'm going to be more aggressive and asser
Łukasz Anforowicz 2016/12/22 17:34:36 Agreed, but please see me comment above.
+ auto result = tracked_edits_.try_emplace(original_text);
+ if (result.second) {
+ result.first->getValue().new_text = new_text;
+ }
+ result.first->getValue().filenames.try_emplace(
+ llvm::sys::path::filename(filename));
+}
+
+void EditTracker::SerializeTo(llvm::StringRef prefix,
+ llvm::raw_ostream& output) const {
+ for (const auto& edit : tracked_edits_) {
+ for (const auto& filename : edit.getValue().filenames) {
+ output << filename.getKey() << ":" << prefix << ":" << edit.getKey()
+ << ":" << edit.getValue().new_text << "\n";
+ }
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698