From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 30293 invoked by alias); 17 Jul 2017 14:55:55 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 30284 invoked by uid 89); 17 Jul 2017 14:55:54 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RP_MATCHES_RCVD,SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=8s X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 17 Jul 2017 14:55:53 +0000 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1B2D47CE11 for ; Mon, 17 Jul 2017 14:55:52 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 1B2D47CE11 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@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 1B2D47CE11 Received: from [127.0.0.1] (ovpn04.gateway.prod.ext.ams2.redhat.com [10.39.146.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id 20523776FB; Mon, 17 Jul 2017 14:55:50 +0000 (UTC) Subject: Re: [PATCH 14/40] Introduce CP_OPERATOR_STR/CP_OPERATOR_LEN and use throughout To: Keith Seitz , gdb-patches@sourceware.org References: <1496406158-12663-1-git-send-email-palves@redhat.com> <1496406158-12663-15-git-send-email-palves@redhat.com> <596907B3.7050508@redhat.com> From: Pedro Alves Message-ID: Date: Mon, 17 Jul 2017 14:55:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.4.0 MIME-Version: 1.0 In-Reply-To: <596907B3.7050508@redhat.com> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit X-SW-Source: 2017-07/txt/msg00227.txt.bz2 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