This is the mail archive of the gcc@gcc.gnu.org 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


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


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