From 5776fca307b8af3d852525b77e9b917a9aa97370 Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Sun, 24 Mar 2019 21:30:56 -0600 Subject: Move lexptr and prev_lexptr to parser_state This removes the lexptr and prev_lexptr globals, in favor of members of parser_state. prev_lexptr could be isolated to each parser, but since every parser uses it, that did not seem necessary. gdb/ChangeLog 2019-04-04 Tom Tromey * rust-exp.y (struct rust_parser) : New methods. Update all rules. (rust_parser::lex_hex, lex_escape): Rename and update. (rust_parser::lex_string, rust_parser::lex_identifier): Update. (rust_parser::lex_operator): Rename and update. (rust_parser::lex_number, rustyylex, rustyyerror) (rust_lex_test_init, rust_lex_test_sequence) (rust_lex_test_push_back, rust_lex_tests): Update. * parser-defs.h (struct parser_state) : Add "input" parameter. : New members. (lexptr, prev_lexptr): Don't declare. * parse.c (lexptr, prev_lexptr): Remove globals. (parse_exp_in_context): Update. * p-exp.y (yylex, yyerror): Update. * m2-exp.y (parse_number, yylex, yyerror): Update. * go-exp.y (lex_one_token, yyerror): Update. * f-exp.y (match_string_literal, yylex, yyerror): Update. * d-exp.y (lex_one_token, yyerror): Update. * c-exp.y (scan_macro_expansion, finished_macro_expansion) (lex_one_token, yyerror): Update. * ada-lex.l (YY_INPUT): Update. (rewind_to_char): Update. * ada-exp.y (yyerror): Update. --- gdb/p-exp.y | 50 +++++++++++++++++++++++++------------------------- 1 file changed, 25 insertions(+), 25 deletions(-) (limited to 'gdb/p-exp.y') diff --git a/gdb/p-exp.y b/gdb/p-exp.y index 65874c6..4487899 100644 --- a/gdb/p-exp.y +++ b/gdb/p-exp.y @@ -1128,10 +1128,10 @@ yylex (void) retry: - prev_lexptr = lexptr; + pstate->prev_lexptr = pstate->lexptr; - tokstart = lexptr; - explen = strlen (lexptr); + tokstart = pstate->lexptr; + explen = strlen (pstate->lexptr); /* See if it is a special token of length 3. */ if (explen > 2) @@ -1141,7 +1141,7 @@ yylex (void) || (!isalpha (tokstart[3]) && !isdigit (tokstart[3]) && tokstart[3] != '_'))) { - lexptr += 3; + pstate->lexptr += 3; yylval.opcode = tokentab3[i].opcode; return tokentab3[i].token; } @@ -1154,7 +1154,7 @@ yylex (void) || (!isalpha (tokstart[2]) && !isdigit (tokstart[2]) && tokstart[2] != '_'))) { - lexptr += 2; + pstate->lexptr += 2; yylval.opcode = tokentab2[i].opcode; return tokentab2[i].token; } @@ -1170,31 +1170,31 @@ yylex (void) case ' ': case '\t': case '\n': - lexptr++; + pstate->lexptr++; goto retry; case '\'': /* We either have a character constant ('0' or '\177' for example) or we have a quoted symbol reference ('foo(int,int)' in object pascal for example). */ - lexptr++; - c = *lexptr++; + pstate->lexptr++; + c = *pstate->lexptr++; if (c == '\\') - c = parse_escape (pstate->gdbarch (), &lexptr); + c = parse_escape (pstate->gdbarch (), &pstate->lexptr); else if (c == '\'') error (_("Empty character constant.")); yylval.typed_val_int.val = c; yylval.typed_val_int.type = parse_type (pstate)->builtin_char; - c = *lexptr++; + c = *pstate->lexptr++; if (c != '\'') { namelen = skip_quoted (tokstart) - tokstart; if (namelen > 2) { - lexptr = tokstart + namelen; - if (lexptr[-1] != '\'') + pstate->lexptr = tokstart + namelen; + if (pstate->lexptr[-1] != '\'') error (_("Unmatched single quote.")); namelen -= 2; tokstart++; @@ -1207,25 +1207,25 @@ yylex (void) case '(': paren_depth++; - lexptr++; + pstate->lexptr++; return c; case ')': if (paren_depth == 0) return 0; paren_depth--; - lexptr++; + pstate->lexptr++; return c; case ',': if (pstate->comma_terminates && paren_depth == 0) return 0; - lexptr++; + pstate->lexptr++; return c; case '.': /* Might be a floating point number. */ - if (lexptr[1] < '0' || lexptr[1] > '9') + if (pstate->lexptr[1] < '0' || pstate->lexptr[1] > '9') { goto symbol; /* Nope, must be a symbol. */ } @@ -1293,7 +1293,7 @@ yylex (void) err_copy[p - tokstart] = 0; error (_("Invalid number \"%s\"."), err_copy); } - lexptr = p; + pstate->lexptr = p; return toktype; } @@ -1317,7 +1317,7 @@ yylex (void) case '{': case '}': symbol: - lexptr++; + pstate->lexptr++; return c; case '"': @@ -1369,7 +1369,7 @@ yylex (void) tempbuf[tempbufindex] = '\0'; /* See note above. */ yylval.sval.ptr = tempbuf; yylval.sval.length = tempbufindex; - lexptr = tokptr; + pstate->lexptr = tokptr; return (STRING); } @@ -1420,7 +1420,7 @@ yylex (void) return 0; } - lexptr += namelen; + pstate->lexptr += namelen; tryname: @@ -1616,7 +1616,7 @@ yylex (void) us whether a type is nested), we just ignore the containing type. */ - p = lexptr; + p = pstate->lexptr; best_sym = sym; while (1) { @@ -1661,7 +1661,7 @@ yylex (void) if (SYMBOL_CLASS (cur_sym) == LOC_TYPEDEF) { best_sym = cur_sym; - lexptr = p; + pstate->lexptr = p; } else break; @@ -1734,8 +1734,8 @@ pascal_parse (struct parser_state *par_state) static void yyerror (const char *msg) { - if (prev_lexptr) - lexptr = prev_lexptr; + if (pstate->prev_lexptr) + pstate->lexptr = pstate->prev_lexptr; - error (_("A %s in expression, near `%s'."), msg, lexptr); + error (_("A %s in expression, near `%s'."), msg, pstate->lexptr); } -- cgit v1.1