mirror of
https://github.com/espressif/binutils-gdb.git
synced 2025-06-18 00:32:30 +08:00
Rewrite the Rust expression parser
The Rust expression parser was written to construct its own AST, then lower this to GDB expressions. I did this primarily because the old expressions were difficult to work with; after rewriting those, I realized I could remove the AST from the Rust parser. After looking at this, I realized it might be simpler to rewrite the parser. This patch reimplements it as a recursive-descent parser. I kept a fair amount of the existing code -- the lexer is pulled in nearly unchanged. There are several benefits to this approach: * The parser is shorter now (from 2882 LOC to 2351). * The parser is just ordinary C++ code that can be debugged in the usual way. * Memory management in the parser is now straightforward, as parsing methods simply return a unique pointer or vector. This required a couple of minor changes to the test suite, as some errors have changed. While this passes the tests, it's possible there are lurking bugs, particularly around error handling. gdb/ChangeLog 2021-04-16 Tom Tromey <tom@tromey.com> * rust-parse.c: New file. * rust-exp.y: Remove. * Makefile.in (COMMON_SFILES): Add rust-parse.c. (SFILES): Remove rust-exp.y. (YYFILES, local-maintainer-clean): Remove rust-exp.c. gdb/testsuite/ChangeLog 2021-04-16 Tom Tromey <tom@tromey.com> * gdb.rust/simple.exp: Change error text. * gdb.rust/expr.exp: Change error text.
This commit is contained in:
@ -1,3 +1,11 @@
|
|||||||
|
2021-04-16 Tom Tromey <tom@tromey.com>
|
||||||
|
|
||||||
|
* rust-parse.c: New file.
|
||||||
|
* rust-exp.y: Remove.
|
||||||
|
* Makefile.in (COMMON_SFILES): Add rust-parse.c.
|
||||||
|
(SFILES): Remove rust-exp.y.
|
||||||
|
(YYFILES, local-maintainer-clean): Remove rust-exp.c.
|
||||||
|
|
||||||
2021-04-16 Luis Machado <luis.machado@linaro.org>
|
2021-04-16 Luis Machado <luis.machado@linaro.org>
|
||||||
|
|
||||||
* arch-utils.c (default_floatformat_for_type): Handle bfloat16.
|
* arch-utils.c (default_floatformat_for_type): Handle bfloat16.
|
||||||
|
@ -1134,6 +1134,7 @@ COMMON_SFILES = \
|
|||||||
reverse.c \
|
reverse.c \
|
||||||
run-on-main-thread.c \
|
run-on-main-thread.c \
|
||||||
rust-lang.c \
|
rust-lang.c \
|
||||||
|
rust-parse.c \
|
||||||
sentinel-frame.c \
|
sentinel-frame.c \
|
||||||
ser-event.c \
|
ser-event.c \
|
||||||
serial.c \
|
serial.c \
|
||||||
@ -1200,7 +1201,6 @@ SFILES = \
|
|||||||
m2-exp.y \
|
m2-exp.y \
|
||||||
p-exp.y \
|
p-exp.y \
|
||||||
proc-service.list \
|
proc-service.list \
|
||||||
rust-exp.y \
|
|
||||||
ser-base.c \
|
ser-base.c \
|
||||||
ser-unix.c \
|
ser-unix.c \
|
||||||
sol-thread.c \
|
sol-thread.c \
|
||||||
@ -1608,8 +1608,7 @@ YYFILES = \
|
|||||||
f-exp.c \
|
f-exp.c \
|
||||||
go-exp.c \
|
go-exp.c \
|
||||||
m2-exp.c \
|
m2-exp.c \
|
||||||
p-exp.c \
|
p-exp.c
|
||||||
rust-exp.c
|
|
||||||
|
|
||||||
# ada-lex.c is included by another file, so it shouldn't wind up as a
|
# ada-lex.c is included by another file, so it shouldn't wind up as a
|
||||||
# .o itself.
|
# .o itself.
|
||||||
@ -1969,7 +1968,7 @@ local-maintainer-clean:
|
|||||||
rm -f c-exp.c \
|
rm -f c-exp.c \
|
||||||
cp-name-parser.c \
|
cp-name-parser.c \
|
||||||
ada-lex.c ada-exp.c \
|
ada-lex.c ada-exp.c \
|
||||||
d-exp.c f-exp.c go-exp.c m2-exp.c p-exp.c rust-exp.c
|
d-exp.c f-exp.c go-exp.c m2-exp.c p-exp.c
|
||||||
rm -f TAGS
|
rm -f TAGS
|
||||||
rm -f $(YYFILES)
|
rm -f $(YYFILES)
|
||||||
rm -f nm.h config.status
|
rm -f nm.h config.status
|
||||||
|
2884
gdb/rust-exp.y
2884
gdb/rust-exp.y
File diff suppressed because it is too large
Load Diff
2351
gdb/rust-parse.c
Normal file
2351
gdb/rust-parse.c
Normal file
File diff suppressed because it is too large
Load Diff
@ -1,3 +1,8 @@
|
|||||||
|
2021-04-16 Tom Tromey <tom@tromey.com>
|
||||||
|
|
||||||
|
* gdb.rust/simple.exp: Change error text.
|
||||||
|
* gdb.rust/expr.exp: Change error text.
|
||||||
|
|
||||||
2021-04-16 Tom Tromey <tom@tromey.com>
|
2021-04-16 Tom Tromey <tom@tromey.com>
|
||||||
|
|
||||||
* gdb.rust/simple.exp: Add parens to 'as' test.
|
* gdb.rust/simple.exp: Add parens to 'as' test.
|
||||||
|
@ -136,6 +136,10 @@ gdb_test "print \[mut 23usize; 4\]" " = \\\[23, 23, 23, 23\\\]"
|
|||||||
# Test lexer corner cases.
|
# Test lexer corner cases.
|
||||||
gdb_test "print 0x0 as *mut ()" " = \\\(\\*mut \\\(\\\)\\\) 0x0"
|
gdb_test "print 0x0 as *mut ()" " = \\\(\\*mut \\\(\\\)\\\) 0x0"
|
||||||
gdb_test "print 0x0 as fn(i64) -> ()" " = \\\(\\*mut fn \\\(i64\\\) -> \\\(\\\)\\\) 0x0"
|
gdb_test "print 0x0 as fn(i64) -> ()" " = \\\(\\*mut fn \\\(i64\\\) -> \\\(\\\)\\\) 0x0"
|
||||||
gdb_test "print r#" "syntax error in expression, near `#'\\."
|
|
||||||
|
# The lexer doesn't treat this as a failure, but rather as two tokens,
|
||||||
|
# and we error out while trying to look up 'r'. This is fine, though
|
||||||
|
# -- what's important is that it isn't accepted.
|
||||||
|
gdb_test "print r#" "No symbol 'r' in current context"
|
||||||
|
|
||||||
gdb_test "printf \"%d %d\\n\", 23+1, 23-1" "24 22"
|
gdb_test "printf \"%d %d\\n\", 23+1, 23-1" "24 22"
|
||||||
|
@ -165,7 +165,7 @@ gdb_test "print simple::HiBob(0xff, 5)" \
|
|||||||
"Type simple::HiBob is not a tuple struct"
|
"Type simple::HiBob is not a tuple struct"
|
||||||
gdb_test "print sizeof(simple::HiBob)" " = \[0-9\]+"
|
gdb_test "print sizeof(simple::HiBob)" " = \[0-9\]+"
|
||||||
gdb_test "print simple::HiBob + 5" \
|
gdb_test "print simple::HiBob + 5" \
|
||||||
"Found type 'simple::HiBob', which can't be evaluated in this context"
|
"Attempt to use a type name as an expression"
|
||||||
gdb_test "print nosuchsymbol" \
|
gdb_test "print nosuchsymbol" \
|
||||||
"No symbol 'nosuchsymbol' in current context"
|
"No symbol 'nosuchsymbol' in current context"
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user