C++ PATCH to add RANGE_FOR_INIT_STMT to cxx_pretty_printer

Message ID 20180907194809.GA12638@redhat.com
State New
Headers show
Series
  • C++ PATCH to add RANGE_FOR_INIT_STMT to cxx_pretty_printer
Related show

Commit Message

Marek Polacek Sept. 7, 2018, 7:48 p.m.
Now that we have RANGE_FOR_INIT_STMT we should handle it in cxx_pretty_printer.
I don't actually know how to trigger it but it seems straightforward to add.

Bootstrapped/regtested on x86_64-linux, ok for trunk?

2018-09-07  Marek Polacek  <polacek@redhat.com>

	* cxx-pretty-print.c (cxx_pretty_printer::statement) <case
	RANGE_FOR_SMT>: Handle RANGE_FOR_INIT_STMT.

Comments

Jason Merrill Sept. 8, 2018, 12:06 p.m. | #1
OK.

On Fri, Sep 7, 2018 at 8:48 PM, Marek Polacek <polacek@redhat.com> wrote:
> Now that we have RANGE_FOR_INIT_STMT we should handle it in cxx_pretty_printer.

> I don't actually know how to trigger it but it seems straightforward to add.

>

> Bootstrapped/regtested on x86_64-linux, ok for trunk?

>

> 2018-09-07  Marek Polacek  <polacek@redhat.com>

>

>         * cxx-pretty-print.c (cxx_pretty_printer::statement) <case

>         RANGE_FOR_SMT>: Handle RANGE_FOR_INIT_STMT.

>

> diff --git gcc/cp/cxx-pretty-print.c gcc/cp/cxx-pretty-print.c

> index df81aa37ce8..8426c7246de 100644

> --- gcc/cp/cxx-pretty-print.c

> +++ gcc/cp/cxx-pretty-print.c

> @@ -2021,6 +2021,12 @@ cxx_pretty_printer::statement (tree t)

>        pp_cxx_ws_string (this, "for");

>        pp_space (this);

>        pp_cxx_left_paren (this);

> +      if (RANGE_FOR_INIT_STMT (t))

> +       {

> +         statement (RANGE_FOR_INIT_STMT (t));

> +         pp_needs_newline (this) = false;

> +         pp_cxx_whitespace (this);

> +       }

>        statement (RANGE_FOR_DECL (t));

>        pp_space (this);

>        pp_needs_newline (this) = false;

Patch

diff --git gcc/cp/cxx-pretty-print.c gcc/cp/cxx-pretty-print.c
index df81aa37ce8..8426c7246de 100644
--- gcc/cp/cxx-pretty-print.c
+++ gcc/cp/cxx-pretty-print.c
@@ -2021,6 +2021,12 @@  cxx_pretty_printer::statement (tree t)
       pp_cxx_ws_string (this, "for");
       pp_space (this);
       pp_cxx_left_paren (this);
+      if (RANGE_FOR_INIT_STMT (t))
+	{
+	  statement (RANGE_FOR_INIT_STMT (t));
+	  pp_needs_newline (this) = false;
+	  pp_cxx_whitespace (this);
+	}
       statement (RANGE_FOR_DECL (t));
       pp_space (this);
       pp_needs_newline (this) = false;