summaryrefslogtreecommitdiff
path: root/gdb/completer.c
diff options
context:
space:
mode:
authorTom Tromey <tromey@redhat.com>2009-02-03 01:00:35 +0000
committerTom Tromey <tromey@redhat.com>2009-02-03 01:00:35 +0000
commit331acbfdd7b4c6734baad6d4d4c2c1489a9a22a1 (patch)
tree7aa84044bd2ae0e6cdec2b412b6af815e8661cec /gdb/completer.c
parent12ee80b84d3220d99f5396deb7b072e51d7d1afd (diff)
downloadgdb-331acbfdd7b4c6734baad6d4d4c2c1489a9a22a1.tar.gz
gdb
PR gdb/2489: * completer.c (count_struct_fields): Count method names. (add_struct_fields): Add matching method names. gdb/testsuite * gdb.cp/Makefile.in (EXECUTABLES): Add pr2489. * gdb.cp/pr2489.cc: New file. * gdb.cp/cpcompletion.exp: New file.
Diffstat (limited to 'gdb/completer.c')
-rw-r--r--gdb/completer.c32
1 files changed, 28 insertions, 4 deletions
diff --git a/gdb/completer.c b/gdb/completer.c
index b1b0cf3a94c..5d7225fdcbc 100644
--- a/gdb/completer.c
+++ b/gdb/completer.c
@@ -339,7 +339,7 @@ location_completer (char *text, char *word)
}
/* Helper for expression_completer which recursively counts the number
- of named fields in a structure or union type. */
+ of named fields and methods in a structure or union type. */
static int
count_struct_fields (struct type *type)
{
@@ -353,17 +353,25 @@ count_struct_fields (struct type *type)
else if (TYPE_FIELD_NAME (type, i))
++result;
}
+
+ for (i = TYPE_NFN_FIELDS (type) - 1; i >= 0; --i)
+ {
+ if (TYPE_FN_FIELDLIST_NAME (type, i))
+ ++result;
+ }
+
return result;
}
-/* Helper for expression_completer which recursively adds field names
- from TYPE, a struct or union type, to the array OUTPUT. This
- function assumes that OUTPUT is correctly-sized. */
+/* Helper for expression_completer which recursively adds field and
+ method names from TYPE, a struct or union type, to the array
+ OUTPUT. This function assumes that OUTPUT is correctly-sized. */
static void
add_struct_fields (struct type *type, int *nextp, char **output,
char *fieldname, int namelen)
{
int i;
+ char *type_name = NULL;
CHECK_TYPEDEF (type);
for (i = 0; i < TYPE_NFIELDS (type); ++i)
@@ -378,6 +386,22 @@ add_struct_fields (struct type *type, int *nextp, char **output,
++*nextp;
}
}
+
+ for (i = TYPE_NFN_FIELDS (type) - 1; i >= 0; --i)
+ {
+ char *name = TYPE_FN_FIELDLIST_NAME (type, i);
+ if (name && ! strncmp (name, fieldname, namelen))
+ {
+ if (!type_name)
+ type_name = type_name_no_tag (type);
+ /* Omit constructors from the completion list. */
+ if (strcmp (type_name, name))
+ {
+ output[*nextp] = xstrdup (name);
+ ++*nextp;
+ }
+ }
+ }
}
/* Complete on expressions. Often this means completing on symbol