From 7813437494ac39f3aef392d06ed5416e84fe386b Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Thu, 14 May 2020 13:46:38 -0400 Subject: gdb: remove TYPE_CODE macro Remove TYPE_CODE, changing all the call sites to use type::code directly. This is quite a big diff, but this was mostly done using sed and coccinelle. A few call sites were done by hand. gdb/ChangeLog: * gdbtypes.h (TYPE_CODE): Remove. Change all call sites to use type::code instead. --- gdb/python/py-finishbreakpoint.c | 2 +- gdb/python/py-framefilter.c | 6 ++--- gdb/python/py-lazy-string.c | 6 ++--- gdb/python/py-type.c | 32 ++++++++++++------------- gdb/python/py-value.c | 50 ++++++++++++++++++++-------------------- gdb/python/py-xmethods.c | 8 +++---- 6 files changed, 52 insertions(+), 52 deletions(-) (limited to 'gdb/python') diff --git a/gdb/python/py-finishbreakpoint.c b/gdb/python/py-finishbreakpoint.c index e05fb55..92ac555 100644 --- a/gdb/python/py-finishbreakpoint.c +++ b/gdb/python/py-finishbreakpoint.c @@ -253,7 +253,7 @@ bpfinishpy_init (PyObject *self, PyObject *args, PyObject *kwargs) check_typedef (TYPE_TARGET_TYPE (SYMBOL_TYPE (function))); /* Remember only non-void return types. */ - if (TYPE_CODE (ret_type) != TYPE_CODE_VOID) + if (ret_type->code () != TYPE_CODE_VOID) { struct value *func_value; diff --git a/gdb/python/py-framefilter.c b/gdb/python/py-framefilter.c index fb41e95..45bf51b 100644 --- a/gdb/python/py-framefilter.c +++ b/gdb/python/py-framefilter.c @@ -240,9 +240,9 @@ py_print_value (struct ui_out *out, struct value *val, if (args_type == MI_PRINT_ALL_VALUES) should_print = 1; else if (args_type == MI_PRINT_SIMPLE_VALUES - && TYPE_CODE (type) != TYPE_CODE_ARRAY - && TYPE_CODE (type) != TYPE_CODE_STRUCT - && TYPE_CODE (type) != TYPE_CODE_UNION) + && type->code () != TYPE_CODE_ARRAY + && type->code () != TYPE_CODE_STRUCT + && type->code () != TYPE_CODE_UNION) should_print = 1; } else if (args_type != NO_VALUES) diff --git a/gdb/python/py-lazy-string.c b/gdb/python/py-lazy-string.c index 18bace9..f71bb1d 100644 --- a/gdb/python/py-lazy-string.c +++ b/gdb/python/py-lazy-string.c @@ -120,7 +120,7 @@ stpy_convert_to_value (PyObject *self, PyObject *args) gdb_assert (type != NULL); realtype = check_typedef (type); - switch (TYPE_CODE (realtype)) + switch (realtype->code ()) { case TYPE_CODE_PTR: /* If a length is specified we need to convert this to an array @@ -194,7 +194,7 @@ gdbpy_create_lazy_string_object (CORE_ADDR address, long length, } realtype = check_typedef (type); - switch (TYPE_CODE (realtype)) + switch (realtype->code ()) { case TYPE_CODE_ARRAY: { @@ -258,7 +258,7 @@ stpy_lazy_string_elt_type (lazy_string_object *lazy) gdb_assert (type != NULL); realtype = check_typedef (type); - switch (TYPE_CODE (realtype)) + switch (realtype->code ()) { case TYPE_CODE_PTR: case TYPE_CODE_ARRAY: diff --git a/gdb/python/py-type.c b/gdb/python/py-type.c index db031e0..e62ff57 100644 --- a/gdb/python/py-type.c +++ b/gdb/python/py-type.c @@ -157,7 +157,7 @@ typy_get_code (PyObject *self, void *closure) { struct type *type = ((type_object *) self)->type; - return PyInt_FromLong (TYPE_CODE (type)); + return PyInt_FromLong (type->code ()); } /* Helper function for typy_fields which converts a single field to a @@ -181,7 +181,7 @@ convert_field (struct type *type, int field) { const char *attrstring; - if (TYPE_CODE (type) == TYPE_CODE_ENUM) + if (type->code () == TYPE_CODE_ENUM) { arg.reset (gdb_py_long_from_longest (TYPE_FIELD_ENUMVAL (type, field))); @@ -227,7 +227,7 @@ convert_field (struct type *type, int field) if (PyObject_SetAttrString (result.get (), "artificial", arg.get ()) < 0) return NULL; - if (TYPE_CODE (type) == TYPE_CODE_STRUCT) + if (type->code () == TYPE_CODE_STRUCT) arg = gdbpy_ref<>::new_reference (field < TYPE_N_BASECLASSES (type) ? Py_True : Py_False); else @@ -356,7 +356,7 @@ typy_fields (PyObject *self, PyObject *args) { struct type *type = ((type_object *) self)->type; - if (TYPE_CODE (type) != TYPE_CODE_ARRAY) + if (type->code () != TYPE_CODE_ARRAY) return typy_fields_items (self, iter_values); /* Array type. Handle this as a special case because the common @@ -405,9 +405,9 @@ typy_get_tag (PyObject *self, void *closure) struct type *type = ((type_object *) self)->type; const char *tagname = nullptr; - if (TYPE_CODE (type) == TYPE_CODE_STRUCT - || TYPE_CODE (type) == TYPE_CODE_UNION - || TYPE_CODE (type) == TYPE_CODE_ENUM) + if (type->code () == TYPE_CODE_STRUCT + || type->code () == TYPE_CODE_UNION + || type->code () == TYPE_CODE_ENUM) tagname = TYPE_NAME (type); if (tagname == nullptr) @@ -463,17 +463,17 @@ typy_get_composite (struct type *type) GDB_PY_HANDLE_EXCEPTION (except); } - if (TYPE_CODE (type) != TYPE_CODE_PTR && !TYPE_IS_REFERENCE (type)) + if (type->code () != TYPE_CODE_PTR && !TYPE_IS_REFERENCE (type)) break; type = TYPE_TARGET_TYPE (type); } /* If this is not a struct, union, or enum type, raise TypeError exception. */ - if (TYPE_CODE (type) != TYPE_CODE_STRUCT - && TYPE_CODE (type) != TYPE_CODE_UNION - && TYPE_CODE (type) != TYPE_CODE_ENUM - && TYPE_CODE (type) != TYPE_CODE_FUNC) + if (type->code () != TYPE_CODE_STRUCT + && type->code () != TYPE_CODE_UNION + && type->code () != TYPE_CODE_ENUM + && type->code () != TYPE_CODE_FUNC) { PyErr_SetString (PyExc_TypeError, "Type is not a structure, union, enum, or function type."); @@ -579,16 +579,16 @@ typy_range (PyObject *self, PyObject *args) /* Initialize these to appease GCC warnings. */ LONGEST low = 0, high = 0; - if (TYPE_CODE (type) != TYPE_CODE_ARRAY - && TYPE_CODE (type) != TYPE_CODE_STRING - && TYPE_CODE (type) != TYPE_CODE_RANGE) + if (type->code () != TYPE_CODE_ARRAY + && type->code () != TYPE_CODE_STRING + && type->code () != TYPE_CODE_RANGE) { PyErr_SetString (PyExc_RuntimeError, _("This type does not have a range.")); return NULL; } - switch (TYPE_CODE (type)) + switch (type->code ()) { case TYPE_CODE_ARRAY: case TYPE_CODE_STRING: diff --git a/gdb/python/py-value.c b/gdb/python/py-value.c index bc75a68..2ebbe0a 100644 --- a/gdb/python/py-value.c +++ b/gdb/python/py-value.c @@ -251,7 +251,7 @@ valpy_referenced_value (PyObject *self, PyObject *args) scoped_value_mark free_values; self_val = ((value_object *) self)->value; - switch (TYPE_CODE (check_typedef (value_type (self_val)))) + switch (check_typedef (value_type (self_val))->code ()) { case TYPE_CODE_PTR: res_val = value_ind (self_val); @@ -400,11 +400,11 @@ valpy_get_dynamic_type (PyObject *self, void *closure) type = value_type (val); type = check_typedef (type); - if (((TYPE_CODE (type) == TYPE_CODE_PTR) || TYPE_IS_REFERENCE (type)) - && (TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_STRUCT)) + if (((type->code () == TYPE_CODE_PTR) || TYPE_IS_REFERENCE (type)) + && (TYPE_TARGET_TYPE (type)->code () == TYPE_CODE_STRUCT)) { struct value *target; - int was_pointer = TYPE_CODE (type) == TYPE_CODE_PTR; + int was_pointer = type->code () == TYPE_CODE_PTR; if (was_pointer) target = value_ind (val); @@ -420,7 +420,7 @@ valpy_get_dynamic_type (PyObject *self, void *closure) type = lookup_lvalue_reference_type (type); } } - else if (TYPE_CODE (type) == TYPE_CODE_STRUCT) + else if (type->code () == TYPE_CODE_STRUCT) type = value_rtti_type (val, NULL, NULL, NULL); else { @@ -488,7 +488,7 @@ valpy_lazy_string (PyObject *self, PyObject *args, PyObject *kw) type = value_type (value); realtype = check_typedef (type); - switch (TYPE_CODE (realtype)) + switch (realtype->code ()) { case TYPE_CODE_ARRAY: { @@ -846,10 +846,10 @@ value_has_field (struct value *v, PyObject *field) { val_type = value_type (v); val_type = check_typedef (val_type); - if (TYPE_IS_REFERENCE (val_type) || TYPE_CODE (val_type) == TYPE_CODE_PTR) + if (TYPE_IS_REFERENCE (val_type) || val_type->code () == TYPE_CODE_PTR) val_type = check_typedef (TYPE_TARGET_TYPE (val_type)); - type_code = TYPE_CODE (val_type); + type_code = val_type->code (); if ((type_code == TYPE_CODE_STRUCT || type_code == TYPE_CODE_UNION) && types_equal (val_type, parent_type)) has_field = 1; @@ -997,12 +997,12 @@ valpy_getitem (PyObject *self, PyObject *key) struct type *val_type; val_type = check_typedef (value_type (tmp)); - if (TYPE_CODE (val_type) == TYPE_CODE_PTR) + if (val_type->code () == TYPE_CODE_PTR) res_val = value_cast (lookup_pointer_type (base_class_type), tmp); - else if (TYPE_CODE (val_type) == TYPE_CODE_REF) + else if (val_type->code () == TYPE_CODE_REF) res_val = value_cast (lookup_lvalue_reference_type (base_class_type), tmp); - else if (TYPE_CODE (val_type) == TYPE_CODE_RVALUE_REF) + else if (val_type->code () == TYPE_CODE_RVALUE_REF) res_val = value_cast (lookup_rvalue_reference_type (base_class_type), tmp); else @@ -1023,8 +1023,8 @@ valpy_getitem (PyObject *self, PyObject *key) tmp = coerce_ref (tmp); type = check_typedef (value_type (tmp)); - if (TYPE_CODE (type) != TYPE_CODE_ARRAY - && TYPE_CODE (type) != TYPE_CODE_PTR) + if (type->code () != TYPE_CODE_ARRAY + && type->code () != TYPE_CODE_PTR) error (_("Cannot subscript requested type.")); else res_val = value_subscript (tmp, value_as_long (idx)); @@ -1072,7 +1072,7 @@ valpy_call (PyObject *self, PyObject *args, PyObject *keywords) GDB_PY_HANDLE_EXCEPTION (except); } - if (TYPE_CODE (ftype) != TYPE_CODE_FUNC) + if (ftype->code () != TYPE_CODE_FUNC) { PyErr_SetString (PyExc_RuntimeError, _("Value is not callable (not TYPE_CODE_FUNC).")); @@ -1279,10 +1279,10 @@ valpy_binop_throw (enum valpy_opcode opcode, PyObject *self, PyObject *other) rtype = STRIP_REFERENCE (rtype); handled = 1; - if (TYPE_CODE (ltype) == TYPE_CODE_PTR + if (ltype->code () == TYPE_CODE_PTR && is_integral_type (rtype)) res_val = value_ptradd (arg1, value_as_long (arg2)); - else if (TYPE_CODE (rtype) == TYPE_CODE_PTR + else if (rtype->code () == TYPE_CODE_PTR && is_integral_type (ltype)) res_val = value_ptradd (arg2, value_as_long (arg1)); else @@ -1303,12 +1303,12 @@ valpy_binop_throw (enum valpy_opcode opcode, PyObject *self, PyObject *other) rtype = STRIP_REFERENCE (rtype); handled = 1; - if (TYPE_CODE (ltype) == TYPE_CODE_PTR - && TYPE_CODE (rtype) == TYPE_CODE_PTR) + if (ltype->code () == TYPE_CODE_PTR + && rtype->code () == TYPE_CODE_PTR) /* A ptrdiff_t for the target would be preferable here. */ res_val = value_from_longest (builtin_type_pyint, value_ptrdiff (arg1, arg2)); - else if (TYPE_CODE (ltype) == TYPE_CODE_PTR + else if (ltype->code () == TYPE_CODE_PTR && is_integral_type (rtype)) res_val = value_ptradd (arg1, - value_as_long (arg2)); else @@ -1492,7 +1492,7 @@ valpy_nonzero (PyObject *self) { type = check_typedef (value_type (self_value->value)); - if (is_integral_type (type) || TYPE_CODE (type) == TYPE_CODE_PTR) + if (is_integral_type (type) || type->code () == TYPE_CODE_PTR) nonzero = !!value_as_long (self_value->value); else if (is_floating_value (self_value->value)) nonzero = !target_float_is_zero (value_contents (self_value->value), @@ -1684,7 +1684,7 @@ valpy_int (PyObject *self) } if (!is_integral_type (type) - && TYPE_CODE (type) != TYPE_CODE_PTR) + && type->code () != TYPE_CODE_PTR) error (_("Cannot convert value to int.")); l = value_as_long (value); @@ -1720,7 +1720,7 @@ valpy_long (PyObject *self) type = check_typedef (type); if (!is_integral_type (type) - && TYPE_CODE (type) != TYPE_CODE_PTR) + && type->code () != TYPE_CODE_PTR) error (_("Cannot convert value to long.")); l = value_as_long (value); @@ -1748,9 +1748,9 @@ valpy_float (PyObject *self) { type = check_typedef (type); - if (TYPE_CODE (type) == TYPE_CODE_FLT && is_floating_value (value)) + if (type->code () == TYPE_CODE_FLT && is_floating_value (value)) d = target_float_to_host_double (value_contents (value), type); - else if (TYPE_CODE (type) == TYPE_CODE_INT) + else if (type->code () == TYPE_CODE_INT) { /* Note that valpy_long accepts TYPE_CODE_PTR and some others here here -- but casting a pointer or bool to a @@ -1972,7 +1972,7 @@ gdbpy_convenience_variable (PyObject *self, PyObject *args) if (var != NULL) { res_val = value_of_internalvar (python_gdbarch, var); - if (TYPE_CODE (value_type (res_val)) == TYPE_CODE_VOID) + if (value_type (res_val)->code () == TYPE_CODE_VOID) res_val = NULL; } } diff --git a/gdb/python/py-xmethods.c b/gdb/python/py-xmethods.c index 274d1bf..d223d49 100644 --- a/gdb/python/py-xmethods.c +++ b/gdb/python/py-xmethods.c @@ -425,7 +425,7 @@ python_xmethod_worker::do_get_result_type (value *obj, obj_type = check_typedef (value_type (obj)); this_type = check_typedef (type_object_to_type (m_this_type)); - if (TYPE_CODE (obj_type) == TYPE_CODE_PTR) + if (obj_type->code () == TYPE_CODE_PTR) { struct type *this_ptr = lookup_pointer_type (this_type); @@ -435,7 +435,7 @@ python_xmethod_worker::do_get_result_type (value *obj, else if (TYPE_IS_REFERENCE (obj_type)) { struct type *this_ref - = lookup_reference_type (this_type, TYPE_CODE (obj_type)); + = lookup_reference_type (this_type, obj_type->code ()); if (!types_equal (obj_type, this_ref)) obj = value_cast (this_ref, obj); @@ -510,7 +510,7 @@ python_xmethod_worker::invoke (struct value *obj, obj_type = check_typedef (value_type (obj)); this_type = check_typedef (type_object_to_type (m_this_type)); - if (TYPE_CODE (obj_type) == TYPE_CODE_PTR) + if (obj_type->code () == TYPE_CODE_PTR) { struct type *this_ptr = lookup_pointer_type (this_type); @@ -520,7 +520,7 @@ python_xmethod_worker::invoke (struct value *obj, else if (TYPE_IS_REFERENCE (obj_type)) { struct type *this_ref - = lookup_reference_type (this_type, TYPE_CODE (obj_type)); + = lookup_reference_type (this_type, obj_type->code ()); if (!types_equal (obj_type, this_ref)) obj = value_cast (this_ref, obj); -- cgit v1.1