This is the mail archive of the
gcc@gcc.gnu.org
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.8020201@codesourcery.com> <AANLkTimzVEXsE4vOZJuegnHFu-pVyNdKImcasoSX_ZDc@mail.gmail.com> <4C039253.5080406@adacore.com> <AANLkTikp-gTh4bCpAFYWhU7fR9tBTxOP6mQp9TAfideB@mail.gmail.com> <4C03EB8D.6010307@codesourcery.com> <8739x8szx1.fsf@basil.nowhere.org> <4C040481.10601@codesourcery.com> <1275334239.22465.45.camel@glinka>
- Reply-to: tromey at redhat dot com
>>>>> "Basile" == Basile Starynkevitch <basile@starynkevitch.net> 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 (some_global);
Mark would be a template function, with specializations for gcc data
types and various STL things (hopefully I got the C++ right here :-):
template<typename T>
void mark (const std::vector<T> &c)
{
T::const_iterator i = c.begin(), e = c.end();
for (; i != e; ++i)
mark (*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.
Tom