Patchwork Clean up pretty printers [17/n]

login
register
mail settings
Submitter Gabriel Dos Reis
Date Aug. 26, 2013, 3:15 a.m.
Message ID <87haed87mf.fsf@euclid.axiomatics.org>
Download mbox | patch
Permalink /patch/269801/
State New
Headers show

Comments

Gabriel Dos Reis - Aug. 26, 2013, 3:15 a.m.
Same topic as patch 15/n, but postfix_expression.
Tested on an x86_64-suse-linux.  Applied to mainline.

-- Gaby

2013-08-25  Gabriel Dos Reis  <gdr@integrable-solutions.net>
 
c-family/
	* c-pretty-print.h (c_pretty_printer::postfix_expression): Now a
	virtual member function.
	(pp_postfix_expression): Adjust.
	(pp_c_postfix_expression): Remove.
	* c-pretty-print.c (c_pretty_printer::postfix_expression): Rename
	from pp_c_postfix_expression.  Adjust.
	(c_pretty_printer::c_pretty_printer): Do not assign to
	postfix_expression.

cp/
	* cxx-pretty-print.h (cxx_pretty_printer::postfix_expression):
	Declare as overrider.
	* cxx-pretty-print.c (cxx_pretty_printer::postfix_expression):
	Rename from pp_cxx_postfix_expression.  Adjust.
	(pp_cxx_expression): Use pp_postfix_expression.
	(cxx_pretty_printer::cxx_pretty_printer): Do not assign to
	postfix_expression.

Patch

Index: c-family/c-pretty-print.c
===================================================================
--- c-family/c-pretty-print.c	(revision 201984)
+++ c-family/c-pretty-print.c	(working copy)
@@ -1463,112 +1463,112 @@ 
       ( type-name ) { initializer-list , }  */
 
 void
-pp_c_postfix_expression (c_pretty_printer *pp, tree e)
+c_pretty_printer::postfix_expression (tree e)
 {
   enum tree_code code = TREE_CODE (e);
   switch (code)
     {
     case POSTINCREMENT_EXPR:
     case POSTDECREMENT_EXPR:
-      pp_postfix_expression (pp, TREE_OPERAND (e, 0));
-      pp_string (pp, code == POSTINCREMENT_EXPR ? "++" : "--");
+      postfix_expression (TREE_OPERAND (e, 0));
+      pp_string (this, code == POSTINCREMENT_EXPR ? "++" : "--");
       break;
 
     case ARRAY_REF:
-      pp_postfix_expression (pp, TREE_OPERAND (e, 0));
-      pp_c_left_bracket (pp);
-      pp_expression (pp, TREE_OPERAND (e, 1));
-      pp_c_right_bracket (pp);
+      postfix_expression (TREE_OPERAND (e, 0));
+      pp_c_left_bracket (this);
+      pp_expression (this, TREE_OPERAND (e, 1));
+      pp_c_right_bracket (this);
       break;
 
     case ARRAY_NOTATION_REF:
-      pp_postfix_expression (pp, ARRAY_NOTATION_ARRAY (e));
-      pp_c_left_bracket (pp);
-      pp_expression (pp, ARRAY_NOTATION_START (e));
-      pp_colon (pp);
-      pp_expression (pp, ARRAY_NOTATION_LENGTH (e));
-      pp_colon (pp);
-      pp_expression (pp, ARRAY_NOTATION_STRIDE (e));
-      pp_c_right_bracket (pp);
+      postfix_expression (ARRAY_NOTATION_ARRAY (e));
+      pp_c_left_bracket (this);
+      pp_expression (this, ARRAY_NOTATION_START (e));
+      pp_colon (this);
+      pp_expression (this, ARRAY_NOTATION_LENGTH (e));
+      pp_colon (this);
+      pp_expression (this, ARRAY_NOTATION_STRIDE (e));
+      pp_c_right_bracket (this);
       break;
       
     case CALL_EXPR:
       {
 	call_expr_arg_iterator iter;
 	tree arg;
-	pp_postfix_expression (pp, CALL_EXPR_FN (e));
-	pp_c_left_paren (pp);
+	postfix_expression (CALL_EXPR_FN (e));
+	pp_c_left_paren (this);
 	FOR_EACH_CALL_EXPR_ARG (arg, iter, e)
 	  {
-	    pp_expression (pp, arg);
+	    pp_expression (this, arg);
 	    if (more_call_expr_args_p (&iter))
-	      pp_separate_with (pp, ',');
+	      pp_separate_with (this, ',');
 	  }
-	pp_c_right_paren (pp);
+	pp_c_right_paren (this);
 	break;
       }
 
     case UNORDERED_EXPR:
-      pp_c_ws_string (pp, flag_isoc99
+      pp_c_ws_string (this, flag_isoc99
 			   ? "isunordered"
 			   : "__builtin_isunordered");
       goto two_args_fun;
 
     case ORDERED_EXPR:
-      pp_c_ws_string (pp, flag_isoc99
+      pp_c_ws_string (this, flag_isoc99
 			   ? "!isunordered"
 			   : "!__builtin_isunordered");
       goto two_args_fun;
 
     case UNLT_EXPR:
-      pp_c_ws_string (pp, flag_isoc99
+      pp_c_ws_string (this, flag_isoc99
 			   ? "!isgreaterequal"
 			   : "!__builtin_isgreaterequal");
       goto two_args_fun;
 
     case UNLE_EXPR:
-      pp_c_ws_string (pp, flag_isoc99
+      pp_c_ws_string (this, flag_isoc99
 			   ? "!isgreater"
 			   : "!__builtin_isgreater");
       goto two_args_fun;
 
     case UNGT_EXPR:
-      pp_c_ws_string (pp, flag_isoc99
+      pp_c_ws_string (this, flag_isoc99
 			   ? "!islessequal"
 			   : "!__builtin_islessequal");
       goto two_args_fun;
 
     case UNGE_EXPR:
-      pp_c_ws_string (pp, flag_isoc99
+      pp_c_ws_string (this, flag_isoc99
 			   ? "!isless"
 			   : "!__builtin_isless");
       goto two_args_fun;
 
     case UNEQ_EXPR:
-      pp_c_ws_string (pp, flag_isoc99
+      pp_c_ws_string (this, flag_isoc99
 			   ? "!islessgreater"
 			   : "!__builtin_islessgreater");
       goto two_args_fun;
 
     case LTGT_EXPR:
-      pp_c_ws_string (pp, flag_isoc99
+      pp_c_ws_string (this, flag_isoc99
 			   ? "islessgreater"
 			   : "__builtin_islessgreater");
       goto two_args_fun;
 
     two_args_fun:
-      pp_c_left_paren (pp);
-      pp_expression (pp, TREE_OPERAND (e, 0));
-      pp_separate_with (pp, ',');
-      pp_expression (pp, TREE_OPERAND (e, 1));
-      pp_c_right_paren (pp);
+      pp_c_left_paren (this);
+      pp_expression (this, TREE_OPERAND (e, 0));
+      pp_separate_with (this, ',');
+      pp_expression (this, TREE_OPERAND (e, 1));
+      pp_c_right_paren (this);
       break;
 
     case ABS_EXPR:
-      pp_c_ws_string (pp, "__builtin_abs");
-      pp_c_left_paren (pp);
-      pp_expression (pp, TREE_OPERAND (e, 0));
-      pp_c_right_paren (pp);
+      pp_c_ws_string (this, "__builtin_abs");
+      pp_c_left_paren (this);
+      pp_expression (this, TREE_OPERAND (e, 0));
+      pp_c_right_paren (this);
       break;
 
     case COMPONENT_REF:
@@ -1576,15 +1576,15 @@ 
 	tree object = TREE_OPERAND (e, 0);
 	if (TREE_CODE (object) == INDIRECT_REF)
 	  {
-	    pp_postfix_expression (pp, TREE_OPERAND (object, 0));
-	    pp_c_arrow (pp);
+	    postfix_expression (TREE_OPERAND (object, 0));
+	    pp_c_arrow (this);
 	  }
 	else
 	  {
-	    pp_postfix_expression (pp, object);
-	    pp_c_dot (pp);
+	    postfix_expression (object);
+	    pp_c_dot (this);
 	  }
-	pp_expression (pp, TREE_OPERAND (e, 1));
+	pp_expression (this, TREE_OPERAND (e, 1));
       }
       break;
 
@@ -1600,63 +1600,63 @@ 
 	    HOST_WIDE_INT size = tree_low_cst (TYPE_SIZE (type), 0);
 	    if ((bitpos % size) == 0)
 	      {
-		pp_c_left_paren (pp);
-		pp_c_left_paren (pp);
-		pp_type_id (pp, type);
-		pp_c_star (pp);
-		pp_c_right_paren (pp);
-		pp_c_ampersand (pp);
-		pp_expression (pp, TREE_OPERAND (e, 0));
-		pp_c_right_paren (pp);
-		pp_c_left_bracket (pp);
-		pp_wide_integer (pp, bitpos / size);
-		pp_c_right_bracket (pp);
+		pp_c_left_paren (this);
+		pp_c_left_paren (this);
+		pp_type_id (this, type);
+		pp_c_star (this);
+		pp_c_right_paren (this);
+		pp_c_ampersand (this);
+		pp_expression (this, TREE_OPERAND (e, 0));
+		pp_c_right_paren (this);
+		pp_c_left_bracket (this);
+		pp_wide_integer (this, bitpos / size);
+		pp_c_right_bracket (this);
 		break;
 	      }
 	  }
-	pp_unsupported_tree (pp, e);
+	pp_unsupported_tree (this, e);
       }
       break;
 
     case MEM_REF:
-      pp_c_expression (pp, e);
+      pp_c_expression (this, e);
       break;
 
     case COMPLEX_CST:
     case VECTOR_CST:
-      pp_c_compound_literal (pp, e);
+      pp_c_compound_literal (this, e);
       break;
 
     case COMPLEX_EXPR:
-      pp_c_complex_expr (pp, e);
+      pp_c_complex_expr (this, e);
       break;
 
     case COMPOUND_LITERAL_EXPR:
       e = DECL_INITIAL (COMPOUND_LITERAL_EXPR_DECL (e));
       /* Fall through.  */
     case CONSTRUCTOR:
-      pp_initializer (pp, e);
+      pp_initializer (this, e);
       break;
 
     case VA_ARG_EXPR:
-      pp_c_ws_string (pp, "__builtin_va_arg");
-      pp_c_left_paren (pp);
-      pp_assignment_expression (pp, TREE_OPERAND (e, 0));
-      pp_separate_with (pp, ',');
-      pp_type_id (pp, TREE_TYPE (e));
-      pp_c_right_paren (pp);
+      pp_c_ws_string (this, "__builtin_va_arg");
+      pp_c_left_paren (this);
+      pp_assignment_expression (this, TREE_OPERAND (e, 0));
+      pp_separate_with (this, ',');
+      pp_type_id (this, TREE_TYPE (e));
+      pp_c_right_paren (this);
       break;
 
     case ADDR_EXPR:
       if (TREE_CODE (TREE_OPERAND (e, 0)) == FUNCTION_DECL)
 	{
-          pp_id_expression (pp, TREE_OPERAND (e, 0));
+          id_expression (TREE_OPERAND (e, 0));
 	  break;
 	}
       /* else fall through.  */
 
     default:
-      pp_primary_expression (pp, e);
+      primary_expression (e);
       break;
     }
 }
@@ -2344,7 +2344,6 @@ 
 
   statement                 = pp_c_statement;
 
-  postfix_expression        = pp_c_postfix_expression;
   unary_expression          = pp_c_unary_expression;
   initializer               = pp_c_initializer;
   multiplicative_expression = pp_c_multiplicative_expression;
Index: c-family/c-pretty-print.h
===================================================================
--- c-family/c-pretty-print.h	(revision 201984)
+++ c-family/c-pretty-print.h	(working copy)
@@ -57,6 +57,7 @@ 
   virtual void constant (tree);
   virtual void id_expression (tree);
   virtual void primary_expression (tree);
+  virtual void postfix_expression (tree);
   /* Points to the first element of an array of offset-list.
      Not used yet.  */
   int *offset_list;
@@ -82,7 +83,6 @@ 
 
   c_pretty_print_fn statement;
 
-  c_pretty_print_fn postfix_expression;
   c_pretty_print_fn unary_expression;
   c_pretty_print_fn multiplicative_expression;
   c_pretty_print_fn conditional_expression;
@@ -115,7 +115,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 (E)
-#define pp_postfix_expression(PP, E)    (PP)->postfix_expression (PP, E)
+#define pp_postfix_expression(PP, E)    (PP)->postfix_expression (E)
 #define pp_unary_expression(PP, E)      (PP)->unary_expression (PP, E)
 #define pp_initializer(PP, E)           (PP)->initializer (PP, E)
 #define pp_multiplicative_expression(PP, E)      \
@@ -169,7 +169,6 @@ 
 void pp_c_call_argument_list (c_pretty_printer *, tree);
 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_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 201984)
+++ cp/cxx-pretty-print.c	(working copy)
@@ -487,8 +487,8 @@ 
      typeid ( expression )
      typeid ( type-id )  */
 
-static void
-pp_cxx_postfix_expression (cxx_pretty_printer *pp, tree t)
+void
+cxx_pretty_printer::postfix_expression (tree t)
 {
   enum tree_code code = TREE_CODE (t);
 
@@ -499,7 +499,7 @@ 
       {
 	tree fun = (code == AGGR_INIT_EXPR ? AGGR_INIT_EXPR_FN (t)
 					   : CALL_EXPR_FN (t));
-	tree saved_scope = pp->enclosing_scope;
+	tree saved_scope = enclosing_scope;
 	bool skipfirst = false;
 	tree arg;
 
@@ -528,21 +528,21 @@ 
 
 	    if (!TYPE_PTR_P (TREE_TYPE (object)))
 	      {
-		pp_cxx_postfix_expression (pp, object);
-		pp_cxx_dot (pp);
+		postfix_expression (object);
+		pp_cxx_dot (this);
 	      }
 	    else
 	      {
-		pp_cxx_postfix_expression (pp, object);
-		pp_cxx_arrow (pp);
+		postfix_expression (object);
+		pp_cxx_arrow (this);
 	      }
 	    skipfirst = true;
-	    pp->enclosing_scope = strip_pointer_operator (TREE_TYPE (object));
+	    enclosing_scope = strip_pointer_operator (TREE_TYPE (object));
 	  }
 
-	pp_cxx_postfix_expression (pp, fun);
-	pp->enclosing_scope = saved_scope;
-	pp_cxx_left_paren (pp);
+	postfix_expression (fun);
+	enclosing_scope = saved_scope;
+	pp_cxx_left_paren (this);
 	if (code == AGGR_INIT_EXPR)
 	  {
 	    aggr_init_expr_arg_iterator iter;
@@ -552,9 +552,9 @@ 
 		  skipfirst = false;
 		else
 		  {
-		    pp_cxx_expression (pp, arg);
+		    pp_cxx_expression (this, arg);
 		    if (more_aggr_init_expr_args_p (&iter))
-		      pp_cxx_separate_with (pp, ',');
+		      pp_cxx_separate_with (this, ',');
 		  }
 	      }
 	  }
@@ -567,18 +567,18 @@ 
 		  skipfirst = false;
 		else
 		  {
-		    pp_cxx_expression (pp, arg);
+		    pp_cxx_expression (this, arg);
 		    if (more_call_expr_args_p (&iter))
-		      pp_cxx_separate_with (pp, ',');
+		      pp_cxx_separate_with (this, ',');
 		  }
 	      }
 	  }
-	pp_cxx_right_paren (pp);
+	pp_cxx_right_paren (this);
       }
       if (code == AGGR_INIT_EXPR && AGGR_INIT_VIA_CTOR_P (t))
 	{
-	  pp_cxx_separate_with (pp, ',');
-	  pp_cxx_postfix_expression (pp, AGGR_INIT_EXPR_SLOT (t));
+	  pp_cxx_separate_with (this, ',');
+	  postfix_expression (AGGR_INIT_EXPR_SLOT (t));
 	}
       break;
 
@@ -591,7 +591,7 @@ 
     case CONST_DECL:
     case TEMPLATE_DECL:
     case RESULT_DECL:
-      pp_primary_expression (pp, t);
+      primary_expression (t);
       break;
 
     case DYNAMIC_CAST_EXPR:
@@ -599,47 +599,47 @@ 
     case REINTERPRET_CAST_EXPR:
     case CONST_CAST_EXPR:
       if (code == DYNAMIC_CAST_EXPR)
-	pp_cxx_ws_string (pp, "dynamic_cast");
+	pp_cxx_ws_string (this, "dynamic_cast");
       else if (code == STATIC_CAST_EXPR)
-	pp_cxx_ws_string (pp, "static_cast");
+	pp_cxx_ws_string (this, "static_cast");
       else if (code == REINTERPRET_CAST_EXPR)
-	pp_cxx_ws_string (pp, "reinterpret_cast");
+	pp_cxx_ws_string (this, "reinterpret_cast");
       else
-	pp_cxx_ws_string (pp, "const_cast");
-      pp_cxx_begin_template_argument_list (pp);
-      pp_cxx_type_id (pp, TREE_TYPE (t));
-      pp_cxx_end_template_argument_list (pp);
-      pp_left_paren (pp);
-      pp_cxx_expression (pp, TREE_OPERAND (t, 0));
-      pp_right_paren (pp);
+	pp_cxx_ws_string (this, "const_cast");
+      pp_cxx_begin_template_argument_list (this);
+      pp_cxx_type_id (this, TREE_TYPE (t));
+      pp_cxx_end_template_argument_list (this);
+      pp_left_paren (this);
+      pp_cxx_expression (this, TREE_OPERAND (t, 0));
+      pp_right_paren (this);
       break;
 
     case EMPTY_CLASS_EXPR:
-      pp_cxx_type_id (pp, TREE_TYPE (t));
-      pp_left_paren (pp);
-      pp_right_paren (pp);
+      pp_cxx_type_id (this, TREE_TYPE (t));
+      pp_left_paren (this);
+      pp_right_paren (this);
       break;
 
     case TYPEID_EXPR:
-      pp_cxx_typeid_expression (pp, t);
+      pp_cxx_typeid_expression (this, t);
       break;
 
     case PSEUDO_DTOR_EXPR:
-      pp_cxx_postfix_expression (pp, TREE_OPERAND (t, 0));
-      pp_cxx_dot (pp);
-      pp_cxx_qualified_id (pp, TREE_OPERAND (t, 1));
-      pp_cxx_colon_colon (pp);
-      pp_complement (pp);
-      pp_cxx_unqualified_id (pp, TREE_OPERAND (t, 2));
+      postfix_expression (TREE_OPERAND (t, 0));
+      pp_cxx_dot (this);
+      pp_cxx_qualified_id (this, TREE_OPERAND (t, 1));
+      pp_cxx_colon_colon (this);
+      pp_complement (this);
+      pp_cxx_unqualified_id (this, TREE_OPERAND (t, 2));
       break;
 
     case ARROW_EXPR:
-      pp_cxx_postfix_expression (pp, TREE_OPERAND (t, 0));
-      pp_cxx_arrow (pp);
+      postfix_expression (TREE_OPERAND (t, 0));
+      pp_cxx_arrow (this);
       break;
 
     default:
-      pp_c_postfix_expression (pp, t);
+      c_pretty_printer::postfix_expression (t);
       break;
     }
 }
@@ -1085,7 +1085,7 @@ 
     case PSEUDO_DTOR_EXPR:
     case AGGR_INIT_EXPR:
     case ARROW_EXPR:
-      pp_cxx_postfix_expression (pp, t);
+      pp_postfix_expression (pp, t);
       break;
 
     case NEW_EXPR:
@@ -2448,7 +2448,6 @@ 
 
   /* pp->statement = (pp_fun) pp_cxx_statement;  */
 
-  postfix_expression = (pp_fun) pp_cxx_postfix_expression;
   unary_expression = (pp_fun) pp_cxx_unary_expression;
   multiplicative_expression = (pp_fun) pp_cxx_multiplicative_expression;
   conditional_expression = (pp_fun) pp_cxx_conditional_expression;
Index: cp/cxx-pretty-print.h
===================================================================
--- cp/cxx-pretty-print.h	(revision 201984)
+++ cp/cxx-pretty-print.h	(working copy)
@@ -36,6 +36,7 @@ 
   void constant (tree);
   void id_expression (tree);
   void primary_expression (tree);
+  void postfix_expression (tree);
   /* This is the enclosing scope of the entity being pretty-printed.  */
   tree enclosing_scope;
 };