{
type = (struct type *) obstack_alloc (&objfile -> type_obstack,
sizeof (struct type));
+ OBJSTAT (objfile, n_types++);
}
memset ((char *) type, 0, sizeof (struct type));
if (TYPE_FLAGS (index_type) & TYPE_FLAG_STUB)
TYPE_FLAGS (result_type) |= TYPE_FLAG_TARGET_STUB;
else
- TYPE_LENGTH (result_type) = TYPE_LENGTH (index_type);
+ TYPE_LENGTH (result_type) = TYPE_LENGTH (check_typedef (index_type));
TYPE_NFIELDS (result_type) = 2;
TYPE_FIELDS (result_type) = (struct field *)
TYPE_ALLOC (result_type, 2 * sizeof (struct field));
return (result_type);
}
-/* A lot of code assumes that the "index type" of an array/string/
- set/bitstring is specifically a range type, though in some languages
- it can be any discrete type. */
+/* Set *LOWP and *HIGHP to the lower and upper bounds of discrete type TYPE.
+ Return 1 of type is a range type, 0 if it is discrete (and bounds
+ will fit in LONGEST), or -1 otherwise. */
-struct type *
-force_to_range_type (type)
+int
+get_discrete_bounds (type, lowp, highp)
struct type *type;
+ LONGEST *lowp, *highp;
{
+ CHECK_TYPEDEF (type);
switch (TYPE_CODE (type))
{
case TYPE_CODE_RANGE:
- return type;
-
+ *lowp = TYPE_LOW_BOUND (type);
+ *highp = TYPE_HIGH_BOUND (type);
+ return 1;
case TYPE_CODE_ENUM:
- {
- int low_bound = TYPE_FIELD_BITPOS (type, 0);
- int high_bound = TYPE_FIELD_BITPOS (type, TYPE_NFIELDS (type) - 1);
- struct type *range_type =
- create_range_type (NULL, type, low_bound, high_bound);
- TYPE_NAME (range_type) = TYPE_NAME (range_type);
- TYPE_DUMMY_RANGE (range_type) = 1;
- return range_type;
- }
+ if (TYPE_NFIELDS (type) > 0)
+ {
+ *lowp = TYPE_FIELD_BITPOS (type, 0);
+ *highp = TYPE_FIELD_BITPOS (type, TYPE_NFIELDS (type) - 1);
+ }
+ else
+ {
+ *lowp = 0;
+ *highp = -1;
+ }
+ return 0;
case TYPE_CODE_BOOL:
- {
- struct type *range_type = create_range_type (NULL, type, 0, 1);
- TYPE_NAME (range_type) = TYPE_NAME (range_type);
- TYPE_DUMMY_RANGE (range_type) = 1;
- return range_type;
- }
+ *lowp = 0;
+ *highp = 1;
+ return 0;
+ case TYPE_CODE_INT:
+ if (TYPE_LENGTH (type) > sizeof (LONGEST)) /* Too big */
+ return -1;
+ if (!TYPE_UNSIGNED (type))
+ {
+ *lowp = - (1 << (TYPE_LENGTH (type) * TARGET_CHAR_BIT - 1));
+ *highp = -*lowp - 1;
+ return 0;
+ }
+ /* ... fall through for unsigned ints ... */
case TYPE_CODE_CHAR:
- {
- int char_max = 1 << (TYPE_LENGTH (type) * HOST_CHAR_BIT) - 1;
- struct type *range_type = create_range_type (NULL, type, 0, char_max);
- TYPE_NAME (range_type) = TYPE_NAME (range_type);
- TYPE_DUMMY_RANGE (range_type) = 1;
- return range_type;
- }
+ *lowp = 0;
+ /* This round-about calculation is to avoid shifting by
+ TYPE_LENGTH (type) * TARGET_CHAR_BIT, which will not work
+ if TYPE_LENGTH (type) == sizeof (LONGEST). */
+ *highp = 1 << (TYPE_LENGTH (type) * TARGET_CHAR_BIT - 1);
+ *highp = (*highp - 1) | *highp;
+ return 0;
default:
- {
- static struct complaint msg =
- { "array index type must be a discrete type", 0, 0};
- complain (&msg);
-
- return create_range_type (NULL, builtin_type_int, 0, 0);
- }
+ return -1;
}
}
struct type *element_type;
struct type *range_type;
{
- int low_bound;
- int high_bound;
+ LONGEST low_bound, high_bound;
- range_type = force_to_range_type (range_type);
if (result_type == NULL)
{
result_type = alloc_type (TYPE_OBJFILE (range_type));
}
TYPE_CODE (result_type) = TYPE_CODE_ARRAY;
TYPE_TARGET_TYPE (result_type) = element_type;
- low_bound = TYPE_LOW_BOUND (range_type);
- high_bound = TYPE_HIGH_BOUND (range_type);
+ if (get_discrete_bounds (range_type, &low_bound, &high_bound) < 0)
+ low_bound = high_bound = 0;
+ CHECK_TYPEDEF (element_type);
TYPE_LENGTH (result_type) =
TYPE_LENGTH (element_type) * (high_bound - low_bound + 1);
TYPE_NFIELDS (result_type) = 1;
struct type *result_type;
struct type *domain_type;
{
- int low_bound, high_bound, bit_length;
+ LONGEST low_bound, high_bound, bit_length;
if (result_type == NULL)
{
result_type = alloc_type (TYPE_OBJFILE (domain_type));
if (! (TYPE_FLAGS (domain_type) & TYPE_FLAG_STUB))
{
- domain_type = force_to_range_type (domain_type);
- low_bound = TYPE_LOW_BOUND (domain_type);
- high_bound = TYPE_HIGH_BOUND (domain_type);
+ if (get_discrete_bounds (domain_type, &low_bound, &high_bound) < 0)
+ low_bound = high_bound = 0;
bit_length = high_bound - low_bound + 1;
TYPE_LENGTH (result_type)
= (bit_length + TARGET_CHAR_BIT - 1) / TARGET_CHAR_BIT;
{
int i;
- while (TYPE_CODE (type) == TYPE_CODE_PTR ||
- TYPE_CODE (type) == TYPE_CODE_REF)
+ 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_STRUCT &&
TYPE_CODE (type) != TYPE_CODE_UNION)
error (" is not a structure or union type.");
}
- check_stub_type (type);
-
#if 0
/* FIXME: This change put in by Michael seems incorrect for the case where
the structure tag name is the same as the member name. I.E. when doing
fill_in_vptr_fieldno (type)
struct type *type;
{
- check_stub_type (type);
+ CHECK_TYPEDEF (type);
if (TYPE_VPTR_FIELDNO (type) < 0)
{
struct complaint stub_noname_complaint =
{"stub type has NULL name", 0, 0};
-void
-check_stub_type (type)
- struct type *type;
+struct type *
+check_typedef (type)
+ register struct type *type;
{
+ struct type *orig_type = type;
+ while (TYPE_CODE (type) == TYPE_CODE_TYPEDEF)
+ {
+ if (!TYPE_TARGET_TYPE (type))
+ {
+ char* name = type_name_no_tag (type);
+ /* FIXME: shouldn't we separately check the TYPE_NAME and the
+ TYPE_TAG_NAME, and look in STRUCT_NAMESPACE and/or VAR_NAMESPACE
+ as appropriate? (this code was written before TYPE_NAME and
+ TYPE_TAG_NAME were separate). */
+ struct symbol *sym;
+ if (name == NULL)
+ {
+ complain (&stub_noname_complaint);
+ return type;
+ }
+ sym = lookup_symbol (name, 0, STRUCT_NAMESPACE, 0,
+ (struct symtab **) NULL);
+ if (sym)
+ TYPE_TARGET_TYPE (type) = SYMBOL_TYPE (sym);
+ else
+ TYPE_TARGET_TYPE (type) = alloc_type (NULL); /* TYPE_CODE_UNDEF */
+ }
+ type = TYPE_TARGET_TYPE (type);
+ }
+
if (TYPE_FLAGS(type) & TYPE_FLAG_STUB)
{
char* name = type_name_no_tag (type);
if (name == NULL)
{
complain (&stub_noname_complaint);
- return;
+ return type;
}
sym = lookup_symbol (name, 0, STRUCT_NAMESPACE, 0,
(struct symtab **) NULL);
if (TYPE_FLAGS (type) & TYPE_FLAG_TARGET_STUB)
{
struct type *range_type;
+ struct type *target_type = check_typedef (TYPE_TARGET_TYPE (type));
- check_stub_type (TYPE_TARGET_TYPE (type));
- if (TYPE_FLAGS (TYPE_TARGET_TYPE (type)) & TYPE_FLAG_STUB)
+ if (TYPE_FLAGS (target_type) & TYPE_FLAG_STUB)
{ }
else if (TYPE_CODE (type) == TYPE_CODE_ARRAY
&& TYPE_NFIELDS (type) == 1
((TYPE_FIELD_BITPOS (range_type, 1)
- TYPE_FIELD_BITPOS (range_type, 0)
+ 1)
- * TYPE_LENGTH (TYPE_TARGET_TYPE (type)));
+ * TYPE_LENGTH (target_type));
TYPE_FLAGS (type) &= ~TYPE_FLAG_TARGET_STUB;
}
else if (TYPE_CODE (type) == TYPE_CODE_RANGE)
{
- TYPE_LENGTH (type) = TYPE_LENGTH (TYPE_TARGET_TYPE (type));
+ TYPE_LENGTH (type) = TYPE_LENGTH (target_type);
TYPE_FLAGS (type) &= ~TYPE_FLAG_TARGET_STUB;
}
}
+ /* Cache TYPE_LENGTH for future use. */
+ TYPE_LENGTH (orig_type) = TYPE_LENGTH (type);
+ return type;
}
/* Ugly hack to convert method stubs into method types.
struct type **argtypes;
struct type *mtype;
- if (demangled_name == NULL)
- {
- error ("Internal: Cannot demangle mangled name `%s'.", mangled_name);
- }
+ /* Make sure we got back a function string that we can use. */
+ if (demangled_name)
+ p = strchr (demangled_name, '(');
+
+ if (demangled_name == NULL || p == NULL)
+ error ("Internal: Cannot demangle mangled name `%s'.", mangled_name);
/* Now, read in the parameters that define this type. */
- argtypetext = strchr (demangled_name, '(') + 1;
- p = argtypetext;
+ p += 1;
+ argtypetext = p;
while (*p)
{
if (*p == '(')
objfile -> fundamental_types = (struct type **)
obstack_alloc (&objfile -> type_obstack, nbytes);
memset ((char *) objfile -> fundamental_types, 0, nbytes);
+ OBJSTAT (objfile, n_types += FT_NUM_MEMBERS);
}
/* Look for this particular type in the fundamental type vector. If one is
struct type *t;
{
/* FIXME: Should we return true for references as well as pointers? */
+ CHECK_TYPEDEF (t);
return
(t != NULL
&& TYPE_CODE (t) == TYPE_CODE_PTR
case TYPE_CODE_BOOL:
printf_filtered ("(TYPE_CODE_BOOL)");
break;
+ case TYPE_CODE_TYPEDEF:
+ printf_filtered ("(TYPE_CODE_TYPEDEF)");
+ break;
default:
printf_filtered ("(UNKNOWN TYPE CODE)");
break;