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]

Pretty print of C++11 scoped enums - request help towards a proper fix

Re: "Pretty print of enumerator never prints the id,
     always falls back to C-style cast output"

The bug report gives a one-line 'fix' to enable output of enum id
but, for C++11 scoped enums, it fails to qualify as enum type::id.

The code is located in c-pretty-print.c
It has not been updated to deal with C++11 scoped enumerations.

'Separation of responsibilities' between c and cxx-pretty-print
seems fairly lax - it's convenient to push some c++ printing to c
(there are a few comments like /* This C++ bit is handled here...*/)

I have not quite managed to make a fix confined to c-pretty-print.c

I have a fix which duplicates the code in pp_c_enumeration_constant
to pp_cxx_enumeration_constant in cxx-pretty print, with modification

  if (value != NULL_TREE)
    if (ENUM_IS_SCOPED (type))
      pp_cxx_nested_name_specifier (pp, type);
    pp->id_expression (TREE_PURPOSE (value));

This works in my testing so far, but
 - It duplicates code from c to cxx (not DRY 'Don't Repeat Yourself)
 - I didn't find a single function to print full nested, scoped id
   so had to check if ENUM_IS_SCOPED to output nested specifiers.

I'm learning by hacking but would like guidance on a proper fix
from anyone more familiar with gcc pretty print and/or grammar -
the guideline comment, at the top of the file, states:

/* The pretty-printer code is primarily designed to closely follow
   (GNU) C and C++ grammars... */

I'd appreciate any recommendations towards a proper fix,
or pointers for how to write unit tests for the fix.

Thanks, Will

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