diff options
Diffstat (limited to 'gdb/rust-lang.c')
-rw-r--r-- | gdb/rust-lang.c | 52 |
1 files changed, 31 insertions, 21 deletions
diff --git a/gdb/rust-lang.c b/gdb/rust-lang.c index 1bb14db..4626685 100644 --- a/gdb/rust-lang.c +++ b/gdb/rust-lang.c @@ -18,7 +18,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#include <ctype.h> #include "block.h" #include "c-lang.h" @@ -126,15 +125,15 @@ rust_underscore_fields (struct type *type) if (type->code () != TYPE_CODE_STRUCT) return false; - for (int i = 0; i < type->num_fields (); ++i) + for (const auto &field : type->fields ()) { - if (!type->field (i).is_static ()) + if (!field.is_static ()) { char buf[20]; xsnprintf (buf, sizeof (buf), "%d", field_number); - const char *field_name = type->field (i).name (); + const char *field_name = field.name (); if (startswith (field_name, "__")) field_name += 2; if (strcmp (buf, field_name) != 0) @@ -376,11 +375,11 @@ rust_array_like_element_type (struct type *type) { /* Caller must check this. */ gdb_assert (rust_slice_type_p (type)); - for (int i = 0; i < type->num_fields (); ++i) + for (const auto &field : type->fields ()) { - if (strcmp (type->field (i).name (), "data_ptr") == 0) + if (strcmp (field.name (), "data_ptr") == 0) { - struct type *base_type = type->field (i).type ()->target_type (); + struct type *base_type = field.type ()->target_type (); if (rewrite_slice_type (base_type, nullptr, 0, nullptr)) return nullptr; return base_type; @@ -1017,9 +1016,9 @@ rust_internal_print_type (struct type *type, const char *varstring, } gdb_puts ("{\n", stream); - for (int i = 0; i < type->num_fields (); ++i) + for (const auto &field : type->fields ()) { - const char *name = type->field (i).name (); + const char *name = field.name (); QUIT; @@ -1142,13 +1141,22 @@ rust_slice_type (const char *name, struct type *elt_type, -/* A helper for rust_evaluate_subexp that handles OP_RANGE. */ +namespace expr +{ struct value * -rust_range (struct type *expect_type, struct expression *exp, - enum noside noside, enum range_flag kind, - struct value *low, struct value *high) +rust_range_operation::evaluate (struct type *expect_type, + struct expression *exp, + enum noside noside) { + auto kind = std::get<0> (m_storage); + value *low = nullptr; + if (std::get<1> (m_storage) != nullptr) + low = std::get<1> (m_storage)->evaluate (nullptr, exp, noside); + value *high = nullptr; + if (std::get<2> (m_storage) != nullptr) + high = std::get<2> (m_storage)->evaluate (nullptr, exp, noside); + struct value *addrval, *result; CORE_ADDR addr; struct type *range_type; @@ -1225,6 +1233,8 @@ rust_range (struct type *expect_type, struct expression *exp, return result; } +} /* namespace expr */ + /* A helper function to compute the range and kind given a range value. TYPE is the type of the range value. RANGE is the range value. LOW, HIGH, and KIND are out parameters. The LOW and HIGH @@ -1266,13 +1276,16 @@ rust_compute_range (struct type *type, struct value *range, } } -/* A helper for rust_evaluate_subexp that handles BINOP_SUBSCRIPT. */ +namespace expr +{ struct value * -rust_subscript (struct type *expect_type, struct expression *exp, - enum noside noside, bool for_addr, - struct value *lhs, struct value *rhs) +rust_subscript_operation::subscript (struct expression *exp, + enum noside noside, bool for_addr) { + value *lhs = std::get<0> (m_storage)->evaluate (nullptr, exp, noside); + value *rhs = std::get<1> (m_storage)->evaluate (nullptr, exp, noside); + struct value *result; struct type *rhstype; LONGEST low, high_bound; @@ -1413,9 +1426,6 @@ rust_subscript (struct type *expect_type, struct expression *exp, return result; } -namespace expr -{ - struct value * rust_unop_ind_operation::evaluate (struct type *expect_type, struct expression *exp, @@ -1777,7 +1787,7 @@ rust_language::emitchar (int ch, struct type *chtype, gdb_puts ("\\t", stream); else if (ch == '\0') gdb_puts ("\\0", stream); - else if (ch >= 32 && ch <= 127 && isprint (ch)) + else if (ch >= 32 && ch <= 127 && c_isprint (ch)) gdb_putc (ch, stream); else if (ch <= 255) gdb_printf (stream, "\\x%02x", ch); |