Patchwork Clean up pretty printers [16/n]

login
register
mail settings
Submitter Gabriel Dos Reis
Date Aug. 25, 2013, 6:16 p.m.
Message ID <87ppt11vr4.fsf@euclid.axiomatics.org>
Download mbox | patch
Permalink /patch/269719/
State New
Headers show

Comments

Gabriel Dos Reis - Aug. 25, 2013, 6:16 p.m.
Same topic as patch 14/n.  This time for primary_expression.

-- Gaby

2013-08-25  Gabriel Dos Reis  <gdr@integrable-solutions.net>
 
c-family/
	* c-pretty-print.h (c_pretty_printer::primary_expression): Now a
	virtua member function.
	(pp_primary_expression): Adjust.
	(pp_c_primary_expression): Remove.
	* c-pretty-print.c (c_pretty_printer::primary_expression): Rename
	from pp_c_primary_expression.  Adjust.
	(pp_c_initializer_list): Use pp_primary_expression.
	(c_pretty_printer::c_pretty_printer): Do not assign to
	primary_expression.

cp/
	* cxx-pretty-print.h (cxx_pretty_printer::primary_expression): Now
	an overrider of c_pretty_printer::primary_expression.
	* cxx-pretty-print.c (cxx_pretty_printer::primary_expression):
	Rename from pp_cxx_primary_expression.  Adjust.
	(pp_cxx_postfix_expression): Use pp_primary_expression.
	(pp_cxx_ctor_initializer): Likewise.
	(cxx_pretty_printer::cxx_pretty_printer): Do not assign to
	primary_expression.

Patch

Index: c-family/c-pretty-print.c
===================================================================
--- c-family/c-pretty-print.c	(revision 201977)
+++ c-family/c-pretty-print.c	(working copy)
@@ -1212,7 +1212,7 @@ 
       ( expression )   */
 
 void
-pp_c_primary_expression (c_pretty_printer *pp, tree e)
+c_pretty_printer::primary_expression (tree e)
 {
   switch (TREE_CODE (e))
     {
@@ -1222,49 +1222,49 @@ 
     case CONST_DECL:
     case FUNCTION_DECL:
     case LABEL_DECL:
-      pp_c_tree_decl_identifier (pp, e);
+      pp_c_tree_decl_identifier (this, e);
       break;
 
     case IDENTIFIER_NODE:
-      pp_c_tree_identifier (pp, e);
+      pp_c_tree_identifier (this, e);
       break;
 
     case ERROR_MARK:
-      pp->translate_string ("<erroneous-expression>");
+      translate_string ("<erroneous-expression>");
       break;
 
     case RESULT_DECL:
-      pp->translate_string ("<return-value>");
+      translate_string ("<return-value>");
       break;
 
     case INTEGER_CST:
     case REAL_CST:
     case FIXED_CST:
     case STRING_CST:
-      pp_constant (pp, e);
+      constant (e);
       break;
 
     case TARGET_EXPR:
-      pp_c_ws_string (pp, "__builtin_memcpy");
-      pp_c_left_paren (pp);
-      pp_ampersand (pp);
-      pp_primary_expression (pp, TREE_OPERAND (e, 0));
-      pp_separate_with (pp, ',');
-      pp_ampersand (pp);
-      pp_initializer (pp, TREE_OPERAND (e, 1));
+      pp_c_ws_string (this, "__builtin_memcpy");
+      pp_c_left_paren (this);
+      pp_ampersand (this);
+      primary_expression (TREE_OPERAND (e, 0));
+      pp_separate_with (this, ',');
+      pp_ampersand (this);
+      pp_initializer (this, TREE_OPERAND (e, 1));
       if (TREE_OPERAND (e, 2))
 	{
-	  pp_separate_with (pp, ',');
-	  pp_c_expression (pp, TREE_OPERAND (e, 2));
+	  pp_separate_with (this, ',');
+	  pp_c_expression (this, TREE_OPERAND (e, 2));
 	}
-      pp_c_right_paren (pp);
+      pp_c_right_paren (this);
       break;
 
     default:
       /* FIXME:  Make sure we won't get into an infinite loop.  */
-      pp_c_left_paren (pp);
-      pp_expression (pp, e);
-      pp_c_right_paren (pp);
+      pp_c_left_paren (this);
+      pp_expression (this, e);
+      pp_c_right_paren (this);
       break;
     }
 }
@@ -1356,7 +1356,7 @@ 
 	    if (code == RECORD_TYPE || code == UNION_TYPE)
 	      {
 		pp_c_dot (pp);
-		pp_c_primary_expression (pp, TREE_PURPOSE (init));
+		pp_primary_expression (pp, TREE_PURPOSE (init));
 	      }
 	    else
 	      {
@@ -2119,7 +2119,7 @@ 
   Implementation note:  instead of going through the usual recursion
   chain, I take the liberty of dispatching nodes to the appropriate
   functions.  This makes some redundancy, but it worths it. That also
-  prevents a possible infinite recursion between pp_c_primary_expression ()
+  prevents a possible infinite recursion between pp_primary_expression ()
   and pp_c_expression ().  */
 
 void
@@ -2344,7 +2344,6 @@ 
 
   statement                 = pp_c_statement;
 
-  primary_expression        = pp_c_primary_expression;
   postfix_expression        = pp_c_postfix_expression;
   unary_expression          = pp_c_unary_expression;
   initializer               = pp_c_initializer;
Index: c-family/c-pretty-print.h
===================================================================
--- c-family/c-pretty-print.h	(revision 201977)
+++ c-family/c-pretty-print.h	(working copy)
@@ -56,6 +56,7 @@ 
 
   virtual void constant (tree);
   virtual void id_expression (tree);
+  virtual void primary_expression (tree);
   /* Points to the first element of an array of offset-list.
      Not used yet.  */
   int *offset_list;
@@ -81,7 +82,6 @@ 
 
   c_pretty_print_fn statement;
 
-  c_pretty_print_fn primary_expression;
   c_pretty_print_fn postfix_expression;
   c_pretty_print_fn unary_expression;
   c_pretty_print_fn multiplicative_expression;
@@ -114,7 +114,7 @@ 
 
 #define pp_constant(PP, E)              (PP)->constant (E)
 #define pp_id_expression(PP, E)         (PP)->id_expression (E)
-#define pp_primary_expression(PP, E)    (PP)->primary_expression (PP, E)
+#define pp_primary_expression(PP, E)    (PP)->primary_expression (E)
 #define pp_postfix_expression(PP, E)    (PP)->postfix_expression (PP, E)
 #define pp_unary_expression(PP, E)      (PP)->unary_expression (PP, E)
 #define pp_initializer(PP, E)           (PP)->initializer (PP, E)
@@ -170,7 +170,6 @@ 
 void pp_c_unary_expression (c_pretty_printer *, tree);
 void pp_c_cast_expression (c_pretty_printer *, tree);
 void pp_c_postfix_expression (c_pretty_printer *, tree);
-void pp_c_primary_expression (c_pretty_printer *, tree);
 void pp_c_init_declarator (c_pretty_printer *, tree);
 void pp_c_ws_string (c_pretty_printer *, const char *);
 void pp_c_identifier (c_pretty_printer *, const char *);
Index: cp/cxx-pretty-print.c
===================================================================
--- cp/cxx-pretty-print.c	(revision 201977)
+++ cp/cxx-pretty-print.c	(working copy)
@@ -407,8 +407,8 @@ 
      __is_trivial ( type-id )
      __is_union ( type-id )  */
 
-static void
-pp_cxx_primary_expression (cxx_pretty_printer *pp, tree t)
+void
+cxx_pretty_printer::primary_expression (tree t)
 {
   switch (TREE_CODE (t))
     {
@@ -416,11 +416,11 @@ 
     case REAL_CST:
     case COMPLEX_CST:
     case STRING_CST:
-      pp_constant (pp, t);
+      constant (t);
       break;
 
     case USERDEF_LITERAL:
-      pp_cxx_userdef_literal (pp, t);
+      pp_cxx_userdef_literal (this, t);
       break;
 
     case BASELINK:
@@ -432,36 +432,36 @@ 
     case OVERLOAD:
     case CONST_DECL:
     case TEMPLATE_DECL:
-      pp_id_expression (pp, t);
+      id_expression (t);
       break;
 
     case RESULT_DECL:
     case TEMPLATE_TYPE_PARM:
     case TEMPLATE_TEMPLATE_PARM:
     case TEMPLATE_PARM_INDEX:
-      pp_cxx_unqualified_id (pp, t);
+      pp_cxx_unqualified_id (this, t);
       break;
 
     case STMT_EXPR:
-      pp_cxx_left_paren (pp);
-      pp_cxx_statement (pp, STMT_EXPR_STMT (t));
-      pp_cxx_right_paren (pp);
+      pp_cxx_left_paren (this);
+      pp_cxx_statement (this, STMT_EXPR_STMT (t));
+      pp_cxx_right_paren (this);
       break;
 
     case TRAIT_EXPR:
-      pp_cxx_trait_expression (pp, t);
+      pp_cxx_trait_expression (this, t);
       break;
 
     case VA_ARG_EXPR:
-      pp_cxx_va_arg_expression (pp, t);
+      pp_cxx_va_arg_expression (this, t);
       break;
 
     case OFFSETOF_EXPR:
-      pp_cxx_offsetof_expression (pp, t);
+      pp_cxx_offsetof_expression (this, t);
       break;
 
     default:
-      pp_c_primary_expression (pp, t);
+      c_pretty_printer::primary_expression (t);
       break;
     }
 }
@@ -591,7 +591,7 @@ 
     case CONST_DECL:
     case TEMPLATE_DECL:
     case RESULT_DECL:
-      pp_cxx_primary_expression (pp, t);
+      pp_primary_expression (pp, t);
       break;
 
     case DYNAMIC_CAST_EXPR:
@@ -1069,7 +1069,7 @@ 
     case TEMPLATE_PARM_INDEX:
     case TEMPLATE_TEMPLATE_PARM:
     case STMT_EXPR:
-      pp_cxx_primary_expression (pp, t);
+      pp_primary_expression (pp, t);
       break;
 
     case CALL_EXPR:
@@ -1608,9 +1608,9 @@ 
       bool is_pack = PACK_EXPANSION_P (purpose);
 
       if (is_pack)
-	pp_cxx_primary_expression (pp, PACK_EXPANSION_PATTERN (purpose));
+	pp_primary_expression (pp, PACK_EXPANSION_PATTERN (purpose));
       else
-	pp_cxx_primary_expression (pp, purpose);
+	pp_primary_expression (pp, purpose);
       pp_cxx_call_argument_list (pp, TREE_VALUE (t));
       if (is_pack)
 	pp_cxx_ws_string (pp, "...");
@@ -2448,7 +2448,6 @@ 
 
   /* pp->statement = (pp_fun) pp_cxx_statement;  */
 
-  primary_expression = (pp_fun) pp_cxx_primary_expression;
   postfix_expression = (pp_fun) pp_cxx_postfix_expression;
   unary_expression = (pp_fun) pp_cxx_unary_expression;
   multiplicative_expression = (pp_fun) pp_cxx_multiplicative_expression;
Index: cp/cxx-pretty-print.h
===================================================================
--- cp/cxx-pretty-print.h	(revision 201977)
+++ cp/cxx-pretty-print.h	(working copy)
@@ -35,6 +35,7 @@ 
 
   void constant (tree);
   void id_expression (tree);
+  void primary_expression (tree);
   /* This is the enclosing scope of the entity being pretty-printed.  */
   tree enclosing_scope;
 };