From 02c727013cc3ae08b86ad360429f9a0dbdc0ec92 Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Fri, 11 Dec 2020 09:59:15 -0700 Subject: Avoid side effects in expression lexers I noticed that some of the lexers were calling write_dollar_variable from the lexer. This seems like a bad practice, so this patch moves the side effects into the parsers. I tested this by re-running gdb.fortran and gdb.modula2; the Pascal compiler on my machine seems not to work, so I couldn't test gdb.pascal. I note that the type-tracking in the Pascal is also incorrect, in that a convenience variable's type may change between parsing and evaluation (or even during the course of evaluation). gdb/ChangeLog 2020-12-11 Tom Tromey * p-exp.y (intvar): Remove global. (DOLLAR_VARIABLE): Change type. (start): Update. (exp): Call write_dollar_variable here... (yylex): ... not here. * m2-exp.y (DOLLAR_VARIABLE): Change type. (variable): Call write_dollar_variable here... (yylex): ... not here. * f-exp.y (DOLLAR_VARIABLE): Change type. (exp): Call write_dollar_variable here... (yylex): ... not here. --- gdb/f-exp.y | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'gdb/f-exp.y') diff --git a/gdb/f-exp.y b/gdb/f-exp.y index edfbe0cd220..ea32056f6db 100644 --- a/gdb/f-exp.y +++ b/gdb/f-exp.y @@ -174,7 +174,7 @@ static int parse_number (struct parser_state *, const char *, int, %token SINGLE DOUBLE PRECISION %token CHARACTER -%token DOLLAR_VARIABLE +%token DOLLAR_VARIABLE %token ASSIGN_MODIFY %token UNOP_INTRINSIC BINOP_INTRINSIC @@ -509,6 +509,7 @@ exp : variable ; exp : DOLLAR_VARIABLE + { write_dollar_variable (pstate, $1); } ; exp : SIZEOF '(' type ')' %prec UNARY @@ -1357,11 +1358,8 @@ yylex (void) yylval.sval.length = namelen; if (*tokstart == '$') - { - write_dollar_variable (pstate, yylval.sval); - return DOLLAR_VARIABLE; - } - + return DOLLAR_VARIABLE; + /* Use token-type TYPENAME for symbols that happen to be defined currently as names of types; NAME for other symbols. The caller is not constrained to care about the distinction. */ -- cgit v1.2.1