public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH 2/2] rm pp_c_base sub classes should just inherit from c_pretty_printer and things should just work
  2013-08-01  1:20 start cleaning up the pretty printers Trevor Saunders
@ 2013-08-01  1:20 ` Trevor Saunders
  2013-08-01  3:04   ` Gabriel Dos Reis
  2013-08-01  1:20 ` [PATCH 1/2] make the c++ pretty printer inherit from the C one instead of include it Trevor Saunders
  2013-08-01  3:04 ` start cleaning up the pretty printers Gabriel Dos Reis
  2 siblings, 1 reply; 10+ messages in thread
From: Trevor Saunders @ 2013-08-01  1:20 UTC (permalink / raw)
  To: gcc-patches; +Cc: Trevor Saunders

bootstrapped and same test results on x86_64-linux-gnu against r201084

gcc/c-family/
	* c-pretty-print.h (PP_C_BASE): remove macro.
	* c-pretty-print.c adjust accordingly.

	gcc/cp/
	* cxx-pretty-print.c adjust accordingly.
	* cxx-pretty-print.h adjust accordingly.
	* error.c adjust accordingly.

---
 gcc/c-family/c-pretty-print.c |  2 +-
 gcc/c-family/c-pretty-print.h | 61 ++++++++++++++++++--------------------
 gcc/cp/cxx-pretty-print.c     | 68 +++++++++++++++++++++----------------------
 gcc/cp/cxx-pretty-print.h     | 43 +++++++++++++--------------
 gcc/cp/error.c                | 13 ++++-----
 5 files changed, 88 insertions(+), 99 deletions(-)

diff --git a/gcc/c-family/c-pretty-print.c b/gcc/c-family/c-pretty-print.c
index b8af90c..b347d44 100644
--- a/gcc/c-family/c-pretty-print.c
+++ b/gcc/c-family/c-pretty-print.c
@@ -703,7 +703,7 @@ pp_c_direct_declarator (c_pretty_printer *pp, tree t)
     case FUNCTION_DECL:
       pp_c_space_for_pointer_operator (pp, TREE_TYPE (TREE_TYPE (t)));
       pp_c_tree_decl_identifier (pp, t);
-      if (pp_c_base (pp)->flags & pp_c_flag_abstract)
+      if (pp->flags & pp_c_flag_abstract)
 	pp_abstract_declarator (pp, TREE_TYPE (t));
       else
 	{
diff --git a/gcc/c-family/c-pretty-print.h b/gcc/c-family/c-pretty-print.h
index 04b72c4..beccc1d 100644
--- a/gcc/c-family/c-pretty-print.h
+++ b/gcc/c-family/c-pretty-print.h
@@ -44,9 +44,8 @@ typedef void (*c_pretty_print_fn) (c_pretty_printer *, tree);
 /* The datatype that contains information necessary for pretty-printing
    a tree that represents a C construct.  Any pretty-printer for a
    language using C/c++ syntax can derive from this datatype and reuse
-   facilities provided here.  It can do so by having a subobject of type
-   c_pretty_printer and override the macro pp_c_base to return a pointer
-   to that subobject.  Such a pretty-printer has the responsibility to
+   facilities provided here.  It can do so by having a sub class of 
+   c_pretty_printer.  Such a pretty-printer has the responsibility to
    initialize the pp_base() part, then call pp_c_pretty_printer_init
    to set up the components that are specific to the C pretty-printer.
    A derived pretty-printer can override any function listed in the
@@ -92,70 +91,66 @@ struct c_pretty_print_info
 };
 
 /* Override the pp_base macro.  Derived pretty-printers should not
-   touch this macro.  Instead they should override pp_c_base instead.  */
+   touch this macro.*/
 #undef pp_base
-#define pp_base(PP)  (&pp_c_base (PP)->base)
+#define pp_base(PP)  (&(PP)->base)
 
 
 #define pp_c_tree_identifier(PPI, ID)              \
    pp_c_identifier (PPI, IDENTIFIER_POINTER (ID))
 
 #define pp_declaration(PPI, T)                    \
-   pp_c_base (PPI)->declaration (pp_c_base (PPI), T)
+   PPI->declaration (PPI, T)
 #define pp_declaration_specifiers(PPI, D)         \
-   pp_c_base (PPI)->declaration_specifiers (pp_c_base (PPI), D)
+   PPI->declaration_specifiers (PPI, D)
 #define pp_abstract_declarator(PP, D)             \
-   pp_c_base (PP)->abstract_declarator (pp_c_base (PP), D)
+   PP->abstract_declarator (PP, D)
 #define pp_type_specifier_seq(PPI, D)             \
-   pp_c_base (PPI)->type_specifier_seq (pp_c_base (PPI), D)
+   PPI->type_specifier_seq (PPI, D)
 #define pp_declarator(PPI, D)                     \
-   pp_c_base (PPI)->declarator (pp_c_base (PPI), D)
+   PPI->declarator (PPI, D)
 #define pp_direct_declarator(PPI, D)              \
-   pp_c_base (PPI)->direct_declarator (pp_c_base (PPI), D)
+   PPI->direct_declarator (PPI, D)
 #define pp_direct_abstract_declarator(PP, D)      \
-   pp_c_base (PP)->direct_abstract_declarator (pp_c_base (PP), D)
+   PP->direct_abstract_declarator (PP, D)
 #define pp_ptr_operator(PP, D)                    \
-   pp_c_base (PP)->ptr_operator (pp_c_base (PP), D)
+   PP->ptr_operator (PP, D)
 #define pp_parameter_list(PPI, T)                 \
-  pp_c_base (PPI)->parameter_list (pp_c_base (PPI), T)
+  PPI->parameter_list (PPI, T)
 #define pp_type_id(PPI, D)                        \
-  pp_c_base (PPI)->type_id (pp_c_base (PPI), D)
+  PPI->type_id (PPI, D)
 #define pp_simple_type_specifier(PP, T)           \
-  pp_c_base (PP)->simple_type_specifier (pp_c_base (PP), T)
+  PP->simple_type_specifier (PP, T)
 #define pp_function_specifier(PP, D)              \
-  pp_c_base (PP)->function_specifier (pp_c_base (PP), D)
+  PP->function_specifier (PP, D)
 #define pp_storage_class_specifier(PP, D)         \
-  pp_c_base (PP)->storage_class_specifier (pp_c_base (PP), D);
+  PP->storage_class_specifier (PP, D);
 
 #define pp_statement(PPI, S)                      \
-  pp_c_base (PPI)->statement (pp_c_base (PPI), S)
+  PPI->statement (PPI, S)
 
 #define pp_constant(PP, E) \
-  pp_c_base (PP)->constant (pp_c_base (PP), E)
+  PP->constant (PP, E)
 #define pp_id_expression(PP, E)  \
-  pp_c_base (PP)->id_expression (pp_c_base (PP), E)
+  PP->id_expression (PP, E)
 #define pp_primary_expression(PPI, E)             \
-  pp_c_base (PPI)->primary_expression (pp_c_base (PPI), E)
+  PPI->primary_expression (PPI, E)
 #define pp_postfix_expression(PPI, E)             \
-  pp_c_base (PPI)->postfix_expression (pp_c_base (PPI), E)
+  PPI->postfix_expression (PPI, E)
 #define pp_unary_expression(PPI, E)               \
-  pp_c_base (PPI)->unary_expression (pp_c_base (PPI), E)
+  PPI->unary_expression (PPI, E)
 #define pp_initializer(PPI, E)                    \
-  pp_c_base (PPI)->initializer (pp_c_base (PPI), E)
+  PPI->initializer (PPI, E)
 #define pp_multiplicative_expression(PPI, E)      \
-  pp_c_base (PPI)->multiplicative_expression (pp_c_base (PPI), E)
+  PPI->multiplicative_expression (PPI, E)
 #define pp_conditional_expression(PPI, E)         \
-  pp_c_base (PPI)->conditional_expression (pp_c_base (PPI), E)
+  PPI->conditional_expression (PPI, E)
 #define pp_assignment_expression(PPI, E)          \
-   pp_c_base (PPI)->assignment_expression (pp_c_base (PPI), E)
+   PPI->assignment_expression (PPI, E)
 #define pp_expression(PP, E)                      \
-   pp_c_base (PP)->expression (pp_c_base (PP), E)
+   PP->expression (PP, E)
 
 
-/* Returns the c_pretty_printer base object of PRETTY-PRINTER.  This
-   macro must be overridden by any subclass of c_pretty_print_info.  */
-#define pp_c_base(PP)  (PP)
-
 extern void pp_c_pretty_printer_init (c_pretty_printer *);
 void pp_c_whitespace (c_pretty_printer *);
 void pp_c_left_paren (c_pretty_printer *);
diff --git a/gcc/cp/cxx-pretty-print.c b/gcc/cp/cxx-pretty-print.c
index 89d14da..099953c 100644
--- a/gcc/cp/cxx-pretty-print.c
+++ b/gcc/cp/cxx-pretty-print.c
@@ -62,15 +62,15 @@ pp_cxx_nonconsecutive_character (cxx_pretty_printer *pp, int c)
 }
 
 #define pp_cxx_storage_class_specifier(PP, T) \
-   pp_c_storage_class_specifier (pp_c_base (PP), T)
+   pp_c_storage_class_specifier (PP, T)
 #define pp_cxx_expression_list(PP, T)    \
-   pp_c_expression_list (pp_c_base (PP), T)
+   pp_c_expression_list (PP, T)
 #define pp_cxx_space_for_pointer_operator(PP, T)  \
-   pp_c_space_for_pointer_operator (pp_c_base (PP), T)
+   pp_c_space_for_pointer_operator (PP, T)
 #define pp_cxx_init_declarator(PP, T)    \
-   pp_c_init_declarator (pp_c_base (PP), T)
+   pp_c_init_declarator (PP, T)
 #define pp_cxx_call_argument_list(PP, T) \
-   pp_c_call_argument_list (pp_c_base (PP), T)
+   pp_c_call_argument_list (PP, T)
 
 void
 pp_cxx_colon_colon (cxx_pretty_printer *pp)
@@ -331,7 +331,7 @@ pp_cxx_constant (cxx_pretty_printer *pp, tree t)
 	const bool in_parens = PAREN_STRING_LITERAL_P (t);
 	if (in_parens)
 	  pp_cxx_left_paren (pp);
-	pp_c_constant (pp_c_base (pp), t);
+	pp_c_constant (pp, t);
 	if (in_parens)
 	  pp_cxx_right_paren (pp);
       }
@@ -346,7 +346,7 @@ pp_cxx_constant (cxx_pretty_printer *pp, tree t)
       /* else fall through.  */
 
     default:
-      pp_c_constant (pp_c_base (pp), t);
+      pp_c_constant (pp, t);
       break;
     }
 }
@@ -465,7 +465,7 @@ pp_cxx_primary_expression (cxx_pretty_printer *pp, tree t)
       break;
 
     default:
-      pp_c_primary_expression (pp_c_base (pp), t);
+      pp_c_primary_expression (pp, t);
       break;
     }
 }
@@ -643,7 +643,7 @@ pp_cxx_postfix_expression (cxx_pretty_printer *pp, tree t)
       break;
 
     default:
-      pp_c_postfix_expression (pp_c_base (pp), t);
+      pp_c_postfix_expression (pp, t);
       break;
     }
 }
@@ -699,7 +699,7 @@ pp_cxx_new_expression (cxx_pretty_printer *pp, tree t)
 	{
 	  pp_left_paren (pp);
 	  if (TREE_CODE (init) == TREE_LIST)
-	    pp_c_expression_list (pp_c_base (pp), init);
+	    pp_c_expression_list (pp, init);
 	  else if (init == void_zero_node)
 	    ;			/* OK, empty initializer list.  */
 	  else
@@ -736,7 +736,7 @@ pp_cxx_delete_expression (cxx_pretty_printer *pp, tree t)
 	  pp_right_bracket (pp);
 	  pp_space (pp);
 	}
-      pp_c_cast_expression (pp_c_base (pp), TREE_OPERAND (t, 0));
+      pp_c_cast_expression (pp, TREE_OPERAND (t, 0));
       break;
 
     default:
@@ -835,7 +835,7 @@ pp_cxx_unary_expression (cxx_pretty_printer *pp, tree t)
       break;
 
     default:
-      pp_c_unary_expression (pp_c_base (pp), t);
+      pp_c_unary_expression (pp, t);
       break;
     }
 }
@@ -856,7 +856,7 @@ pp_cxx_cast_expression (cxx_pretty_printer *pp, tree t)
       break;
 
     default:
-      pp_c_cast_expression (pp_c_base (pp), t);
+      pp_c_cast_expression (pp, t);
       break;
     }
 }
@@ -939,7 +939,7 @@ pp_cxx_conditional_expression (cxx_pretty_printer *pp, tree e)
 {
   if (TREE_CODE (e) == COND_EXPR)
     {
-      pp_c_logical_or_expression (pp_c_base (pp), TREE_OPERAND (e, 0));
+      pp_c_logical_or_expression (pp, TREE_OPERAND (e, 0));
       pp_space (pp);
       pp_question (pp);
       pp_space (pp);
@@ -948,7 +948,7 @@ pp_cxx_conditional_expression (cxx_pretty_printer *pp, tree e)
       pp_cxx_assignment_expression (pp, TREE_OPERAND (e, 2));
     }
   else
-    pp_c_logical_or_expression (pp_c_base (pp), e);
+    pp_c_logical_or_expression (pp, e);
 }
 
 /* Pretty-print a compound assignment operator token as indicated by T.  */
@@ -1007,7 +1007,7 @@ pp_cxx_assignment_expression (cxx_pretty_printer *pp, tree e)
     {
     case MODIFY_EXPR:
     case INIT_EXPR:
-      pp_c_logical_or_expression (pp_c_base (pp), TREE_OPERAND (e, 0));
+      pp_c_logical_or_expression (pp, TREE_OPERAND (e, 0));
       pp_space (pp);
       pp_equal (pp);
       pp_space (pp);
@@ -1021,7 +1021,7 @@ pp_cxx_assignment_expression (cxx_pretty_printer *pp, tree e)
       break;
 
     case MODOP_EXPR:
-      pp_c_logical_or_expression (pp_c_base (pp), TREE_OPERAND (e, 0));
+      pp_c_logical_or_expression (pp, TREE_OPERAND (e, 0));
       pp_cxx_assignment_operator (pp, TREE_OPERAND (e, 1));
       pp_cxx_assignment_expression (pp, TREE_OPERAND (e, 2));
       break;
@@ -1174,7 +1174,7 @@ pp_cxx_expression (cxx_pretty_printer *pp, tree t)
       break;
 
     default:
-      pp_c_expression (pp_c_base (pp), t);
+      pp_c_expression (pp, t);
       break;
     }
 }
@@ -1198,7 +1198,7 @@ pp_cxx_function_specifier (cxx_pretty_printer *pp, tree t)
       else if (DECL_CONSTRUCTOR_P (t) && DECL_NONCONVERTING_P (t))
 	pp_cxx_ws_string (pp, "explicit");
       else
-	pp_c_function_specifier (pp_c_base (pp), t);
+	pp_c_function_specifier (pp, t);
 
     default:
       break;
@@ -1242,7 +1242,7 @@ pp_cxx_decl_specifier_seq (cxx_pretty_printer *pp, tree t)
 	pp_cxx_decl_specifier_seq (pp, TREE_TYPE (TREE_TYPE (t)));
       else
 	default:
-      pp_c_declaration_specifiers (pp_c_base (pp), t);
+      pp_c_declaration_specifiers (pp, t);
       break;
     }
 }
@@ -1287,7 +1287,7 @@ pp_cxx_simple_type_specifier (cxx_pretty_printer *pp, tree t)
       break;
 
     default:
-      pp_c_type_specifier (pp_c_base (pp), t);
+      pp_c_type_specifier (pp, t);
       break;
     }
 }
@@ -1342,7 +1342,7 @@ pp_cxx_type_specifier_seq (cxx_pretty_printer *pp, tree t)
 
     default:
       if (!(TREE_CODE (t) == FUNCTION_DECL && DECL_CONSTRUCTOR_P (t)))
-	pp_c_specifier_qualifier_list (pp_c_base (pp), t);
+	pp_c_specifier_qualifier_list (pp, t);
     }
 }
 
@@ -1362,8 +1362,7 @@ pp_cxx_ptr_operator (cxx_pretty_printer *pp, tree t)
     case POINTER_TYPE:
       if (TYPE_PTR_OR_PTRMEM_P (TREE_TYPE (t)))
 	pp_cxx_ptr_operator (pp, TREE_TYPE (t));
-      pp_c_attributes_display (pp_c_base (pp),
-			       TYPE_ATTRIBUTES (TREE_TYPE (t)));
+      pp_c_attributes_display (pp, TYPE_ATTRIBUTES (TREE_TYPE (t)));
       if (TYPE_PTR_P (t))
 	{
 	  pp_star (pp);
@@ -1436,8 +1435,7 @@ pp_cxx_parameter_declaration_clause (cxx_pretty_printer *pp, tree t)
   tree args = TYPE_P (t) ? NULL : FUNCTION_FIRST_USER_PARM (t);
   tree types =
     TYPE_P (t) ? TYPE_ARG_TYPES (t) : FUNCTION_FIRST_USER_PARMTYPE (t);
-  const bool abstract = args == NULL
-    || pp_c_base (pp)->flags & pp_c_flag_abstract;
+  const bool abstract = args == NULL || pp->flags & pp_c_flag_abstract;
   bool first = true;
 
   /* Skip artificial parameter for nonstatic member functions.  */
@@ -1451,7 +1449,7 @@ pp_cxx_parameter_declaration_clause (cxx_pretty_printer *pp, tree t)
 	pp_cxx_separate_with (pp, ',');
       first = false;
       pp_cxx_parameter_declaration (pp, abstract ? TREE_VALUE (types) : args);
-      if (!abstract && pp_c_base (pp)->flags & pp_cxx_flag_default_argument)
+      if (!abstract && pp->flags & pp_cxx_flag_default_argument)
 	{
 	  pp_cxx_whitespace (pp);
 	  pp_equal (pp);
@@ -1572,7 +1570,7 @@ pp_cxx_direct_declarator (cxx_pretty_printer *pp, tree t)
       break;
 
     default:
-      pp_c_direct_declarator (pp_c_base (pp), t);
+      pp_c_direct_declarator (pp, t);
       break;
     }
 }
@@ -1704,7 +1702,7 @@ pp_cxx_direct_abstract_declarator (cxx_pretty_printer *pp, tree t)
       break;
 
     default:
-      pp_c_direct_abstract_declarator (pp_c_base (pp), t);
+      pp_c_direct_abstract_declarator (pp, t);
       break;
     }
 }
@@ -1715,8 +1713,8 @@ pp_cxx_direct_abstract_declarator (cxx_pretty_printer *pp, tree t)
 static void
 pp_cxx_type_id (cxx_pretty_printer *pp, tree t)
 {
-  pp_flags saved_flags = pp_c_base (pp)->flags;
-  pp_c_base (pp)->flags |= pp_c_flag_abstract;
+  pp_flags saved_flags = pp->flags;
+  pp->flags |= pp_c_flag_abstract;
 
   switch (TREE_CODE (t))
     {
@@ -1744,11 +1742,11 @@ pp_cxx_type_id (cxx_pretty_printer *pp, tree t)
       break;
 
     default:
-      pp_c_type_id (pp_c_base (pp), t);
+      pp_c_type_id (pp, t);
       break;
     }
 
-  pp_c_base (pp)->flags = saved_flags;
+  pp->flags = saved_flags;
 }
 
 /* template-argument-list:
@@ -2021,7 +2019,7 @@ pp_cxx_statement (cxx_pretty_printer *pp, tree t)
       break;
 
     default:
-      pp_c_statement (pp_c_base (pp), t);
+      pp_c_statement (pp, t);
       break;
     }
 }
@@ -2437,7 +2435,7 @@ typedef c_pretty_print_fn pp_fun;
 void
 pp_cxx_pretty_printer_init (cxx_pretty_printer *pp)
 {
-  pp_c_pretty_printer_init (pp_c_base (pp));
+  pp_c_pretty_printer_init (pp);
   pp_set_line_maximum_length (pp, 0);
 
   pp->declaration = (pp_fun) pp_cxx_declaration;
diff --git a/gcc/cp/cxx-pretty-print.h b/gcc/cp/cxx-pretty-print.h
index f93287e..0baf323 100644
--- a/gcc/cp/cxx-pretty-print.h
+++ b/gcc/cp/cxx-pretty-print.h
@@ -23,9 +23,6 @@ along with GCC; see the file COPYING3.  If not see
 
 #include "c-family/c-pretty-print.h"
 
-#undef pp_c_base
-#define pp_c_base(PP) (PP)
-
 typedef enum
 {
   /* Ask for a qualified-id.  */
@@ -40,28 +37,28 @@ struct cxx_pretty_printer : public c_pretty_printer
 };
 
 #define pp_cxx_cv_qualifier_seq(PP, T)   \
-   pp_c_type_qualifier_list (pp_c_base (PP), T)
+   pp_c_type_qualifier_list (PP, T)
 #define pp_cxx_cv_qualifiers(PP, CV)   \
-   pp_c_cv_qualifiers (pp_c_base (PP), CV, false)
-
-#define pp_cxx_whitespace(PP)		pp_c_whitespace (pp_c_base (PP))
-#define pp_cxx_left_paren(PP)		pp_c_left_paren (pp_c_base (PP))
-#define pp_cxx_right_paren(PP)		pp_c_right_paren (pp_c_base (PP))
-#define pp_cxx_left_brace(PP)		pp_c_left_brace (pp_c_base (PP))
-#define pp_cxx_right_brace(PP)		pp_c_right_brace (pp_c_base (PP))
-#define pp_cxx_left_bracket(PP)		pp_c_left_bracket (pp_c_base (PP))
-#define pp_cxx_right_bracket(PP)	pp_c_right_bracket (pp_c_base (PP))
-#define pp_cxx_dot(PP)			pp_c_dot (pp_c_base (PP))
-#define pp_cxx_ampersand(PP)		pp_c_ampersand (pp_c_base (PP))
-#define pp_cxx_star(PP)			pp_c_star (pp_c_base (PP))
-#define pp_cxx_arrow(PP)		pp_c_arrow (pp_c_base (PP))
-#define pp_cxx_semicolon(PP)		pp_c_semicolon (pp_c_base (PP))
-#define pp_cxx_complement(PP)		pp_c_complement (pp_c_base (PP))
-
-#define pp_cxx_ws_string(PP, I)		pp_c_ws_string (pp_c_base (PP), I)
-#define pp_cxx_identifier(PP, I)	pp_c_identifier (pp_c_base (PP), I)
+   pp_c_cv_qualifiers (PP, CV, false)
+
+#define pp_cxx_whitespace(PP)		pp_c_whitespace (PP)
+#define pp_cxx_left_paren(PP)		pp_c_left_paren (PP)
+#define pp_cxx_right_paren(PP)		pp_c_right_paren (PP)
+#define pp_cxx_left_brace(PP)		pp_c_left_brace (PP)
+#define pp_cxx_right_brace(PP)		pp_c_right_brace (PP)
+#define pp_cxx_left_bracket(PP)		pp_c_left_bracket (PP)
+#define pp_cxx_right_bracket(PP)	pp_c_right_bracket (PP)
+#define pp_cxx_dot(PP)			pp_c_dot (PP)
+#define pp_cxx_ampersand(PP)		pp_c_ampersand (PP)
+#define pp_cxx_star(PP)			pp_c_star (PP)
+#define pp_cxx_arrow(PP)		pp_c_arrow (PP)
+#define pp_cxx_semicolon(PP)		pp_c_semicolon (PP)
+#define pp_cxx_complement(PP)		pp_c_complement (PP)
+
+#define pp_cxx_ws_string(PP, I)		pp_c_ws_string (PP, I)
+#define pp_cxx_identifier(PP, I)	pp_c_identifier (PP, I)
 #define pp_cxx_tree_identifier(PP, T) \
-  pp_c_tree_identifier (pp_c_base (PP), T)
+  pp_c_tree_identifier (PP, T)
 
 void pp_cxx_pretty_printer_init (cxx_pretty_printer *);
 void pp_cxx_begin_template_argument_list (cxx_pretty_printer *);
diff --git a/gcc/cp/error.c b/gcc/cp/error.c
index a8f52cd..6509811 100644
--- a/gcc/cp/error.c
+++ b/gcc/cp/error.c
@@ -706,8 +706,7 @@ dump_type_prefix (tree t, int flags)
 	  {
 	    pp_cxx_whitespace (cxx_pp);
 	    pp_cxx_left_paren (cxx_pp);
-	    pp_c_attributes_display (pp_c_base (cxx_pp),
-				     TYPE_ATTRIBUTES (sub));
+	    pp_c_attributes_display (cxx_pp, TYPE_ATTRIBUTES (sub));
 	  }
 	if (TYPE_PTR_P (t))
 	  pp_character(cxx_pp, '*');
@@ -1048,7 +1047,7 @@ dump_decl (tree t, int flags)
 	  flags &= ~TFF_UNQUALIFIED_NAME;
 	  if (DECL_NAME (t) == NULL_TREE)
             {
-              if (!(pp_c_base (cxx_pp)->flags & pp_c_flag_gnu_v3))
+              if (!(cxx_pp->flags & pp_c_flag_gnu_v3))
                 pp_cxx_ws_string (cxx_pp, M_("{anonymous}"));
               else
                 pp_cxx_ws_string (cxx_pp, M_("(anonymous namespace)"));
@@ -2659,10 +2658,10 @@ decl_as_dwarf_string (tree decl, int flags)
   const char *name;
   /* Curiously, reinit_cxx_pp doesn't reset the flags field, so setting the flag
      here will be adequate to get the desired behaviour.  */
-  pp_c_base (cxx_pp)->flags |= pp_c_flag_gnu_v3;
+  cxx_pp->flags |= pp_c_flag_gnu_v3;
   name = decl_as_string (decl, flags);
   /* Subsequent calls to the pretty printer shouldn't use this style.  */
-  pp_c_base (cxx_pp)->flags &= ~pp_c_flag_gnu_v3;
+  cxx_pp->flags &= ~pp_c_flag_gnu_v3;
   return name;
 }
 
@@ -2691,10 +2690,10 @@ lang_decl_dwarf_name (tree decl, int v, bool translate)
   const char *name;
   /* Curiously, reinit_cxx_pp doesn't reset the flags field, so setting the flag
      here will be adequate to get the desired behaviour.  */
-  pp_c_base (cxx_pp)->flags |= pp_c_flag_gnu_v3;
+  cxx_pp->flags |= pp_c_flag_gnu_v3;
   name = lang_decl_name (decl, v, translate);
   /* Subsequent calls to the pretty printer shouldn't use this style.  */
-  pp_c_base (cxx_pp)->flags &= ~pp_c_flag_gnu_v3;
+  cxx_pp->flags &= ~pp_c_flag_gnu_v3;
   return name;
 }
 
-- 
1.8.4.rc0

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 1/2] make the c++ pretty printer inherit from the C one instead of include it
  2013-08-01  1:20 start cleaning up the pretty printers Trevor Saunders
  2013-08-01  1:20 ` [PATCH 2/2] rm pp_c_base sub classes should just inherit from c_pretty_printer and things should just work Trevor Saunders
@ 2013-08-01  1:20 ` Trevor Saunders
  2013-08-01  3:02   ` Gabriel Dos Reis
  2013-08-01  3:04 ` start cleaning up the pretty printers Gabriel Dos Reis
  2 siblings, 1 reply; 10+ messages in thread
From: Trevor Saunders @ 2013-08-01  1:20 UTC (permalink / raw)
  To: gcc-patches; +Cc: Trevor Saunders

bootstrapped and same test results on x86_64-linux-gnu against r201084

gcc/cp/
	* cxx-pretty-print.h (cxx_pretty_printer): inherit from c_pretty_printer
	instead of include it.
	* (cxx_pretty_print.c): adjust accordingly.

---
 gcc/cp/cxx-pretty-print.c | 40 ++++++++++++++++++++--------------------
 gcc/cp/cxx-pretty-print.h |  7 +++----
 2 files changed, 23 insertions(+), 24 deletions(-)

diff --git a/gcc/cp/cxx-pretty-print.c b/gcc/cp/cxx-pretty-print.c
index ef8df70..89d14da 100644
--- a/gcc/cp/cxx-pretty-print.c
+++ b/gcc/cp/cxx-pretty-print.c
@@ -2440,29 +2440,29 @@ pp_cxx_pretty_printer_init (cxx_pretty_printer *pp)
   pp_c_pretty_printer_init (pp_c_base (pp));
   pp_set_line_maximum_length (pp, 0);
 
-  pp->c_base.declaration = (pp_fun) pp_cxx_declaration;
-  pp->c_base.declaration_specifiers = (pp_fun) pp_cxx_decl_specifier_seq;
-  pp->c_base.function_specifier = (pp_fun) pp_cxx_function_specifier;
-  pp->c_base.type_specifier_seq = (pp_fun) pp_cxx_type_specifier_seq;
-  pp->c_base.declarator = (pp_fun) pp_cxx_declarator;
-  pp->c_base.direct_declarator = (pp_fun) pp_cxx_direct_declarator;
-  pp->c_base.parameter_list = (pp_fun) pp_cxx_parameter_declaration_clause;
-  pp->c_base.type_id = (pp_fun) pp_cxx_type_id;
-  pp->c_base.abstract_declarator = (pp_fun) pp_cxx_abstract_declarator;
-  pp->c_base.direct_abstract_declarator =
+  pp->declaration = (pp_fun) pp_cxx_declaration;
+  pp->declaration_specifiers = (pp_fun) pp_cxx_decl_specifier_seq;
+  pp->function_specifier = (pp_fun) pp_cxx_function_specifier;
+  pp->type_specifier_seq = (pp_fun) pp_cxx_type_specifier_seq;
+  pp->declarator = (pp_fun) pp_cxx_declarator;
+  pp->direct_declarator = (pp_fun) pp_cxx_direct_declarator;
+  pp->parameter_list = (pp_fun) pp_cxx_parameter_declaration_clause;
+  pp->type_id = (pp_fun) pp_cxx_type_id;
+  pp->abstract_declarator = (pp_fun) pp_cxx_abstract_declarator;
+  pp->direct_abstract_declarator =
     (pp_fun) pp_cxx_direct_abstract_declarator;
-  pp->c_base.simple_type_specifier = (pp_fun)pp_cxx_simple_type_specifier;
+  pp->simple_type_specifier = (pp_fun)pp_cxx_simple_type_specifier;
 
   /* pp->c_base.statement = (pp_fun) pp_cxx_statement;  */
 
-  pp->c_base.constant = (pp_fun) pp_cxx_constant;
-  pp->c_base.id_expression = (pp_fun) pp_cxx_id_expression;
-  pp->c_base.primary_expression = (pp_fun) pp_cxx_primary_expression;
-  pp->c_base.postfix_expression = (pp_fun) pp_cxx_postfix_expression;
-  pp->c_base.unary_expression = (pp_fun) pp_cxx_unary_expression;
-  pp->c_base.multiplicative_expression = (pp_fun) pp_cxx_multiplicative_expression;
-  pp->c_base.conditional_expression = (pp_fun) pp_cxx_conditional_expression;
-  pp->c_base.assignment_expression = (pp_fun) pp_cxx_assignment_expression;
-  pp->c_base.expression = (pp_fun) pp_cxx_expression;
+  pp->constant = (pp_fun) pp_cxx_constant;
+  pp->id_expression = (pp_fun) pp_cxx_id_expression;
+  pp->primary_expression = (pp_fun) pp_cxx_primary_expression;
+  pp->postfix_expression = (pp_fun) pp_cxx_postfix_expression;
+  pp->unary_expression = (pp_fun) pp_cxx_unary_expression;
+  pp->multiplicative_expression = (pp_fun) pp_cxx_multiplicative_expression;
+  pp->conditional_expression = (pp_fun) pp_cxx_conditional_expression;
+  pp->assignment_expression = (pp_fun) pp_cxx_assignment_expression;
+  pp->expression = (pp_fun) pp_cxx_expression;
   pp->enclosing_scope = global_namespace;
 }
diff --git a/gcc/cp/cxx-pretty-print.h b/gcc/cp/cxx-pretty-print.h
index 0f7dc4a..f93287e 100644
--- a/gcc/cp/cxx-pretty-print.h
+++ b/gcc/cp/cxx-pretty-print.h
@@ -24,7 +24,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "c-family/c-pretty-print.h"
 
 #undef pp_c_base
-#define pp_c_base(PP) (&(PP)->c_base)
+#define pp_c_base(PP) (PP)
 
 typedef enum
 {
@@ -33,12 +33,11 @@ typedef enum
 
 } cxx_pretty_printer_flags;
 
-typedef struct
+struct cxx_pretty_printer : public c_pretty_printer
 {
-  c_pretty_printer c_base;
   /* This is the enclosing scope of the entity being pretty-printed.  */
   tree enclosing_scope;
-} cxx_pretty_printer;
+};
 
 #define pp_cxx_cv_qualifier_seq(PP, T)   \
    pp_c_type_qualifier_list (pp_c_base (PP), T)
-- 
1.8.4.rc0

^ permalink raw reply	[flat|nested] 10+ messages in thread

* start cleaning up the pretty printers
@ 2013-08-01  1:20 Trevor Saunders
  2013-08-01  1:20 ` [PATCH 2/2] rm pp_c_base sub classes should just inherit from c_pretty_printer and things should just work Trevor Saunders
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Trevor Saunders @ 2013-08-01  1:20 UTC (permalink / raw)
  To: gcc-patches

Hi!

its my first time sending patches here so please be gentle :)

I'm working on further patches to use c++ inheritance instead of macros here, but I figured I might as well send these out now.

Trev

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 1/2] make the c++ pretty printer inherit from the C one instead of include it
  2013-08-01  1:20 ` [PATCH 1/2] make the c++ pretty printer inherit from the C one instead of include it Trevor Saunders
@ 2013-08-01  3:02   ` Gabriel Dos Reis
  2013-08-01  3:21     ` Trevor Saunders
  2013-08-05  1:40     ` Trevor Saunders
  0 siblings, 2 replies; 10+ messages in thread
From: Gabriel Dos Reis @ 2013-08-01  3:02 UTC (permalink / raw)
  To: Trevor Saunders; +Cc: gcc-patches

On Wed, Jul 31, 2013 at 8:14 PM, Trevor Saunders <tsaunders@mozilla.com> wrote:
> bootstrapped and same test results on x86_64-linux-gnu against r201084
>
> gcc/cp/
>         * cxx-pretty-print.h (cxx_pretty_printer): inherit from c_pretty_printer
>         instead of include it.
>         * (cxx_pretty_print.c): adjust accordingly.

This is on my todo stack; thanks for looking into it.

The way to handle this is:

  * yes, use inheritance -- that is what I simulated with the C abstractions
  * declare the "pointer to function fields" as virtual functions --
that is what I meant
    with the (necessarily poor) emulation through the casts.
  * override those that needed to be overridden  in cxx_pretty_printer.
  * adjust the macros.
  * Have the associated constructors do the right thing.



-- Gaby

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: start cleaning up the pretty printers
  2013-08-01  1:20 start cleaning up the pretty printers Trevor Saunders
  2013-08-01  1:20 ` [PATCH 2/2] rm pp_c_base sub classes should just inherit from c_pretty_printer and things should just work Trevor Saunders
  2013-08-01  1:20 ` [PATCH 1/2] make the c++ pretty printer inherit from the C one instead of include it Trevor Saunders
@ 2013-08-01  3:04 ` Gabriel Dos Reis
  2 siblings, 0 replies; 10+ messages in thread
From: Gabriel Dos Reis @ 2013-08-01  3:04 UTC (permalink / raw)
  To: Trevor Saunders; +Cc: gcc-patches

On Wed, Jul 31, 2013 at 8:14 PM, Trevor Saunders <tsaunders@mozilla.com> wrote:
> Hi!
>
> its my first time sending patches here so please be gentle :)

it is very much appreciated.  Thanks for tackling it.

-- Gaby

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 2/2] rm pp_c_base sub classes should just inherit from c_pretty_printer and things should just work
  2013-08-01  1:20 ` [PATCH 2/2] rm pp_c_base sub classes should just inherit from c_pretty_printer and things should just work Trevor Saunders
@ 2013-08-01  3:04   ` Gabriel Dos Reis
  0 siblings, 0 replies; 10+ messages in thread
From: Gabriel Dos Reis @ 2013-08-01  3:04 UTC (permalink / raw)
  To: Trevor Saunders; +Cc: gcc-patches

On Wed, Jul 31, 2013 at 8:14 PM, Trevor Saunders <tsaunders@mozilla.com> wrote:
> bootstrapped and same test results on x86_64-linux-gnu against r201084
>
> gcc/c-family/
>         * c-pretty-print.h (PP_C_BASE): remove macro.
>         * c-pretty-print.c adjust accordingly.
>
>         gcc/cp/
>         * cxx-pretty-print.c adjust accordingly.
>         * cxx-pretty-print.h adjust accordingly.
>         * error.c adjust accordingly.

See my comments for the first part of this patch series.
Use inheritance AND virtual functions.  Remove the casts.
Add constructors.

-- Gaby

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 1/2] make the c++ pretty printer inherit from the C one instead of include it
  2013-08-01  3:02   ` Gabriel Dos Reis
@ 2013-08-01  3:21     ` Trevor Saunders
  2013-08-01  3:48       ` Gabriel Dos Reis
  2013-08-05  1:40     ` Trevor Saunders
  1 sibling, 1 reply; 10+ messages in thread
From: Trevor Saunders @ 2013-08-01  3:21 UTC (permalink / raw)
  To: Gabriel Dos Reis; +Cc: gcc-patches

On Wed, Jul 31, 2013 at 10:02:29PM -0500, Gabriel Dos Reis wrote:
> On Wed, Jul 31, 2013 at 8:14 PM, Trevor Saunders <tsaunders@mozilla.com> wrote:
> > bootstrapped and same test results on x86_64-linux-gnu against r201084
> >
> > gcc/cp/
> >         * cxx-pretty-print.h (cxx_pretty_printer): inherit from c_pretty_printer
> >         instead of include it.
> >         * (cxx_pretty_print.c): adjust accordingly.
> 
> This is on my todo stack; thanks for looking into it.
> 
> The way to handle this is:
> 
>   * yes, use inheritance -- that is what I simulated with the C abstractions
>   * declare the "pointer to function fields" as virtual functions --
> that is what I meant
>     with the (necessarily poor) emulation through the casts.
>   * override those that needed to be overridden  in cxx_pretty_printer.
>   * adjust the macros.
>   * Have the associated constructors do the right thing.

I agree with all of that, I was just trying to keep patches small but if
you prefer I guess I could do one giant patch that redoes all of this.

Trev

> 
> 
> 
> -- Gaby

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 1/2] make the c++ pretty printer inherit from the C one instead of include it
  2013-08-01  3:21     ` Trevor Saunders
@ 2013-08-01  3:48       ` Gabriel Dos Reis
  0 siblings, 0 replies; 10+ messages in thread
From: Gabriel Dos Reis @ 2013-08-01  3:48 UTC (permalink / raw)
  To: Trevor Saunders; +Cc: gcc-patches

On Wed, Jul 31, 2013 at 10:16 PM, Trevor Saunders <tsaunders@mozilla.com> wrote:
> On Wed, Jul 31, 2013 at 10:02:29PM -0500, Gabriel Dos Reis wrote:
>> On Wed, Jul 31, 2013 at 8:14 PM, Trevor Saunders <tsaunders@mozilla.com> wrote:
>> > bootstrapped and same test results on x86_64-linux-gnu against r201084
>> >
>> > gcc/cp/
>> >         * cxx-pretty-print.h (cxx_pretty_printer): inherit from c_pretty_printer
>> >         instead of include it.
>> >         * (cxx_pretty_print.c): adjust accordingly.
>>
>> This is on my todo stack; thanks for looking into it.
>>
>> The way to handle this is:
>>
>>   * yes, use inheritance -- that is what I simulated with the C abstractions
>>   * declare the "pointer to function fields" as virtual functions --
>> that is what I meant
>>     with the (necessarily poor) emulation through the casts.
>>   * override those that needed to be overridden  in cxx_pretty_printer.
>>   * adjust the macros.
>>   * Have the associated constructors do the right thing.
>
> I agree with all of that, I was just trying to keep patches small but if
> you prefer I guess I could do one giant patch that redoes all of this.

At the minimum, the inheritance and the virtual functions should go together.

-- Gaby

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 1/2] make the c++ pretty printer inherit from the C one instead of include it
  2013-08-01  3:02   ` Gabriel Dos Reis
  2013-08-01  3:21     ` Trevor Saunders
@ 2013-08-05  1:40     ` Trevor Saunders
  2013-08-05  2:54       ` Gabriel Dos Reis
  1 sibling, 1 reply; 10+ messages in thread
From: Trevor Saunders @ 2013-08-05  1:40 UTC (permalink / raw)
  To: Gabriel Dos Reis; +Cc: gcc-patches

On Wed, Jul 31, 2013 at 10:02:29PM -0500, Gabriel Dos Reis wrote:
>   * declare the "pointer to function fields" as virtual functions --
> that is what I meant
>     with the (necessarily poor) emulation through the casts.

I guess you'll work on this later in the patch series you're sending,
but its worth noting making pretty_print_info::format_decoder a virtual
function is non-trivial, it turns out to be important that some
consumers can leave it null instead of making it  what is currently
default_tree_printer.  This is because gcov and maybe other things link
against diagnostic.c and pretty-print.c but not all the tree stuff that
would be required for default_tree_printer.

Trev

>   * override those that needed to be overridden  in cxx_pretty_printer.
>   * adjust the macros.
>   * Have the associated constructors do the right thing.
> 
> 
> 
> -- Gaby

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 1/2] make the c++ pretty printer inherit from the C one instead of include it
  2013-08-05  1:40     ` Trevor Saunders
@ 2013-08-05  2:54       ` Gabriel Dos Reis
  0 siblings, 0 replies; 10+ messages in thread
From: Gabriel Dos Reis @ 2013-08-05  2:54 UTC (permalink / raw)
  To: Trevor Saunders; +Cc: gcc-patches

On Sun, Aug 4, 2013 at 8:37 PM, Trevor Saunders <tsaunders@mozilla.com> wrote:
> On Wed, Jul 31, 2013 at 10:02:29PM -0500, Gabriel Dos Reis wrote:
>>   * declare the "pointer to function fields" as virtual functions --
>> that is what I meant
>>     with the (necessarily poor) emulation through the casts.
>
> I guess you'll work on this later in the patch series you're sending,
> but its worth noting making pretty_print_info::format_decoder a virtual
> function is non-trivial, it turns out to be important that some
> consumers can leave it null instead of making it  what is currently
> default_tree_printer.  This is because gcov and maybe other things link
> against diagnostic.c and pretty-print.c but not all the tree stuff that
> would be required for default_tree_printer.

Trev --

Thanks for the piece of info.

Writing OO programming in C is not  fun at all; and undoing
OO C programs is even less fun.

I originally expected clients to derive from the pretty printers and add
their own behavior.  But, it turns out that since OO programming in C
isn't fun, things have grown barnacles and entangled in ways I did not
intend or anticipate.  Hopefully, now that we have a better abstraction tool,
we can express the intent much more directly.

I will send in a patch that adds the inheritance chain from pretty_printer
to cxx_pretty_printer.  Unfortunately, it does not add the virtual functions.
This is because I want to handle 'constructors' in a separate patch.

-- Gaby

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2013-08-05  2:54 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-08-01  1:20 start cleaning up the pretty printers Trevor Saunders
2013-08-01  1:20 ` [PATCH 2/2] rm pp_c_base sub classes should just inherit from c_pretty_printer and things should just work Trevor Saunders
2013-08-01  3:04   ` Gabriel Dos Reis
2013-08-01  1:20 ` [PATCH 1/2] make the c++ pretty printer inherit from the C one instead of include it Trevor Saunders
2013-08-01  3:02   ` Gabriel Dos Reis
2013-08-01  3:21     ` Trevor Saunders
2013-08-01  3:48       ` Gabriel Dos Reis
2013-08-05  1:40     ` Trevor Saunders
2013-08-05  2:54       ` Gabriel Dos Reis
2013-08-01  3:04 ` start cleaning up the pretty printers Gabriel Dos Reis

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).