From 3cbc7ac344cd6b500b54588a9099c037de58e75a Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Fri, 16 Apr 2021 16:34:07 -0600 Subject: 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 * 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 * gdb.rust/simple.exp: Change error text. * gdb.rust/expr.exp: Change error text. --- gdb/Makefile.in | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'gdb/Makefile.in') diff --git a/gdb/Makefile.in b/gdb/Makefile.in index 3318c1a..4904190 100644 --- a/gdb/Makefile.in +++ b/gdb/Makefile.in @@ -1134,6 +1134,7 @@ COMMON_SFILES = \ reverse.c \ run-on-main-thread.c \ rust-lang.c \ + rust-parse.c \ sentinel-frame.c \ ser-event.c \ serial.c \ @@ -1200,7 +1201,6 @@ SFILES = \ m2-exp.y \ p-exp.y \ proc-service.list \ - rust-exp.y \ ser-base.c \ ser-unix.c \ sol-thread.c \ @@ -1608,8 +1608,7 @@ YYFILES = \ f-exp.c \ go-exp.c \ m2-exp.c \ - p-exp.c \ - rust-exp.c + p-exp.c # ada-lex.c is included by another file, so it shouldn't wind up as a # .o itself. @@ -1969,7 +1968,7 @@ local-maintainer-clean: rm -f c-exp.c \ cp-name-parser.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 $(YYFILES) rm -f nm.h config.status -- cgit v1.1