From patchwork Wed Apr 3 01:38:00 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 32141 Received: (qmail 27491 invoked by alias); 3 Apr 2019 01:38:16 -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 27273 invoked by uid 89); 3 Apr 2019 01:38:15 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-17.2 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS autolearn=ham version=3.3.1 spammy= X-HELO: gateway22.websitewelcome.com Received: from gateway22.websitewelcome.com (HELO gateway22.websitewelcome.com) (192.185.46.126) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 03 Apr 2019 01:38:10 +0000 Received: from cm14.websitewelcome.com (cm14.websitewelcome.com [100.42.49.7]) by gateway22.websitewelcome.com (Postfix) with ESMTP id 703A0993D for ; Tue, 2 Apr 2019 20:38:09 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id BUqvhr2N12qH7BUqvhFYeI; Tue, 02 Apr 2019 20:38:09 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Sender:Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=wifGYgZbaxV1UISEsDM54olzMG8IF6YQqsSIQhXNWOM=; b=XbnVFAtDfeRsTCni5Q/3+85+F2 AkrslHt90JZ2/0KK5kAEpl7HmkTF5J1zZw+CEttONRsocz4/v7t2kK1xVWAUm1MfNhPj3WkLrLND+ BMmbYLhPdIsqDSNUmPpztwV69; Received: from 174-29-37-56.hlrn.qwest.net ([174.29.37.56]:34720 helo=bapiya.Home) by box5379.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.91) (envelope-from ) id 1hBUqv-002Gj6-8C; Tue, 02 Apr 2019 20:38:09 -0500 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH 08/13] Move comma_terminates global to parser_state Date: Tue, 2 Apr 2019 19:38:00 -0600 Message-Id: <20190403013805.11978-9-tom@tromey.com> In-Reply-To: <20190403013805.11978-1-tom@tromey.com> References: <20190403013805.11978-1-tom@tromey.com> This moves the comma_terminates global to parser_state. 2019-04-02 Tom Tromey * rust-exp.y (rustyylex, rust_lex_tests): Update. * parser-defs.h (struct parser_state) : Add new parameter. : New member. (comma_terminates): Don't declare global. * parse.c (comma_terminates): Remove global. (parse_exp_in_context): Update. * p-exp.y (yylex): Update. * m2-exp.y (yylex): Update. * go-exp.y (lex_one_token): Update. * f-exp.y (yylex): Update. * d-exp.y (lex_one_token): Update. * c-exp.y (lex_one_token): Update. * ada-lex.l: Update. --- gdb/ChangeLog | 17 +++++++++++++++++ gdb/ada-lex.l | 2 +- gdb/c-exp.y | 2 +- gdb/d-exp.y | 2 +- gdb/f-exp.y | 2 +- gdb/go-exp.y | 2 +- gdb/m2-exp.y | 2 +- gdb/p-exp.y | 2 +- gdb/parse.c | 5 +---- gdb/parser-defs.h | 14 ++++++++------ gdb/rust-exp.y | 5 +++-- 11 files changed, 36 insertions(+), 19 deletions(-) diff --git a/gdb/ada-lex.l b/gdb/ada-lex.l index 6163405545d..43bd25c1e2f 100644 --- a/gdb/ada-lex.l +++ b/gdb/ada-lex.l @@ -232,7 +232,7 @@ false { return FALSEKEYWORD; } [-&*+./:<>=|;\[\]] { return yytext[0]; } -"," { if (paren_depth == 0 && comma_terminates) +"," { if (paren_depth == 0 && pstate->comma_terminates) { rewind_to_char (','); return 0; diff --git a/gdb/c-exp.y b/gdb/c-exp.y index cb9e9e002c7..16b291f9c70 100644 --- a/gdb/c-exp.y +++ b/gdb/c-exp.y @@ -2637,7 +2637,7 @@ lex_one_token (struct parser_state *par_state, bool *is_quoted_name) return c; case ',': - if (comma_terminates + if (pstate->comma_terminates && paren_depth == 0 && ! scanning_macro_expansion ()) return 0; diff --git a/gdb/d-exp.y b/gdb/d-exp.y index c1519953521..06e12e32011 100644 --- a/gdb/d-exp.y +++ b/gdb/d-exp.y @@ -1098,7 +1098,7 @@ lex_one_token (struct parser_state *par_state) return c; case ',': - if (comma_terminates && paren_depth == 0) + if (pstate->comma_terminates && paren_depth == 0) return 0; lexptr++; return c; diff --git a/gdb/f-exp.y b/gdb/f-exp.y index 100a3bbec14..522751d2263 100644 --- a/gdb/f-exp.y +++ b/gdb/f-exp.y @@ -1115,7 +1115,7 @@ yylex (void) return c; case ',': - if (comma_terminates && paren_depth == 0) + if (pstate->comma_terminates && paren_depth == 0) return 0; lexptr++; return c; diff --git a/gdb/go-exp.y b/gdb/go-exp.y index aaffe3d45a0..ea1487cb008 100644 --- a/gdb/go-exp.y +++ b/gdb/go-exp.y @@ -1077,7 +1077,7 @@ lex_one_token (struct parser_state *par_state) return c; case ',': - if (comma_terminates + if (pstate->comma_terminates && paren_depth == 0) return 0; lexptr++; diff --git a/gdb/m2-exp.y b/gdb/m2-exp.y index c0f5e75be2a..2174014e79a 100644 --- a/gdb/m2-exp.y +++ b/gdb/m2-exp.y @@ -819,7 +819,7 @@ yylex (void) return c; case ',': - if (comma_terminates && paren_depth == 0) + if (pstate->comma_terminates && paren_depth == 0) return 0; lexptr++; return c; diff --git a/gdb/p-exp.y b/gdb/p-exp.y index 768f3025921..65874c6327d 100644 --- a/gdb/p-exp.y +++ b/gdb/p-exp.y @@ -1218,7 +1218,7 @@ yylex (void) return c; case ',': - if (comma_terminates && paren_depth == 0) + if (pstate->comma_terminates && paren_depth == 0) return 0; lexptr++; return c; diff --git a/gdb/parse.c b/gdb/parse.c index 4ac79faaeae..617ff70d67e 100644 --- a/gdb/parse.c +++ b/gdb/parse.c @@ -71,7 +71,6 @@ int arglist_len; static struct type_stack type_stack; const char *lexptr; const char *prev_lexptr; -int comma_terminates; /* True if parsing an expression to attempt completion. */ int parse_completion; @@ -1122,8 +1121,6 @@ parse_exp_in_context (const char **stringptr, CORE_ADDR pc, expout_completion_name.reset (); innermost_block.reset (tracker_types); - comma_terminates = comma; - if (lexptr == 0 || *lexptr == 0) error_no_arg (_("expression to compute")); @@ -1187,7 +1184,7 @@ parse_exp_in_context (const char **stringptr, CORE_ADDR pc, to the value matching SELECTED_FRAME as set by get_current_arch. */ parser_state ps (lang, get_current_arch (), expression_context_block, - expression_context_pc); + expression_context_pc, comma); scoped_restore_current_language lang_saver; set_language (lang->la_language); diff --git a/gdb/parser-defs.h b/gdb/parser-defs.h index 6fb0f8e5533..f2bb18fd9c7 100644 --- a/gdb/parser-defs.h +++ b/gdb/parser-defs.h @@ -88,10 +88,12 @@ struct parser_state : public expr_builder parser_state (const struct language_defn *lang, struct gdbarch *gdbarch, const struct block *context_block, - CORE_ADDR context_pc) + CORE_ADDR context_pc, + int comma) : expr_builder (lang, gdbarch), expression_context_block (context_block), - expression_context_pc (context_pc) + expression_context_pc (context_pc), + comma_terminates (comma) { } @@ -108,6 +110,10 @@ struct parser_state : public expr_builder at, and then look up the macro definitions active at that point. */ const CORE_ADDR expression_context_pc; + + /* Nonzero means stop parsing on first comma (if not within parentheses). */ + + int comma_terminates; }; /* When parsing expressions we track the innermost block that was @@ -355,10 +361,6 @@ extern const char *lexptr; /* After a token has been recognized, this variable points to it. Currently used only for error reporting. */ extern const char *prev_lexptr; - -/* Nonzero means stop parsing on first comma (if not within parentheses). */ - -extern int comma_terminates; /* These codes indicate operator precedences for expression printing, least tightly binding first. */ diff --git a/gdb/rust-exp.y b/gdb/rust-exp.y index 9d3083ead92..2f2cc8f31fe 100644 --- a/gdb/rust-exp.y +++ b/gdb/rust-exp.y @@ -1674,7 +1674,8 @@ rustyylex (YYSTYPE *lvalp, rust_parser *parser) /* Falls through to lex_operator. */ ++parser->paren_depth; } - else if (lexptr[0] == ',' && comma_terminates && parser->paren_depth == 0) + else if (lexptr[0] == ',' && parser->pstate->comma_terminates + && parser->paren_depth == 0) return 0; return lex_operator (lvalp); @@ -2713,7 +2714,7 @@ rust_lex_tests (void) // Set up dummy "parser", so that rust_type works. struct parser_state ps (&rust_language_defn, target_gdbarch (), - nullptr, 0); + nullptr, 0, 0); rust_parser parser (&ps); rust_lex_test_one (&parser, "", 0);