This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Using C++ in GCC is OK

>>>>> "Basile" == Basile Starynkevitch <> 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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]