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: Paolo Bonzini <bonzini at gnu dot org>
- To: Ian Lance Taylor <iant at google dot com>
- Cc: GCC <gcc at gcc dot gnu dot org>
- Date: Wed, 02 Jun 2010 09:44:19 +0200
- Subject: Re: Using C++ in GCC is OK
- References: <4C030228.8020201@codesourcery.com> <1275283728.21123.24.camel@glinka> <4C03DB74.7090704@codesourcery.com> <1275323168.22465.12.camel@glinka> <4C04C561.3070707@gnu.org> <mcr7hmin8pj.fsf@dhcp-172-17-9-151.mtv.corp.google.com>
On 06/01/2010 04:11 PM, Ian Lance Taylor wrote:
In the gccgo IR I don't represent everything with a single type.
Instead, I use a separate base class for types, expressions and
statements (in Go there is more of a distinction between expressions
and statements than there is in C/C++). I represent specific types,
etc., as child classes. The base class uses a protected virtual
function interface which the child classes implement.
However, as you observe, some code does need to use pattern matching,
so that approach is awkward to use by itself. I also declare an enum
in the base class, and so given a pointer to the base class you can
examine that enum to know which kind of object you have.
This made me wondering if we are looking at the C++ conversion from the
wrong point of view.
In particular, I wonder if the best use of C++ wouldn't be a set of
functions (including templates, etc.) implementing a kind of RTTI with a
less verbose syntax than what we have now.
Just to give an idea:
template<enum tree_code CODE>
static inline bool isa(tree t)
{
return TREE_CODE (t) == CODE;
}
template<enum tree_node_structure_enum TS>
static inline bool isa(tree t)
{
return CODE_CONTAINS_STRUCT (TREE_CODE (t), TS);
}
template<enum tree_code_class CLASS>
static inline bool isa(tree t)
{
return TREE_CODE_CLASS (TREE_CODE (t)) == CLASS;
}
template<enum rtx_code CODE>
static inline bool isa(rtx t)
{
return GET_RTX_CODE (t) == CODE;
}
This is just a stupid example of course, but my point is: are we sure
that the main benefit of C++ comes from object-orientation?
Paolo