aboutsummaryrefslogtreecommitdiff
path: root/gdb/rust-lang.c
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2018-03-29 14:14:07 -0600
committerTom Tromey <tom@tromey.com>2018-04-27 13:20:13 -0600
commit6873858b7e464e114f9a877e216949ad8350b4cf (patch)
tree8812199c58f09c14b00dc50805d9b066f02d28bd /gdb/rust-lang.c
parent632e107b32c0fe8aede62e070b00756e9fdd2c01 (diff)
downloadgdb-6873858b7e464e114f9a877e216949ad8350b4cf.zip
gdb-6873858b7e464e114f9a877e216949ad8350b4cf.tar.gz
gdb-6873858b7e464e114f9a877e216949ad8350b4cf.tar.bz2
Add inclusive range support for Rust
This is version 2 of the patch to add inclusive range support for Rust. I believe it addresses all review comments. Rust recently stabilized the inclusive range feature: https://github.com/rust-lang/rust/issues/28237 An inclusive range is an expression like "..= EXPR" or "EXPR ..= EXPR". It is like an ordinary range, except the upper bound is inclusive, not exclusive. This patch adds support for this feature to gdb. Regression tested on x86-64 Fedora 27. 2018-04-27 Tom Tromey <tom@tromey.com> PR rust/22545: * rust-lang.c (rust_inclusive_range_type_p): New function. (rust_range): Handle inclusive ranges. (rust_compute_range): Likewise. * rust-exp.y (struct rust_op) <inclusive>: New field. (DOTDOTEQ): New constant. (range_expr): Add "..=" productions. (operator_tokens): Add "..=" token. (ast_range): Add "inclusive" parameter. (convert_ast_to_expression) <case OP_RANGE>: Handle inclusive ranges. * parse.c (operator_length_standard) <case OP_RANGE>: Handle new bounds values. * expression.h (enum range_type) <NONE_BOUND_DEFAULT_EXCLUSIVE, LOW_BOUND_DEFAULT_EXCLUSIVE>: New constants. Update comments. * expprint.c (print_subexp_standard): Handle new bounds values. (dump_subexp_body_standard): Likewise. 2018-04-27 Tom Tromey <tom@tromey.com> PR rust/22545: * gdb.rust/simple.exp: Add inclusive range tests.
Diffstat (limited to 'gdb/rust-lang.c')
-rw-r--r--gdb/rust-lang.c26
1 files changed, 22 insertions, 4 deletions
diff --git a/gdb/rust-lang.c b/gdb/rust-lang.c
index cf8a15e..5d1c0a7 100644
--- a/gdb/rust-lang.c
+++ b/gdb/rust-lang.c
@@ -180,6 +180,17 @@ rust_range_type_p (struct type *type)
return strcmp (TYPE_FIELD_NAME (type, i), "end") == 0;
}
+/* Return true if TYPE is an inclusive range type, otherwise false.
+ This is only valid for types which are already known to be range
+ types. */
+
+static bool
+rust_inclusive_range_type_p (struct type *type)
+{
+ return (strstr (TYPE_TAG_NAME (type), "::RangeInclusive") != NULL
+ || strstr (TYPE_TAG_NAME (type), "::RangeToInclusive") != NULL);
+}
+
/* Return true if TYPE seems to be the type "u8", otherwise false. */
static bool
@@ -1136,10 +1147,13 @@ rust_range (struct expression *exp, int *pos, enum noside noside)
kind = (enum range_type) longest_to_int (exp->elts[*pos + 1].longconst);
*pos += 3;
- if (kind == HIGH_BOUND_DEFAULT || kind == NONE_BOUND_DEFAULT)
+ if (kind == HIGH_BOUND_DEFAULT || kind == NONE_BOUND_DEFAULT
+ || kind == NONE_BOUND_DEFAULT_EXCLUSIVE)
low = evaluate_subexp (NULL_TYPE, exp, pos, noside);
- if (kind == LOW_BOUND_DEFAULT || kind == NONE_BOUND_DEFAULT)
+ if (kind == LOW_BOUND_DEFAULT || kind == LOW_BOUND_DEFAULT_EXCLUSIVE
+ || kind == NONE_BOUND_DEFAULT || kind == NONE_BOUND_DEFAULT_EXCLUSIVE)
high = evaluate_subexp (NULL_TYPE, exp, pos, noside);
+ bool inclusive = (kind == NONE_BOUND_DEFAULT || kind == LOW_BOUND_DEFAULT);
if (noside == EVAL_SKIP)
return value_from_longest (builtin_type (exp->gdbarch)->builtin_int, 1);
@@ -1154,7 +1168,8 @@ rust_range (struct expression *exp, int *pos, enum noside noside)
else
{
index_type = value_type (high);
- name = "std::ops::RangeTo";
+ name = (inclusive
+ ? "std::ops::RangeToInclusive" : "std::ops::RangeTo");
}
}
else
@@ -1169,7 +1184,7 @@ rust_range (struct expression *exp, int *pos, enum noside noside)
if (!types_equal (value_type (low), value_type (high)))
error (_("Range expression with different types"));
index_type = value_type (low);
- name = "std::ops::Range";
+ name = inclusive ? "std::ops::RangeInclusive" : "std::ops::Range";
}
}
@@ -1245,6 +1260,9 @@ rust_compute_range (struct type *type, struct value *range,
*kind = (*kind == BOTH_BOUND_DEFAULT
? LOW_BOUND_DEFAULT : NONE_BOUND_DEFAULT);
*high = value_as_long (value_field (range, i));
+
+ if (rust_inclusive_range_type_p (type))
+ ++*high;
}
}