From: Andrew Pinski <pinskia@gmail.com>
To: Bert Wesarg <bert.wesarg@googlemail.com>
Cc: David Malcolm <dmalcolm@redhat.com>, gcc-patches@gcc.gnu.org
Subject: Re: [pushed 2/3] libcpp: move label_text to its own header
Date: Thu, 6 Jun 2024 08:40:26 -0700 [thread overview]
Message-ID: <CA+=Sn1k1FaBKX782QNwh18P81_4vYzXAswLXm2B4LphY0AKq1A@mail.gmail.com> (raw)
In-Reply-To: <CAKPyHN0uUD08AY5QOq3GKCxncBVYq6Ovfj270vqr9CuqU913iw@mail.gmail.com>
On Thu, Jun 6, 2024 at 6:02 AM Bert Wesarg <bert.wesarg@googlemail.com> wrote:
>
> Dear David,
>
> On Tue, May 28, 2024 at 10:07 PM David Malcolm <dmalcolm@redhat.com> wrote:
> >
> > No functional change intended.
> >
> > Successfully bootstrapped & regrtested on x86_64-pc-linux-gnu.
> > Pushed to trunk as r15-874-g9bda2c4c81b668.
> >
> > 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 | 2 +-
> > libcpp/include/label-text.h | 102 +++++++++++++++++++++++++++++++++
> > libcpp/include/rich-location.h | 79 +------------------------
> > 3 files changed, 105 insertions(+), 78 deletions(-)
> > create mode 100644 libcpp/include/label-text.h
> >
> > diff --git a/libcpp/Makefile.in b/libcpp/Makefile.in
> > index ebbca37777fb..7e47153264c0 100644
> > --- a/libcpp/Makefile.in
> > +++ b/libcpp/Makefile.in
> > @@ -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
>
> this does not seem to be enough that the new header will be installed.
> I get compile errors when compiling an plug-in with this patch:
>
> In file included from
> /home/bitten/opt/gcc-15-20240602/lib/gcc/x86_64-pc-linux-gnu/15.0.0/plugin/include/diagnostic.h:24,
> from /home/bitten/builds/oCyPvWN6/1/perftools/cicd/scorep/src/build-gcc-plugin/../src/adapters/compiler/gcc-plugin/scorep_plugin_inst_descriptor.cpp:43:
> /home/bitten/opt/gcc-15-20240602/lib/gcc/x86_64-pc-linux-gnu/15.0.0/plugin/include/rich-location.h:25:10:
> fatal error: label-text.h: No such file or directory
> 25 | #include "label-text.h"
> | ^~~~~~~~~~~~~~
> compilation terminated.
I have a fix which I am testing.
>
> Best,
> Bert
>
> >
> >
> > TAGS: $(TAGS_SOURCES)
> > diff --git a/libcpp/include/label-text.h b/libcpp/include/label-text.h
> > new file mode 100644
> > index 000000000000..13562cda41f9
> > --- /dev/null
> > +++ b/libcpp/include/label-text.h
> > @@ -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 */
> > diff --git a/libcpp/include/rich-location.h b/libcpp/include/rich-location.h
> > index a2ece8b033c0..be424cb4b65f 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).
> >
> > --
> > 2.26.3
> >
next prev parent reply other threads:[~2024-06-06 15:40 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-28 20:07 [pushed 1/3] selftests: split out make_fndecl from selftest.h " David Malcolm
2024-05-28 20:07 ` [pushed 2/3] libcpp: move label_text " David Malcolm
2024-06-06 13:01 ` Bert Wesarg
2024-06-06 15:40 ` Andrew Pinski [this message]
2024-06-06 16:00 ` David Malcolm
2024-06-06 17:05 ` Andrew Pinski
2024-06-17 17:42 ` Bert Wesarg
2024-05-28 20:07 ` [pushed 3/3] diagnostics: consolidate global state in diagnostic-color.cc David Malcolm
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CA+=Sn1k1FaBKX782QNwh18P81_4vYzXAswLXm2B4LphY0AKq1A@mail.gmail.com' \
--to=pinskia@gmail.com \
--cc=bert.wesarg@googlemail.com \
--cc=dmalcolm@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).