This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [PATCH 14/40] Introduce CP_OPERATOR_STR/CP_OPERATOR_LEN and use throughout
- From: Pedro Alves <palves at redhat dot com>
- To: Keith Seitz <keiths at redhat dot com>, gdb-patches at sourceware dot org
- Date: Mon, 17 Jul 2017 15:55:49 +0100
- Subject: Re: [PATCH 14/40] Introduce CP_OPERATOR_STR/CP_OPERATOR_LEN and use throughout
- Authentication-results: sourceware.org; auth=none
- Authentication-results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com
- Authentication-results: ext-mx04.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=palves at redhat dot com
- Dkim-filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 1B2D47CE11
- Dmarc-filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 1B2D47CE11
- References: <1496406158-12663-1-git-send-email-palves@redhat.com> <1496406158-12663-15-git-send-email-palves@redhat.com> <596907B3.7050508@redhat.com>
On 07/14/2017 07:04 PM, Keith Seitz wrote:
> On 06/02/2017 05:22 AM, Pedro Alves wrote:
>> I ran into LENGTH_OF_OPERATOR in cp-support.c and wanted to use it
>> elsewhere, so I moved it to cp-support.h. Since there's already
>> CP_ANONYMOUS_NAMESPACE_STR/CP_ANONYMOUS_NAMESPACE_LEN there, I
>> followed the same naming pattern for the new symbols.
>
> Looks pretty straightforward (even?) to me, but I do notice that there are still one or two places that could be updated:
>
> c-exp.y:2281: {"operator", OPERATOR, OP_NULL, FLAG_CXX},
> cp-name-parser.y:1839: if (strncmp (tokstart, "operator", 8) == 0)
I had left these two because looking at the context around them, I'm
thinking that using the macro would obfuscate more than help. c-exp.y has:
...
{"new", NEW, OP_NULL, FLAG_CXX},
{"delete", DELETE, OP_NULL, FLAG_CXX},
{"operator", OPERATOR, OP_NULL, FLAG_CXX},
{"and", ANDAND, BINOP_END, FLAG_CXX},
{"and_eq", ASSIGN_MODIFY, BINOP_BITWISE_AND, FLAG_CXX},
{"bitand", '&', OP_NULL, FLAG_CXX},
...
And cp-name-parser.y has:
...
case 8:
HANDLE_SPECIAL ("typeinfo for ", DEMANGLE_COMPONENT_TYPEINFO);
HANDLE_SPECIAL ("typeinfo fn for ", DEMANGLE_COMPONENT_TYPEINFO_FN);
HANDLE_SPECIAL ("typeinfo name for ", DEMANGLE_COMPONENT_TYPEINFO_NAME);
if (strncmp (tokstart, "operator", 8) == 0)
return OPERATOR;
if (strncmp (tokstart, "restrict", 8) == 0)
return RESTRICT;
if (strncmp (tokstart, "unsigned", 8) == 0)
return UNSIGNED;
if (strncmp (tokstart, "template", 8) == 0)
return TEMPLATE;
...
Note all those "8"s match the size in the switch case. (Likewise
the other switch cases.)
Given that nowadays compilers optimize strlen("string literal") to a
constant, this cp-name-parser.y case might be tweaked as:
if (startswith (tokstart, "operator"))
return OPERATOR;
if (startswith (tokstart, "restrict"))
return RESTRICT;
if (startswith (tokstart, "unsigned"))
return UNSIGNED;
if (startswith (tokstart, "template"))
return TEMPLATE;
etc.
So for now, I've pushed the patch as it was.
Thanks,
Pedro Alves