static struct parser_state *pstate = NULL;
+/* The original expression string. */
+static const char *original_expr;
+
int yyparse (void);
static int yylex (void);
static struct type* write_var_or_type (struct parser_state *,
const struct block *, struct stoken);
+static struct type *write_var_or_type_completion (struct parser_state *,
+ const struct block *,
+ struct stoken);
static void write_name_assoc (struct parser_state *, struct stoken);
static struct type *type_system_address (struct parser_state *);
+static std::string find_completion_bounds (struct parser_state *);
+
using namespace expr;
/* Handle Ada type resolution for OP. DEPROCEDURE_P and CONTEXT_TYPE
%token <typed_val_float> FLOAT
%token TRUEKEYWORD FALSEKEYWORD
%token COLONCOLON
-%token <sval> STRING NAME DOT_ID TICK_COMPLETE
+%token <sval> STRING NAME DOT_ID TICK_COMPLETE DOT_COMPLETE NAME_COMPLETE
%type <bval> block
%type <lval> arglist tick_arglist
/* 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. */
-%right '.' '(' '[' DOT_ID
+%right '.' '(' '[' DOT_ID DOT_COMPLETE
%token NEW OTHERS
}
;
+primary : primary DOT_COMPLETE
+ {
+ /* This is done even for ".all", because
+ that might be a prefix. */
+ operation_up arg = ada_pop ();
+ ada_structop_operation *str_op
+ = (new ada_structop_operation
+ (std::move (arg), copy_name ($2)));
+ str_op->set_prefix (find_completion_bounds (pstate));
+ pstate->push (operation_up (str_op));
+ pstate->mark_struct_expression (str_op);
+ }
+ ;
+
primary : primary '(' arglist ')'
{ ada_funcall ($3); }
| var_or_type '(' arglist ')'
var_or_type: NAME %prec VAR
{ $$ = write_var_or_type (pstate, NULL, $1); }
+ | NAME_COMPLETE %prec VAR
+ {
+ $$ = write_var_or_type_completion (pstate,
+ NULL,
+ $1);
+ }
| block NAME %prec VAR
{ $$ = write_var_or_type (pstate, $1, $2); }
+ | block NAME_COMPLETE %prec VAR
+ {
+ $$ = write_var_or_type_completion (pstate,
+ $1,
+ $2);
+ }
| NAME TICK_ACCESS
{
$$ = write_var_or_type (pstate, NULL, $1);
scoped_restore pstate_restore = make_scoped_restore (&pstate);
gdb_assert (par_state != NULL);
pstate = par_state;
+ original_expr = par_state->lexptr;
scoped_restore restore_yydebug = make_scoped_restore (&yydebug,
parser_debug);
/* Given that SELS is a string of the form (<sep><identifier>)*, where
<sep> is '__' or '.', write the indicated sequence of
- STRUCTOP_STRUCT expression operators. */
-static void
+ STRUCTOP_STRUCT expression operators. Returns a pointer to the
+ last operation that was pushed. */
+static ada_structop_operation *
write_selectors (struct parser_state *par_state, const char *sels)
{
+ ada_structop_operation *result = nullptr;
while (*sels != '\0')
{
const char *p = chop_separator (sels);
&& (sels[0] != '_' || sels[1] != '_'))
sels += 1;
operation_up arg = ada_pop ();
- pstate->push_new<ada_structop_operation>
- (std::move (arg), std::string (p, sels - p));
+ result = new ada_structop_operation (std::move (arg),
+ std::string (p, sels - p));
+ pstate->push (operation_up (result));
}
+ return result;
}
/* Write a variable access (OP_VAR_VALUE) to ambiguous encoded name
}
+/* Because ada_completer_word_break_characters does not contain '.' --
+ and it cannot easily be added, this breaks other completions -- we
+ have to recreate the completion word-splitting here, so that we can
+ provide a prefix that is then used when completing field names.
+ Without this, an attempt like "complete print abc.d" will give a
+ result like "print def" rather than "print abc.def". */
+
+static std::string
+find_completion_bounds (struct parser_state *par_state)
+{
+ const char *end = pstate->lexptr;
+ /* First the end of the prefix. Here we stop at the token start or
+ at '.' or space. */
+ for (; end > original_expr && end[-1] != '.' && !isspace (end[-1]); --end)
+ {
+ /* Nothing. */
+ }
+ /* Now find the start of the prefix. */
+ const char *ptr = end;
+ /* Here we allow '.'. */
+ for (;
+ ptr > original_expr && (ptr[-1] == '.'
+ || ptr[-1] == '_'
+ || (ptr[-1] >= 'a' && ptr[-1] <= 'z')
+ || (ptr[-1] >= 'A' && ptr[-1] <= 'Z')
+ || (ptr[-1] & 0xff) >= 0x80);
+ --ptr)
+ {
+ /* Nothing. */
+ }
+ /* ... except, skip leading spaces. */
+ ptr = skip_spaces (ptr);
+
+ return std::string (ptr, end);
+}
+
+/* A wrapper for write_var_or_type that is used specifically when
+ completion is requested for the last of a sequence of
+ identifiers. */
+
+static struct type *
+write_var_or_type_completion (struct parser_state *par_state,
+ const struct block *block, struct stoken name0)
+{
+ int tail_index = chop_selector (name0.ptr, name0.length);
+ /* If there's no separator, just defer to ordinary symbol
+ completion. */
+ if (tail_index == -1)
+ return write_var_or_type (par_state, block, name0);
+
+ std::string copy (name0.ptr, tail_index);
+ struct type *type = write_var_or_type (par_state, block,
+ { copy.c_str (),
+ (int) copy.length () });
+ /* For completion purposes, it's enough that we return a type
+ here. */
+ if (type != nullptr)
+ return type;
+
+ ada_structop_operation *op = write_selectors (par_state,
+ name0.ptr + tail_index);
+ op->set_prefix (find_completion_bounds (par_state));
+ par_state->mark_struct_expression (op);
+ return nullptr;
+}
+
/* Write a left side of a component association (e.g., NAME in NAME =>
exp). If NAME has the form of a selected component, write it as an
ordinary expression. If it is a simple variable that unambiguously
/* Helper for structop_base_operation::complete which recursively adds
field and method names from TYPE, a struct or union type, to the
- OUTPUT list. */
+ OUTPUT list. PREFIX is prepended to each result. */
static void
add_struct_fields (struct type *type, completion_list &output,
- const char *fieldname, int namelen)
+ const char *fieldname, int namelen, const char *prefix)
{
int i;
int computed_type_name = 0;
{
if (i < TYPE_N_BASECLASSES (type))
add_struct_fields (TYPE_BASECLASS (type, i),
- output, fieldname, namelen);
+ output, fieldname, namelen, prefix);
else if (type->field (i).name ())
{
if (type->field (i).name ()[0] != '\0')
{
if (! strncmp (type->field (i).name (),
fieldname, namelen))
- output.emplace_back (xstrdup (type->field (i).name ()));
+ output.emplace_back (concat (prefix, type->field (i).name (),
+ nullptr));
}
else if (type->field (i).type ()->code () == TYPE_CODE_UNION)
{
/* Recurse into anonymous unions. */
add_struct_fields (type->field (i).type (),
- output, fieldname, namelen);
+ output, fieldname, namelen, prefix);
}
}
}
}
/* Omit constructors from the completion list. */
if (!type_name || strcmp (type_name, name))
- output.emplace_back (xstrdup (name));
+ output.emplace_back (concat (prefix, name, nullptr));
}
}
}
bool
structop_base_operation::complete (struct expression *exp,
- completion_tracker &tracker)
+ completion_tracker &tracker,
+ const char *prefix)
{
const std::string &fieldname = std::get<1> (m_storage);
completion_list result;
add_struct_fields (type, result, fieldname.c_str (),
- fieldname.length ());
+ fieldname.length (), prefix);
tracker.add_completions (std::move (result));
return true;
}
gdb_test "ptype circle.pos.x" \
"type = <\[0-9\]+-byte integer>"
+
+gdb_test "complete print my_circ" "print my_circle"
+gdb_test "complete print my_circle.r" "print my_circle\\.radius"
+gdb_test "complete print my_circle.po" "print my_circle\\.pos"
+gdb_test "complete print my_circle . po" "print my_circle \\. pos" \
+ "complete with spaces"
+gdb_test "complete print my_circle." \
+ [multi_line \
+ "print my_circle\\.pos" \
+ "print my_circle\\.radius"]
+gdb_test "complete print (my_circle).r" "print \\(my_circle\\)\\.radius"
+gdb_test "complete print (my_circle).po" "print \\(my_circle\\)\\.pos"
+gdb_test "complete print (my_circle)." \
+ [multi_line \
+ "print \\(my_circle\\)\\.pos" \
+ "print \\(my_circle\\)\\.radius"]
+
+gdb_test "complete ptype pck.pos" "ptype pck\\.position"
+gdb_test "complete ptype pck.c" "ptype pck\\.circle"
+
+# We can't query the members of a package yet, and this yields a bit
+# too much output, so comment out for now instead of kfailing.
+# gdb_test "complete ptype pck." \
+# [multi_line \
+# "ptype pck\\.circle" \
+# "ptype pck\\.position"]
+
+gdb_test "complete ptype circle.pos." \
+ [multi_line \
+ "ptype circle\\.pos\\.x" \
+ "ptype circle\\.pos\\.y"]