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 #ifndef TOOLS_CLANG_REWRITE_TO_CHROME_STYLE_EDIT_TRACKER_H_ 6 #define TOOLS_CLANG_REWRITE_TO_CHROME_STYLE_EDIT_TRACKER_H_ 7 8 #include <map> 9 10 #include "clang/Basic/SourceLocation.h" 11 #include "clang/Basic/SourceManager.h" 12 #include "llvm/ADT/StringMap.h" 13 #include "llvm/ADT/StringRef.h" 14 #include "llvm/ADT/StringSet.h" 15 16 namespace llvm { 17 class raw_ostream; 18 } // namespace llvm 19 20 struct EditInfo { 21 std::string new_text; 22 llvm::StringSet<> filenames; 23 }; 24 25 // Simple class that tracks the edits made by path. Used to dump the databaes 26 // used by the Blink rebase helper. 27 class EditTracker { 28 public: 29 EditTracker() = default; 30 31 void Add(const clang::SourceManager& source_manager, 32 clang::SourceLocation location, 33 llvm::StringRef original_text, 34 llvm::StringRef new_text); 35 36 // Serializes the tracked edits to |output|. Emits: 37 // <filename>:<tag>:<original text>:<new text> 38 // for each distinct filename for each tracked edit. 39 void SerializeTo(llvm::StringRef tag, llvm::raw_ostream& output) const; 40 41 private: 42 EditTracker(const EditTracker&) = delete; 43 EditTracker& operator=(const EditTracker&) = delete; 44 45 // The string key is the original text. 46 llvm::StringMap<EditInfo> tracked_edits_; 47 }; 48 49 #endif // #define TOOLS_CLANG_REWRITE_TO_CHROME_STYLE_EDIT_TRACKER_H_ 50