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 enum class RenameCategory { 26 kEnumValue, 27 kField, 28 kFunction, 29 kUnresolved, 30 kVariable, 31 }; 32 33 // Simple class that tracks the edits made by path. Used to dump the databaes 34 // used by the Blink rebase helper. 35 class EditTracker { 36 public: 37 explicit EditTracker(RenameCategory category); 38 39 void Add(const clang::SourceManager& source_manager, 40 clang::SourceLocation location, 41 llvm::StringRef original_text, 42 llvm::StringRef new_text); 43 44 // Serializes the tracked edits to |output|. Emits: 45 // <filename>:<tag>:<original text>:<new text> 46 // for each distinct filename for each tracked edit. 47 void SerializeTo(llvm::raw_ostream& output) const; 48 49 private: 50 EditTracker(const EditTracker&) = delete; 51 EditTracker& operator=(const EditTracker&) = delete; 52 53 // The string key is the original text. 54 llvm::StringMap<EditInfo> tracked_edits_; 55 56 RenameCategory category_; 57 }; 58 59 #endif // #define TOOLS_CLANG_REWRITE_TO_CHROME_STYLE_EDIT_TRACKER_H_ 60