diff options
author | Tom Tromey <tom@tromey.com> | 2019-03-24 11:33:10 -0600 |
---|---|---|
committer | Tom Tromey <tom@tromey.com> | 2019-04-04 19:55:10 -0600 |
commit | 28aaf3fdf9562c018dcf6ab4d0a4c644fff8d696 (patch) | |
tree | b4ca770f82e55440997751bd9297de577396e1f8 /gdb/rust-exp.y | |
parent | 1e58a4a4db997cf09315c22f3da725d1da7f9ee7 (diff) | |
download | fsf-binutils-gdb-28aaf3fdf9562c018dcf6ab4d0a4c644fff8d696.zip fsf-binutils-gdb-28aaf3fdf9562c018dcf6ab4d0a4c644fff8d696.tar.gz fsf-binutils-gdb-28aaf3fdf9562c018dcf6ab4d0a4c644fff8d696.tar.bz2 |
Remove paren_depth global
This removes the "paren_depth" global. In most cases, it is made into
a static global in a given parser. I consider this a slight
improvement, because it makes it clear that the variable isn't used
for communication between different modules of gdb. The one exception
is the Rust parser, which already incorporates all local state into a
transient object; in this case the parser depth is now a member.
gdb/ChangeLog
2019-04-04 Tom Tromey <tom@tromey.com>
* rust-exp.y (struct rust_parser) <paren_depth>: New member.
(rustyylex, rust_lex_test_init, rust_lex_test_one)
(rust_lex_test_sequence, rust_lex_test_push_back): Update.
* parser-defs.h (paren_depth): Don't declare.
* parse.c (paren_depth): Remove global.
(parse_exp_in_context): Update.
* p-exp.y (paren_depth): New global.
(pascal_parse): Initialize it.
* m2-exp.y (paren_depth): New global.
(m2_parse): Initialize it.
* go-exp.y (paren_depth): New global.
(go_parse): Initialize it.
* f-exp.y (paren_depth): New global.
(f_parse): Initialize it.
* d-exp.y (paren_depth): New global.
(d_parse): Initialize it.
* c-exp.y (paren_depth): New global.
(c_parse): Initialize it.
* ada-lex.l (paren_depth): New global.
(lexer_init): Initialize it.
Diffstat (limited to 'gdb/rust-exp.y')
-rw-r--r-- | gdb/rust-exp.y | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/gdb/rust-exp.y b/gdb/rust-exp.y index 1b7e33e..9d3083e 100644 --- a/gdb/rust-exp.y +++ b/gdb/rust-exp.y @@ -300,6 +300,9 @@ struct rust_parser /* The parser state gdb gave us. */ struct parser_state *pstate; + + /* Depth of parentheses. */ + int paren_depth = 0; }; /* Rust AST operations. We build a tree of these; then lower them to @@ -1664,14 +1667,14 @@ rustyylex (YYSTYPE *lvalp, rust_parser *parser) else if (lexptr[0] == '}' || lexptr[0] == ']') { /* Falls through to lex_operator. */ - --paren_depth; + --parser->paren_depth; } else if (lexptr[0] == '(' || lexptr[0] == '{') { /* Falls through to lex_operator. */ - ++paren_depth; + ++parser->paren_depth; } - else if (lexptr[0] == ',' && comma_terminates && paren_depth == 0) + else if (lexptr[0] == ',' && comma_terminates && parser->paren_depth == 0) return 0; return lex_operator (lvalp); @@ -2552,11 +2555,11 @@ rustyyerror (rust_parser *parser, const char *msg) /* Initialize the lexer for testing. */ static void -rust_lex_test_init (const char *input) +rust_lex_test_init (rust_parser *parser, const char *input) { prev_lexptr = NULL; lexptr = input; - paren_depth = 0; + parser->paren_depth = 0; } /* A test helper that lexes a string, expecting a single token. It @@ -2568,7 +2571,7 @@ rust_lex_test_one (rust_parser *parser, const char *input, int expected) int token; RUSTSTYPE result; - rust_lex_test_init (input); + rust_lex_test_init (parser, input); token = rustyylex (&result, parser); SELF_CHECK (token == expected); @@ -2632,7 +2635,7 @@ rust_lex_test_sequence (rust_parser *parser, const char *input, int len, int i; lexptr = input; - paren_depth = 0; + parser->paren_depth = 0; for (i = 0; i < len; ++i) { @@ -2686,7 +2689,7 @@ rust_lex_test_push_back (rust_parser *parser) int token; RUSTSTYPE lval; - rust_lex_test_init (">>="); + rust_lex_test_init (parser, ">>="); token = rustyylex (&lval, parser); SELF_CHECK (token == COMPOUND_ASSIGN); |