From 1e237aba2216f89b9a4b3235ad8d09d1b1b8f039 Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Tue, 22 Feb 2022 09:48:25 -0700 Subject: Refactor expression completion This refactors the gdb expression completion code to make it easier to add more types of completers. In the old approach, just two kinds of completers were supported: field names for some sub-expression, or tag names (like "enum something"). The data for each kind was combined in single structure, "expr_completion_state", and handled explicitly by complete_expression. In the new approach, the parser state just holds an object that is responsible for implementing completion. This way, new completion types can be added by subclassing this base object. The structop completer is moved into structop_base_operation, and new objects are defined for use by the completion code. This moves much of the logic of expression completion out of completer.c as well. --- gdb/expression.h | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) (limited to 'gdb/expression.h') diff --git a/gdb/expression.h b/gdb/expression.h index ff3990e..3ba68a2 100644 --- a/gdb/expression.h +++ b/gdb/expression.h @@ -232,8 +232,26 @@ extern expression_up parse_expression (const char *, extern expression_up parse_expression_with_language (const char *string, enum language lang); -extern struct type *parse_expression_for_completion - (const char *, gdb::unique_xmalloc_ptr *, enum type_code *); + +class completion_tracker; + +/* Base class for expression completion. An instance of this + represents a completion request from the parser. */ +struct expr_completion_base +{ + /* Perform this object's completion. EXP is the expression in which + the completion occurs. TRACKER is the tracker to update with the + results. Return true if completion was possible (even if no + completions were found), false to fall back to ordinary + expression completion (i.e., symbol names). */ + virtual bool complete (struct expression *exp, + completion_tracker &tracker) = 0; + + virtual ~expr_completion_base () = default; +}; + +extern expression_up parse_expression_for_completion + (const char *, std::unique_ptr *completer); class innermost_block_tracker; extern expression_up parse_exp_1 (const char **, CORE_ADDR pc, -- cgit v1.1