Allow subscripting raw pointers
authorManish Goregaokar <manish@mozilla.com>
Wed, 6 Jul 2016 05:25:10 +0000 (10:55 +0530)
committerManish Goregaokar <manish@mozilla.com>
Wed, 6 Jul 2016 05:26:21 +0000 (10:56 +0530)
This will be useful for dealing with vectors; regardless of our final solution
for the Index trait.

2016-07-06  Manish Goregaokar  <manish@mozilla.com>

gdb/ChangeLog:
    * rust-lang.c (rust_subscript): Allow subscripting pointers

gdb/testsuite/ChangeLog:
    * simple.rs: Add test for raw pointer subscripting
    * simple.exp: Add test expectations

gdb/ChangeLog
gdb/rust-lang.c
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.rust/simple.exp
gdb/testsuite/gdb.rust/simple.rs

index acd29c3babba6c88ad71b4c4c771f927d163297f..7cec5ad8c23454eb827d0833321f2e7907641ada 100644 (file)
@@ -1,3 +1,7 @@
+2016-07-06  Manish Goregaokar  <manish@mozilla.com>
+
+       * rust-lang.c (rust_subscript): Allow subscripting pointers
+
 2016-07-05  Jan Kratochvil  <jan.kratochvil@redhat.com>
 
        * configure: Regenerate.
index 1849349f49a0866ec34eadaaadc7a05b4693781b..17b20c66aabca2cb02e2636bca8596f00aeda2a2 100644 (file)
@@ -1415,6 +1415,12 @@ rust_subscript (struct expression *exp, int *pos, enum noside noside,
          low_bound = 0;
          high_bound = value_as_long (len);
        }
+      else if (TYPE_CODE (type) == TYPE_CODE_PTR)
+       {
+         base = lhs;
+         low_bound = 0;
+         high_bound = LONGEST_MAX;
+       }
       else
        error (_("Cannot subscript non-array type"));
 
index be0cf9d2227a8a8f68c3f98f6288d3610108ec30..6445a10fb41708861d7b25cc4739f2d815b49869 100644 (file)
@@ -1,3 +1,8 @@
+2016-07-06  Manish Goregaokar  <manish@mozilla.com>
+
+       * simple.rs: Add test for raw pointer subscripting
+       * simple.exp: Add test expectations
+
 2016-07-05  Yao Qi  <yao.qi@linaro.org>
 
        * gdb.mi/mi-reverse.exp: Match =record-started output.
index 4622f75b1d3b99a2da6061614eebee756c5ef2b0..32b3785c97172b8201a0e2ab4923283fad27cd1e 100644 (file)
@@ -73,6 +73,7 @@ gdb_test "print w" " = \\\[1, 2, 3, 4\\\]"
 gdb_test "ptype w" " = \\\[i32; 4\\\]"
 gdb_test "print w\[2\]" " = 3"
 gdb_test "print w\[2\] @ 2" " = \\\[3, 4\\\]"
+gdb_test "print w_ptr\[2\]" " = 3"
 gdb_test "print fromslice" " = 3"
 gdb_test "print slice\[0\]" " = 3"
 gdb_test "print slice as &\[i32\]\[0\]" " = 3"
index 3d28e272982189016628a3a3644a36f138370a5c..49808261324226cc8110f3a290f211a89eab0672 100644 (file)
@@ -87,6 +87,7 @@ fn main () {
 
     let v = Something::Three;
     let w = [1,2,3,4];
+    let w_ptr = &w[0];
     let x = (23, 25.5);
     let y = HiBob {field1: 7, field2: 8};
     let z = ByeBob(7, 8);
This page took 0.040798 seconds and 4 git commands to generate.