aboutsummaryrefslogtreecommitdiff
path: root/gdb/parser-defs.h
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2019-03-24 22:50:14 -0600
committerTom Tromey <tom@tromey.com>2019-04-04 19:55:11 -0600
commit2a61252965c91540133bece7deb92eb22e3cf929 (patch)
tree5774206de4966e8835801e71da5c6661b368dcec /gdb/parser-defs.h
parent43476f0b1b628352ad8e3064e50128cb3461d3d0 (diff)
downloadgdb-2a61252965c91540133bece7deb92eb22e3cf929.zip
gdb-2a61252965c91540133bece7deb92eb22e3cf929.tar.gz
gdb-2a61252965c91540133bece7deb92eb22e3cf929.tar.bz2
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.
Diffstat (limited to 'gdb/parser-defs.h')
-rw-r--r--gdb/parser-defs.h53
1 files changed, 42 insertions, 11 deletions
diff --git a/gdb/parser-defs.h b/gdb/parser-defs.h
index a015115..2c1ea15 100644
--- a/gdb/parser-defs.h
+++ b/gdb/parser-defs.h
@@ -76,6 +76,22 @@ struct expr_builder
size_t expout_ptr;
};
+/* This is used for expression completion. */
+
+struct expr_completion_state
+{
+ /* The index of the last struct expression directly before a '.' or
+ '->'. This is set when parsing and is only used when completing a
+ field name. It is -1 if no dereference operation was found. */
+ int expout_last_struct = -1;
+
+ /* If we are completing a tagged type name, this will be nonzero. */
+ enum type_code expout_tag_completion_type = TYPE_CODE_UNDEF;
+
+ /* The token for tagged type name completion. */
+ gdb::unique_xmalloc_ptr<char> expout_completion_name;
+};
+
/* An instance of this type is instantiated during expression parsing,
and passed to the appropriate parser. It holds both inputs to the
parser, and result. */
@@ -90,12 +106,14 @@ struct parser_state : public expr_builder
const struct block *context_block,
CORE_ADDR context_pc,
int comma,
- const char *input)
+ const char *input,
+ int completion)
: expr_builder (lang, gdbarch),
expression_context_block (context_block),
expression_context_pc (context_pc),
comma_terminates (comma),
- lexptr (input)
+ lexptr (input),
+ parse_completion (completion)
{
}
@@ -121,6 +139,17 @@ struct parser_state : public expr_builder
return val;
}
+ /* Mark the current index as the starting location of a structure
+ expression. This is used when completing on field names. */
+
+ void mark_struct_expression ();
+
+ /* Indicate that the current parser invocation is completing a tag.
+ TAG is the type code of the tag, and PTR and LENGTH represent the
+ start of the tag name. */
+
+ void mark_completion_tag (enum type_code tag, const char *ptr, int length);
+
/* If this is nonzero, this block is used as the lexical context for
symbol names. */
@@ -151,6 +180,12 @@ struct parser_state : public expr_builder
int arglist_len = 0;
+ /* True if parsing an expression to attempt completion. */
+ int parse_completion;
+
+ /* Completion state is updated here. */
+ expr_completion_state m_completion_state;
+
private:
/* Data structure for saving values of arglist_len for function calls whose
@@ -300,12 +335,13 @@ struct type_stack
/* Reverse an expression from suffix form (in which it is constructed)
to prefix form (in which we can conveniently print or execute it).
- Ordinarily this always returns -1. However, if EXPOUT_LAST_STRUCT
+ Ordinarily this always returns -1. However, if LAST_STRUCT
is not -1 (i.e., we are trying to complete a field name), it will
return the index of the subexpression which is the left-hand-side
- of the struct operation at EXPOUT_LAST_STRUCT. */
+ of the struct operation at LAST_STRUCT. */
-extern int prefixify_expression (struct expression *expr);
+extern int prefixify_expression (struct expression *expr,
+ int last_struct = -1);
extern void write_exp_elt_opcode (struct expr_builder *, enum exp_opcode);
@@ -336,8 +372,6 @@ extern void write_exp_msymbol (struct expr_builder *,
extern void write_dollar_variable (struct parser_state *, struct stoken str);
-extern void mark_struct_expression (struct expr_builder *);
-
extern const char *find_template_name_end (const char *);
extern char *copy_name (struct stoken);
@@ -384,7 +418,7 @@ extern struct type *follow_types (struct type *);
extern type_instance_flags follow_type_instance_flags ();
-extern void null_post_parser (expression_up *, int);
+extern void null_post_parser (expression_up *, int, int);
extern bool parse_float (const char *p, int len,
const struct type *type, gdb_byte *data);
@@ -483,8 +517,5 @@ extern void parser_fprintf (FILE *, const char *, ...) ATTRIBUTE_PRINTF (2, 3);
extern int exp_uses_objfile (struct expression *exp, struct objfile *objfile);
-extern void mark_completion_tag (enum type_code, const char *ptr,
- int length);
-
#endif /* PARSER_DEFS_H */