* Preparatory PATCH for pretty-print
@ 2002-07-29 12:54 Gabriel Dos Reis
2002-07-29 17:31 ` Diego Novillo
` (3 more replies)
0 siblings, 4 replies; 13+ messages in thread
From: Gabriel Dos Reis @ 2002-07-29 12:54 UTC (permalink / raw)
To: gcc-patches
This patch prepares for pretty-printing in the C and C++ front-end.
The machinary is not complete (therefore not turned on).
Bootstrapped and tested on an i686-pc-linux. No regression.
-- Gaby
2002-07-29 Gabriel Dos Reis <gdr@nerim.net>
* Makefile.in (C_OBJS): Include c-pretty-print.o
(c-pretty-print.o): Add dependency rule.
* pretty-print.h: Add more macros.
* c-pretty-print.c: New file.
* c-pretty-print.h: Likewise.
cp/
2002-07-29 Gabriel Dos Reis <gdr@nerim.net>
* Make-lang.in (CXX_C_OBJS): Include.
Index: Makefile.in
===================================================================
RCS file: /cvs/gcc/egcs/gcc/Makefile.in,v
retrieving revision 1.918
diff -p -r1.918 Makefile.in
*** Makefile.in 29 Jul 2002 18:02:46 -0000 1.918
--- Makefile.in 29 Jul 2002 19:28:40 -0000
*************** C_AND_OBJC_OBJS = attribs.o c-errors.o c
*** 718,724 ****
c-objc-common.o c-dump.o libcpp.a $(C_TARGET_OBJS)
# Language-specific object files for C.
! C_OBJS = c-parse.o c-lang.o $(C_AND_OBJC_OBJS)
# Language-independent object files.
--- 718,724 ----
c-objc-common.o c-dump.o libcpp.a $(C_TARGET_OBJS)
# Language-specific object files for C.
! C_OBJS = c-parse.o c-lang.o c-pretty-print.o $(C_AND_OBJC_OBJS)
# Language-independent object files.
*************** c-common.o : c-common.c $(CONFIG_H) $(SY
*** 1230,1235 ****
--- 1230,1237 ----
$(C_COMMON_H) flags.h toplev.h output.h c-pragma.h $(RTL_H) $(GGC_H) \
$(EXPR_H) $(TM_P_H) builtin-types.def builtin-attrs.def $(TARGET_H) \
diagnostic.h tree-inline.h except.h gt-c-common.h real.h langhooks.h
+ c-pretty-print.o : c-pretty-print.c c-pretty-print.h pretty-print.h \
+ $(C_COMMON_H) $(CONFIG_H) $(SYSTEM_H) real.h
# A file used by all variants of C and some other languages.
Index: c-pretty-print.c
===================================================================
RCS file: c-pretty-print.c
diff -N c-pretty-print.c
*** /dev/null 1 Jan 1970 00:00:00 -0000
--- c-pretty-print.c 29 Jul 2002 19:28:40 -0000
***************
*** 0 ****
--- 1,835 ----
+ /* Subroutines common to both C and C++ pretty-printers.
+ Copyright (C) 2002 Free Software Foundation, Inc.
+ Contributed by Gabriel Dos Reis <gdr@integrable-solutions.net>
+
+ This file is part of GCC.
+
+ GCC is free software; you can redistribute it and/or modify it under
+ the terms of the GNU General Public License as published by the Free
+ Software Foundation; either version 2, or (at your option) any later
+ version.
+
+ GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with GCC; see the file COPYING. If not, write to the Free
+ Software Foundation, 59 Temple Place - Suite 330, Boston, MA
+ 02111-1307, USA. */
+
+ #include "config.h"
+ #include "system.h"
+ #include "real.h"
+ #include "c-pretty-print.h"
+
+ /* literal */
+ static void pp_c_char PARAMS ((c_pretty_print_info *, int));
+ static void pp_c_character_literal PARAMS ((c_pretty_print_info *, tree));
+ static void pp_c_bool_literal PARAMS ((c_pretty_print_info *, tree));
+ static bool pp_c_enumerator PARAMS ((c_pretty_print_info *, tree));
+ static void pp_c_integer_literal PARAMS ((c_pretty_print_info *, tree));
+ static void pp_c_real_literal PARAMS ((c_pretty_print_info *, tree));
+ static void pp_c_string_literal PARAMS ((c_pretty_print_info *, tree));
+
+ static void pp_c_primary_expression PARAMS ((c_pretty_print_info *, tree));
+
+ static void pp_c_unary_expression PARAMS ((c_pretty_print_info *, tree));
+ static void pp_c_multiplicative_expression PARAMS ((c_pretty_print_info *,
+ tree));
+ static void pp_c_additive_expression PARAMS ((c_pretty_print_info *, tree));
+ static void pp_c_shift_expression PARAMS ((c_pretty_print_info *, tree));
+ static void pp_c_relational_expression PARAMS ((c_pretty_print_info *, tree));
+ static void pp_c_equality_expression PARAMS ((c_pretty_print_info *, tree));
+ static void pp_c_and_expression PARAMS ((c_pretty_print_info *, tree));
+ static void pp_c_exclusive_or_expression PARAMS ((c_pretty_print_info *,
+ tree));
+ static void pp_c_inclusive_or_expression PARAMS ((c_pretty_print_info *,
+ tree));
+ static void pp_c_logical_and_expression PARAMS ((c_pretty_print_info *, tree));
+ static void pp_c_conditional_expression PARAMS ((c_pretty_print_info *, tree));
+ static void pp_c_assignment_expression PARAMS ((c_pretty_print_info *, tree));
+ \f
+ /* Declarations. */
+
+ /* Print out CV-qualifiers. Take care of possible extension. */
+ void
+ pp_c_cv_qualifier (ppi, cv)
+ c_pretty_print_info *ppi;
+ int cv;
+ {
+ if (cv & TYPE_QUAL_CONST)
+ pp_c_identifier (ppi, "const");
+ if (cv & TYPE_QUAL_VOLATILE)
+ pp_c_identifier (ppi, "volatile");
+ if (cv & TYPE_QUAL_RESTRICT)
+ pp_c_identifier (ppi, flag_isoc99 ? "restrict" : "__restrict__");
+ }
+
+ \f
+ /* Statements. */
+
+ \f
+ /* Expressions. */
+
+ /* Print out a c-char. */
+ static void
+ pp_c_char (ppi, c)
+ c_pretty_print_info *ppi;
+ int c;
+ {
+ switch (c)
+ {
+ case TARGET_NEWLINE:
+ pp_identifier (ppi, "\\n");
+ break;
+ case TARGET_TAB:
+ pp_identifier (ppi, "\\t");
+ break;
+ case TARGET_VT:
+ pp_identifier (ppi, "\\v");
+ break;
+ case TARGET_BS:
+ pp_identifier (ppi, "\\b");
+ break;
+ case TARGET_CR:
+ pp_identifier (ppi, "\\r");
+ break;
+ case TARGET_FF:
+ pp_identifier (ppi, "\\f");
+ break;
+ case TARGET_BELL:
+ pp_identifier (ppi, "\\a");
+ break;
+ case '\\':
+ pp_identifier (ppi, "\\\\");
+ break;
+ case '\'':
+ pp_identifier (ppi, "\\'");
+ break;
+ case '\"':
+ pp_identifier (ppi, "\\\"");
+ break;
+ default:
+ if (ISPRINT (c))
+ pp_character (ppi, c);
+ else
+ pp_format_integer (ppi, "\\%03o", (unsigned) c);
+ break;
+ }
+ }
+
+ /* Print out a STRING literal. */
+ static inline void
+ pp_c_string_literal (ppi, s)
+ c_pretty_print_info *ppi;
+ tree s;
+ {
+ const char *p = TREE_STRING_POINTER (s);
+ int n = TREE_STRING_LENGTH (s) - 1;
+ int i;
+ pp_doublequote (ppi);
+ for (i = 0; i < n; ++i)
+ pp_c_char (ppi, p[i]);
+ pp_doublequote (ppi);
+ }
+
+ /* Print out a CHARACTER literal. */
+ static inline void
+ pp_c_character_literal (ppi, c)
+ c_pretty_print_info *ppi;
+ tree c;
+ {
+ pp_quote (ppi);
+ pp_c_char (ppi, tree_low_cst (c, 0));
+ pp_quote (ppi);
+ }
+
+ /* Print out a BOOLEAN literal. */
+ static inline void
+ pp_c_bool_literal (ppi, b)
+ c_pretty_print_info *ppi;
+ tree b;
+ {
+ if (b == boolean_false_node || integer_zerop (b))
+ {
+ if (c_language == clk_cplusplus)
+ pp_c_identifier (ppi, "false");
+ else if (c_language == clk_c && flag_isoc99)
+ pp_c_identifier (ppi, "_False");
+ else
+ pp_unsupported_tree (ppi, b);
+ }
+ else if (b == boolean_true_node)
+ {
+ if (c_language == clk_cplusplus)
+ pp_c_identifier (ppi, "true");
+ else if (c_language == clk_c && flag_isoc99)
+ pp_c_identifier (ppi, "_True");
+ else
+ pp_unsupported_tree (ppi, b);
+ }
+ else
+ pp_unsupported_tree (ppi, b);
+ }
+
+ /* Attempt to print out an ENUMERATOR. Return true on success. Else return
+ false; that means the value was obtained by a cast, in which case
+ print out the type-id part of the cast-expression -- the casted value
+ is then printed by pp_c_integer_literal. */
+ static bool
+ pp_c_enumerator (ppi, e)
+ c_pretty_print_info *ppi;
+ tree e;
+ {
+ tree type = TREE_TYPE (e);
+ tree value;
+
+ /* Find the name of this constant. */
+ for (value = TYPE_VALUES (type);
+ value != NULL_TREE && !tree_int_cst_equal (TREE_VALUE (value), e);
+ value = TREE_CHAIN (value))
+ ;
+
+ if (value != NULL_TREE)
+ pp_c_tree_identifier (ppi, TREE_PURPOSE (value));
+ else
+ {
+ /* Value must have been cast. */
+ pp_c_left_paren (ppi);
+ pp_type_id (ppi, type);
+ pp_c_right_paren (ppi);
+ return false;
+ }
+
+ return true;
+ }
+
+ /* Print out an INTEGER constant value. */
+ static void
+ pp_c_integer_literal (ppi, i)
+ c_pretty_print_info *ppi;
+ tree i;
+ {
+ tree type = TREE_TYPE (i);
+
+ if (type == boolean_type_node)
+ pp_c_bool_literal (ppi, i);
+ else if (type == char_type_node)
+ pp_c_character_literal (ppi, i);
+ else if (TREE_CODE (type) == ENUMERAL_TYPE
+ && pp_c_enumerator (ppi, i))
+ ;
+ else
+ {
+ if (host_integerp (i, 0))
+ pp_wide_integer (ppi, TREE_INT_CST_LOW (i));
+ else
+ {
+ if (tree_int_cst_sgn (i) < 0)
+ {
+ static char format[10]; /* "%x%09999x\0" */
+ if (!format[0])
+ sprintf (format, "%%x%%0%dx", HOST_BITS_PER_INT / 4);
+
+ pp_c_char (ppi, '-');
+ i = build_int_2 (-TREE_INT_CST_LOW (i),
+ ~TREE_INT_CST_HIGH (i) + !TREE_INT_CST_LOW (i));
+ sprintf (pp_buffer (ppi)->digit_buffer, format,
+ TREE_INT_CST_HIGH (i), TREE_INT_CST_LOW (i));
+ pp_identifier (ppi, pp_buffer (ppi)->digit_buffer);
+
+ }
+ }
+ }
+ }
+
+ /* Print out a REAL value. */
+ static inline void
+ pp_c_real_literal (ppi, r)
+ c_pretty_print_info *ppi;
+ tree r;
+ {
+ REAL_VALUE_TO_DECIMAL (TREE_REAL_CST (r), "%.16g",
+ pp_buffer (ppi)->digit_buffer);
+ pp_identifier (ppi, pp_buffer(ppi)->digit_buffer);
+ }
+
+
+ void
+ pp_c_literal (ppi, e)
+ c_pretty_print_info *ppi;
+ tree e;
+ {
+ switch (TREE_CODE (e))
+ {
+ case INTEGER_CST:
+ pp_c_integer_literal (ppi, e);
+ break;
+
+ case REAL_CST:
+ pp_c_real_literal (ppi, e);
+ break;
+
+ case STRING_CST:
+ pp_c_string_literal (ppi, e);
+ break;
+
+ default:
+ pp_unsupported_tree (ppi, e);
+ break;
+ }
+ }
+
+ /* Pretty-print a C primary-expression. */
+ static void
+ pp_c_primary_expression (ppi, e)
+ c_pretty_print_info *ppi;
+ tree e;
+ {
+ switch (TREE_CODE (e))
+ {
+ case VAR_DECL:
+ case PARM_DECL:
+ case FIELD_DECL:
+ case CONST_DECL:
+ case FUNCTION_DECL:
+ case LABEL_DECL:
+ e = DECL_NAME (e);
+ /* Fall through. */
+ case IDENTIFIER_NODE:
+ pp_c_tree_identifier (ppi, e);
+ break;
+
+ case ERROR_MARK:
+ pp_c_identifier (ppi, "<erroneous-expression>");
+ break;
+
+ case RESULT_DECL:
+ pp_c_identifier (ppi, "<return-value>");
+ break;
+
+ case INTEGER_CST:
+ case REAL_CST:
+ case STRING_CST:
+ pp_c_literal (ppi, e);
+ break;
+
+ default:
+ /* Make sure this call won't cause any infinite loop. */
+ pp_c_left_paren (ppi);
+ pp_c_expression (ppi, e);
+ pp_c_right_paren (ppi);
+ break;
+ }
+ }
+
+ void
+ pp_c_postfix_expression (ppi, e)
+ c_pretty_print_info *ppi;
+ tree e;
+ {
+ enum tree_code code = TREE_CODE (e);
+ switch (code)
+ {
+ case POSTINCREMENT_EXPR:
+ case POSTDECREMENT_EXPR:
+ pp_postfix_expression (ppi, TREE_OPERAND (e, 0));
+ pp_identifier (ppi, code == POSTINCREMENT_EXPR ? "++" : "--");
+ break;
+
+ case ARRAY_REF:
+ pp_postfix_expression (ppi, TREE_OPERAND (e, 0));
+ pp_c_left_bracket (ppi);
+ pp_c_expression (ppi, TREE_OPERAND (e, 1));
+ pp_c_right_bracket (ppi);
+ break;
+
+ case CALL_EXPR:
+ pp_postfix_expression (ppi, TREE_OPERAND (e, 0));
+ pp_c_left_paren (ppi);
+ pp_c_expression_list (ppi, TREE_OPERAND (e, 1));
+ pp_c_right_paren (ppi);
+ break;
+
+ case COMPONENT_REF:
+ {
+ tree object = TREE_OPERAND (e, 0);
+ if (TREE_CODE (object) == INDIRECT_REF)
+ {
+ pp_postfix_expression (ppi, TREE_OPERAND (object, 0));
+ pp_arrow (ppi);
+ }
+ else
+ {
+ pp_postfix_expression (ppi, object);
+ pp_dot (ppi);
+ }
+ pp_c_expression (ppi, TREE_OPERAND (e, 1));
+ }
+ break;
+
+ case CONSTRUCTOR:
+ case COMPLEX_CST:
+ case VECTOR_CST:
+ pp_unsupported_tree (ppi, e);
+ break;
+
+ default:
+ pp_primary_expression (ppi, e);
+ break;
+ }
+ }
+
+ /* Print out an expession-list; E is expected to be a TREE_LIST */
+ void
+ pp_c_expression_list (ppi, e)
+ c_pretty_print_info *ppi;
+ tree e;
+ {
+ for (; e != NULL_TREE; e = TREE_CHAIN (e))
+ {
+ pp_c_assignment_expression (ppi, TREE_VALUE (e));
+ if (TREE_CHAIN (e))
+ pp_separate_with (ppi, ',');
+ }
+ }
+
+ static void
+ pp_c_unary_expression (ppi, e)
+ c_pretty_print_info *ppi;
+ tree e;
+ {
+ enum tree_code code = TREE_CODE (e);
+ switch (code)
+ {
+ case PREINCREMENT_EXPR:
+ case PREDECREMENT_EXPR:
+ pp_identifier (ppi, code == PREINCREMENT_EXPR ? "++" : "--");
+ pp_c_unary_expression (ppi, TREE_OPERAND (e, 0));
+ break;
+
+ case ADDR_EXPR:
+ case INDIRECT_REF:
+ case CONVERT_EXPR:
+ case NEGATE_EXPR:
+ case BIT_NOT_EXPR:
+ case TRUTH_NOT_EXPR:
+ if (code == ADDR_EXPR)
+ pp_ampersand (ppi);
+ else if (code == INDIRECT_REF)
+ pp_star (ppi);
+ else if (code == NEGATE_EXPR)
+ pp_minus (ppi);
+ else if (code == BIT_NOT_EXPR)
+ pp_complement (ppi);
+ else if (code == TRUTH_NOT_EXPR)
+ pp_exclamation (ppi);
+ pp_c_cast_expression (ppi, TREE_OPERAND (e, 0));
+ break;
+
+ case SIZEOF_EXPR:
+ case ALIGNOF_EXPR:
+ pp_c_identifier (ppi, code == SIZEOF_EXPR ? "sizeof" : "__alignof__");
+ pp_c_whitespace (ppi);
+ if (TYPE_P (TREE_OPERAND (e, 0)))
+ {
+ pp_c_left_paren (ppi);
+ pp_type_id (ppi, TREE_OPERAND (e, 0));
+ pp_c_right_paren (ppi);
+ }
+ else
+ pp_c_unary_expression (ppi, TREE_OPERAND (e, 0));
+ break;
+
+ default:
+ pp_postfix_expression (ppi, e);
+ break;
+ }
+ }
+
+ void
+ pp_c_cast_expression (ppi, e)
+ c_pretty_print_info *ppi;
+ tree e;
+ {
+ if (TREE_CODE (e) == CONVERT_EXPR)
+ {
+ pp_c_left_paren (ppi);
+ pp_type_id (ppi, TREE_TYPE (e));
+ pp_c_right_paren (ppi);
+ pp_c_cast_expression (ppi, TREE_OPERAND (e, 0));
+ }
+ else
+ pp_unary_expression (ppi, e);
+ }
+
+ static void
+ pp_c_multiplicative_expression (ppi, e)
+ c_pretty_print_info *ppi;
+ tree e;
+ {
+ enum tree_code code = TREE_CODE (e);
+ switch (code)
+ {
+ case MULT_EXPR:
+ case TRUNC_DIV_EXPR:
+ case TRUNC_MOD_EXPR:
+ pp_c_multiplicative_expression (ppi, TREE_OPERAND (e, 0));
+ pp_c_whitespace (ppi);
+ if (code == MULT_EXPR)
+ pp_star (ppi);
+ else if (code == TRUNC_DIV_EXPR)
+ pp_slash (ppi);
+ else
+ pp_modulo (ppi);
+ pp_c_whitespace (ppi);
+ pp_c_cast_expression (ppi, TREE_OPERAND (e, 1));
+ break;
+
+ default:
+ pp_c_cast_expression (ppi, e);
+ break;
+ }
+ }
+
+ static inline void
+ pp_c_additive_expression (ppi, e)
+ c_pretty_print_info *ppi;
+ tree e;
+ {
+ enum tree_code code = TREE_CODE (e);
+ switch (code)
+ {
+ case PLUS_EXPR:
+ case MINUS_EXPR:
+ pp_c_additive_expression (ppi, TREE_OPERAND (e, 0));
+ pp_c_whitespace (ppi);
+ if (code == PLUS_EXPR)
+ pp_plus (ppi);
+ else
+ pp_minus (ppi);
+ pp_c_whitespace (ppi);
+ pp_multiplicative_expression (ppi, TREE_OPERAND (e, 1));
+ break;
+
+ default:
+ pp_multiplicative_expression (ppi, e);
+ break;
+ }
+ }
+
+ static inline void
+ pp_c_shift_expression (ppi, e)
+ c_pretty_print_info *ppi;
+ tree e;
+ {
+ enum tree_code code = TREE_CODE (e);
+ switch (code)
+ {
+ case LSHIFT_EXPR:
+ case RSHIFT_EXPR:
+ pp_c_shift_expression (ppi, TREE_OPERAND (e, 0));
+ pp_c_whitespace (ppi);
+ pp_identifier (ppi, code == LSHIFT_EXPR ? "<<" : ">>");
+ pp_c_whitespace (ppi);
+ pp_c_additive_expression (ppi, TREE_OPERAND (e, 1));
+ break;
+
+ default:
+ pp_c_additive_expression (ppi, e);
+ }
+ }
+
+ static void
+ pp_c_relational_expression (ppi, e)
+ c_pretty_print_info *ppi;
+ tree e;
+ {
+ enum tree_code code = TREE_CODE (e);
+ switch (code)
+ {
+ case LT_EXPR:
+ case GT_EXPR:
+ case LE_EXPR:
+ case GE_EXPR:
+ pp_c_relational_expression (ppi, TREE_OPERAND (e, 0));
+ pp_c_whitespace (ppi);
+ if (code == LT_EXPR)
+ pp_less (ppi);
+ else if (code == GT_EXPR)
+ pp_greater (ppi);
+ else if (code == LE_EXPR)
+ pp_identifier (ppi, "<=");
+ else if (code == GE_EXPR)
+ pp_identifier (ppi, ">=");
+ pp_c_whitespace (ppi);
+ pp_c_shift_expression (ppi, TREE_OPERAND (e, 1));
+ break;
+
+ default:
+ pp_c_shift_expression (ppi, e);
+ break;
+ }
+ }
+
+ static inline void
+ pp_c_equality_expression (ppi, e)
+ c_pretty_print_info *ppi;
+ tree e;
+ {
+ enum tree_code code = TREE_CODE (e);
+ switch (code)
+ {
+ case EQ_EXPR:
+ case NE_EXPR:
+ pp_c_equality_expression (ppi, TREE_OPERAND (e, 0));
+ pp_c_maybe_whitespace (ppi);
+ pp_identifier (ppi, code == EQ_EXPR ? "==" : "!=");
+ pp_c_whitespace (ppi);
+ pp_c_relational_expression (ppi, TREE_OPERAND (e, 1));
+ break;
+
+ default:
+ pp_c_relational_expression (ppi, e);
+ break;
+ }
+ }
+
+ static inline void
+ pp_c_and_expression (ppi, e)
+ c_pretty_print_info *ppi;
+ tree e;
+ {
+ if (TREE_CODE (e) == BIT_AND_EXPR)
+ {
+ pp_c_and_expression (ppi, TREE_OPERAND (e, 0));
+ pp_c_maybe_whitespace (ppi);
+ pp_ampersand (ppi);
+ pp_c_whitespace (ppi);
+ pp_c_equality_expression (ppi, TREE_OPERAND (e, 1));
+ }
+ else
+ pp_c_equality_expression (ppi, e);
+ }
+
+ static inline void
+ pp_c_exclusive_or_expression (ppi, e)
+ c_pretty_print_info *ppi;
+ tree e;
+ {
+ if (TREE_CODE (e) == BIT_XOR_EXPR)
+ {
+ pp_c_exclusive_or_expression (ppi, TREE_OPERAND (e, 0));
+ pp_c_maybe_whitespace (ppi);
+ pp_carret (ppi);
+ pp_c_whitespace (ppi);
+ pp_c_and_expression (ppi, TREE_OPERAND (e, 1));
+ }
+ else
+ pp_c_and_expression (ppi, e);
+ }
+
+ static inline void
+ pp_c_inclusive_or_expression (ppi, e)
+ c_pretty_print_info *ppi;
+ tree e;
+ {
+ if (TREE_CODE (e) == BIT_IOR_EXPR)
+ {
+ pp_c_exclusive_or_expression (ppi, TREE_OPERAND (e, 0));
+ pp_c_maybe_whitespace (ppi);
+ pp_bar (ppi);
+ pp_c_whitespace (ppi);
+ pp_c_exclusive_or_expression (ppi, TREE_OPERAND (e, 1));
+ }
+ else
+ pp_c_exclusive_or_expression (ppi, e);
+ }
+
+ static inline void
+ pp_c_logical_and_expression (ppi, e)
+ c_pretty_print_info *ppi;
+ tree e;
+ {
+ if (TREE_CODE (e) == TRUTH_ANDIF_EXPR)
+ {
+ pp_c_logical_and_expression (ppi, TREE_OPERAND (e, 0));
+ pp_c_maybe_whitespace (ppi);
+ pp_identifier (ppi, "&&");
+ pp_c_whitespace (ppi);
+ pp_c_inclusive_or_expression (ppi, TREE_OPERAND (e, 1));
+ }
+ else
+ pp_c_inclusive_or_expression (ppi, e);
+ }
+
+ void
+ pp_c_logical_or_expression (ppi, e)
+ c_pretty_print_info *ppi;
+ tree e;
+ {
+ if (TREE_CODE (e) == TRUTH_ORIF_EXPR)
+ {
+ pp_c_logical_or_expression (ppi, TREE_OPERAND (e, 0));
+ pp_c_maybe_whitespace (ppi);
+ pp_identifier (ppi, "||");
+ pp_c_whitespace (ppi);
+ pp_c_logical_and_expression (ppi, TREE_OPERAND (e, 1));
+ }
+ else
+ pp_c_logical_and_expression (ppi, e);
+ }
+
+ static void
+ pp_c_conditional_expression (ppi, e)
+ c_pretty_print_info *ppi;
+ tree e;
+ {
+ if (TREE_CODE (e) == COND_EXPR)
+ {
+ pp_c_logical_or_expression (ppi, TREE_OPERAND (e, 0));
+ pp_c_maybe_whitespace (ppi);
+ pp_question (ppi);
+ pp_c_whitespace (ppi);
+ pp_c_expression (ppi, TREE_OPERAND (e, 1));
+ pp_c_maybe_whitespace (ppi);
+ pp_colon (ppi);
+ pp_c_whitespace (ppi);
+ pp_c_conditional_expression (ppi, TREE_OPERAND (e, 2));
+ }
+ else
+ pp_c_logical_or_expression (ppi, e);
+ }
+
+
+ /* Pretty-print a C assignment-expression. */
+ static void
+ pp_c_assignment_expression (ppi, e)
+ c_pretty_print_info *ppi;
+ tree e;
+ {
+ if (TREE_CODE (e) == MODIFY_EXPR)
+ {
+ pp_c_unary_expression (ppi, TREE_OPERAND (e, 0));
+ pp_c_maybe_whitespace (ppi);
+ pp_equal (ppi);
+ pp_whitespace (ppi);
+ pp_c_assignment_expression (ppi, TREE_OPERAND (e, 1));
+ }
+ else
+ pp_c_conditional_expression (ppi, e);
+ }
+
+ /* Pretty-print an expression. */
+ void
+ pp_c_expression (ppi, e)
+ c_pretty_print_info *ppi;
+ tree e;
+ {
+ switch (TREE_CODE (e))
+ {
+ case INTEGER_CST:
+ pp_c_integer_literal (ppi, e);
+ break;
+
+ case REAL_CST:
+ pp_c_real_literal (ppi, e);
+ break;
+
+ case STRING_CST:
+ pp_c_string_literal (ppi, e);
+ break;
+
+ case FUNCTION_DECL:
+ case VAR_DECL:
+ case CONST_DECL:
+ case PARM_DECL:
+ case RESULT_DECL:
+ case FIELD_DECL:
+ case LABEL_DECL:
+ case ERROR_MARK:
+ pp_c_primary_expression (ppi, e);
+ break;
+
+ case POSTINCREMENT_EXPR:
+ case POSTDECREMENT_EXPR:
+ case ARRAY_REF:
+ case CALL_EXPR:
+ case COMPONENT_REF:
+ case CONSTRUCTOR:
+ case COMPLEX_CST:
+ case VECTOR_CST:
+ pp_c_postfix_expression (ppi, e);
+ break;
+
+ case CONVERT_EXPR:
+ pp_c_cast_expression (ppi, e);
+ break;
+
+ case MULT_EXPR:
+ case TRUNC_MOD_EXPR:
+ case TRUNC_DIV_EXPR:
+ pp_c_multiplicative_expression (ppi, e);
+ break;
+
+ case LSHIFT_EXPR:
+ case RSHIFT_EXPR:
+ pp_c_shift_expression (ppi, e);
+ break;
+
+ case LT_EXPR:
+ case GT_EXPR:
+ case LE_EXPR:
+ case GE_EXPR:
+ pp_c_relational_expression (ppi, e);
+ break;
+
+ case BIT_AND_EXPR:
+ pp_c_and_expression (ppi, e);
+ break;
+
+ case BIT_XOR_EXPR:
+ pp_c_exclusive_or_expression (ppi, e);
+ break;
+
+ case BIT_IOR_EXPR:
+ pp_c_inclusive_or_expression (ppi, e);
+ break;
+
+ case TRUTH_ANDIF_EXPR:
+ pp_c_logical_and_expression (ppi, e);
+ break;
+
+ case TRUTH_ORIF_EXPR:
+ pp_c_logical_or_expression (ppi, e);
+ break;
+
+ case COND_EXPR:
+ pp_c_conditional_expression (ppi, e);
+ break;
+
+ case MODIFY_EXPR:
+ pp_c_assignment_expression (ppi, e);
+ break;
+
+ case NOP_EXPR:
+ pp_c_expression (ppi, TREE_OPERAND (e, 0));
+ break;
+
+ case COMPOUND_EXPR:
+ pp_c_left_paren (ppi);
+ pp_c_expression (ppi, TREE_OPERAND (e, 0));
+ pp_separate_with (ppi, ',');
+ pp_assignment_expression (ppi, TREE_OPERAND (e, 1));
+ pp_c_right_paren (ppi);
+ break;
+
+
+ default:
+ pp_unsupported_tree (ppi, e);
+ break;
+ }
+ }
+
Index: c-pretty-print.h
===================================================================
RCS file: c-pretty-print.h
diff -N c-pretty-print.h
*** /dev/null 1 Jan 1970 00:00:00 -0000
--- c-pretty-print.h 29 Jul 2002 19:28:40 -0000
***************
*** 0 ****
--- 1,139 ----
+ /* Various declarations for the C and C++ pretty-printers.
+ Copyright (C) 2002 Free Software Foundation, Inc.
+ Contributed by Gabriel Dos Reis <gdr@integrable-solutions.net>
+
+ This file is part of GCC.
+
+ GCC is free software; you can redistribute it and/or modify it under
+ the terms of the GNU General Public License as published by the Free
+ Software Foundation; either version 2, or (at your option) any later
+ version.
+
+ GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with GCC; see the file COPYING. If not, write to the Free
+ Software Foundation, 59 Temple Place - Suite 330, Boston, MA
+ 02111-1307, USA. */
+
+ #include "tree.h"
+ #include "c-common.h"
+ #include "pretty-print.h"
+
+
+ /* The data type used to bundle information necessary for pretty-printing
+ a C or C++ entity. */
+ typedef struct c_pretty_print_info c_pretty_print_info;
+
+ /* The type of a C pretty-printer 'member' function. */
+ typedef void (*c_pretty_print_fn) PARAMS ((c_pretty_print_info *, tree));
+
+ struct c_pretty_print_info
+ {
+ struct pretty_print_info base;
+ /* Points to the first element of an array of offset-list.
+ Not used yet. */
+ int *offset_list;
+
+ /* These must be overriden by each of the C and C++ front-end to
+ reflect their understanding of syntatic productions when they differ. */
+ c_pretty_print_fn declaration;
+ c_pretty_print_fn declaration_specifiers;
+ c_pretty_print_fn type_specifier;
+ c_pretty_print_fn declarator;
+ c_pretty_print_fn direct_declarator;
+ c_pretty_print_fn parameter_declaration;
+ c_pretty_print_fn type_id;
+
+ 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;
+ c_pretty_print_fn conditional_expression;
+ c_pretty_print_fn assignment_expression;
+ };
+
+ #define pp_buffer(PPI) (PPI)->base.buffer
+ #define pp_c_left_paren(PPI) \
+ do { \
+ pp_left_paren (PPI); \
+ (PPI)->base.padding = pp_none; \
+ } while (0)
+ #define pp_c_right_paren(PPI) \
+ do { \
+ pp_right_paren (PPI); \
+ (PPI)->base.padding = pp_none; \
+ } while (0)
+ #define pp_c_left_bracket(PPI) \
+ do { \
+ pp_left_bracket (PPI); \
+ (PPI)->base.padding = pp_none; \
+ } while (0)
+ #define pp_c_right_bracket(PPI) \
+ do { \
+ pp_right_bracket (PPI); \
+ (PPI)->base.padding = pp_none; \
+ } while (0)
+ #define pp_c_whitespace(PPI) \
+ do { \
+ pp_whitespace (PPI); \
+ (PPI)->base.padding = pp_none; \
+ } while (0)
+ #define pp_c_maybe_whitespace(PPI) \
+ do { \
+ if ((PPI)->base.padding != pp_none) \
+ pp_c_whitespace (PPI); \
+ } while (0)
+ #define pp_c_identifier(PPI, ID) \
+ do { \
+ pp_c_maybe_whitespace (PPI); \
+ pp_identifier (PPI, ID); \
+ (PPI)->base.padding = pp_before; \
+ } while (0)
+
+ #define pp_c_tree_identifier(PPI, ID) \
+ pp_c_identifier (PPI, IDENTIFIER_POINTER (ID))
+
+
+ #define pp_declaration(PPI, T) (*(PPI)->declaration) (PPI, T)
+ #define pp_declaration_specifiers(PPI, D) \
+ (*(PPI)->declaration_specifiers) (PPI, D)
+ #define pp_type_specifier(PPI, D) (*(PPI)->type_specifier) (PPI, D)
+ #define pp_declarator(PPI, D) (*(PPI)->declarator) (PPI, D)
+ #define pp_direct_declarator(PPI, D) (*(PPI)->direct_declarator) (PPI, D)
+ #define pp_parameter_declaration(PPI, T) \
+ (*(PPI)->parameter_declaration) (PPI, T)
+ #define pp_type_id(PPI, D) (*(PPI)->type_id) (PPI, D)
+
+ #define pp_statement(PPI, S) (*(PPI)->statement) (PPI, S)
+
+ #define pp_primary_expression(PPI, E) (*(PPI)->primary_expression) (PPI, E)
+ #define pp_postfix_expression(PPI, E) (*(PPI)->postfix_expression) (PPI, E)
+ #define pp_unary_expression(PPI, E) (*(PPI)->unary_expression) (PPI, E)
+ #define pp_multiplicative_expression(PPI, E)\
+ (*(PPI)->multiplicative_expression) (PPI, E)
+ #define pp_conditional_expession(PPI, E) \
+ (*(PPI)->conditional_expression (PPI, E))
+ #define pp_assignment_expression(PPI, E) \
+ (*(PPI)->assignment_expression) (PPI, E)
+
+
+ /* Declarations. */
+ void pp_c_cv_qualifier PARAMS ((c_pretty_print_info *, int));
+ void pp_c_parameter_declaration_clause PARAMS ((c_pretty_print_info *, tree));
+ void pp_c_declaration PARAMS ((c_pretty_print_info *, tree));
+ void pp_c_statement PARAMS ((c_pretty_print_info *, tree));
+ void pp_c_expression PARAMS ((c_pretty_print_info *, tree));
+
+ /* Expressions. */
+ void pp_c_expression PARAMS ((c_pretty_print_info *, tree));
+ void pp_c_logical_or_expression PARAMS ((c_pretty_print_info *, tree));
+ void pp_c_expression_list PARAMS ((c_pretty_print_info *, tree));
+ void pp_c_cast_expression PARAMS ((c_pretty_print_info *, tree));
+ void pp_c_postfix_expression PARAMS ((c_pretty_print_info *, tree));
+ void pp_c_literal PARAMS ((c_pretty_print_info *, tree));
Index: pretty-print.h
===================================================================
RCS file: /cvs/gcc/egcs/gcc/pretty-print.h,v
retrieving revision 1.3
diff -p -r1.3 pretty-print.h
*** pretty-print.h 29 Jul 2002 08:26:45 -0000 1.3
--- pretty-print.h 29 Jul 2002 19:28:40 -0000
*************** struct pretty_print_info
*** 53,59 ****
--- 53,72 ----
#define pp_colon(PPI) output_add_character (pp_buffer (PPI), ':')
#define pp_colon_colon(PPI) output_add_string (pp_buffer (PPI), "::")
#define pp_arrow(PPI) output_add_string (pp_buffer (PPI), "->")
+ #define pp_equal(PPI) output_add_character (pp_buffer (PPI), '=')
+ #define pp_question(PPI) output_add_character (pp_buffer (PPI), '?')
+ #define pp_bar(PPI) output_add_character (pp_buffer (PPI), '|')
+ #define pp_carret(PPI) output_add_character (pp_buffer (PPI), '^')
+ #define pp_ampersand(PPI) output_add_character (pp_buffer (PPI), '&')
+ #define pp_less(PPI) output_add_character (pp_buffer (PPI), '<')
+ #define pp_greater(PPI) output_add_character (pp_buffer (PPI), '>')
+ #define pp_plus(PPI) output_add_character (pp_buffer (PPI), '+')
+ #define pp_minus(PPI) output_add_character (pp_buffer (PPI), '-')
#define pp_star(PPI) output_add_character (pp_buffer (PPI), '*')
+ #define pp_slash(PPI) output_add_character (pp_buffer (PPI), '/')
+ #define pp_modulo(PPI) output_add_character (pp_buffer (PPI), '%')
+ #define pp_exclamation(PPI) output_add_character (pp_buffer (PPI), '!')
+ #define pp_complement(PPI) output_add_character (pp_buffer (PPI), '~')
#define pp_quote(PPI) output_add_character (pp_buffer (PPI), '\'')
#define pp_backquote(PPI) output_add_character (pp_buffer (PPI), '`')
#define pp_doublequote(PPI) output_add_character (pp_buffer (PPI), '"')
*************** struct pretty_print_info
*** 80,86 ****
#define pp_tree_identifier(PPI, T) pp_identifier(PPI, IDENTIFIER_POINTER (T))
#define pp_unsupported_tree(PPI, T) \
! output_verbatim (pp_buffer((PPI), "#`%s' not supported by %s#",\
tree_code_name[(int) TREE_CODE (T)], __FUNCTION__)
#endif /* GCC_PRETTY_PRINT_H */
--- 93,99 ----
#define pp_tree_identifier(PPI, T) pp_identifier(PPI, IDENTIFIER_POINTER (T))
#define pp_unsupported_tree(PPI, T) \
! output_verbatim (pp_buffer(PPI), "#`%s' not supported by %s#",\
tree_code_name[(int) TREE_CODE (T)], __FUNCTION__)
#endif /* GCC_PRETTY_PRINT_H */
Index: cp/Make-lang.in
===================================================================
RCS file: /cvs/gcc/egcs/gcc/cp/Make-lang.in,v
retrieving revision 1.117
diff -p -r1.117 Make-lang.in
*** cp/Make-lang.in 26 Jul 2002 13:45:38 -0000 1.117
--- cp/Make-lang.in 29 Jul 2002 19:28:41 -0000
*************** $(DEMANGLER_PROG): cxxmain.o underscore.
*** 96,102 ****
# The compiler itself.
# Shared with C front end:
CXX_C_OBJS = attribs.o c-common.o c-format.o c-pragma.o c-semantics.o c-lex.o \
! c-dump.o $(CXX_TARGET_OBJS)
# Language-specific object files.
CXX_OBJS = cp/call.o cp/decl.o cp/expr.o cp/pt.o cp/typeck2.o \
--- 96,102 ----
# The compiler itself.
# Shared with C front end:
CXX_C_OBJS = attribs.o c-common.o c-format.o c-pragma.o c-semantics.o c-lex.o \
! c-dump.o $(CXX_TARGET_OBJS) c-pretty-print.o
# Language-specific object files.
CXX_OBJS = cp/call.o cp/decl.o cp/expr.o cp/pt.o cp/typeck2.o \
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Preparatory PATCH for pretty-print
2002-07-29 12:54 Preparatory PATCH for pretty-print Gabriel Dos Reis
@ 2002-07-29 17:31 ` Diego Novillo
2002-07-29 18:05 ` Gabriel Dos Reis
2002-07-29 17:44 ` Devang Patel
` (2 subsequent siblings)
3 siblings, 1 reply; 13+ messages in thread
From: Diego Novillo @ 2002-07-29 17:31 UTC (permalink / raw)
To: Gabriel Dos Reis; +Cc: gcc-patches
On Mon, 2002-07-29 at 15:36, Gabriel Dos Reis wrote:
> This patch prepares for pretty-printing in the C and C++ front-end.
> The machinary is not complete (therefore not turned on).
>
Gaby, will you be merging the features we already have working in the
tree-ssa branch? I see that you are adding files that will be
conflicting with the weekly trunk->branch merges.
Thanks. Diego.
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Preparatory PATCH for pretty-print
2002-07-29 17:31 ` Diego Novillo
@ 2002-07-29 18:05 ` Gabriel Dos Reis
2002-07-29 19:05 ` Diego Novillo
0 siblings, 1 reply; 13+ messages in thread
From: Gabriel Dos Reis @ 2002-07-29 18:05 UTC (permalink / raw)
To: Diego Novillo; +Cc: gcc-patches
Diego Novillo <dnovillo@redhat.com> writes:
| On Mon, 2002-07-29 at 15:36, Gabriel Dos Reis wrote:
|
| > This patch prepares for pretty-printing in the C and C++ front-end.
| > The machinary is not complete (therefore not turned on).
| >
| Gaby, will you be merging the features we already have working in the
| tree-ssa branch? I see that you are adding files that will be
| conflicting with the weekly trunk->branch merges.
I'm trying to put in enough things as soon as possible. Working the
other way would have been more work, IMHO.
For the time being, you can just skip the files I added, for the weekly
merge. I'll incoporate things that already are on the branch.
Thanks,
-- Gaby
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Preparatory PATCH for pretty-print
2002-07-29 12:54 Preparatory PATCH for pretty-print Gabriel Dos Reis
2002-07-29 17:31 ` Diego Novillo
@ 2002-07-29 17:44 ` Devang Patel
2002-07-29 18:43 ` Gabriel Dos Reis
2002-07-29 18:24 ` Mike Stump
2002-08-04 16:01 ` Joseph S. Myers
3 siblings, 1 reply; 13+ messages in thread
From: Devang Patel @ 2002-07-29 17:44 UTC (permalink / raw)
To: Gabriel Dos Reis; +Cc: gcc-patches
[-- Attachment #1: Type: text/plain, Size: 419 bytes --]
Is there any place where I can look to find some info. about
pretty-printing ?
I want to know what is pretty-printing ?
My initial impression is that it will beautify source, though I may be
totally wrong.
On Monday, July 29, 2002, at 12:36 PM, Gabriel Dos Reis wrote:
> This patch prepares for pretty-printing in the C and C++ front-end.
I hope, you are also planning to include Objective-C.
Thank you,
-Devang
[-- Attachment #2: Type: text/enriched, Size: 458 bytes --]
Is there any place where I can look to find some info. about
pretty-printing ?
I want to know what is pretty-printing ?
My initial impression is that it will beautify source, though I may be
totally wrong.
On Monday, July 29, 2002, at 12:36 PM, Gabriel Dos Reis wrote:
<excerpt><fixed>This patch prepares for pretty-printing in the C and
C++ front-end.
</fixed></excerpt>
I hope, you are also planning to include Objective-C.
Thank you,
-Devang
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Preparatory PATCH for pretty-print
2002-07-29 17:44 ` Devang Patel
@ 2002-07-29 18:43 ` Gabriel Dos Reis
2002-07-29 22:24 ` Devang Patel
2002-07-31 15:56 ` Pop Sébastian
0 siblings, 2 replies; 13+ messages in thread
From: Gabriel Dos Reis @ 2002-07-29 18:43 UTC (permalink / raw)
To: Devang Patel; +Cc: gcc-patches
Devang Patel <dpatel@apple.com> writes:
| Is there any place where I can look to find some info. about
| pretty-printing ?
Hmm, I don't think there is any place in the GCC documentation where
pretty-printing (in the front-ends) is mentioned -- although it's done
in various forms for the RTL.
| I want to know what is pretty-printing ?
What I'm doing is just to render the tree-representation (built by
the C or C++ front-ends) into a human readable form -- usually as a
GNU C/C++ program constructs.
The goal actually is two-fold: (1) make it possible to visualize the
effects of various tree-level transformations on program sources;
(2) improve the C/C++ diagnostics reporter.
| My initial impression is that it will beautify source, though I may be
| totally wrong.
Well, the intent isn't to build an "indent"-clone into GCC although
I'll try hard to make the output the "best" readable as possible.
Future works include "styles" -- but I have enought for the time being :-)
| On Monday, July 29, 2002, at 12:36 PM, Gabriel Dos Reis wrote:
|
| > This patch prepares for pretty-printing in the C and C++ front-end.
|
| I hope, you are also planning to include Objective-C.
Well, Objective-C isn't currently on my radar-screen but if you think
there are opportunities to reuse what I'm doing for the C/C++
front-ends then, please just submit a patch.
Thanks,
-- Gaby
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Preparatory PATCH for pretty-print
2002-07-29 18:43 ` Gabriel Dos Reis
@ 2002-07-29 22:24 ` Devang Patel
2002-07-30 6:50 ` Diego Novillo
2002-07-31 15:56 ` Pop Sébastian
1 sibling, 1 reply; 13+ messages in thread
From: Devang Patel @ 2002-07-29 22:24 UTC (permalink / raw)
To: Gabriel Dos Reis; +Cc: gcc-patches
On Monday, July 29, 2002, at 06:06 PM, Gabriel Dos Reis wrote:
> Devang Patel <dpatel@apple.com> writes:
>
> | Is there any place where I can look to find some info. about
> | pretty-printing ?
>
> Hmm, I don't think there is any place in the GCC documentation where
> pretty-printing (in the front-ends) is mentioned -- although it's done
> in various forms for the RTL.
I hope you will add some info. when you are done.
> | I want to know what is pretty-printing ?
>
> What I'm doing is just to render the tree-representation (built by
> the C or C++ front-ends) into a human readable form -- usually as a
> GNU C/C++ program constructs.
>
> The goal actually is two-fold: (1) make it possible to visualize the
> effects of various tree-level transformations on program sources;
> (2) improve the C/C++ diagnostics reporter.
Mike Stump explained me what it is and it's primary use (2).
But, I am more interested in (1) goal.
> | My initial impression is that it will beautify source, though I may
> be
> | totally wrong.
>
> Well, the intent isn't to build an "indent"-clone into GCC although
That's what I was afraid of, hence I asked the question.
> I'll try hard to make the output the "best" readable as possible.
> Future works include "styles" -- but I have enought for the time being
> :-)
:-)
> | On Monday, July 29, 2002, at 12:36 PM, Gabriel Dos Reis wrote:
> |
> | > This patch prepares for pretty-printing in the C and C++ front-end.
> |
> | I hope, you are also planning to include Objective-C.
>
> Well, Objective-C isn't currently on my radar-screen but if you think
> there are opportunities to reuse what I'm doing for the C/C++
> front-ends then, please just submit a patch.
I will play with what you've added in C/C++ and add Objective-C stuff
whenever I get chance.
Thank you,
-Devang
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Preparatory PATCH for pretty-print
2002-07-29 22:24 ` Devang Patel
@ 2002-07-30 6:50 ` Diego Novillo
0 siblings, 0 replies; 13+ messages in thread
From: Diego Novillo @ 2002-07-30 6:50 UTC (permalink / raw)
To: Devang Patel; +Cc: Gabriel Dos Reis, gcc-patches
On Tue, 2002-07-30 at 01:04, Devang Patel wrote:
>
> On Monday, July 29, 2002, at 06:06 PM, Gabriel Dos Reis wrote:
>
> > The goal actually is two-fold: (1) make it possible to visualize the
> > effects of various tree-level transformations on program sources;
> > (2) improve the C/C++ diagnostics reporter.
>
> Mike Stump explained me what it is and it's primary use (2).
> But, I am more interested in (1) goal.
>
If you take a look at tree-ssa-20020619-branch, you will find an earlier
version of the pretty printer that is used for this purpose. If you
compile with the switch -fdump-tree-all-ssa, you get an output dump
after each tree transformation.
The initial idea is to be able to diff successive dumps to visualize
what changed in each stage.
> > Well, the intent isn't to build an "indent"-clone into GCC although
>
> That's what I was afraid of, hence I asked the question.
>
So far we have found it tricky to produce compilable code. The problem
is pointer arithmetic. The parser turns offsets into byte offsets. At
the moment, the pretty printer just prints byte offsets. There are
other tree nodes (like SAVE_EXPRs or nodes for complex types) that the
parser builds that we just print out as-is.
Diego.
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Preparatory PATCH for pretty-print
2002-07-29 18:43 ` Gabriel Dos Reis
2002-07-29 22:24 ` Devang Patel
@ 2002-07-31 15:56 ` Pop Sébastian
2002-07-31 15:57 ` Neil Booth
2002-07-31 17:03 ` Gabriel Dos Reis
1 sibling, 2 replies; 13+ messages in thread
From: Pop Sébastian @ 2002-07-31 15:56 UTC (permalink / raw)
To: Gabriel Dos Reis; +Cc: Devang Patel, gcc-patches
Hi,
Thanks for your work on the C/C++ pretty printer.
On Tue, Jul 30, 2002 at 03:06:20AM +0200, Gabriel Dos Reis wrote:
> Devang Patel <dpatel@apple.com> writes:
>
> | Is there any place where I can look to find some info. about
> | pretty-printing ?
>
> Hmm, I don't think there is any place in the GCC documentation where
> pretty-printing (in the front-ends) is mentioned -- although it's done
> in various forms for the RTL.
>
> | I want to know what is pretty-printing ?
>
> What I'm doing is just to render the tree-representation (built by
> the C or C++ front-ends) into a human readable form -- usually as a
> GNU C/C++ program constructs.
>
> The goal actually is two-fold: (1) make it possible to visualize the
> effects of various tree-level transformations on program sources;
> (2) improve the C/C++ diagnostics reporter.
>
> | My initial impression is that it will beautify source, though I may be
> | totally wrong.
>
> Well, the intent isn't to build an "indent"-clone into GCC although
> I'll try hard to make the output the "best" readable as possible.
Here are some things that would be nice to have in the pretty printer:
1. Include comments from original source code
I know that this would require to store comments with their original line number
and modify the preprocessor in order to keep comments (or transform comments
in such a way we're able to redump them at the right place.)
This will not destroy completely the source structure and
2. Another feature, similar to the previous one, is dumping the right name
for enum elements. This could improve readability of pretty-printed dumps.
(do you have something that does that in diagnostics files ?)
3. store macros names and dump them instead of the expansed macro
4. store file inclusions (and don't dump header files contents)
5. Make pretty printers output compilable.
All these features are not really needed for debugging purposes; however they
would be useful for users who want to use the compiler as a source to source
transformer (and for example verify that GCC does the right optimization on
their code).
> Future works include "styles" -- but I have enought for the time being :-)
>
Maybe this feature is not needed (since you can always pass pretty printer's
output to indent).
> |
> | I hope, you are also planning to include Objective-C.
>
Hmm, here again this is not needed for developping source level optimizations,
but yes it would be nice to have the same syntax on output (from the user's
point of view :-) ).
Here is a patch that does a minimum for enable ObjC pretty printer to work
(with pretty printer version in tree-ssa branch):
http://gcc.gnu.org/ml/gcc-patches/2002-06/msg00797.html
I wrote:
> For example you'll see:
> printf ("%s\n", objc_msg_lookup (objc_msg_lookup (aString, &_OBJC_SELECTOR_TABLE, "Hi!"), &_OBJC_SELECTOR_TABLE + 2))
> instead of the original:
> printf ("%s\n", [[aString stringWithString:"Hi!"] cString]);
I think that this form is enough for debugging purposes.
> Well, Objective-C isn't currently on my radar-screen but if you think
> there are opportunities to reuse what I'm doing for the C/C++
> front-ends then, please just submit a patch.
>
In fact there's nothing else to do than imitating C behaviour for dumping ObjC nodes.
The patch above uses the following code:
void
objc_pretty_print_node (buffer, node)
output_buffer *buffer;
tree node;
{
if (node == NULL_TREE)
return;
switch (TREE_CODE (node))
{
case CLASS_INTERFACE_TYPE:
case CLASS_IMPLEMENTATION_TYPE:
case CATEGORY_INTERFACE_TYPE:
case CATEGORY_IMPLEMENTATION_TYPE:
case PROTOCOL_INTERFACE_TYPE:
case KEYWORD_DECL:
case INSTANCE_METHOD_DECL:
case CLASS_METHOD_DECL:
NIY;
default:
/* The default behaviour is that of a C node. */
c_pretty_print_node (buffer, node);
break;
}
}
-- Sebastian
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Preparatory PATCH for pretty-print
2002-07-31 15:56 ` Pop Sébastian
@ 2002-07-31 15:57 ` Neil Booth
2002-07-31 17:03 ` Gabriel Dos Reis
1 sibling, 0 replies; 13+ messages in thread
From: Neil Booth @ 2002-07-31 15:57 UTC (permalink / raw)
To: Pop S?bastian; +Cc: Gabriel Dos Reis, Devang Patel, gcc-patches
Pop S?bastian wrote:-
> Here are some things that would be nice to have in the pretty printer:
>
> 1. Include comments from original source code
> I know that this would require to store comments with their original line number
> and modify the preprocessor in order to keep comments (or transform comments
> in such a way we're able to redump them at the right place.)
> This will not destroy completely the source structure and
If the current functionality is not enough, then I think that's too bad.
Believe me, it's hard enough work keeping -C and -CC working; indeed
they are already a performance issue and make things more complex than
they otherwise would be. Anything extra is not worthwhile IMO.
> 3. store macros names and dump them instead of the expansed macro
You mean expand macros but don't dump the result? That sounds like
another source of sluggishness.
> 4. store file inclusions (and don't dump header files contents)
File inclusions are fully handled by line-map.c.
Neil.
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Preparatory PATCH for pretty-print
2002-07-31 15:56 ` Pop Sébastian
2002-07-31 15:57 ` Neil Booth
@ 2002-07-31 17:03 ` Gabriel Dos Reis
1 sibling, 0 replies; 13+ messages in thread
From: Gabriel Dos Reis @ 2002-07-31 17:03 UTC (permalink / raw)
To: Pop Sébastian; +Cc: Devang Patel, gcc-patches
Pop Sébastian <pop@gauvain.u-strasbg.fr> writes:
[...]
| 2. Another feature, similar to the previous one, is dumping the right name
| for enum elements.
I added a code attempting to do that -- have a look at pp_c_enumerator().
| This could improve readability of pretty-printed dumps.
| (do you have something that does that in diagnostics files ?)
cp/error.c contains a code to that effect.
[...]
| 5. Make pretty printers output compilable.
I'm not sure this is doable, even in GNU C/C++. For example, a
FILE_STMT says basically something like
__FILE__ = "a-new-file-name";
but then __FILE__ is not assignable. The only way to change its value
is to use the #line preprocessor directive; but the FILE_STMT does not
record a value for __LINE__.
Another examples include things like WRAPPER (in the C++ front-end) or
SRCLOC expressions... I'm not talking of the nightmarre SAVE_EXPR.
But I'm trying to make the output as C/C++ as possible :-)
-- Gaby
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Preparatory PATCH for pretty-print
2002-07-29 12:54 Preparatory PATCH for pretty-print Gabriel Dos Reis
2002-07-29 17:31 ` Diego Novillo
2002-07-29 17:44 ` Devang Patel
@ 2002-07-29 18:24 ` Mike Stump
2002-08-04 16:01 ` Joseph S. Myers
3 siblings, 0 replies; 13+ messages in thread
From: Mike Stump @ 2002-07-29 18:24 UTC (permalink / raw)
To: Devang Patel; +Cc: Gabriel Dos Reis, gcc-patches
On Monday, July 29, 2002, at 05:34 PM, Devang Patel wrote:
> Is there any place where I can look to find some info. about
> pretty-printing ?
> I want to know what is pretty-printing ?
I chatted with Devang about this.
I might suggest www.google.com for those that want to know more...
<http://www-2.cs.cmu.edu/afs/cs.cmu.edu/project/ai-repository/ai/html/
cltl/clm/node253.html>
for example has some classic bits of pretty-printing.
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Preparatory PATCH for pretty-print
2002-07-29 12:54 Preparatory PATCH for pretty-print Gabriel Dos Reis
` (2 preceding siblings ...)
2002-07-29 18:24 ` Mike Stump
@ 2002-08-04 16:01 ` Joseph S. Myers
3 siblings, 0 replies; 13+ messages in thread
From: Joseph S. Myers @ 2002-08-04 16:01 UTC (permalink / raw)
To: Gabriel Dos Reis; +Cc: gcc-patches
On 29 Jul 2002, Gabriel Dos Reis wrote:
> * c-pretty-print.c: New file.
> * c-pretty-print.h: Likewise.
New source files need documenting in passes.texi.
--
Joseph S. Myers
jsm28@cam.ac.uk
^ permalink raw reply [flat|nested] 13+ messages in thread
end of thread, other threads:[~2002-08-04 23:01 UTC | newest]
Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-07-29 12:54 Preparatory PATCH for pretty-print Gabriel Dos Reis
2002-07-29 17:31 ` Diego Novillo
2002-07-29 18:05 ` Gabriel Dos Reis
2002-07-29 19:05 ` Diego Novillo
2002-07-29 17:44 ` Devang Patel
2002-07-29 18:43 ` Gabriel Dos Reis
2002-07-29 22:24 ` Devang Patel
2002-07-30 6:50 ` Diego Novillo
2002-07-31 15:56 ` Pop Sébastian
2002-07-31 15:57 ` Neil Booth
2002-07-31 17:03 ` Gabriel Dos Reis
2002-07-29 18:24 ` Mike Stump
2002-08-04 16:01 ` Joseph S. Myers
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).