[RFC] type safe trees

Gabriel Dos Reis gdr@acm.org
Wed Jun 23 16:23:00 GMT 2004


You Wrote Nathan Sidwell
> Hi,
> I've been thinking more about type safe trees.  At the summit Zack & I
> showed y'all a two level hierarchy implemented with macros.  (The
> slides are at http://www.codesourcery.com/publications.html.)
>
> We talked about language dependent derivations and such like, plus
> how much of this could be automatically generated.  Some responses
> from the floor were along the lines of 'can we use C++?'
>
> Whilst avoiding the C++ route, I've come to the conclusion that a
> two level scheme is too restrictive.  And anything more than two
> levels would be a maintainance nightmare, unless it was automatically
> generated.

> 	#ifndef GTY
> 	/* define the root expression node */
> 	class expr ('e')
> 	{
> 	  static char klass; // in C++ speak this would be a virtual member
> *variable*
>
> 	  unsigned char code; // must have this, it's the vtable equivalent
> 	  type_t type;
> 	};
> 	#else
> 	#include "expr_t.h"
> 	#endif

> you'd do something like,
> 	#ifndef GTY
> 	class dyadic_expr ('2'): expr
> 	{
> 	  expr_t ops[2];
> 	};
> 	#else
> 	#include "dyadic_expr_t.h"
> 	#endif

> comments?

So, we don't want C++, we find C too restrictive in the expressive
power it gives us and we end up inventing a new language we
have to learn?

If we were going to teach gentype a new language and use it
for anything, I would strongly suggest we teach it a *subset* of
C++ that is simple enought to get it generate the C bits we
want out of it.

(Interestingly, more than 20 years ago, the first C++ compiler
was written in C++ and used on a variety of plateforms.)

-- Gaby



More information about the Gcc mailing list