This is the mail archive of the
mailing list for the GCC project.
Re: Using C++ in GCC is OK
- From: Tom Tromey <tromey at redhat dot com>
- To: basile at starynkevitch dot net
- Cc: GCC <gcc at gcc dot gnu dot org>
- Date: Wed, 02 Jun 2010 10:03:24 -0600
- Subject: Re: Using C++ in GCC is OK
- References: <4C030228.firstname.lastname@example.org> <AANLkTimzVEXsE4vOZJuegnHFu-pVyNdKImcasoSX_ZDc@mail.gmail.com> <4C039253.email@example.com> <AANLkTikp-gTh4bCpAFYWhU7fR9tBTxOP6mQp9TAfideB@mail.gmail.com> <4C03EB8D.firstname.lastname@example.org> <email@example.com> <4C040481.firstname.lastname@example.org> <1275334239.22465.45.camel@glinka>
- Reply-to: tromey at redhat dot com
>>>>> "Basile" == Basile Starynkevitch <email@example.com> writes:
Basile> Still, my concerns on C++ is mostly gengtype related. I believe we need
Basile> to keep a garbage collector even with C++, and I believe that changing
Basile> gengtype to follow C++ could be quite painful if we follow the usual
Basile> route of parsing our headers. Making a gengtype able to parse almost any
Basile> C++ header file would be painful.
It seems to me that C++ can actually make gengtype's job simpler.
For example, rather than generating code that knows about the layout of
container types, we can just instantiate template functions that walk a
container using the standard iterator API.
So if you see:
static GTY(()) std::vector<tree> some_global;
gengtype can just emit
template mark< std::vector<tree> > ();
Mark would be a template function, with specializations for gcc data
types and various STL things (hopefully I got the C++ right here :-):
void mark (const std::vector<T> &c)
T::const_iterator i = c.begin(), e = c.end();
for (; i != e; ++i)
In this sort of setup, unlike with C, gengtype needs to know very little
about the structure of std::vector. Instead most of the work is
deferred to g++. With this approach, maybe gengtype only needs to know
about roots; each data type could supply its own mark specialization.