argument, assertion.
* c-exp.y (typebase): Add completion productions.
* completer.c (expression_completer): Handle tag completion.
* expression.h (parse_expression_for_completion): Add argument.
* f-lang.c (f_make_symbol_completion_list): Add 'code'
argument.
* language.h (struct language_defn)
<la_make_symbol_completion_list>: Add 'code' argument.
* parse.c (expout_tag_completion_type, expout_completion_name):
New globals.
(mark_struct_expression): Add assertion.
(mark_completion_tag): New function.
(parse_exp_in_context): Initialize new globals.
(parse_expression_for_completion): Add 'code' argument. Handle
tag completion.
* parser-defs.h (mark_completion_tag): Declare.
* symtab.c (default_make_symbol_completion_list_break_on): Add
'code' argument. Update.
(default_make_symbol_completion_list): Add 'code' argument.
(make_symbol_completion_list): Update.
(make_symbol_completion_type): New function.
* symtab.h (default_make_symbol_completion_list_break_on)
(default_make_symbol_completion_list): Update.
(make_symbol_completion_type): Declare.
testsuite
* gdb.base/break1.c (enum some_enum, union some_union): New.
(some_enum_global, some_union_global, some_value): New globals.
* gdb.base/completion.exp: Add tag completion tests.
2012-12-07 Tom Tromey <tromey@redhat.com>
+ * ada-lang.c (ada_make_symbol_completion_list): Add 'code'
+ argument, assertion.
+ * c-exp.y (typebase): Add completion productions.
+ * completer.c (expression_completer): Handle tag completion.
+ * expression.h (parse_expression_for_completion): Add argument.
+ * f-lang.c (f_make_symbol_completion_list): Add 'code'
+ argument.
+ * language.h (struct language_defn)
+ <la_make_symbol_completion_list>: Add 'code' argument.
+ * parse.c (expout_tag_completion_type, expout_completion_name):
+ New globals.
+ (mark_struct_expression): Add assertion.
+ (mark_completion_tag): New function.
+ (parse_exp_in_context): Initialize new globals.
+ (parse_expression_for_completion): Add 'code' argument. Handle
+ tag completion.
+ * parser-defs.h (mark_completion_tag): Declare.
+ * symtab.c (default_make_symbol_completion_list_break_on): Add
+ 'code' argument. Update.
+ (default_make_symbol_completion_list): Add 'code' argument.
+ (make_symbol_completion_list): Update.
+ (make_symbol_completion_type): New function.
+ * symtab.h (default_make_symbol_completion_list_break_on)
+ (default_make_symbol_completion_list): Update.
+ (make_symbol_completion_type): Declare.
+
+2012-12-07 Tom Tromey <tromey@redhat.com>
+
* expression.h (parse_expression_for_completion): Rename
from parse_field_expression.
(parse_completion): Rename from in_parse_field.
the entire command on which completion is made. */
static VEC (char_ptr) *
-ada_make_symbol_completion_list (char *text0, char *word)
+ada_make_symbol_completion_list (char *text0, char *word, enum type_code code)
{
char *text;
int text_len;
int i;
struct block_iterator iter;
+ gdb_assert (code == TYPE_CODE_UNDEF);
+
if (text0[0] == '<')
{
text = xstrdup (text0);
| STRUCT name
{ $$ = lookup_struct (copy_name ($2),
expression_context_block); }
+ | STRUCT COMPLETE
+ {
+ mark_completion_tag (TYPE_CODE_STRUCT, "", 0);
+ $$ = NULL;
+ }
+ | STRUCT name COMPLETE
+ {
+ mark_completion_tag (TYPE_CODE_STRUCT, $2.ptr,
+ $2.length);
+ $$ = NULL;
+ }
| CLASS name
{ $$ = lookup_struct (copy_name ($2),
expression_context_block); }
+ | CLASS COMPLETE
+ {
+ mark_completion_tag (TYPE_CODE_CLASS, "", 0);
+ $$ = NULL;
+ }
+ | CLASS name COMPLETE
+ {
+ mark_completion_tag (TYPE_CODE_CLASS, $2.ptr,
+ $2.length);
+ $$ = NULL;
+ }
| UNION name
{ $$ = lookup_union (copy_name ($2),
expression_context_block); }
+ | UNION COMPLETE
+ {
+ mark_completion_tag (TYPE_CODE_UNION, "", 0);
+ $$ = NULL;
+ }
+ | UNION name COMPLETE
+ {
+ mark_completion_tag (TYPE_CODE_UNION, $2.ptr,
+ $2.length);
+ $$ = NULL;
+ }
| ENUM name
{ $$ = lookup_enum (copy_name ($2),
expression_context_block); }
+ | ENUM COMPLETE
+ {
+ mark_completion_tag (TYPE_CODE_ENUM, "", 0);
+ $$ = NULL;
+ }
+ | ENUM name COMPLETE
+ {
+ mark_completion_tag (TYPE_CODE_ENUM, $2.ptr,
+ $2.length);
+ $$ = NULL;
+ }
| UNSIGNED typename
{ $$ = lookup_unsigned_typename (parse_language,
parse_gdbarch,
struct type *type = NULL;
char *fieldname, *p;
volatile struct gdb_exception except;
+ enum type_code code = TYPE_CODE_UNDEF;
/* Perform a tentative parse of the expression, to see whether a
field completion is required. */
fieldname = NULL;
TRY_CATCH (except, RETURN_MASK_ERROR)
{
- type = parse_expression_for_completion (text, &fieldname);
+ type = parse_expression_for_completion (text, &fieldname, &code);
}
if (except.reason < 0)
return NULL;
return result;
}
}
+ else if (fieldname && code != TYPE_CODE_UNDEF)
+ {
+ VEC (char_ptr) *result;
+ struct cleanup *cleanup = make_cleanup (xfree, fieldname);
+
+ result = make_symbol_completion_type (fieldname, fieldname, code);
+ do_cleanups (cleanup);
+ return result;
+ }
xfree (fieldname);
/* Commands which complete on locations want to see the entire
extern struct expression *parse_expression (char *);
-extern struct type *parse_expression_for_completion (char *, char **);
+extern struct type *parse_expression_for_completion (char *, char **,
+ enum type_code *);
extern struct expression *parse_exp_1 (char **, CORE_ADDR pc,
const struct block *, int);
class. */
static VEC (char_ptr) *
-f_make_symbol_completion_list (char *text, char *word)
+f_make_symbol_completion_list (char *text, char *word, enum type_code code)
{
- return default_make_symbol_completion_list_break_on (text, word, ":");
+ return default_make_symbol_completion_list_break_on (text, word, ":", code);
}
const struct language_defn f_language_defn =
/* Should return a vector of all symbols which are possible
completions for TEXT. WORD is the entire command on which the
- completion is being made. */
- VEC (char_ptr) *(*la_make_symbol_completion_list) (char *text, char *word);
+ completion is being made. If CODE is TYPE_CODE_UNDEF, then all
+ symbols should be examined; otherwise, only STRUCT_DOMAIN
+ symbols whose type has a code of CODE should be matched. */
+ VEC (char_ptr) *(*la_make_symbol_completion_list) (char *text, char *word,
+ enum type_code code);
/* The per-architecture (OS/ABI) language information. */
void (*la_language_arch_info) (struct gdbarch *,
'->'. This is set when parsing and is only used when completing a
field name. It is -1 if no dereference operation was found. */
static int expout_last_struct = -1;
+
+/* If we are completing a tagged type name, this will be nonzero. */
+static enum type_code expout_tag_completion_type = TYPE_CODE_UNDEF;
+
+/* The token for tagged type name completion. */
+static char *expout_completion_name;
+
\f
static unsigned int expressiondebug = 0;
static void
void
mark_struct_expression (void)
{
+ gdb_assert (parse_completion
+ && expout_tag_completion_type == TYPE_CODE_UNDEF);
expout_last_struct = expout_ptr;
}
+/* 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)
+{
+ gdb_assert (parse_completion
+ && expout_tag_completion_type == TYPE_CODE_UNDEF
+ && expout_completion_name == NULL
+ && expout_last_struct == -1);
+ gdb_assert (tag == TYPE_CODE_UNION
+ || tag == TYPE_CODE_STRUCT
+ || tag == TYPE_CODE_CLASS
+ || tag == TYPE_CODE_ENUM);
+ expout_tag_completion_type = tag;
+ expout_completion_name = xmalloc (length + 1);
+ memcpy (expout_completion_name, ptr, length);
+ expout_completion_name[length] = '\0';
+}
+
\f
/* Recognize tokens that start with '$'. These include:
paren_depth = 0;
type_stack.depth = 0;
expout_last_struct = -1;
+ expout_tag_completion_type = TYPE_CODE_UNDEF;
+ xfree (expout_completion_name);
+ expout_completion_name = NULL;
comma_terminates = comma;
*NAME must be freed by the caller. */
struct type *
-parse_expression_for_completion (char *string, char **name)
+parse_expression_for_completion (char *string, char **name,
+ enum type_code *code)
{
struct expression *exp = NULL;
struct value *val;
parse_completion = 0;
if (except.reason < 0 || ! exp)
return NULL;
+
+ if (expout_tag_completion_type != TYPE_CODE_UNDEF)
+ {
+ *code = expout_tag_completion_type;
+ *name = expout_completion_name;
+ expout_completion_name = NULL;
+ return NULL;
+ }
+
if (expout_last_struct == -1)
{
xfree (exp);
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 */
+
VEC (char_ptr) *
default_make_symbol_completion_list_break_on (char *text, char *word,
- const char *break_on)
+ const char *break_on,
+ enum type_code code)
{
/* Problem: All of the symbols have to be copied because readline
frees them. I'm not going to worry about this; hopefully there
anything that isn't a text symbol (everything else will be
handled by the psymtab code above). */
- ALL_MSYMBOLS (objfile, msymbol)
- {
- QUIT;
- COMPLETION_LIST_ADD_SYMBOL (msymbol, sym_text, sym_text_len, text, word);
+ if (code == TYPE_CODE_UNDEF)
+ {
+ ALL_MSYMBOLS (objfile, msymbol)
+ {
+ QUIT;
+ COMPLETION_LIST_ADD_SYMBOL (msymbol, sym_text, sym_text_len, text,
+ word);
- completion_list_objc_symbol (msymbol, sym_text, sym_text_len, text, word);
- }
+ completion_list_objc_symbol (msymbol, sym_text, sym_text_len, text,
+ word);
+ }
+ }
/* Search upwards from currently selected frame (so that we can
complete on local vars). Also catch fields of types defined in
ALL_BLOCK_SYMBOLS (b, iter, sym)
{
- COMPLETION_LIST_ADD_SYMBOL (sym, sym_text, sym_text_len, text,
- word);
- completion_list_add_fields (sym, sym_text, sym_text_len, text,
- word);
+ if (code == TYPE_CODE_UNDEF)
+ {
+ COMPLETION_LIST_ADD_SYMBOL (sym, sym_text, sym_text_len, text,
+ word);
+ completion_list_add_fields (sym, sym_text, sym_text_len, text,
+ word);
+ }
+ else if (SYMBOL_DOMAIN (sym) == STRUCT_DOMAIN
+ && TYPE_CODE (SYMBOL_TYPE (sym)) == code)
+ COMPLETION_LIST_ADD_SYMBOL (sym, sym_text, sym_text_len, text,
+ word);
}
/* Stop when we encounter an enclosing function. Do not stop for
/* Add fields from the file's types; symbols will be added below. */
- if (surrounding_static_block != NULL)
- ALL_BLOCK_SYMBOLS (surrounding_static_block, iter, sym)
- completion_list_add_fields (sym, sym_text, sym_text_len, text, word);
+ if (code == TYPE_CODE_UNDEF)
+ {
+ if (surrounding_static_block != NULL)
+ ALL_BLOCK_SYMBOLS (surrounding_static_block, iter, sym)
+ completion_list_add_fields (sym, sym_text, sym_text_len, text, word);
- if (surrounding_global_block != NULL)
- ALL_BLOCK_SYMBOLS (surrounding_global_block, iter, sym)
- completion_list_add_fields (sym, sym_text, sym_text_len, text, word);
+ if (surrounding_global_block != NULL)
+ ALL_BLOCK_SYMBOLS (surrounding_global_block, iter, sym)
+ completion_list_add_fields (sym, sym_text, sym_text_len, text, word);
+ }
/* Go through the symtabs and check the externs and statics for
symbols which match. */
b = BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), GLOBAL_BLOCK);
ALL_BLOCK_SYMBOLS (b, iter, sym)
{
- COMPLETION_LIST_ADD_SYMBOL (sym, sym_text, sym_text_len, text, word);
+ if (code == TYPE_CODE_UNDEF
+ || (SYMBOL_DOMAIN (sym) == STRUCT_DOMAIN
+ && TYPE_CODE (SYMBOL_TYPE (sym)) == code))
+ COMPLETION_LIST_ADD_SYMBOL (sym, sym_text, sym_text_len, text, word);
}
}
b = BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), STATIC_BLOCK);
ALL_BLOCK_SYMBOLS (b, iter, sym)
{
- COMPLETION_LIST_ADD_SYMBOL (sym, sym_text, sym_text_len, text, word);
+ if (code == TYPE_CODE_UNDEF
+ || (SYMBOL_DOMAIN (sym) == STRUCT_DOMAIN
+ && TYPE_CODE (SYMBOL_TYPE (sym)) == code))
+ COMPLETION_LIST_ADD_SYMBOL (sym, sym_text, sym_text_len, text, word);
}
}
- if (current_language->la_macro_expansion == macro_expansion_c)
+ /* Skip macros if we are completing a struct tag -- arguable but
+ usually what is expected. */
+ if (current_language->la_macro_expansion == macro_expansion_c
+ && code == TYPE_CODE_UNDEF)
{
struct macro_scope *scope;
}
VEC (char_ptr) *
-default_make_symbol_completion_list (char *text, char *word)
+default_make_symbol_completion_list (char *text, char *word,
+ enum type_code code)
{
- return default_make_symbol_completion_list_break_on (text, word, "");
+ return default_make_symbol_completion_list_break_on (text, word, "", code);
}
/* Return a vector of all symbols (regardless of class) which begin by
VEC (char_ptr) *
make_symbol_completion_list (char *text, char *word)
{
- return current_language->la_make_symbol_completion_list (text, word);
+ return current_language->la_make_symbol_completion_list (text, word,
+ TYPE_CODE_UNDEF);
+}
+
+/* Like make_symbol_completion_list, but only return STRUCT_DOMAIN
+ symbols whose type code is CODE. */
+
+VEC (char_ptr) *
+make_symbol_completion_type (char *text, char *word, enum type_code code)
+{
+ gdb_assert (code == TYPE_CODE_UNION
+ || code == TYPE_CODE_STRUCT
+ || code == TYPE_CODE_CLASS
+ || code == TYPE_CODE_ENUM);
+ return current_language->la_make_symbol_completion_list (text, word, code);
}
/* Like make_symbol_completion_list, but suitable for use as a
#include "vec.h"
#include "gdb_vecs.h"
+#include "gdbtypes.h"
/* Opaque declarations. */
struct ui_file;
extern void select_source_symtab (struct symtab *);
extern VEC (char_ptr) *default_make_symbol_completion_list_break_on
- (char *text, char *word, const char *break_on);
-extern VEC (char_ptr) *default_make_symbol_completion_list (char *, char *);
+ (char *text, char *word, const char *break_on,
+ enum type_code code);
+extern VEC (char_ptr) *default_make_symbol_completion_list (char *, char *,
+ enum type_code);
extern VEC (char_ptr) *make_symbol_completion_list (char *, char *);
+extern VEC (char_ptr) *make_symbol_completion_type (char *, char *,
+ enum type_code);
extern VEC (char_ptr) *make_symbol_completion_list_fn (struct cmd_list_element *,
char *, char *);
2012-12-07 Tom Tromey <tromey@redhat.com>
+ * gdb.base/break1.c (enum some_enum, union some_union): New.
+ (some_enum_global, some_union_global, some_value): New globals.
+ * gdb.base/completion.exp: Add tag completion tests.
+
+2012-12-07 Tom Tromey <tromey@redhat.com>
+
* gdb.base/completion.exp: Add tests for ptype and whatis
completion.
struct some_struct values[50];
+/* Some definitions for tag completion. */
+enum some_enum { VALUE };
+
+enum some_enum some_enum_global;
+
+union some_union
+{
+ int f1;
+ double f2;
+};
+
+union some_union some_union_global;
+
+/* A variable with a name "similar" to the above struct, to test that
+ tag completion works ok. */
+int some_variable;
+
/* The following functions do nothing useful. They are included
simply as places to try setting breakpoints at. They are
explicitly "one-line functions" to verify that this case works
gdb_test "complete save-t" "save-tracepoints" "test deprecated completion"
+#
+# Tag name completion.
+#
+
+gdb_test "complete ptype struct some_" "ptype struct some_struct"
+gdb_test "complete ptype enum some_" "ptype enum some_enum"
+gdb_test "complete ptype union some_" "ptype union some_union"
+
# Restore globals modified in this test...
set timeout $oldtimeout1