[RFA,1/4] Remove make_cleanup_clear_parser_state
Commit Message
This removes make_cleanup_clear_parser_state in favor of
scoped_restore.
ChangeLog
2017-09-05 Tom Tromey <tom@tromey.com>
* utils.c (do_clear_parser_state): Remove.
(make_cleanup_clear_parser_state): Remove.
* p-exp.y (pascal_parse): Use scoped_restore.
* m2-exp.y (m2_parse): Use scoped_restore.
* f-exp.y (f_parse): Use scoped_restore.
* d-exp.y (d_parse): Use scoped_restore.
* c-exp.y (c_parse): Use scoped_restore.
* ada-exp.y (ada_parse): Use scoped_restore.
* utils.h (make_cleanup_clear_parser_state): Remove.
---
gdb/ChangeLog | 12 ++++++++++++
gdb/ada-exp.y | 8 ++------
gdb/c-exp.y | 2 +-
gdb/d-exp.y | 2 +-
gdb/f-exp.y | 3 +--
gdb/go-exp.y | 2 +-
gdb/m2-exp.y | 9 ++-------
gdb/p-exp.y | 8 ++------
gdb/utils.c | 18 ------------------
gdb/utils.h | 4 ----
10 files changed, 22 insertions(+), 46 deletions(-)
Comments
On 09/06/2017 06:13 AM, Tom Tromey wrote:
> f_parse (struct parser_state *par_state)
> {
> int result;
> - struct cleanup *c = make_cleanup_clear_parser_state (&pstate);
>
> /* Setting up the parser state. */
> + scoped_restore pstate_restore = make_scoped_restore (&pstate);
> gdb_assert (par_state != NULL);
> pstate = par_state;
>
> result = yyparse ();
> - do_cleanups (c);
> return result;
You could remove "result" here too.
Otherwise looks fine to me, thanks!
Pedro Alves
@@ -1,3 +1,15 @@
+2017-09-05 Tom Tromey <tom@tromey.com>
+
+ * utils.c (do_clear_parser_state): Remove.
+ (make_cleanup_clear_parser_state): Remove.
+ * p-exp.y (pascal_parse): Use scoped_restore.
+ * m2-exp.y (m2_parse): Use scoped_restore.
+ * f-exp.y (f_parse): Use scoped_restore.
+ * d-exp.y (d_parse): Use scoped_restore.
+ * c-exp.y (c_parse): Use scoped_restore.
+ * ada-exp.y (ada_parse): Use scoped_restore.
+ * utils.h (make_cleanup_clear_parser_state): Remove.
+
2017-09-05 Philippe Waroquiers <philippe.waroquiers@skynet.be>
* objfiles.c (get_objfile_bfd_data): Remove useless obstack_init
@@ -733,10 +733,8 @@ static struct obstack temp_parse_space;
int
ada_parse (struct parser_state *par_state)
{
- int result;
- struct cleanup *c = make_cleanup_clear_parser_state (&pstate);
-
/* Setting up the parser state. */
+ scoped_restore pstate_restore = make_scoped_restore (&pstate);
gdb_assert (par_state != NULL);
pstate = par_state;
@@ -745,9 +743,7 @@ ada_parse (struct parser_state *par_state)
obstack_free (&temp_parse_space, NULL);
obstack_init (&temp_parse_space);
- result = yyparse ();
- do_cleanups (c);
- return result;
+ return yyparse ();
}
void
@@ -3232,6 +3232,7 @@ c_parse (struct parser_state *par_state)
struct cleanup *back_to;
/* Setting up the parser state. */
+ scoped_restore pstate_restore = make_scoped_restore (&pstate);
gdb_assert (par_state != NULL);
pstate = par_state;
@@ -3239,7 +3240,6 @@ c_parse (struct parser_state *par_state)
assuming they'll be run here (below). */
back_to = make_cleanup (free_current_contents, &expression_macro_scope);
- make_cleanup_clear_parser_state (&pstate);
/* Set up the scope for macro expansion. */
expression_macro_scope = NULL;
@@ -1624,6 +1624,7 @@ d_parse (struct parser_state *par_state)
struct cleanup *back_to;
/* Setting up the parser state. */
+ scoped_restore pstate_restore = make_scoped_restore (&pstate);
gdb_assert (par_state != NULL);
pstate = par_state;
@@ -1633,7 +1634,6 @@ d_parse (struct parser_state *par_state)
scoped_restore restore_yydebug = make_scoped_restore (&yydebug,
parser_debug);
- make_cleanup_clear_parser_state (&pstate);
/* Initialize some state used by the lexer. */
last_was_structop = 0;
@@ -1207,14 +1207,13 @@ int
f_parse (struct parser_state *par_state)
{
int result;
- struct cleanup *c = make_cleanup_clear_parser_state (&pstate);
/* Setting up the parser state. */
+ scoped_restore pstate_restore = make_scoped_restore (&pstate);
gdb_assert (par_state != NULL);
pstate = par_state;
result = yyparse ();
- do_cleanups (c);
return result;
}
@@ -1564,6 +1564,7 @@ go_parse (struct parser_state *par_state)
struct cleanup *back_to;
/* Setting up the parser state. */
+ scoped_restore pstate_restore = make_scoped_restore (&pstate);
gdb_assert (par_state != NULL);
pstate = par_state;
@@ -1573,7 +1574,6 @@ go_parse (struct parser_state *par_state)
scoped_restore restore_yydebug = make_scoped_restore (&yydebug,
parser_debug);
- make_cleanup_clear_parser_state (&pstate);
/* Initialize some state used by the lexer. */
last_was_structop = 0;
@@ -1036,17 +1036,12 @@ yylex (void)
int
m2_parse (struct parser_state *par_state)
{
- int result;
- struct cleanup *c = make_cleanup_clear_parser_state (&pstate);
-
/* Setting up the parser state. */
+ scoped_restore pstate_restore = make_scoped_restore (&pstate);
gdb_assert (par_state != NULL);
pstate = par_state;
- result = yyparse ();
- do_cleanups (c);
-
- return result;
+ return yyparse ();
}
void
@@ -1701,16 +1701,12 @@ yylex (void)
int
pascal_parse (struct parser_state *par_state)
{
- int result;
- struct cleanup *c = make_cleanup_clear_parser_state (&pstate);
-
/* Setting up the parser state. */
+ scoped_restore pstate_restore = make_scoped_restore (&pstate);
gdb_assert (par_state != NULL);
pstate = par_state;
- result = yyparse ();
- do_cleanups (c);
- return result;
+ return yyparse ();
}
void
@@ -257,24 +257,6 @@ make_cleanup_value_free (struct value *value)
return make_cleanup (do_value_free, value);
}
-/* Helper function for make_cleanup_clear_parser_state. */
-
-static void
-do_clear_parser_state (void *ptr)
-{
- struct parser_state **p = (struct parser_state **) ptr;
-
- *p = NULL;
-}
-
-/* Clean (i.e., set to NULL) the parser state variable P. */
-
-struct cleanup *
-make_cleanup_clear_parser_state (struct parser_state **p)
-{
- return make_cleanup (do_clear_parser_state, (void *) p);
-}
-
/* This function is useful for cleanups.
Do
@@ -236,10 +236,6 @@ struct htab_deleter
/* A unique_ptr wrapper for htab_t. */
typedef std::unique_ptr<htab, htab_deleter> htab_up;
-struct parser_state;
-extern struct cleanup *make_cleanup_clear_parser_state
- (struct parser_state **p);
-
extern void free_current_contents (void *);
extern void init_page_info (void);