>>>>> "Basile" == Basile Starynkevitch <[email protected]> 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