edit-context.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /* Determining the results of applying fix-it hints.
  2. Copyright (C) 2016-2019 Free Software Foundation, Inc.
  3. This file is part of GCC.
  4. GCC is free software; you can redistribute it and/or modify it under
  5. the terms of the GNU General Public License as published by the Free
  6. Software Foundation; either version 3, or (at your option) any later
  7. version.
  8. GCC is distributed in the hope that it will be useful, but WITHOUT ANY
  9. WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10. FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  11. for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with GCC; see the file COPYING3. If not see
  14. <http://www.gnu.org/licenses/>. */
  15. #ifndef GCC_EDIT_CONTEXT_H
  16. #define GCC_EDIT_CONTEXT_H
  17. #include "typed-splay-tree.h"
  18. class edit_context;
  19. class edited_file;
  20. /* A set of changes to the source code.
  21. The changes are "atomic" - if any changes can't be applied,
  22. none of them can be (tracked by the m_valid flag).
  23. Similarly, attempts to add the changes from a rich_location flagged
  24. as containing invalid changes mean that the whole of the edit_context
  25. is flagged as invalid.
  26. A complication here is that fix-its are expressed relative to coordinates
  27. in the files when they were parsed, before any changes have been made, and
  28. so if there's more that one fix-it to be applied, we have to adjust
  29. later fix-its to allow for the changes made by earlier ones. This
  30. is done by the various "get_effective_column" methods. */
  31. class edit_context
  32. {
  33. public:
  34. edit_context ();
  35. bool valid_p () const { return m_valid; }
  36. void add_fixits (rich_location *richloc);
  37. char *get_content (const char *filename);
  38. int get_effective_column (const char *filename, int line, int column);
  39. char *generate_diff (bool show_filenames);
  40. void print_diff (pretty_printer *pp, bool show_filenames);
  41. private:
  42. bool apply_fixit (const fixit_hint *hint);
  43. edited_file *get_file (const char *filename);
  44. edited_file &get_or_insert_file (const char *filename);
  45. bool m_valid;
  46. typed_splay_tree<const char *, edited_file *> m_files;
  47. };
  48. #endif /* GCC_EDIT_CONTEXT_H. */