diff options
author | Simon Marchi <simon.marchi@efficios.com> | 2020-05-14 13:45:40 -0400 |
---|---|---|
committer | Simon Marchi <simon.marchi@efficios.com> | 2020-05-14 13:45:40 -0400 |
commit | 67607e24d0413828acdfa9bc38f6fbac40b860b9 (patch) | |
tree | 244fb4d92616ef31b9b22197d5a90df09e0147b2 | |
parent | 02eba61aa6cad683e96cf13f483adc04982c0c2b (diff) | |
download | fsf-binutils-gdb-67607e24d0413828acdfa9bc38f6fbac40b860b9.zip fsf-binutils-gdb-67607e24d0413828acdfa9bc38f6fbac40b860b9.tar.gz fsf-binutils-gdb-67607e24d0413828acdfa9bc38f6fbac40b860b9.tar.bz2 |
gdb: add type::code / type::set_code
Add the code and set_code methods on code, in order to remove the
TYPE_CODE macro. In this patch, the TYPE_CODE macro is changed to use
type::code, so all the call sites that are used to set the type code are
changed to use type::set_code. The next patch will remove TYPE_CODE
completely.
gdb/ChangeLog:
* gdbtypes.h (struct type) <code, set_code>: New methods.
(TYPE_CODE): Use type::code. Change all call sites used to set
the code to use type::set_code instead.
-rw-r--r-- | gdb/ChangeLog | 6 | ||||
-rw-r--r-- | gdb/ada-lang.c | 10 | ||||
-rw-r--r-- | gdb/coffread.c | 10 | ||||
-rw-r--r-- | gdb/ctfread.c | 8 | ||||
-rw-r--r-- | gdb/dwarf2/read.c | 14 | ||||
-rw-r--r-- | gdb/eval.c | 2 | ||||
-rw-r--r-- | gdb/gdbtypes.c | 30 | ||||
-rw-r--r-- | gdb/gdbtypes.h | 19 | ||||
-rw-r--r-- | gdb/mdebugread.c | 6 | ||||
-rw-r--r-- | gdb/rust-lang.c | 2 | ||||
-rw-r--r-- | gdb/stabsread.c | 14 | ||||
-rw-r--r-- | gdb/valops.c | 2 |
12 files changed, 71 insertions, 52 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog index c4da2a9..c945505 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,9 @@ +2020-05-14 Simon Marchi <simon.marchi@efficios.com> + + * gdbtypes.h (struct type) <code, set_code>: New methods. + (TYPE_CODE): Use type::code. Change all call sites used to set + the code to use type::set_code instead. + 2020-05-14 Tankut Baris Aktemur <tankut.baris.aktemur@intel.com> Tom de Vries <tdevries@suse.de> Pedro Alves <palves@redhat.com> diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c index bce0bb6..9bed643 100644 --- a/gdb/ada-lang.c +++ b/gdb/ada-lang.c @@ -8027,7 +8027,7 @@ empty_record (struct type *templ) { struct type *type = alloc_type_copy (templ); - TYPE_CODE (type) = TYPE_CODE_STRUCT; + type->set_code (TYPE_CODE_STRUCT); TYPE_NFIELDS (type) = 0; TYPE_FIELDS (type) = NULL; INIT_NONE_SPECIFIC (type); @@ -8083,7 +8083,7 @@ ada_template_to_fixed_record_type_1 (struct type *type, } rtype = alloc_type_copy (type); - TYPE_CODE (rtype) = TYPE_CODE_STRUCT; + rtype->set_code (TYPE_CODE_STRUCT); INIT_NONE_SPECIFIC (rtype); TYPE_NFIELDS (rtype) = nfields; TYPE_FIELDS (rtype) = (struct field *) @@ -8358,7 +8358,7 @@ template_to_static_fixed_type (struct type *type0) if (type == type0) { TYPE_TARGET_TYPE (type0) = type = alloc_type_copy (type0); - TYPE_CODE (type) = TYPE_CODE (type0); + type->set_code (TYPE_CODE(type0)); INIT_NONE_SPECIFIC (type); TYPE_NFIELDS (type) = nfields; TYPE_FIELDS (type) = (struct field *) @@ -8407,7 +8407,7 @@ to_record_with_fixed_variant_part (struct type *type, const gdb_byte *valaddr, dval = dval0; rtype = alloc_type_copy (type); - TYPE_CODE (rtype) = TYPE_CODE_STRUCT; + rtype->set_code (TYPE_CODE_STRUCT); INIT_NONE_SPECIFIC (rtype); TYPE_NFIELDS (rtype) = nfields; TYPE_FIELDS (rtype) = @@ -10376,7 +10376,7 @@ ada_evaluate_subexp (struct type *expect_type, struct expression *exp, /* The result type will have code OP_STRING, bashed there from OP_ARRAY. Bash it back. */ if (TYPE_CODE (value_type (result)) == TYPE_CODE_STRING) - TYPE_CODE (value_type (result)) = TYPE_CODE_ARRAY; + value_type (result)->set_code (TYPE_CODE_ARRAY); return result; } diff --git a/gdb/coffread.c b/gdb/coffread.c index 7fbdcc4..4b2993f 100644 --- a/gdb/coffread.c +++ b/gdb/coffread.c @@ -1880,7 +1880,7 @@ decode_base_type (struct coff_symbol *cs, { /* Anonymous structure type. */ type = coff_alloc_type (cs->c_symnum); - TYPE_CODE (type) = TYPE_CODE_STRUCT; + type->set_code (TYPE_CODE_STRUCT); TYPE_NAME (type) = NULL; INIT_CPLUS_SPECIFIC (type); TYPE_LENGTH (type) = 0; @@ -1914,7 +1914,7 @@ decode_base_type (struct coff_symbol *cs, aux->x_sym.x_fcnary.x_fcn.x_endndx.l, objfile); } - TYPE_CODE (type) = TYPE_CODE_UNION; + type->set_code (TYPE_CODE_UNION); return type; case T_ENUM: @@ -1922,7 +1922,7 @@ decode_base_type (struct coff_symbol *cs, { /* Anonymous enum type. */ type = coff_alloc_type (cs->c_symnum); - TYPE_CODE (type) = TYPE_CODE_ENUM; + type->set_code (TYPE_CODE_ENUM); TYPE_NAME (type) = NULL; TYPE_LENGTH (type) = 0; TYPE_FIELDS (type) = 0; @@ -1990,7 +1990,7 @@ coff_read_struct_type (int index, int length, int lastsym, int done = 0; type = coff_alloc_type (index); - TYPE_CODE (type) = TYPE_CODE_STRUCT; + type->set_code (TYPE_CODE_STRUCT); INIT_CPLUS_SPECIFIC (type); TYPE_LENGTH (type) = length; @@ -2121,7 +2121,7 @@ coff_read_enum_type (int index, int length, int lastsym, TYPE_LENGTH (type) = length; else /* Assume ints. */ TYPE_LENGTH (type) = gdbarch_int_bit (gdbarch) / TARGET_CHAR_BIT; - TYPE_CODE (type) = TYPE_CODE_ENUM; + type->set_code (TYPE_CODE_ENUM); TYPE_NFIELDS (type) = nsyms; TYPE_FIELDS (type) = (struct field *) TYPE_ALLOC (type, sizeof (struct field) * nsyms); diff --git a/gdb/ctfread.c b/gdb/ctfread.c index 8cc7271..06c036d 100644 --- a/gdb/ctfread.c +++ b/gdb/ctfread.c @@ -600,9 +600,9 @@ read_structure_type (struct ctf_context *ccp, ctf_id_t tid) kind = ctf_type_kind (fp, tid); if (kind == CTF_K_UNION) - TYPE_CODE (type) = TYPE_CODE_UNION; + type->set_code (TYPE_CODE_UNION); else - TYPE_CODE (type) = TYPE_CODE_STRUCT; + type->set_code (TYPE_CODE_STRUCT); TYPE_LENGTH (type) = ctf_type_size (fp, tid); set_type_align (type, ctf_type_align (fp, tid)); @@ -656,7 +656,7 @@ read_func_kind_type (struct ctf_context *ccp, ctf_id_t tid) if (name != NULL && strlen (name.get ()) != 0) TYPE_NAME (type) = obstack_strdup (&of->objfile_obstack, name.get ()); - TYPE_CODE (type) = TYPE_CODE_FUNC; + type->set_code (TYPE_CODE_FUNC); ctf_func_type_info (fp, tid, &cfi); rettype = get_tid_type (of, cfi.ctc_return); TYPE_TARGET_TYPE (type) = rettype; @@ -682,7 +682,7 @@ read_enum_type (struct ctf_context *ccp, ctf_id_t tid) if (name != NULL && strlen (name.get ()) != 0) TYPE_NAME (type) = obstack_strdup (&of->objfile_obstack, name.get ()); - TYPE_CODE (type) = TYPE_CODE_ENUM; + type->set_code (TYPE_CODE_ENUM); TYPE_LENGTH (type) = ctf_type_size (fp, tid); ctf_func_type_info (fp, tid, &fi); target_type = get_tid_type (of, fi.ctc_return); diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index 27bf40a..4809202 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -9325,7 +9325,7 @@ quirk_rust_enum (struct type *type, struct objfile *objfile) /* Smash this type to be a structure type. We have to do this because the type has already been recorded. */ - TYPE_CODE (type) = TYPE_CODE_STRUCT; + type->set_code (TYPE_CODE_STRUCT); TYPE_NFIELDS (type) = 3; /* Save the field we care about. */ struct field saved_field = TYPE_FIELD (type, 0); @@ -9368,7 +9368,7 @@ quirk_rust_enum (struct type *type, struct objfile *objfile) { /* Smash this type to be a structure type. We have to do this because the type has already been recorded. */ - TYPE_CODE (type) = TYPE_CODE_STRUCT; + type->set_code (TYPE_CODE_STRUCT); struct type *field_type = TYPE_FIELD_TYPE (type, 0); const char *variant_name @@ -9415,7 +9415,7 @@ quirk_rust_enum (struct type *type, struct objfile *objfile) /* Smash this type to be a structure type. We have to do this because the type has already been recorded. */ - TYPE_CODE (type) = TYPE_CODE_STRUCT; + type->set_code (TYPE_CODE_STRUCT); /* Make space for the discriminant field. */ struct field *disr_field = &TYPE_FIELD (disr_type, 0); @@ -15369,15 +15369,15 @@ read_structure_type (struct die_info *die, struct dwarf2_cu *cu) if (die->tag == DW_TAG_structure_type) { - TYPE_CODE (type) = TYPE_CODE_STRUCT; + type->set_code (TYPE_CODE_STRUCT); } else if (die->tag == DW_TAG_union_type) { - TYPE_CODE (type) = TYPE_CODE_UNION; + type->set_code (TYPE_CODE_UNION); } else { - TYPE_CODE (type) = TYPE_CODE_STRUCT; + type->set_code (TYPE_CODE_STRUCT); } if (cu->language == language_cplus && die->tag == DW_TAG_class_type) @@ -15937,7 +15937,7 @@ read_enumeration_type (struct die_info *die, struct dwarf2_cu *cu) type = alloc_type (objfile); - TYPE_CODE (type) = TYPE_CODE_ENUM; + type->set_code (TYPE_CODE_ENUM); name = dwarf2_full_name (NULL, die, cu); if (name != NULL) TYPE_NAME (type) = name; @@ -658,7 +658,7 @@ fake_method::fake_method (type_instance_flags flags, TYPE_MAIN_TYPE (type) = &m_main_type; TYPE_LENGTH (type) = 1; - TYPE_CODE (type) = TYPE_CODE_METHOD; + type->set_code (TYPE_CODE_METHOD); TYPE_CHAIN (type) = type; TYPE_INSTANCE_FLAGS (type) = flags; if (num_types > 0) diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c index 3f82924..671ee52 100644 --- a/gdb/gdbtypes.c +++ b/gdb/gdbtypes.c @@ -182,7 +182,7 @@ alloc_type (struct objfile *objfile) /* Initialize the fields that might not be zero. */ - TYPE_CODE (type) = TYPE_CODE_UNDEF; + type->set_code (TYPE_CODE_UNDEF); TYPE_CHAIN (type) = type; /* Chain back to itself. */ return type; @@ -209,7 +209,7 @@ alloc_type_arch (struct gdbarch *gdbarch) /* Initialize the fields that might not be zero. */ - TYPE_CODE (type) = TYPE_CODE_UNDEF; + type->set_code (TYPE_CODE_UNDEF); TYPE_CHAIN (type) = type; /* Chain back to itself. */ return type; @@ -366,7 +366,7 @@ make_pointer_type (struct type *type, struct type **typeptr) TYPE_LENGTH (ntype) = gdbarch_ptr_bit (get_type_arch (type)) / TARGET_CHAR_BIT; - TYPE_CODE (ntype) = TYPE_CODE_PTR; + ntype->set_code (TYPE_CODE_PTR); /* Mark pointers as unsigned. The target converts between pointers and addresses (CORE_ADDRs) using gdbarch_pointer_to_address and @@ -450,7 +450,7 @@ make_reference_type (struct type *type, struct type **typeptr, TYPE_LENGTH (ntype) = gdbarch_ptr_bit (get_type_arch (type)) / TARGET_CHAR_BIT; - TYPE_CODE (ntype) = refcode; + ntype->set_code (refcode); *reftype = ntype; @@ -515,7 +515,7 @@ make_function_type (struct type *type, struct type **typeptr) TYPE_TARGET_TYPE (ntype) = type; TYPE_LENGTH (ntype) = 1; - TYPE_CODE (ntype) = TYPE_CODE_FUNC; + ntype->set_code (TYPE_CODE_FUNC); INIT_FUNC_SPECIFIC (ntype); @@ -861,7 +861,7 @@ allocate_stub_method (struct type *type) struct type *mtype; mtype = alloc_type_copy (type); - TYPE_CODE (mtype) = TYPE_CODE_METHOD; + mtype->set_code (TYPE_CODE_METHOD); TYPE_LENGTH (mtype) = 1; TYPE_STUB (mtype) = 1; TYPE_TARGET_TYPE (mtype) = type; @@ -928,7 +928,7 @@ create_range_type (struct type *result_type, struct type *index_type, if (result_type == NULL) result_type = alloc_type_copy (index_type); - TYPE_CODE (result_type) = TYPE_CODE_RANGE; + result_type->set_code (TYPE_CODE_RANGE); TYPE_TARGET_TYPE (result_type) = index_type; if (TYPE_STUB (index_type)) TYPE_TARGET_STUB (result_type) = 1; @@ -1278,7 +1278,7 @@ create_array_type_with_stride (struct type *result_type, if (result_type == NULL) result_type = alloc_type_copy (range_type); - TYPE_CODE (result_type) = TYPE_CODE_ARRAY; + result_type->set_code (TYPE_CODE_ARRAY); TYPE_TARGET_TYPE (result_type) = element_type; TYPE_NFIELDS (result_type) = 1; @@ -1357,7 +1357,7 @@ create_string_type (struct type *result_type, result_type = create_array_type (result_type, string_char_type, range_type); - TYPE_CODE (result_type) = TYPE_CODE_STRING; + result_type->set_code (TYPE_CODE_STRING); return result_type; } @@ -1369,7 +1369,7 @@ lookup_string_range_type (struct type *string_char_type, result_type = lookup_array_range_type (string_char_type, low_bound, high_bound); - TYPE_CODE (result_type) = TYPE_CODE_STRING; + result_type->set_code (TYPE_CODE_STRING); return result_type; } @@ -1379,7 +1379,7 @@ create_set_type (struct type *result_type, struct type *domain_type) if (result_type == NULL) result_type = alloc_type_copy (domain_type); - TYPE_CODE (result_type) = TYPE_CODE_SET; + result_type->set_code (TYPE_CODE_SET); TYPE_NFIELDS (result_type) = 1; TYPE_FIELDS (result_type) = (struct field *) TYPE_ZALLOC (result_type, sizeof (struct field)); @@ -1508,7 +1508,7 @@ smash_to_memberptr_type (struct type *type, struct type *self_type, struct type *to_type) { smash_type (type); - TYPE_CODE (type) = TYPE_CODE_MEMBERPTR; + type->set_code (TYPE_CODE_MEMBERPTR); TYPE_TARGET_TYPE (type) = to_type; set_type_self_type (type, self_type); /* Assume that a data member pointer is the same size as a normal @@ -1527,7 +1527,7 @@ void smash_to_methodptr_type (struct type *type, struct type *to_type) { smash_type (type); - TYPE_CODE (type) = TYPE_CODE_METHODPTR; + type->set_code (TYPE_CODE_METHODPTR); TYPE_TARGET_TYPE (type) = to_type; set_type_self_type (type, TYPE_SELF_TYPE (to_type)); TYPE_LENGTH (type) = cplus_method_ptr_size (to_type); @@ -1546,7 +1546,7 @@ smash_to_method_type (struct type *type, struct type *self_type, int nargs, int varargs) { smash_type (type); - TYPE_CODE (type) = TYPE_CODE_METHOD; + type->set_code (TYPE_CODE_METHOD); TYPE_TARGET_TYPE (type) = to_type; set_type_self_type (type, self_type); TYPE_FIELDS (type) = args; @@ -3111,7 +3111,7 @@ allocate_gnat_aux_type (struct type *type) static void set_type_code (struct type *type, enum type_code code) { - TYPE_CODE (type) = code; + type->set_code (code); switch (code) { diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h index 7514bd2..9f4924e 100644 --- a/gdb/gdbtypes.h +++ b/gdb/gdbtypes.h @@ -874,6 +874,21 @@ struct main_type struct type { + /* Get the type code of this type. + + Note that the code can be TYPE_CODE_TYPEDEF, so if you want the real + type, you need to do `check_typedef (type)->code ()`. */ + type_code code () const + { + return this->main_type->code; + } + + /* Set the type code of this type. */ + void set_code (type_code code) + { + this->main_type->code = code; + } + /* * Return the dynamic property of the requested KIND from this type's list of dynamic properties. */ dynamic_prop *dyn_prop (dynamic_prop_node_kind kind) const; @@ -1420,9 +1435,7 @@ extern unsigned type_align (struct type *); space in struct type. */ extern bool set_type_align (struct type *, ULONGEST); -/* * Note that TYPE_CODE can be TYPE_CODE_TYPEDEF, so if you want the real - type, you need to do TYPE_CODE (check_type (this_type)). */ -#define TYPE_CODE(thistype) TYPE_MAIN_TYPE(thistype)->code +#define TYPE_CODE(thistype) ((thistype)->code ()) #define TYPE_NFIELDS(thistype) TYPE_MAIN_TYPE(thistype)->nfields #define TYPE_FIELDS(thistype) TYPE_MAIN_TYPE(thistype)->flds_bnds.fields diff --git a/gdb/mdebugread.c b/gdb/mdebugread.c index 5c4158c..621069e 100644 --- a/gdb/mdebugread.c +++ b/gdb/mdebugread.c @@ -1015,7 +1015,7 @@ parse_symbol (SYMR *sh, union aux_ext *ax, char *ext_sh, int bigend, TYPE_NAME (t) = obconcat (&mdebugread_objfile->objfile_obstack, name, (char *) NULL); - TYPE_CODE (t) = type_code; + t->set_code (type_code); TYPE_LENGTH (t) = sh->value; TYPE_NFIELDS (t) = nfields; TYPE_FIELDS (t) = f = ((struct field *) @@ -1668,7 +1668,7 @@ parse_type (int fd, union aux_ext *ax, unsigned int aux_index, int *bs, if (TYPE_CODE (tp) != type_code) { - TYPE_CODE (tp) = type_code; + tp->set_code (type_code); } /* Do not set the tag name if it is a compiler generated tag name @@ -1709,7 +1709,7 @@ parse_type (int fd, union aux_ext *ax, unsigned int aux_index, int *bs, if (TYPE_CODE (tp) != type_code) { bad_tag_guess_complaint (sym_name); - TYPE_CODE (tp) = type_code; + tp->set_code (type_code); } if (TYPE_NAME (tp) == NULL || strcmp (TYPE_NAME (tp), name) != 0) diff --git a/gdb/rust-lang.c b/gdb/rust-lang.c index f2fb011..eb0ea1b 100644 --- a/gdb/rust-lang.c +++ b/gdb/rust-lang.c @@ -981,7 +981,7 @@ rust_composite_type (struct type *original, if (field2 != NULL) ++nfields; - TYPE_CODE (result) = TYPE_CODE_STRUCT; + result->set_code (TYPE_CODE_STRUCT); TYPE_NAME (result) = name; TYPE_NFIELDS (result) = nfields; diff --git a/gdb/stabsread.c b/gdb/stabsread.c index eac4740..5601c80 100644 --- a/gdb/stabsread.c +++ b/gdb/stabsread.c @@ -1687,7 +1687,7 @@ again: fill in the rest of the fields when we get the full type. */ type = dbx_alloc_type (typenums, objfile); - TYPE_CODE (type) = code; + type->set_code (code); TYPE_NAME (type) = type_name; INIT_CPLUS_SPECIFIC (type); TYPE_STUB (type) = 1; @@ -1716,14 +1716,14 @@ again: /* Allocate and enter the typedef type first. This handles recursive types. */ type = dbx_alloc_type (typenums, objfile); - TYPE_CODE (type) = TYPE_CODE_TYPEDEF; + type->set_code (TYPE_CODE_TYPEDEF); { struct type *xtype = read_type (pp, objfile); if (type == xtype) { /* It's being defined as itself. That means it is "void". */ - TYPE_CODE (type) = TYPE_CODE_VOID; + type->set_code (TYPE_CODE_VOID); TYPE_LENGTH (type) = 1; } else if (type_size >= 0 || is_string) @@ -2022,7 +2022,7 @@ again: type = dbx_alloc_type (typenums, objfile); type = read_array_type (pp, type, objfile); if (is_string) - TYPE_CODE (type) = TYPE_CODE_STRING; + type->set_code (TYPE_CODE_STRING); if (is_vector) make_vector_type (type); break; @@ -2370,7 +2370,7 @@ read_member_functions (struct stab_field_info *fip, const char **pp, /* These are methods, not functions. */ if (TYPE_CODE (new_sublist->fn_field.type) == TYPE_CODE_FUNC) - TYPE_CODE (new_sublist->fn_field.type) = TYPE_CODE_METHOD; + new_sublist->fn_field.type->set_code (TYPE_CODE_METHOD); else gdb_assert (TYPE_CODE (new_sublist->fn_field.type) == TYPE_CODE_METHOD); @@ -3477,7 +3477,7 @@ read_struct_type (const char **pp, struct type *type, enum type_code type_code, } INIT_CPLUS_SPECIFIC (type); - TYPE_CODE (type) = type_code; + type->set_code (type_code); TYPE_STUB (type) = 0; /* First comes the total size in bytes. */ @@ -3652,7 +3652,7 @@ read_enum_type (const char **pp, struct type *type, TYPE_LENGTH (type) = gdbarch_int_bit (gdbarch) / HOST_CHAR_BIT; set_length_in_type_chain (type); - TYPE_CODE (type) = TYPE_CODE_ENUM; + type->set_code (TYPE_CODE_ENUM); TYPE_STUB (type) = 0; if (unsigned_enum) TYPE_UNSIGNED (type) = 1; diff --git a/gdb/valops.c b/gdb/valops.c index aa995e6..2e7abf5 100644 --- a/gdb/valops.c +++ b/gdb/valops.c @@ -3792,7 +3792,7 @@ value_slice (struct value *array, int lowbound, int length) slice_type = create_array_type (NULL, element_type, slice_range_type); - TYPE_CODE (slice_type) = TYPE_CODE (array_type); + slice_type->set_code (TYPE_CODE (array_type)); if (VALUE_LVAL (array) == lval_memory && value_lazy (array)) slice = allocate_value_lazy (slice_type); |