diff options
author | David Malcolm <dmalcolm@redhat.com> | 2024-05-28 15:55:24 -0400 |
---|---|---|
committer | David Malcolm <dmalcolm@redhat.com> | 2024-05-28 15:55:24 -0400 |
commit | 9bda2c4c81b668b1d9abbb58cc4e805ac955a639 (patch) | |
tree | df4cd9d51d62b3bc7f0343abc2ba945c1858baeb /libcpp/include/rich-location.h | |
parent | fb7a943ead689e80e1ffdf6fa4e129dc155312d3 (diff) | |
download | gcc-9bda2c4c81b668b1d9abbb58cc4e805ac955a639.zip gcc-9bda2c4c81b668b1d9abbb58cc4e805ac955a639.tar.gz gcc-9bda2c4c81b668b1d9abbb58cc4e805ac955a639.tar.bz2 |
libcpp: move label_text to its own header
No functional change intended.
libcpp/ChangeLog:
* Makefile.in (TAGS_SOURCES): Add include/label-text.h.
* include/label-text.h: New file.
* include/rich-location.h: Include "label-text.h".
(class label_text): Move to label-text.h.
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
Diffstat (limited to 'libcpp/include/rich-location.h')
-rw-r--r-- | libcpp/include/rich-location.h | 79 |
1 files changed, 2 insertions, 77 deletions
diff --git a/libcpp/include/rich-location.h b/libcpp/include/rich-location.h index a2ece8b..be424cb 100644 --- a/libcpp/include/rich-location.h +++ b/libcpp/include/rich-location.h @@ -22,6 +22,8 @@ along with this program; see the file COPYING3. If not see #ifndef LIBCPP_RICH_LOCATION_H #define LIBCPP_RICH_LOCATION_H +#include "label-text.h" + class range_label; class label_effects; @@ -541,83 +543,6 @@ protected: const diagnostic_path *m_path; }; -/* A struct for the result of range_label::get_text: a NUL-terminated buffer - of localized text, and a flag to determine if the caller should "free" the - buffer. */ - -class label_text -{ -public: - label_text () - : m_buffer (NULL), m_owned (false) - {} - - ~label_text () - { - if (m_owned) - free (m_buffer); - } - - /* Move ctor. */ - label_text (label_text &&other) - : m_buffer (other.m_buffer), m_owned (other.m_owned) - { - other.release (); - } - - /* Move assignment. */ - label_text & operator= (label_text &&other) - { - if (m_owned) - free (m_buffer); - m_buffer = other.m_buffer; - m_owned = other.m_owned; - other.release (); - return *this; - } - - /* Delete the copy ctor and copy-assignment operator. */ - label_text (const label_text &) = delete; - label_text & operator= (const label_text &) = delete; - - /* Create a label_text instance that borrows BUFFER from a - longer-lived owner. */ - static label_text borrow (const char *buffer) - { - return label_text (const_cast <char *> (buffer), false); - } - - /* Create a label_text instance that takes ownership of BUFFER. */ - static label_text take (char *buffer) - { - return label_text (buffer, true); - } - - void release () - { - m_buffer = NULL; - m_owned = false; - } - - const char *get () const - { - return m_buffer; - } - - bool is_owner () const - { - return m_owned; - } - -private: - char *m_buffer; - bool m_owned; - - label_text (char *buffer, bool owned) - : m_buffer (buffer), m_owned (owned) - {} -}; - /* Abstract base class for labelling a range within a rich_location (e.g. for labelling expressions with their type). |