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

Side by Side 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 3 years, 12 months 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "EditTracker.h"
6
7 #include <assert.h>
8 #include <stdio.h>
9 #include "llvm/Support/Path.h"
10 #include "llvm/Support/raw_ostream.h"
11
12 void EditTracker::Add(const clang::SourceManager& source_manager,
13 clang::SourceLocation location,
14 llvm::StringRef original_text,
15 llvm::StringRef new_text) {
16 // TODO(dcheng): Can we assume filenames in Chrome are unique? I recall some
17 // 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
18 llvm::StringRef filename;
19 for (int i = 0; i < 10; i++) {
20 filename = source_manager.getFilename(location);
21 if (!filename.empty() || !location.isMacroID())
22 break;
23 // Otherwise, no filename and the SourceLocation is a macro ID. Look one
24 // level up the stack...
25 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
26 }
27 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.
28 auto result = tracked_edits_.try_emplace(original_text);
29 if (result.second) {
30 result.first->getValue().new_text = new_text;
31 }
32 result.first->getValue().filenames.try_emplace(
33 llvm::sys::path::filename(filename));
34 }
35
36 void EditTracker::SerializeTo(llvm::StringRef prefix,
37 llvm::raw_ostream& output) const {
38 for (const auto& edit : tracked_edits_) {
39 for (const auto& filename : edit.getValue().filenames) {
40 output << filename.getKey() << ":" << prefix << ":" << edit.getKey()
41 << ":" << edit.getValue().new_text << "\n";
42 }
43 }
44 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698