+ int i;
+ int computed_type_name = 0;
+ const char *type_name = NULL;
+
+ CHECK_TYPEDEF (type);
+ for (i = 0; i < TYPE_NFIELDS (type); ++i)
+ {
+ if (i < TYPE_N_BASECLASSES (type))
+ add_struct_fields (TYPE_BASECLASS (type, i),
+ output, fieldname, namelen);
+ else if (TYPE_FIELD_NAME (type, i))
+ {
+ if (TYPE_FIELD_NAME (type, i)[0] != '\0')
+ {
+ if (! strncmp (TYPE_FIELD_NAME (type, i),
+ fieldname, namelen))
+ VEC_safe_push (char_ptr, *output,
+ xstrdup (TYPE_FIELD_NAME (type, i)));
+ }
+ else if (TYPE_CODE (TYPE_FIELD_TYPE (type, i)) == TYPE_CODE_UNION)
+ {
+ /* Recurse into anonymous unions. */
+ add_struct_fields (TYPE_FIELD_TYPE (type, i),
+ output, fieldname, namelen);
+ }
+ }
+ }
+
+ for (i = TYPE_NFN_FIELDS (type) - 1; i >= 0; --i)
+ {
+ const char *name = TYPE_FN_FIELDLIST_NAME (type, i);
+
+ if (name && ! strncmp (name, fieldname, namelen))
+ {
+ if (!computed_type_name)
+ {
+ type_name = type_name_no_tag (type);
+ computed_type_name = 1;
+ }
+ /* Omit constructors from the completion list. */
+ if (!type_name || strcmp (type_name, name))
+ VEC_safe_push (char_ptr, *output, xstrdup (name));
+ }
+ }
+}
+
+/* Complete on expressions. Often this means completing on symbol
+ names, but some language parsers also have support for completing
+ field names. */
+VEC (char_ptr) *
+expression_completer (struct cmd_list_element *ignore,
+ const char *text, const char *word)
+{
+ struct type *type = NULL;
+ char *fieldname;
+ const char *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, &code);
+ }
+ if (except.reason < 0)
+ return NULL;
+ if (fieldname && type)
+ {
+ for (;;)
+ {
+ CHECK_TYPEDEF (type);
+ if (TYPE_CODE (type) != TYPE_CODE_PTR
+ && TYPE_CODE (type) != TYPE_CODE_REF)
+ break;
+ type = TYPE_TARGET_TYPE (type);
+ }
+
+ if (TYPE_CODE (type) == TYPE_CODE_UNION
+ || TYPE_CODE (type) == TYPE_CODE_STRUCT)
+ {
+ int flen = strlen (fieldname);
+ VEC (char_ptr) *result = NULL;
+
+ add_struct_fields (type, &result, fieldname, flen);
+ xfree (fieldname);
+ 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
+ argument. */
+ for (p = word;
+ p > text && p[-1] != ' ' && p[-1] != '\t';
+ p--)
+ ;
+
+ /* Not ideal but it is what we used to do before... */
+ return location_completer (ignore, p, word);