Move arglist_len et al to parser_state

This moves arglist_len, start_arglist, and end_arglist to
parser_state.

gdb/ChangeLog
2019-04-04  Tom Tromey  <tom@tromey.com>

	* parser-defs.h (struct parser_state) <start_arglist,
	end_arglist>: New methods.
	<arglist_len, m_funcall_chain>: 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.
This commit is contained in:
Tom Tromey 2019-03-24 21:38:40 -06:00
parent 5776fca307
commit 43476f0b1b
9 changed files with 89 additions and 80 deletions

View File

@ -1,3 +1,19 @@
2019-04-04 Tom Tromey <tom@tromey.com>
* parser-defs.h (struct parser_state) <start_arglist,
end_arglist>: New methods.
<arglist_len, m_funcall_chain>: 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.
2019-04-04 Tom Tromey <tom@tromey.com>
* rust-exp.y (struct rust_parser) <lex_hex, lex_escape,

View File

@ -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);

View File

@ -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:

View File

@ -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. */

View File

@ -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

View File

@ -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 */

View File

@ -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

View File

@ -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<int> *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<int> 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;

View File

@ -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<int> 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);