From patchwork Wed Apr 3 01:38:02 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 32142 Received: (qmail 27951 invoked by alias); 3 Apr 2019 01:38:20 -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 27696 invoked by uid 89); 3 Apr 2019 01:38:18 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-17.3 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=evalc X-HELO: gateway21.websitewelcome.com Received: from gateway21.websitewelcome.com (HELO gateway21.websitewelcome.com) (192.185.46.113) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 03 Apr 2019 01:38:11 +0000 Received: from cm17.websitewelcome.com (cm17.websitewelcome.com [100.42.49.20]) by gateway21.websitewelcome.com (Postfix) with ESMTP id 4E2D1400C8336 for ; Tue, 2 Apr 2019 20:38:10 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id BUqwhpQyF90onBUqwh3F0J; Tue, 02 Apr 2019 20:38:10 -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=Zc4LqzA21o7fe+G1qmmJz9tNrJCR/KFE8ID/lbGKcPM=; b=PpEsFly10ivbP8G3/tCb2Jigo0 b4tSVfdqDS2p/AqkSmsj8Vdd1sDpR3u/X4nWSzTXSSmiT3CJPlwaFFqmQ2x4FcDG3MiZZaRVV4uJl QXPYAj7/GNCd4H0r0aaf7yRMy; 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 1hBUqw-002Gj6-0W; Tue, 02 Apr 2019 20:38:10 -0500 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH 10/13] Move arglist_len et al to parser_state Date: Tue, 2 Apr 2019 19:38:02 -0600 Message-Id: <20190403013805.11978-11-tom@tromey.com> In-Reply-To: <20190403013805.11978-1-tom@tromey.com> References: <20190403013805.11978-1-tom@tromey.com> This moves arglist_len, start_arglist, and end_arglist to parser_state. gdb/ChangeLog 2019-04-02 Tom Tromey * parser-defs.h (struct parser_state) : New methods. : New members. (arglist_len, start_arglist, end_arglist): Don't declare. * parse.c (arglist_len, funcall_chain): Remove global. (start_arglist, end_arglist): Remove functions. (parse_exp_in_context): Update. * p-exp.y: Update rules. * m2-exp.y: Update rules. * go-exp.y: Update rules. * f-exp.y: Update rules. * d-exp.y: Update rules. * c-exp.y: Update rules. --- gdb/ChangeLog | 16 ++++++++++++++++ gdb/c-exp.y | 20 ++++++++++---------- gdb/d-exp.y | 16 ++++++++-------- gdb/f-exp.y | 10 +++++----- gdb/go-exp.y | 12 ++++++------ gdb/m2-exp.y | 16 ++++++++-------- gdb/p-exp.y | 8 ++++---- gdb/parse.c | 32 -------------------------------- gdb/parser-defs.h | 39 ++++++++++++++++++++++++++++++++------- 9 files changed, 89 insertions(+), 80 deletions(-) diff --git a/gdb/c-exp.y b/gdb/c-exp.y index c85bb3133e8..cab5cd55dbd 100644 --- a/gdb/c-exp.y +++ b/gdb/c-exp.y @@ -534,11 +534,11 @@ msgarg : name ':' exp exp : exp '(' /* This is to save the value of arglist_len being accumulated by an outer function call. */ - { start_arglist (); } + { pstate->start_arglist (); } arglist ')' %prec ARROW { write_exp_elt_opcode (pstate, OP_FUNCALL); write_exp_elt_longcst (pstate, - (LONGEST) end_arglist ()); + pstate->end_arglist ()); write_exp_elt_opcode (pstate, OP_FUNCALL); } ; @@ -546,10 +546,10 @@ exp : exp '(' "func()::static_var" further below, which uses function_method_void. */ exp : exp '(' ')' %prec ARROW - { start_arglist (); + { pstate->start_arglist (); write_exp_elt_opcode (pstate, OP_FUNCALL); write_exp_elt_longcst (pstate, - (LONGEST) end_arglist ()); + pstate->end_arglist ()); write_exp_elt_opcode (pstate, OP_FUNCALL); } ; @@ -569,30 +569,30 @@ exp : UNKNOWN_CPP_NAME '(' /* This is to save the value of arglist_len being accumulated by an outer function call. */ - start_arglist (); + pstate->start_arglist (); } arglist ')' %prec ARROW { write_exp_elt_opcode (pstate, OP_FUNCALL); write_exp_elt_longcst (pstate, - (LONGEST) end_arglist ()); + pstate->end_arglist ()); write_exp_elt_opcode (pstate, OP_FUNCALL); } ; lcurly : '{' - { start_arglist (); } + { pstate->start_arglist (); } ; arglist : ; arglist : exp - { arglist_len = 1; } + { pstate->arglist_len = 1; } ; arglist : arglist ',' exp %prec ABOVE_COMMA - { arglist_len++; } + { pstate->arglist_len++; } ; function_method: exp '(' parameter_typelist ')' const_or_volatile @@ -645,7 +645,7 @@ exp : function_method_void_or_typelist COLONCOLON name ; rcurly : '}' - { $$ = end_arglist () - 1; } + { $$ = pstate->end_arglist () - 1; } ; exp : lcurly arglist rcurly %prec ARROW { write_exp_elt_opcode (pstate, OP_ARRAY); diff --git a/gdb/d-exp.y b/gdb/d-exp.y index 9addf6c0410..c14c2d6fd6f 100644 --- a/gdb/d-exp.y +++ b/gdb/d-exp.y @@ -366,32 +366,32 @@ PostfixExpression: ArgumentList: AssignExpression - { arglist_len = 1; } + { pstate->arglist_len = 1; } | ArgumentList ',' AssignExpression - { arglist_len++; } + { pstate->arglist_len++; } ; ArgumentList_opt: /* EMPTY */ - { arglist_len = 0; } + { pstate->arglist_len = 0; } | ArgumentList ; CallExpression: PostfixExpression '(' - { start_arglist (); } + { pstate->start_arglist (); } ArgumentList_opt ')' { write_exp_elt_opcode (pstate, OP_FUNCALL); - write_exp_elt_longcst (pstate, (LONGEST) end_arglist ()); + write_exp_elt_longcst (pstate, pstate->end_arglist ()); write_exp_elt_opcode (pstate, OP_FUNCALL); } ; IndexExpression: PostfixExpression '[' ArgumentList ']' - { if (arglist_len > 0) + { if (pstate->arglist_len > 0) { write_exp_elt_opcode (pstate, MULTI_SUBSCRIPT); - write_exp_elt_longcst (pstate, (LONGEST) arglist_len); + write_exp_elt_longcst (pstate, pstate->arglist_len); write_exp_elt_opcode (pstate, MULTI_SUBSCRIPT); } else @@ -558,7 +558,7 @@ PrimaryExpression: ArrayLiteral: '[' ArgumentList_opt ']' - { $$ = arglist_len; } + { $$ = pstate->arglist_len; } ; IdentifierExp: diff --git a/gdb/f-exp.y b/gdb/f-exp.y index fce90b48ef5..da4732237d3 100644 --- a/gdb/f-exp.y +++ b/gdb/f-exp.y @@ -245,12 +245,12 @@ exp : KIND '(' exp ')' %prec UNARY later in eval.c. */ exp : exp '(' - { start_arglist (); } + { pstate->start_arglist (); } arglist ')' { write_exp_elt_opcode (pstate, OP_F77_UNDETERMINED_ARGLIST); write_exp_elt_longcst (pstate, - (LONGEST) end_arglist ()); + pstate->end_arglist ()); write_exp_elt_opcode (pstate, OP_F77_UNDETERMINED_ARGLIST); } ; @@ -263,15 +263,15 @@ arglist : ; arglist : exp - { arglist_len = 1; } + { pstate->arglist_len = 1; } ; arglist : subrange - { arglist_len = 1; } + { pstate->arglist_len = 1; } ; arglist : arglist ',' exp %prec ABOVE_COMMA - { arglist_len++; } + { pstate->arglist_len++; } ; /* There are four sorts of subrange types in F90. */ diff --git a/gdb/go-exp.y b/gdb/go-exp.y index 6754d5217e5..358fd530918 100644 --- a/gdb/go-exp.y +++ b/gdb/go-exp.y @@ -269,31 +269,31 @@ exp : exp '[' exp1 ']' exp : exp '(' /* This is to save the value of arglist_len being accumulated by an outer function call. */ - { start_arglist (); } + { pstate->start_arglist (); } arglist ')' %prec LEFT_ARROW { write_exp_elt_opcode (pstate, OP_FUNCALL); write_exp_elt_longcst (pstate, - (LONGEST) end_arglist ()); + pstate->end_arglist ()); write_exp_elt_opcode (pstate, OP_FUNCALL); } ; lcurly : '{' - { start_arglist (); } + { pstate->start_arglist (); } ; arglist : ; arglist : exp - { arglist_len = 1; } + { pstate->arglist_len = 1; } ; arglist : arglist ',' exp %prec ABOVE_COMMA - { arglist_len++; } + { pstate->arglist_len++; } ; rcurly : '}' - { $$ = end_arglist () - 1; } + { $$ = pstate->end_arglist () - 1; } ; exp : lcurly type rcurly exp %prec UNARY diff --git a/gdb/m2-exp.y b/gdb/m2-exp.y index 6ba8eaf8554..3e4bc073801 100644 --- a/gdb/m2-exp.y +++ b/gdb/m2-exp.y @@ -298,11 +298,11 @@ exp : exp '[' /* This function just saves the number of arguments that follow in the list. It is *not* specific to function types */ - { start_arglist(); } + { pstate->start_arglist(); } non_empty_arglist ']' %prec DOT { write_exp_elt_opcode (pstate, MULTI_SUBSCRIPT); write_exp_elt_longcst (pstate, - (LONGEST) end_arglist()); + pstate->end_arglist()); write_exp_elt_opcode (pstate, MULTI_SUBSCRIPT); } ; @@ -313,11 +313,11 @@ exp : exp '[' exp ']' exp : exp '(' /* This is to save the value of arglist_len being accumulated by an outer function call. */ - { start_arglist (); } + { pstate->start_arglist (); } arglist ')' %prec DOT { write_exp_elt_opcode (pstate, OP_FUNCALL); write_exp_elt_longcst (pstate, - (LONGEST) end_arglist ()); + pstate->end_arglist ()); write_exp_elt_opcode (pstate, OP_FUNCALL); } ; @@ -325,21 +325,21 @@ arglist : ; arglist : exp - { arglist_len = 1; } + { pstate->arglist_len = 1; } ; arglist : arglist ',' exp %prec ABOVE_COMMA - { arglist_len++; } + { pstate->arglist_len++; } ; non_empty_arglist : exp - { arglist_len = 1; } + { pstate->arglist_len = 1; } ; non_empty_arglist : non_empty_arglist ',' exp %prec ABOVE_COMMA - { arglist_len++; } + { pstate->arglist_len++; } ; /* GDB construct */ diff --git a/gdb/p-exp.y b/gdb/p-exp.y index 4487899ead9..0f78126222c 100644 --- a/gdb/p-exp.y +++ b/gdb/p-exp.y @@ -334,11 +334,11 @@ exp : exp '(' /* This is to save the value of arglist_len being accumulated by an outer function call. */ { push_current_type (); - start_arglist (); } + pstate->start_arglist (); } arglist ')' %prec ARROW { write_exp_elt_opcode (pstate, OP_FUNCALL); write_exp_elt_longcst (pstate, - (LONGEST) end_arglist ()); + pstate->end_arglist ()); write_exp_elt_opcode (pstate, OP_FUNCALL); pop_current_type (); if (current_type) @@ -348,9 +348,9 @@ exp : exp '(' arglist : | exp - { arglist_len = 1; } + { pstate->arglist_len = 1; } | arglist ',' exp %prec ABOVE_COMMA - { arglist_len++; } + { pstate->arglist_len++; } ; exp : type '(' exp ')' %prec UNARY diff --git a/gdb/parse.c b/gdb/parse.c index 5692e23386b..6ee61577068 100644 --- a/gdb/parse.c +++ b/gdb/parse.c @@ -67,7 +67,6 @@ const struct exp_descriptor exp_descriptor_standard = /* Global variables declared in parser-defs.h (and commented there). */ innermost_block_tracker innermost_block; -int arglist_len; static struct type_stack type_stack; /* True if parsing an expression to attempt completion. */ @@ -128,33 +127,6 @@ innermost_block_tracker::update (const struct block *b, m_innermost_block = b; } -/* Data structure for saving values of arglist_len for function calls whose - arguments contain other function calls. */ - -static std::vector *funcall_chain; - -/* Begin counting arguments for a function call, - saving the data about any containing call. */ - -void -start_arglist (void) -{ - funcall_chain->push_back (arglist_len); - arglist_len = 0; -} - -/* Return the number of arguments in a function call just terminated, - and restore the data for the containing function call. */ - -int -end_arglist (void) -{ - int val = arglist_len; - arglist_len = funcall_chain->back (); - funcall_chain->pop_back (); - return val; -} - /* See definition in parser-defs.h. */ @@ -1119,10 +1091,6 @@ parse_exp_in_context (const char **stringptr, CORE_ADDR pc, if (*stringptr == 0 || **stringptr == 0) error_no_arg (_("expression to compute")); - std::vector funcalls; - scoped_restore save_funcall_chain = make_scoped_restore (&funcall_chain, - &funcalls); - const struct block *expression_context_block = block; CORE_ADDR expression_context_pc = 0; diff --git a/gdb/parser-defs.h b/gdb/parser-defs.h index 66828e0f772..a01511584d7 100644 --- a/gdb/parser-defs.h +++ b/gdb/parser-defs.h @@ -101,6 +101,27 @@ struct parser_state : public expr_builder DISABLE_COPY_AND_ASSIGN (parser_state); + /* Begin counting arguments for a function call, + saving the data about any containing call. */ + + void start_arglist () + { + m_funcall_chain.push_back (arglist_len); + arglist_len = 0; + } + + /* Return the number of arguments in a function call just terminated, + and restore the data for the containing function call. */ + + int end_arglist () + { + int val = arglist_len; + arglist_len = m_funcall_chain.back (); + m_funcall_chain.pop_back (); + return val; + } + + /* If this is nonzero, this block is used as the lexical context for symbol names. */ @@ -125,6 +146,17 @@ struct parser_state : public expr_builder /* After a token has been recognized, this variable points to it. Currently used only for error reporting. */ const char *prev_lexptr = nullptr; + + /* Number of arguments seen so far in innermost function call. */ + + int arglist_len = 0; + +private: + + /* Data structure for saving values of arglist_len for function calls whose + arguments contain other function calls. */ + + std::vector m_funcall_chain; }; /* When parsing expressions we track the innermost block that was @@ -185,9 +217,6 @@ private: once the parse is complete. */ extern innermost_block_tracker innermost_block; -/* Number of arguments seen so far in innermost function call. */ -extern int arglist_len; - /* A string token, either a char-string or bit-string. Char-strings are used, for example, for the names of symbols. */ @@ -311,10 +340,6 @@ extern void mark_struct_expression (struct expr_builder *); extern const char *find_template_name_end (const char *); -extern void start_arglist (void); - -extern int end_arglist (void); - extern char *copy_name (struct stoken); extern void insert_type (enum type_pieces);