From patchwork Fri Jun 2 12:22:12 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Alves X-Patchwork-Id: 20706 Received: (qmail 130136 invoked by alias); 2 Jun 2017 12:22:54 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 130058 invoked by uid 89); 2 Jun 2017 12:22:54 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy= 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; Fri, 02 Jun 2017 12:22:51 +0000 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0977B80E7E for ; Fri, 2 Jun 2017 12:22:54 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 0977B80E7E Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=palves@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 0977B80E7E Received: from cascais.lan (ovpn04.gateway.prod.ext.ams2.redhat.com [10.39.146.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id 631F15C549 for ; Fri, 2 Jun 2017 12:22:53 +0000 (UTC) From: Pedro Alves To: gdb-patches@sourceware.org Subject: [PATCH 14/40] Introduce CP_OPERATOR_STR/CP_OPERATOR_LEN and use throughout Date: Fri, 2 Jun 2017 13:22:12 +0100 Message-Id: <1496406158-12663-15-git-send-email-palves@redhat.com> In-Reply-To: <1496406158-12663-1-git-send-email-palves@redhat.com> References: <1496406158-12663-1-git-send-email-palves@redhat.com> 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. gdb/ChangeLog: yyyy-mm-dd Pedro Alves * c-exp.y (operator_stoken): Use CP_OPERATOR_LEN and CP_OPERATOR_STR. * c-typeprint.c (is_type_conversion_operator): Use CP_OPERATOR_STR. * cp-support.c (LENGTH_OF_OPERATOR): Delete. (cp_find_first_component_aux): Use CP_OPERATOR_STR and CP_OPERATOR_LEN. * cp-support.h (CP_OPERATOR_STR, CP_OPERATOR_LEN): New. * gnu-v2-abi.c (gnuv2_is_operator_name): Use CP_OPERATOR_STR. * gnu-v3-abi.c (gnuv3_is_operator_name): Use CP_OPERATOR_STR. * linespec.c (linespec_lexer_lex_string): Use CP_OPERATOR_LEN and CP_OPERATOR_STR. * location.c: Include "cp-support.h". (explicit_location_lex_one): Use CP_OPERATOR_LEN and CP_OPERATOR_STR. * symtab.c (operator_chars): Use CP_OPERATOR_STR and CP_OPERATOR_LEN. --- gdb/c-exp.y | 5 ++--- gdb/c-typeprint.c | 2 +- gdb/cp-support.c | 9 ++------- gdb/cp-support.h | 8 ++++++++ gdb/gnu-v2-abi.c | 2 +- gdb/gnu-v3-abi.c | 2 +- gdb/linespec.c | 5 ++--- gdb/location.c | 5 +++-- gdb/symtab.c | 4 ++-- 9 files changed, 22 insertions(+), 20 deletions(-) diff --git a/gdb/c-exp.y b/gdb/c-exp.y index bdcd51f..24a2fbd 100644 --- a/gdb/c-exp.y +++ b/gdb/c-exp.y @@ -1625,13 +1625,12 @@ write_destructor_name (struct parser_state *par_state, struct stoken token) static struct stoken operator_stoken (const char *op) { - static const char *operator_string = "operator"; struct stoken st = { NULL, 0 }; char *buf; - st.length = strlen (operator_string) + strlen (op); + st.length = CP_OPERATOR_LEN + strlen (op); buf = (char *) malloc (st.length + 1); - strcpy (buf, operator_string); + strcpy (buf, CP_OPERATOR_STR); strcat (buf, op); st.ptr = buf; diff --git a/gdb/c-typeprint.c b/gdb/c-typeprint.c index 9e197f5..890888b 100644 --- a/gdb/c-typeprint.c +++ b/gdb/c-typeprint.c @@ -547,7 +547,7 @@ is_type_conversion_operator (struct type *type, int i, int j) some other way, feel free to rewrite this function. */ const char *name = TYPE_FN_FIELDLIST_NAME (type, i); - if (!startswith (name, "operator")) + if (!startswith (name, CP_OPERATOR_STR)) return 0; name += 8; diff --git a/gdb/cp-support.c b/gdb/cp-support.c index 5704466..122fadd 100644 --- a/gdb/cp-support.c +++ b/gdb/cp-support.c @@ -931,10 +931,6 @@ cp_find_first_component (const char *name) the recursion easier, it also stops if it reaches an unexpected ')' or '>' if the value of PERMISSIVE is nonzero. */ -/* Let's optimize away calls to strlen("operator"). */ - -#define LENGTH_OF_OPERATOR 8 - static unsigned int cp_find_first_component_aux (const char *name, int permissive) { @@ -1006,10 +1002,9 @@ cp_find_first_component_aux (const char *name, int permissive) case 'o': /* Operator names can screw up the recursion. */ if (operator_possible - && strncmp (name + index, "operator", - LENGTH_OF_OPERATOR) == 0) + && startswith (name + index, CP_OPERATOR_STR)) { - index += LENGTH_OF_OPERATOR; + index += CP_OPERATOR_LEN; while (ISSPACE(name[index])) ++index; switch (name[index]) diff --git a/gdb/cp-support.h b/gdb/cp-support.h index 9054bf6..37b281f 100644 --- a/gdb/cp-support.h +++ b/gdb/cp-support.h @@ -46,6 +46,14 @@ struct using_direct; #define CP_ANONYMOUS_NAMESPACE_LEN 21 +/* A string representing the start of an operator name. */ + +#define CP_OPERATOR_STR "operator" + +/* The length of CP_OPERATOR_STR. */ + +#define CP_OPERATOR_LEN 8 + /* The result of parsing a name. */ struct demangle_parse_info diff --git a/gdb/gnu-v2-abi.c b/gdb/gnu-v2-abi.c index 0af684f..91c4201 100644 --- a/gdb/gnu-v2-abi.c +++ b/gdb/gnu-v2-abi.c @@ -68,7 +68,7 @@ gnuv2_is_vtable_name (const char *name) static int gnuv2_is_operator_name (const char *name) { - return startswith (name, "operator"); + return startswith (name, CP_OPERATOR_STR); } diff --git a/gdb/gnu-v3-abi.c b/gdb/gnu-v3-abi.c index 0090990..f5d3d13 100644 --- a/gdb/gnu-v3-abi.c +++ b/gdb/gnu-v3-abi.c @@ -46,7 +46,7 @@ gnuv3_is_vtable_name (const char *name) static int gnuv3_is_operator_name (const char *name) { - return startswith (name, "operator"); + return startswith (name, CP_OPERATOR_STR); } diff --git a/gdb/linespec.c b/gdb/linespec.c index 4c076fe..25ebdca 100644 --- a/gdb/linespec.c +++ b/gdb/linespec.c @@ -688,10 +688,9 @@ linespec_lexer_lex_string (linespec_parser *parser) { if ((PARSER_STATE (parser)->language->la_language == language_cplus) - && (PARSER_STREAM (parser) - start) > 8 - /* strlen ("operator") */) + && (PARSER_STREAM (parser) - start) > CP_OPERATOR_LEN) { - const char *p = strstr (start, "operator"); + const char *p = strstr (start, CP_OPERATOR_STR); if (p != NULL && is_operator_name (p)) { diff --git a/gdb/location.c b/gdb/location.c index 8796320..d711d7b 100644 --- a/gdb/location.c +++ b/gdb/location.c @@ -24,6 +24,7 @@ #include "linespec.h" #include "cli/cli-utils.h" #include "probe.h" +#include "cp-support.h" #include #include @@ -473,8 +474,8 @@ explicit_location_lex_one (const char **inp, { /* Special case: C++ operator,. */ if (language->la_language == language_cplus - && strncmp (*inp, "operator", 8) == 0) - (*inp) += 8; + && startswith (*inp, CP_OPERATOR_STR)) + (*inp) += CP_OPERATOR_LEN; ++(*inp); } } diff --git a/gdb/symtab.c b/gdb/symtab.c index cd78a16..91e8b90 100644 --- a/gdb/symtab.c +++ b/gdb/symtab.c @@ -3837,9 +3837,9 @@ static const char * operator_chars (const char *p, const char **end) { *end = ""; - if (!startswith (p, "operator")) + if (!startswith (p, CP_OPERATOR_STR)) return *end; - p += 8; + p += CP_OPERATOR_LEN; /* Don't get faked out by `operator' being part of a longer identifier. */