diff options
author | Tom Tromey <tromey@adacore.com> | 2022-02-22 11:18:01 -0700 |
---|---|---|
committer | Tom Tromey <tromey@adacore.com> | 2022-04-04 12:46:09 -0600 |
commit | c66ed94ae961c19b0d3028489d00a2df5a949aac (patch) | |
tree | 9a61add0242fd5914ed0ba3578bcbcb90fe76dcc /gdb/ada-exp.y | |
parent | 1e237aba2216f89b9a4b3235ad8d09d1b1b8f039 (diff) | |
download | binutils-gdb-c66ed94ae961c19b0d3028489d00a2df5a949aac.tar.gz |
Implement completion for Ada attributes
This adds a completer for Ada attributes. Some work in the lexer is
required in order to match end-of-input correctly, as flex does not
have a general-purpose way of doing this. (The approach taken here is
recommended in the flex manual.)
Diffstat (limited to 'gdb/ada-exp.y')
-rw-r--r-- | gdb/ada-exp.y | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/gdb/ada-exp.y b/gdb/ada-exp.y index ebf3925b98c..204e77af6ca 100644 --- a/gdb/ada-exp.y +++ b/gdb/ada-exp.y @@ -393,6 +393,30 @@ pop_associations (int n) return result; } +/* Expression completer for attributes. */ +struct ada_tick_completer : public expr_completion_base +{ + explicit ada_tick_completer (std::string &&name) + : m_name (std::move (name)) + { + } + + bool complete (struct expression *exp, + completion_tracker &tracker) override; + +private: + + std::string m_name; +}; + +/* Make a new ada_tick_completer and wrap it in a unique pointer. */ +static std::unique_ptr<expr_completion_base> +make_tick_completer (struct stoken tok) +{ + return (std::unique_ptr<expr_completion_base> + (new ada_tick_completer (std::string (tok.ptr, tok.length)))); +} + %} %union @@ -420,7 +444,7 @@ pop_associations (int n) %token <typed_val_float> FLOAT %token TRUEKEYWORD FALSEKEYWORD %token COLONCOLON -%token <sval> STRING NAME DOT_ID +%token <sval> STRING NAME DOT_ID TICK_COMPLETE %type <bval> block %type <lval> arglist tick_arglist @@ -449,6 +473,7 @@ pop_associations (int n) %right TICK_ACCESS TICK_ADDRESS TICK_FIRST TICK_LAST TICK_LENGTH %right TICK_MAX TICK_MIN TICK_MODULUS %right TICK_POS TICK_RANGE TICK_SIZE TICK_TAG TICK_VAL +%right TICK_COMPLETE /* The following are right-associative only so that reductions at this precedence have lower precedence than '.' and '('. The syntax still forces a.b.c, e.g., to be LEFT-associated. */ @@ -784,6 +809,10 @@ primary : primary TICK_ACCESS { ada_addrof (); } | primary TICK_ADDRESS { ada_addrof (type_system_address (pstate)); } + | primary TICK_COMPLETE + { + pstate->mark_completion (make_tick_completer ($2)); + } | primary TICK_FIRST tick_arglist { operation_up arg = ada_pop (); |