Move completion parsing to parser_state

This moves the globals and functions related to parsing for completion
to parser_state.  A new structure is introduced in order to return
completion results from the parse back to
parse_expression_for_completion.

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

	* rust-exp.y (rust_parser::lex_identifier, rustyylex)
	(rust_parser::convert_ast_to_expression, rust_parse)
	(rust_lex_test_completion, rust_lex_tests): Update.
	* parser-defs.h (struct expr_completion_state): New.
	(struct parser_state) <parser_state>: Add completion parameter.
	<mark_struct_expression, mark_completion_tag>: New methods.
	<parse_completion, m_completion_state>: New members.
	(prefixify_expression, null_post_parser): Update.
	(mark_struct_expression, mark_completion_tag): Don't declare.
	* parse.c (parse_completion, expout_last_struct)
	(expout_tag_completion_type, expout_completion_name): Remove
	globals.
	(parser_state::mark_struct_expression)
	(parser_state::mark_completion_tag): Now methods.
	(prefixify_expression): Add last_struct parameter.
	(prefixify_subexp): Likewise.
	(parse_exp_1): Update.
	(parse_exp_in_context): Add cstate parameter.  Update.
	(parse_expression_for_completion): Create an
	expr_completion_state.
	(null_post_parser): Add "completion" parameter.
	* p-exp.y: Update rules.
	(yylex): Update.
	* language.h (struct language_defn) <la_post_parser>: Add
	"completing" parameter.
	* go-exp.y: Update rules.
	(lex_one_token): Update.
	* expression.h (parse_completion): Don't declare.
	* d-exp.y: Update rules.
	(lex_one_token): Update rules.
	* c-exp.y: Update rules.
	(lex_one_token): Update.
	* ada-lang.c (resolve): Add "parse_completion" parameter.
	(resolve_subexp): Likewise.
	(ada_resolve_function): Likewise.
This commit is contained in:
Tom Tromey 2019-03-24 22:50:14 -06:00
parent 43476f0b1b
commit 2a61252965
11 changed files with 188 additions and 123 deletions

View file

@ -125,7 +125,7 @@ static int num_defns_collected (struct obstack *);
static struct block_symbol *defns_collected (struct obstack *, int);
static struct value *resolve_subexp (expression_up *, int *, int,
struct type *);
struct type *, int);
static void replace_operator_with_call (expression_up *, int, int, int,
struct symbol *, const struct block *);
@ -225,7 +225,7 @@ static int find_struct_field (const char *, struct type *, int,
static int ada_resolve_function (struct block_symbol *, int,
struct value **, int, const char *,
struct type *);
struct type *, int);
static int ada_is_direct_array_type (struct type *);
@ -3220,7 +3220,7 @@ ada_decoded_op_name (enum exp_opcode op)
return type is preferred. May change (expand) *EXP. */
static void
resolve (expression_up *expp, int void_context_p)
resolve (expression_up *expp, int void_context_p, int parse_completion)
{
struct type *context_type = NULL;
int pc = 0;
@ -3228,7 +3228,7 @@ resolve (expression_up *expp, int void_context_p)
if (void_context_p)
context_type = builtin_type ((*expp)->gdbarch)->builtin_void;
resolve_subexp (expp, &pc, 1, context_type);
resolve_subexp (expp, &pc, 1, context_type, parse_completion);
}
/* Resolve the operator of the subexpression beginning at
@ -3242,7 +3242,7 @@ resolve (expression_up *expp, int void_context_p)
static struct value *
resolve_subexp (expression_up *expp, int *pos, int deprocedure_p,
struct type *context_type)
struct type *context_type, int parse_completion)
{
int pc = *pos;
int i;
@ -3267,19 +3267,20 @@ resolve_subexp (expression_up *expp, int *pos, int deprocedure_p,
else
{
*pos += 3;
resolve_subexp (expp, pos, 0, NULL);
resolve_subexp (expp, pos, 0, NULL, parse_completion);
}
nargs = longest_to_int (exp->elts[pc + 1].longconst);
break;
case UNOP_ADDR:
*pos += 1;
resolve_subexp (expp, pos, 0, NULL);
resolve_subexp (expp, pos, 0, NULL, parse_completion);
break;
case UNOP_QUAL:
*pos += 3;
resolve_subexp (expp, pos, 1, check_typedef (exp->elts[pc + 1].type));
resolve_subexp (expp, pos, 1, check_typedef (exp->elts[pc + 1].type),
parse_completion);
break;
case OP_ATR_MODULUS:
@ -3310,11 +3311,11 @@ resolve_subexp (expression_up *expp, int *pos, int deprocedure_p,
struct value *arg1;
*pos += 1;
arg1 = resolve_subexp (expp, pos, 0, NULL);
arg1 = resolve_subexp (expp, pos, 0, NULL, parse_completion);
if (arg1 == NULL)
resolve_subexp (expp, pos, 1, NULL);
resolve_subexp (expp, pos, 1, NULL, parse_completion);
else
resolve_subexp (expp, pos, 1, value_type (arg1));
resolve_subexp (expp, pos, 1, value_type (arg1), parse_completion);
break;
}
@ -3402,7 +3403,7 @@ resolve_subexp (expression_up *expp, int *pos, int deprocedure_p,
argvec = XALLOCAVEC (struct value *, nargs + 1);
for (i = 0; i < nargs; i += 1)
argvec[i] = resolve_subexp (expp, pos, 1, NULL);
argvec[i] = resolve_subexp (expp, pos, 1, NULL, parse_completion);
argvec[i] = NULL;
exp = expp->get ();
@ -3471,7 +3472,7 @@ resolve_subexp (expression_up *expp, int *pos, int deprocedure_p,
i = ada_resolve_function
(candidates.data (), n_candidates, NULL, 0,
SYMBOL_LINKAGE_NAME (exp->elts[pc + 2].symbol),
context_type);
context_type, parse_completion);
if (i < 0)
error (_("Could not find a match for %s"),
SYMBOL_PRINT_NAME (exp->elts[pc + 2].symbol));
@ -3522,7 +3523,7 @@ resolve_subexp (expression_up *expp, int *pos, int deprocedure_p,
(candidates.data (), n_candidates,
argvec, nargs,
SYMBOL_LINKAGE_NAME (exp->elts[pc + 5].symbol),
context_type);
context_type, parse_completion);
if (i < 0)
error (_("Could not find a match for %s"),
SYMBOL_PRINT_NAME (exp->elts[pc + 5].symbol));
@ -3566,7 +3567,8 @@ resolve_subexp (expression_up *expp, int *pos, int deprocedure_p,
&candidates);
i = ada_resolve_function (candidates.data (), n_candidates, argvec,
nargs, ada_decoded_op_name (op), NULL);
nargs, ada_decoded_op_name (op), NULL,
parse_completion);
if (i < 0)
break;
@ -3733,7 +3735,8 @@ return_match (struct type *func_type, struct type *context_type)
static int
ada_resolve_function (struct block_symbol syms[],
int nsyms, struct value **args, int nargs,
const char *name, struct type *context_type)
const char *name, struct type *context_type,
int parse_completion)
{
int fallback;
int k;