RFA: parse Sun's STABS syntax for prototyped function types

Jim Blandy
2002-02-09T07:00:26Z

GCC doesn't emit this --- yet. :)

Note the 'to do' items; that's why this is an RFA and not a patch.

2002-02-08 Jim Blandy <jimb@redhat.com>

* stabsread.c (read_type): Add code to parse Sun's syntax for
prototyped function types.

Index: gdb/stabsread.c
===================================================================
RCS file: /cvs/src/src/gdb/stabsread.c,v
retrieving revision 1.24
diff -c -r1.24 stabsread.c
*** gdb/stabsread.c 2002/02/03 22:57:56 1.24
--- gdb/stabsread.c 2002/02/09 06:56:05
***************
*** 2586,2591 ****
--- 2586,2649 ----
type = make_function_type (type1, dbx_lookup_type (typenums));
break;

+ case 'g': /* Prototyped function. (Sun) */
+ {
+ const char *type_start = (*pp) - 1;
+ struct type *return_type = read_type (pp, objfile);
+ struct type *func_type
+ = make_function_type (return_type, dbx_lookup_type (typenums));
+ struct type_list {
+ struct type *type;
+ struct type_list *next;
+ } *arg_types = 0;
+ int num_args = 0;
+
+ /* To do:
+ - void argument list?
+ - '0' for varargs?
+ - Sun emits integer arguments as types which ref themselves?
+ (See comment in define_symbol)
+ - Complain if we didn't find the ending #.
+ - Check that complaint is created properly. */
+ while (**pp && **pp != '#')
+ {
+ struct type *arg_type = read_type (pp, objfile);
+ struct type_list *new = alloca (sizeof (*new));
+ new->type = arg_type;
+ new->next = arg_types;
+ arg_types = new;
+ num_args++;
+ }
+ if (**pp == '#')
+ ++*pp;
+ else
+ {
+ static struct complaint msg =
+ {"Prototyped function type didn't end arguments with `#' ", 0, 0};
+ complain (&msg, type_start);
+ }
+
+ TYPE_FIELDS (func_type)
+ = (struct field *) TYPE_ALLOC (func_type,
+ num_args * sizeof (struct field));
+ memset (TYPE_FIELDS (func_type), 0, num_args * sizeof (struct field));
+ {
+ int i;
+ struct type_list *t;
+
+ /* We stuck each argument type onto the front of the list
+ when we read it, so the list is reversed. Build the
+ fields array right-to-left. */
+ for (t = arg_types, i = num_args - 1; t; t = t->next, i--)
+ TYPE_FIELD_TYPE (func_type, i) = t->type;
+ }
+ TYPE_NFIELDS (func_type) = num_args;
+ TYPE_FLAGS (func_type) |= TYPE_FLAG_PROTOTYPED;
+
+ type = func_type;
+ break;
+ }
+
case 'k': /* Const qualifier on some type (Sun) */
case 'c': /* Const qualifier on some type (OS9000) */
/* Because 'c' means other things to AIX and 'k' is perfectly good,