aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gdb/ChangeLog7
-rw-r--r--gdb/gdbtypes.c42
-rw-r--r--gdb/gdbtypes.h10
3 files changed, 59 insertions, 0 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 2f01146..3940517 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,10 @@
+2002-03-22 Andrew Cagney <ac131313@redhat.com>
+
+ * gdbtypes.c (append_composite_type_field): New function.
+ (init_composite_type): New function.
+ * gdbtypes.h (append_composite_type_field): Declare.
+ (init_composite_type): Ditto.
+
2002-03-22 Elena Zannoni <ezannoni@redhat.com>
* ppc-linux-tdep.c (ppc_sysv_abi_use_struct_convention): New
diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
index a13847e..7b59d72 100644
--- a/gdb/gdbtypes.c
+++ b/gdb/gdbtypes.c
@@ -1753,6 +1753,48 @@ init_type (enum type_code code, int length, int flags, char *name,
return (type);
}
+/* Helper function. Create an empty composite type. */
+
+struct type *
+init_composite_type (char *name, enum type_code code)
+{
+ struct type *t;
+ gdb_assert (code == TYPE_CODE_STRUCT
+ || code == TYPE_CODE_UNION);
+ t = init_type (code, 0, 0, NULL, NULL);
+ TYPE_TAG_NAME (t) = name;
+ return t;
+}
+
+/* Helper function. Append a field to a composite type. */
+
+void
+append_composite_type_field (struct type *t, char *name, struct type *field)
+{
+ struct field *f;
+ TYPE_NFIELDS (t) = TYPE_NFIELDS (t) + 1;
+ TYPE_FIELDS (t) = xrealloc (TYPE_FIELDS (t),
+ sizeof (struct field) * TYPE_NFIELDS (t));
+ f = &(TYPE_FIELDS (t)[TYPE_NFIELDS (t) - 1]);
+ memset (f, 0, sizeof f[0]);
+ FIELD_TYPE (f[0]) = field;
+ FIELD_NAME (f[0]) = name;
+ if (TYPE_CODE (t) == TYPE_CODE_UNION)
+ {
+ if (TYPE_LENGTH (t) > TYPE_LENGTH (field))
+ TYPE_LENGTH (t) = TYPE_LENGTH (field);
+ }
+ else if (TYPE_CODE (t) == TYPE_CODE_STRUCT)
+ {
+ TYPE_LENGTH (t) = TYPE_LENGTH (t) + TYPE_LENGTH (field);
+ if (TYPE_NFIELDS (t) > 1)
+ {
+ FIELD_BITPOS (f[0]) = (FIELD_BITPOS (f[-1])
+ + TYPE_LENGTH (field) * TARGET_CHAR_BIT);
+ }
+ }
+}
+
/* Look up a fundamental type for the specified objfile.
May need to construct such a type if this is the first use.
diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h
index 74b521a..f4a2cf6 100644
--- a/gdb/gdbtypes.h
+++ b/gdb/gdbtypes.h
@@ -1054,6 +1054,16 @@ extern struct type *alloc_type (struct objfile *);
extern struct type *init_type (enum type_code, int, int, char *,
struct objfile *);
+/* Helper functions to construct a struct or record type. An
+ initially empty type is created using init_composite_type().
+ Fields are then added using append_struct_type_field(). A union
+ type has its size set to the largest field. A struct type has each
+ field packed against the previous. */
+
+extern struct type *init_composite_type (char *name, enum type_code code);
+extern void append_composite_type_field (struct type *t, char *name,
+ struct type *field);
+
extern struct type *lookup_reference_type (struct type *);
extern struct type *make_reference_type (struct type *, struct type **);