diff mbox series

[RFA,(print-tree)] c++: improve print_node of PTRMEM_CST

Message ID 20211104155234.1945303-1-jason@redhat.com
State New
Headers show
Series [RFA,(print-tree)] c++: improve print_node of PTRMEM_CST | expand

Commit Message

Jason Merrill Nov. 4, 2021, 3:52 p.m. UTC
It's been inconvenient that pretty-printing of PTRMEM_CST didn't display
what member the constant refers to.

Adding that is complicated by the absence of a langhook for CONSTANT_CLASS_P
nodes; the simplest fix for that is to use the tcc_exceptional hook for
tcc_constant as well.

Tested x86_64-pc-linux-gnu.  OK for trunk, or should I add a new hook for
constants?

gcc/cp/ChangeLog:

	* ptree.c (cxx_print_xnode): Handle PTRMEM_CST.

gcc/ChangeLog:

	* print-tree.c (print_node): Also call print_xnode hook for
	tcc_constant class.
---
 gcc/cp/ptree.c   | 3 +++
 gcc/print-tree.c | 3 +--
 2 files changed, 4 insertions(+), 2 deletions(-)


base-commit: fae00a0ac0e5687343a60ae02bf60352002ab9aa

Comments

Jakub Jelinek Nov. 4, 2021, 8:32 p.m. UTC | #1
On Thu, Nov 04, 2021 at 11:52:34AM -0400, Jason Merrill via Gcc-patches wrote:
> It's been inconvenient that pretty-printing of PTRMEM_CST didn't display
> what member the constant refers to.
> 
> Adding that is complicated by the absence of a langhook for CONSTANT_CLASS_P
> nodes; the simplest fix for that is to use the tcc_exceptional hook for
> tcc_constant as well.
> 
> Tested x86_64-pc-linux-gnu.  OK for trunk, or should I add a new hook for
> constants?
> 
> gcc/cp/ChangeLog:
> 
> 	* ptree.c (cxx_print_xnode): Handle PTRMEM_CST.
> 
> gcc/ChangeLog:
> 
> 	* print-tree.c (print_node): Also call print_xnode hook for
> 	tcc_constant class.

I think using the same langhook is fine, but in that case certainly
  /* Called by print_tree when there is a tree of class tcc_exceptional
     that it doesn't know how to display.  */
should be adjusted so that it mentions also tcc_constant.
And maybe rename it from print_xnode to print_node?

	Jakub
diff mbox series

Patch

diff --git a/gcc/cp/ptree.c b/gcc/cp/ptree.c
index 1dcd764af01..9e981d656e3 100644
--- a/gcc/cp/ptree.c
+++ b/gcc/cp/ptree.c
@@ -379,6 +379,9 @@  cxx_print_xnode (FILE *file, tree node, int indent)
       if (tree message = STATIC_ASSERT_MESSAGE (node))
 	print_node (file, "message", message, indent+4);
       break;
+    case PTRMEM_CST:
+      print_node (file, "member", PTRMEM_CST_MEMBER (node), indent+4);
+      break;
     default:
       break;
     }
diff --git a/gcc/print-tree.c b/gcc/print-tree.c
index d1fbd044c27..b5dc523fcb1 100644
--- a/gcc/print-tree.c
+++ b/gcc/print-tree.c
@@ -1004,8 +1004,7 @@  print_node (FILE *file, const char *prefix, tree node, int indent,
 	  break;
 
 	default:
-	  if (EXCEPTIONAL_CLASS_P (node))
-	    lang_hooks.print_xnode (file, node, indent);
+	  lang_hooks.print_xnode (file, node, indent);
 	  break;
 	}