EditTracker.h 1.6 KB

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