]> gcc.gnu.org Git - gcc.git/commitdiff
libcpp: move label_text to its own header
authorDavid Malcolm <dmalcolm@redhat.com>
Tue, 28 May 2024 19:55:24 +0000 (15:55 -0400)
committerDavid Malcolm <dmalcolm@redhat.com>
Tue, 28 May 2024 19:55:24 +0000 (15:55 -0400)
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>
libcpp/Makefile.in
libcpp/include/label-text.h [new file with mode: 0644]
libcpp/include/rich-location.h

index ebbca37777fb4fe586233ffb4bb83c90ec753005..7e47153264c01ac856f68298b0f5cedd8263a599 100644 (file)
@@ -271,7 +271,7 @@ ETAGS = @ETAGS@
 
 TAGS_SOURCES = $(libcpp_a_SOURCES) internal.h system.h ucnid.h \
     include/cpplib.h include/line-map.h include/mkdeps.h include/symtab.h \
-    include/rich-location.h
+    include/rich-location.h include/label-text.h
 
 
 TAGS: $(TAGS_SOURCES)
diff --git a/libcpp/include/label-text.h b/libcpp/include/label-text.h
new file mode 100644 (file)
index 0000000..13562cd
--- /dev/null
@@ -0,0 +1,102 @@
+/* A very simple string class.
+   Copyright (C) 2015-2024 Free Software Foundation, Inc.
+
+This program is free software; you can redistribute it and/or modify it
+under the terms of the GNU General Public License as published by the
+Free Software Foundation; either version 3, or (at your option) any
+later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; see the file COPYING3.  If not see
+<http://www.gnu.org/licenses/>.
+
+ In other words, you are welcome to use, share and improve this program.
+ You are forbidden to forbid anyone else to use, share and improve
+ what you give them.   Help stamp out software-hoarding!  */
+
+#ifndef LIBCPP_LABEL_TEXT_H
+#define LIBCPP_LABEL_TEXT_H
+
+/* 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)
+  {}
+};
+
+#endif /* !LIBCPP_LABEL_TEXT_H  */
index a2ece8b033c0decb6a9e261db40f30b729ee84f5..be424cb4b65f8145cb12a15f214f37e359d1fd73 100644 (file)
@@ -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).
 
This page took 0.070482 seconds and 5 git commands to generate.