You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

62 lines
2.0KB

  1. /* A class for referring to events within a diagnostic_path.
  2. Copyright (C) 2019-2020 Free Software Foundation, Inc.
  3. Contributed by David Malcolm <dmalcolm@redhat.com>
  4. This file is part of GCC.
  5. GCC is free software; you can redistribute it and/or modify it under
  6. the terms of the GNU General Public License as published by the Free
  7. Software Foundation; either version 3, or (at your option) any later
  8. version.
  9. GCC is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  12. for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with GCC; see the file COPYING3. If not see
  15. <http://www.gnu.org/licenses/>. */
  16. #ifndef GCC_DIAGNOSTIC_EVENT_ID_H
  17. #define GCC_DIAGNOSTIC_EVENT_ID_H
  18. /* A class for referring to events within a diagnostic_path.
  19. They are stored as 0-based offsets into the events, but
  20. printed (e.g. via %@) as 1-based numbers.
  21. For example, a 3-event path has event offsets 0, 1, and 2,
  22. which would be shown to the user as "(1)", "(2)" and "(3)".
  23. This has its own header so that pretty-print.c can use this
  24. to implement "%@" without bringing in all of diagnostic_path
  25. (which e.g. refers to "tree"). */
  26. class diagnostic_event_id_t
  27. {
  28. public:
  29. diagnostic_event_id_t () : m_index (UNKNOWN_EVENT_IDX) {}
  30. diagnostic_event_id_t (int zero_based_idx) : m_index (zero_based_idx) {}
  31. bool known_p () const { return m_index != UNKNOWN_EVENT_IDX; }
  32. int one_based () const
  33. {
  34. gcc_assert (known_p ());
  35. return m_index + 1;
  36. }
  37. private:
  38. static const int UNKNOWN_EVENT_IDX = -1;
  39. int m_index; // zero-based
  40. };
  41. /* A pointer to a diagnostic_event_id_t, for use with the "%@" format
  42. code, which will print a 1-based representation for it, with suitable
  43. colorization, e.g. "(1)".
  44. The %@ format code requires that known_p be true for the event ID. */
  45. typedef diagnostic_event_id_t *diagnostic_event_id_ptr;
  46. #endif /* ! GCC_DIAGNOSTIC_EVENT_ID_H */