From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id kWljIPQ4/2rgyiAAWB0awg (envelope-from ) for ; Thu, 19 Nov 2026 12:59:16 -0500 Authentication-Results: simark.ca; dkim=pass (2048-bit key; secure) header.d=adacore.com header.i=@adacore.com header.a=rsa-sha256 header.s=google header.b=VthrBUPQ; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 7D2F71E0BC; Thu, 19 Nov 2026 12:59:16 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-5.4 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,RCVD_IN_MSPIKE_H2 autolearn=ham autolearn_force=no version=4.0.1 Received: from vm01.sourceware.org (vm01.sourceware.org [38.145.34.32]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id B1C711E023 for ; Thu, 19 Nov 2026 12:59:15 -0500 (EST) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4B6074BA2E26 for ; Thu, 19 Nov 2026 17:59:15 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4B6074BA2E26 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, secure) header.d=adacore.com header.i=@adacore.com header.a=rsa-sha256 header.s=google header.b=VthrBUPQ Received: from mail-ot1-x32b.google.com (mail-ot1-x32b.google.com [IPv6:2607:f8b0:4864:20::32b]) by sourceware.org (Postfix) with ESMTPS id A64CA4BA2E36 for ; Thu, 19 Nov 2026 17:58:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A64CA4BA2E36 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org A64CA4BA2E36 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::32b ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1795111101; cv=none; b=B98ewlYtYIbunPfysyJh/qtEltkTn5sNsG88Z1Fvf6FsrtoiYLUmp8bLGmVuOGvF+xDJl34yNiq7OCAX4V6hYDcntHnf8PJTc8PW2h5nsHaB7hVqQcKv6cXU/OjVye96rVrIqZr45XBJNmaZ1z/uC34ZJfTuWUblG/iec6riCHg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1795111101; c=relaxed/simple; bh=NvJuNz6Q2TaSE1l7bTfmKLKI67yGhLeMaOxpwoecWOA=; h=DKIM-Signature:From:Date:Subject:MIME-Version:Message-Id:To; b=P+rQ/PaQ+kGMowrSgk/PaPh4HUk3BPpz8prdly28JFSazVmU9iCX7b/93jW3UsNYLYRzyIkGASA/SJbO/E6wXXjSN0wP7PYAVZIfy8cH9zP3CxQwwaEmfs37Awt8N+GlShM4LNC4f5hKPF9TfqthMCImZeCWSbKOEJgFCittLUA= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (2048-bit key, secure) header.d=adacore.com header.i=@adacore.com header.a=rsa-sha256 header.s=google header.b=VthrBUPQ DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A64CA4BA2E36 Received: by mail-ot1-x32b.google.com with SMTP id 46e09a7af769-862a19300b7so18091a34.2 for ; Thu, 19 Nov 2026 09:58:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1795111101; x=1795715901; darn=sourceware.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=n6VmvBn4ZU1bGczq8c3fNQox3Aj3OmL2fb/IYsAOJD0=; b=VthrBUPQX2+aHd1ulzxffF5PYlUaPPNSEf+pqzt4D0aZ+pLZJawYl0kyrb4WfcYO1u Ztb2alqU2WvGJFB/TpeyaAZgtN6WDCEemBlQE48FQgWz/5sMlTGnXPLC3z3xchG0XJ2f jqc70++Uot21BSKC9SEgrjwmAsE7BWxEdkdPLburI/gAhlyGYitkLiLtBCPHvgsARhAV dJbFY7aBQHNkzOvR2xPc1X8LSex27z5qY+wK6oNprRnV2ovobN7hU4f/Ndzzkx9igUoC ODtKWX/0I2tDbYewKgnQ0YpTsMSHgBAQYrdqDDfVmnvveNkZO0K+RRC5O5n56Hqg2oMF yg9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1795111101; x=1795715901; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=n6VmvBn4ZU1bGczq8c3fNQox3Aj3OmL2fb/IYsAOJD0=; b=yzKl/vkGVL/JkOJDZkk0D+2AJ98dKhb/W8snWC7Iz2em5YbYrmOTxTm63rKpAcZu4S lX/T3gG/gjuen71lPesZh6Y8wE+tFRgUQSiRVCxaaCLRT2Jtuj406pkY0ERpBFMZnIHq wCu2DEULtYP1FuBuJR0qXeBcKBkunQEFfKnM4JtsfKy5A6tOkwQDiZS7lbaNDsUyL02l 0zid2FY+fco3he9vleX7TgfRXGe7EslsjJAJQEilT+TSm1xk+u7h+eMMRvWOWG9dBLKK 8YBMERh9M9Q2EqPXfXHtytGTRbhfVrjZTXopqQcW87KGCHjEgBHDcH+6hobuIzdt6Y7l rWKA== X-Gm-Message-State: APuU4Z+DBpJQNGGeSjHiKF0AmRoZbaTNxPyB2Xhb6Fb39dPKR4DApu0K fo6l0U3Jda4eqlaUY6FT6Il4Gr8EYhRWgvRcRhUmoUz/1SOYSggMLi3igLOw9ErT7eTnQvDNcY3 rJ6aLTQ== X-Gm-Gg: AYBFou3R2kidzhZ2p4AanB1fJmlnszcCdn0oGIdyR6hPfMtSF1JL+D7d7GCHlMk35tP Q3auavS57v/SdMHJNrjy3ATwD3d/F1nLjDg60BK266BwdKddLJ7vzdhFaiqUDLsI8yPbi62NFKW dXt7KL2VeeKVW15HQXVpejCOhOlbU7oigAzyr4Q4tRE6zDiGCuAV9RSfEevUzY9fSYsbUuW8G2K oiTPl4CqasM/g51Cq8uqEIgMg6wRp4moeadihOLxFBhgGAZCKbhQrfLKjhuMN11UuqT3KswKfz2 Yb18WEuIiPGdqePfLhcJUqgGTxkjIn3JJQSR9bpzaxNhVTpPVyJvdXJOHW0snXd8/oQr8S2Ar5V B+5Mxuk5XhcNgS7P+OGFqyQexd1+IqlcugIsggAcyC+nzQ6FKM6Sr42zuI7ZVldNj1EotNAs+hI Yjj35uwTUJh85HQKIaC7Lx57LETo+KFJXrzhnABoRan2ZM+iblarZKG8dbfvrbBKw+LxUtNbLFZ sCdOeTiAWNLqCFj+4147mcG4NSyWtmNHp4oYAoYvErE4AsGqjP1Qb1p9DaHI7CdrtP+mdzcPLpS 2uQPpNVHieGJHmkZWTgoAvYl46rG3a1F5J+uzSRQNPgiS7IPINGaH9MQiwyI8g== X-Received: by 2002:a05:6830:640d:b0:85b:c75:dc65 with SMTP id 46e09a7af769-86315611616mr807429a34.7.1795111100838; Thu, 19 Nov 2026 09:58:20 -0800 (PST) Received: from [192.168.0.26] (97-122-110-129.hlrn.qwest.net. [97.122.110.129]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-863168c1be6sm165773a34.4.2026.11.19.09.58.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Nov 2026 09:58:20 -0800 (PST) From: Tom Tromey Date: Thu, 19 Nov 2026 10:58:18 -0700 Subject: [PATCH 3/7] Change some Ada parser functions into methods MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20261119-more-parser-cleanups-v1-3-d85241f3fede@adacore.com> References: <20261119-more-parser-cleanups-v1-0-d85241f3fede@adacore.com> In-Reply-To: <20261119-more-parser-cleanups-v1-0-d85241f3fede@adacore.com> To: gdb-patches@sourceware.org Cc: Tom Tromey X-Mailer: b4 0.16.0 X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~public-inbox=simark.ca@sourceware.org This turns a few Ada parser functions into methods of ada_parse_state. This also renames some functions to conform to the gdb style. This approach is somewhat cleaner. Ultimately I think the Ada lexer (and hopefully someday the parser) would more resemble how the Rust parser works -- a self-contained class. --- gdb/ada-exp-parser.c | 73 ++++++++++++++++++++++++++-------------------------- gdb/ada-exp-parser.h | 38 ++++++++++++--------------- 2 files changed, 53 insertions(+), 58 deletions(-) diff --git a/gdb/ada-exp-parser.c b/gdb/ada-exp-parser.c index 2757877b605..896e97798b4 100644 --- a/gdb/ada-exp-parser.c +++ b/gdb/ada-exp-parser.c @@ -189,8 +189,8 @@ canonicalize_numeral (char *s1, const char *s2, const char *end) /* See ada-exp-parser.h. */ int -processInt (struct parser_state *par_state, const char *base0, - const char *num0, const char *exp0) +ada_parse_state::process_int (const char *base0, const char *num0, + const char *exp0) { long exp; int base; @@ -250,58 +250,58 @@ processInt (struct parser_state *par_state, const char *base0, { struct type *fp_type; if (floating_point_l_count == 0) - fp_type = language_lookup_primitive_type (par_state->language (), - par_state->gdbarch (), + fp_type = language_lookup_primitive_type (pstate->language (), + pstate->gdbarch (), "float"); else if (floating_point_l_count == 1) - fp_type = language_lookup_primitive_type (par_state->language (), - par_state->gdbarch (), + fp_type = language_lookup_primitive_type (pstate->language (), + pstate->gdbarch (), "long_float"); else { /* This assertion is ensured by the pattern. */ gdb_assert (floating_point_l_count == 2); - fp_type = language_lookup_primitive_type (par_state->language (), - par_state->gdbarch (), + fp_type = language_lookup_primitive_type (pstate->language (), + pstate->gdbarch (), "long_long_float"); } ada_yylval.typed_val_float.type = fp_type; result.write (gdb::make_span (ada_yylval.typed_val_float.val, - fp_type->length ()), + fp_type->length ()), type_byte_order (fp_type), true); return FLOAT; } - const gdb_mpz *value = ada_parser->push_integer (std::move (result)); + const gdb_mpz *value = push_integer (std::move (result)); - int int_bits = gdbarch_int_bit (par_state->gdbarch ()); - int long_bits = gdbarch_long_bit (par_state->gdbarch ()); - int long_long_bits = gdbarch_long_long_bit (par_state->gdbarch ()); + int int_bits = gdbarch_int_bit (pstate->gdbarch ()); + int long_bits = gdbarch_long_bit (pstate->gdbarch ()); + int long_long_bits = gdbarch_long_long_bit (pstate->gdbarch ()); if (fits_in_type (1, *value, int_bits, true)) - ada_yylval.typed_val.type = parse_type (par_state)->builtin_int; + ada_yylval.typed_val.type = parse_type (pstate)->builtin_int; else if (fits_in_type (1, *value, long_bits, true)) - ada_yylval.typed_val.type = parse_type (par_state)->builtin_long; + ada_yylval.typed_val.type = parse_type (pstate)->builtin_long; else if (fits_in_type (1, *value, long_bits, false)) ada_yylval.typed_val.type - = builtin_type (par_state->gdbarch ())->builtin_unsigned_long; + = builtin_type (pstate->gdbarch ())->builtin_unsigned_long; else if (fits_in_type (1, *value, long_long_bits, true)) - ada_yylval.typed_val.type = parse_type (par_state)->builtin_long_long; + ada_yylval.typed_val.type = parse_type (pstate)->builtin_long_long; else if (fits_in_type (1, *value, long_long_bits, false)) ada_yylval.typed_val.type - = builtin_type (par_state->gdbarch ())->builtin_unsigned_long_long; + = builtin_type (pstate->gdbarch ())->builtin_unsigned_long_long; else if (fits_in_type (1, *value, 128, true)) ada_yylval.typed_val.type - = language_lookup_primitive_type (par_state->language (), - par_state->gdbarch (), + = language_lookup_primitive_type (pstate->language (), + pstate->gdbarch (), "long_long_long_integer"); else if (fits_in_type (1, *value, 128, false)) ada_yylval.typed_val.type - = language_lookup_primitive_type (par_state->language (), - par_state->gdbarch (), + = language_lookup_primitive_type (pstate->language (), + pstate->gdbarch (), "unsigned_long_long_long_integer"); else error (_("Integer literal out of range")); @@ -313,9 +313,9 @@ processInt (struct parser_state *par_state, const char *base0, /* See ada-exp-parser.h. */ int -processReal (struct parser_state *par_state, const char *num0) +ada_parse_state::process_real (const char *num0) { - ada_yylval.typed_val_float.type = parse_type (par_state)->builtin_long_double; + ada_yylval.typed_val_float.type = parse_type (pstate)->builtin_long_double; bool parsed = parse_float (num0, strlen (num0), ada_yylval.typed_val_float.type, @@ -378,14 +378,13 @@ ada_parse_state::process_id (std::string_view name0) /* See ada-exp-parser.h. */ struct stoken -processString (const char *text, int len) +ada_parse_state::process_string (const char *text, const char *lim) { const char *p; char *q; - const char *lim = text + len; struct stoken result; - q = (char *) obstack_alloc (&ada_parser->temp_space, len); + q = (char *) obstack_alloc (&temp_space, lim - text); result.ptr = q; p = text; while (p < lim) @@ -420,16 +419,16 @@ processString (const char *text, int len) case. */ static int -subseqMatch (const char *subseq, const char *str) +subseq_match (const char *subseq, const char *str) { if (subseq[0] == '\0') return 1; else if (str[0] == '\0') return 0; else if (c_tolower (subseq[0]) == c_tolower (str[0])) - return subseqMatch (subseq+1, str+1) || subseqMatch (subseq, str+1); + return subseq_match (subseq+1, str+1) || subseq_match (subseq, str+1); else - return subseqMatch (subseq, str+1); + return subseq_match (subseq, str+1); } /* See ada-exp-parser.h. */ @@ -451,7 +450,7 @@ ada_parse_state::process_attribute (const std::string &str, bool completing) std::optional found; for (const auto &item : attributes) - if (subseqMatch (str.c_str (), item.name)) + if (subseq_match (str.c_str (), item.name)) { if (!found.has_value ()) found = item.code; @@ -482,19 +481,19 @@ ada_parse_state::lex_number () if (subexps[HEX_NUMBER].rm_so != -1) { canonicalize_numeral (numbuf, num_start + 2, pstate->lexptr); - return processInt (pstate, "16#", numbuf, nullptr); + return process_int ("16#", numbuf, nullptr); } else if (subexps[FLOAT_POSEXP].rm_so != -1) { canonicalize_numeral (numbuf, num_start, pstate->lexptr); char *e_ptr = strrchr (numbuf, 'e'); *e_ptr = '\0'; - return processInt (pstate, nullptr, numbuf, e_ptr + 1); + return process_int (nullptr, numbuf, e_ptr + 1); } else if (subexps[FLOAT_OPTEXP].rm_so != -1) { canonicalize_numeral (numbuf, num_start, pstate->lexptr); - return processReal (pstate, numbuf); + return process_real (numbuf); } else if (subexps[FLOAT_EXTENSION].rm_so != -1) { @@ -512,14 +511,14 @@ ada_parse_state::lex_number () *e_ptr = '\0'; ++e_ptr; } - return processInt (pstate, numbuf, strchr (numbuf, '#') + 1, e_ptr); + return process_int (numbuf, strchr (numbuf, '#') + 1, e_ptr); } else if (subexps[BASED_REAL].rm_so != -1) error (_("Based real literals not implemented yet.")); /* Must be a simple integer. */ canonicalize_numeral (numbuf, num_start, pstate->lexptr); - return processInt (pstate, nullptr, numbuf, nullptr); + return process_int (nullptr, numbuf, nullptr); } static const code_entry keywords[] = @@ -859,7 +858,7 @@ ada_parse_state::lex_double_quote () if (*iter != '"') error (_("ill-formed or non-terminated string literal")); - ada_yylval.sval = processString (start, iter - start); + ada_yylval.sval = process_string (start, iter); pstate->lexptr = iter + 1; return STRING; } diff --git a/gdb/ada-exp-parser.h b/gdb/ada-exp-parser.h index 4de2263ed6c..3d851e8fe7d 100644 --- a/gdb/ada-exp-parser.h +++ b/gdb/ada-exp-parser.h @@ -137,6 +137,23 @@ struct ada_parse_state */ stoken process_id (std::string_view name0); + /* Return TEXT (up to LIM), a string literal without surrounding + quotes, with special hex character notations replaced with + characters. Result valid until the next call to ada_parse. */ + struct stoken process_string (const char *text, const char *lim); + + /* Interprets the prefix of NUM that consists of digits of the given BASE + as an integer of that BASE, with the string EXP as an exponent. + Puts value in yylval, and returns INT, if the string is valid. Causes + an error if the number is improperly formatted. BASE, if NULL, defaults + to "10", and EXP to "1". The EXP does not contain a leading 'e' or 'E'. + */ + int process_int (const char *base0, const char *num0, const char *exp0); + + /* Parse NUM0 as a floating-point literal, store the result in + yylval, and return the FLOAT token. */ + int process_real (const char *num0); + /* Throw an exception when lexing, indicating that an invalid character was seen. */ [[noreturn]] void invalid_char (); @@ -168,27 +185,6 @@ extern struct parser_state *pstate; extern struct ada_parse_state *ada_parser; -/* Return TEXT[0..LEN-1], a string literal without surrounding quotes, - with special hex character notations replaced with characters. - Result valid until the next call to ada_parse. */ - -stoken processString (const char *text, int len); - -/* Interprets the prefix of NUM that consists of digits of the given BASE - as an integer of that BASE, with the string EXP as an exponent. - Puts value in yylval, and returns INT, if the string is valid. Causes - an error if the number is improperly formatted. BASE, if NULL, defaults - to "10", and EXP to "1". The EXP does not contain a leading 'e' or 'E'. - */ - -int processInt (parser_state *par_state, const char *base0, const char *num0, - const char *exp0); - -/* Parse NUM0 as a floating-point literal, store the result in yylval, - and return the FLOAT token. */ - -int processReal (struct parser_state *par_state, const char *num0); - /* Like parser_state::pop, but handles Ada type resolution. DEPROCEDURE_P and CONTEXT_TYPE are passed to the resolve method, if called. */ -- 2.56.0