gdb: merge error handling from different expression parsers
Many (all?) of the expression parsers implement yyerror to handle parser errors, and all of these functions are basically identical. This commit adds a new parser_state::parse_error() function, which implements the common error handling code, this function can then be called from all the different yyerror functions. The benefit of this is that (in a future commit) I can improve the error output, and all the expression parsers will benefit. This commit is pure refactoring though, and so, there should be no user visible changes after this commit. Approved-By: John Baldwin <jhb@FreeBSD.org>
This commit is contained in:
+1
-1
@@ -1212,7 +1212,7 @@ ada_parse (struct parser_state *par_state)
|
||||
static void
|
||||
yyerror (const char *msg)
|
||||
{
|
||||
error (_("Error in expression, near `%s'."), pstate->lexptr);
|
||||
pstate->parse_error (msg);
|
||||
}
|
||||
|
||||
/* Emit expression to access an instance of SYM, in block BLOCK (if
|
||||
|
||||
+1
-4
@@ -3482,8 +3482,5 @@ c_print_token (FILE *file, int type, YYSTYPE value)
|
||||
static void
|
||||
yyerror (const char *msg)
|
||||
{
|
||||
if (pstate->prev_lexptr)
|
||||
pstate->lexptr = pstate->prev_lexptr;
|
||||
|
||||
error (_("A %s in expression, near `%s'."), msg, pstate->lexptr);
|
||||
pstate->parse_error (msg);
|
||||
}
|
||||
|
||||
+1
-4
@@ -1631,9 +1631,6 @@ d_parse (struct parser_state *par_state)
|
||||
static void
|
||||
yyerror (const char *msg)
|
||||
{
|
||||
if (pstate->prev_lexptr)
|
||||
pstate->lexptr = pstate->prev_lexptr;
|
||||
|
||||
error (_("A %s in expression, near `%s'."), msg, pstate->lexptr);
|
||||
pstate->parse_error (msg);
|
||||
}
|
||||
|
||||
|
||||
+1
-4
@@ -1736,8 +1736,5 @@ f_language::parser (struct parser_state *par_state) const
|
||||
static void
|
||||
yyerror (const char *msg)
|
||||
{
|
||||
if (pstate->prev_lexptr)
|
||||
pstate->lexptr = pstate->prev_lexptr;
|
||||
|
||||
error (_("A %s in expression, near `%s'."), msg, pstate->lexptr);
|
||||
pstate->parse_error (msg);
|
||||
}
|
||||
|
||||
+1
-4
@@ -1545,8 +1545,5 @@ go_language::parser (struct parser_state *par_state) const
|
||||
static void
|
||||
yyerror (const char *msg)
|
||||
{
|
||||
if (pstate->prev_lexptr)
|
||||
pstate->lexptr = pstate->prev_lexptr;
|
||||
|
||||
error (_("A %s in expression, near `%s'."), msg, pstate->lexptr);
|
||||
pstate->parse_error (msg);
|
||||
}
|
||||
|
||||
+1
-4
@@ -1006,8 +1006,5 @@ m2_language::parser (struct parser_state *par_state) const
|
||||
static void
|
||||
yyerror (const char *msg)
|
||||
{
|
||||
if (pstate->prev_lexptr)
|
||||
pstate->lexptr = pstate->prev_lexptr;
|
||||
|
||||
error (_("A %s in expression, near `%s'."), msg, pstate->lexptr);
|
||||
pstate->parse_error (msg);
|
||||
}
|
||||
|
||||
+1
-4
@@ -1660,8 +1660,5 @@ pascal_language::parser (struct parser_state *par_state) const
|
||||
static void
|
||||
yyerror (const char *msg)
|
||||
{
|
||||
if (pstate->prev_lexptr)
|
||||
pstate->lexptr = pstate->prev_lexptr;
|
||||
|
||||
error (_("A %s in expression, near `%s'."), msg, pstate->lexptr);
|
||||
pstate->parse_error (msg);
|
||||
}
|
||||
|
||||
+11
@@ -244,6 +244,17 @@ parser_state::push_dollar (struct stoken str)
|
||||
(create_internalvar (copy.c_str () + 1));
|
||||
}
|
||||
|
||||
/* See parser-defs.h. */
|
||||
|
||||
void
|
||||
parser_state::parse_error (const char *msg)
|
||||
{
|
||||
if (this->prev_lexptr)
|
||||
this->lexptr = this->prev_lexptr;
|
||||
|
||||
error (_("A %s in expression, near `%s'."), msg, this->lexptr);
|
||||
}
|
||||
|
||||
|
||||
|
||||
const char *
|
||||
|
||||
@@ -262,6 +262,11 @@ struct parser_state : public expr_builder
|
||||
push (expr::make_operation<T> (std::move (lhs), std::move (rhs)));
|
||||
}
|
||||
|
||||
/* Function called from the various parsers' yyerror functions to throw
|
||||
an error. The error will include a message identifying the location
|
||||
of the error within the current expression. */
|
||||
void parse_error (const char *msg);
|
||||
|
||||
/* If this is nonzero, this block is used as the lexical context for
|
||||
symbol names. */
|
||||
|
||||
|
||||
Reference in New Issue
Block a user