This is the mail archive of the gcc-patches@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: [Patch] Add TYPE_NAME_IDENTIFIER


Hi,

On 04/14/2014 06:20 AM, Jason Merrill wrote:
On 04/13/2014 12:20 PM, Paolo Carlini wrote:
this is a small clean-up discussed some time ago with Jason. The basic
idea seems pretty straightforward to me. However, at variance with that
discussion, I'm not proposing replacing the C++ front-end
TYPE_IDENTIFIER with the new TYPE_NAME_IDENTIFIER because, as far as I
can see, that front-end really needs DECL_NAME (TYPE_NAME
unconditionally. Eg, code like (in error.c):

     case TEMPLATE_TEMPLATE_PARM:
       /* For parameters inside template signature.  */
       if (TYPE_IDENTIFIER (t))
     pp_cxx_tree_identifier (pp, TYPE_IDENTIFIER (t));
       else
     pp_cxx_canonical_template_parameter (pp, t);
       break;

assumes that TYPE_IDENTIFIER is indeed an identifier and that would not
be necessarily the case in C++ when TYPE_NAME_IDENTIFIER boils down to
TYPE_NAME itself (in practice, fails like eg, abi/mangle12.C, where
TYPE_NAME is a TEMPLATE_DECL).

You could avoid that issue if TYPE_NAME_IDENTIFIER checked for IDENTIFIER_NODE rather than TYPE_DECL.
I see, but then, if I understand correctly what you are saying, I'm afraid we could end up with a somewhat loose condition, which would make me a little nervous:

#define TYPE_IDENTIFIER(NODE) \
 (TYPE_NAME (NODE) && TREE_CODE (TYPE_NAME (NODE)) != IDENTIFIER_NODE \
 ? DECL_NAME (TYPE_NAME (NODE)) : TYPE_NAME (NODE))

are we sure this is Ok vs the other front-ends, errors, etc? I'm wondering if alternately we could extend the condition to encompass the C++-specific cases while keeping it precise. For example the attached appears to pass the testsuite...

Or, it occurs to me:

#define TYPE_IDENTIFIER(NODE) \
 (TYPE_NAME (NODE) && DECL_P (TYPE_NAME (NODE)) \
 ? DECL_NAME (TYPE_NAME (NODE)) : TYPE_NAME (NODE))

which also appears to work and has the advantage that at least it picks the right tree class without using TEMPLATE_DECL explicitly (which, admittedly is a bit weird outside /cp). Sort of a compromise.

Paolo.

/////////////////////

Attachment: patch_type_identifier
Description: Text document


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