Mercurial > hg > CbC > CbC_gcc
diff gcc/c-family/c-pretty-print.c @ 132:d34655255c78
update gcc-8.2
author | mir3636 |
---|---|
date | Thu, 25 Oct 2018 10:21:07 +0900 |
parents | 367f9f4f266e 84e7813d76e9 |
children | 351920fa3827 |
line wrap: on
line diff
--- a/gcc/c-family/c-pretty-print.c Thu Oct 25 08:08:40 2018 +0900 +++ b/gcc/c-family/c-pretty-print.c Thu Oct 25 10:21:07 2018 +0900 @@ -1,5 +1,5 @@ /* Subroutines common to both C and C++ pretty-printers. - Copyright (C) 2002-2017 Free Software Foundation, Inc. + Copyright (C) 2002-2018 Free Software Foundation, Inc. Contributed by Gabriel Dos Reis <gdr@integrable-solutions.net> This file is part of GCC. @@ -28,6 +28,7 @@ #include "attribs.h" #include "intl.h" #include "tree-pretty-print.h" +#include "selftest.h" #ifndef noCbC #include "../c/cbc-tree.h" #endif @@ -194,7 +195,7 @@ /* Pretty-print T using the type-cast notation '( type-name )'. */ -static void +void pp_c_type_cast (c_pretty_printer *pp, tree t) { pp_c_left_paren (pp); @@ -910,7 +911,7 @@ /* Pretty-print an INTEGER literal. */ -static void +void pp_c_integer_constant (c_pretty_printer *pp, tree i) { if (tree_fits_shwi_p (i)) @@ -970,21 +971,20 @@ pp_unsupported_tree (pp, 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. */ +/* Given a value e of ENUMERAL_TYPE: + Print out the first ENUMERATOR id with value e, if one is found, + else print out the value as a C-style cast (type-id)value. */ -static bool +static void pp_c_enumeration_constant (c_pretty_printer *pp, tree e) { - bool value_is_named = true; 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 != NULL_TREE + && !tree_int_cst_equal (DECL_INITIAL (TREE_VALUE (value)), e); value = TREE_CHAIN (value)) ; @@ -994,10 +994,8 @@ { /* Value must have been cast. */ pp_c_type_cast (pp, type); - value_is_named = false; + pp_c_integer_constant (pp, e); } - - return value_is_named; } /* Print out a REAL value as a decimal-floating-constant. */ @@ -1142,9 +1140,8 @@ pp_c_bool_constant (this, e); else if (type == char_type_node) pp_c_character_constant (this, e); - else if (TREE_CODE (type) == ENUMERAL_TYPE - && pp_c_enumeration_constant (this, e)) - ; + else if (TREE_CODE (type) == ENUMERAL_TYPE) + pp_c_enumeration_constant (this, e); else pp_c_integer_constant (this, e); } @@ -1382,8 +1379,9 @@ case VECTOR_TYPE: if (TREE_CODE (e) == VECTOR_CST) { - unsigned i; - for (i = 0; i < VECTOR_CST_NELTS (e); ++i) + /* We don't create variable-length VECTOR_CSTs. */ + unsigned int nunits = VECTOR_CST_NELTS (e).to_constant (); + for (unsigned int i = 0; i < nunits; ++i) { if (i > 0) pp_separate_with (pp, ','); @@ -1485,17 +1483,6 @@ pp_c_right_bracket (this); break; - case ARRAY_NOTATION_REF: - postfix_expression (ARRAY_NOTATION_ARRAY (e)); - pp_c_left_bracket (this); - expression (ARRAY_NOTATION_START (e)); - pp_colon (this); - expression (ARRAY_NOTATION_LENGTH (e)); - pp_colon (this); - expression (ARRAY_NOTATION_STRIDE (e)); - pp_c_right_bracket (this); - break; - case CALL_EXPR: { call_expr_arg_iterator iter; @@ -1822,7 +1809,8 @@ case FIX_TRUNC_EXPR: CASE_CONVERT: case VIEW_CONVERT_EXPR: - pp_c_type_cast (pp, TREE_TYPE (e)); + if (!location_wrapper_p (e)) + pp_c_type_cast (pp, TREE_TYPE (e)); pp_c_cast_expression (pp, TREE_OPERAND (e, 0)); break; @@ -1852,7 +1840,7 @@ pp_c_whitespace (this); if (code == MULT_EXPR) pp_c_star (this); - else if (code == TRUNC_DIV_EXPR) + else if (code != TRUNC_MOD_EXPR) pp_slash (this); else pp_modulo (this); @@ -1879,6 +1867,7 @@ { case POINTER_PLUS_EXPR: case PLUS_EXPR: + case POINTER_DIFF_EXPR: case MINUS_EXPR: pp_c_additive_expression (pp, TREE_OPERAND (e, 0)); pp_c_whitespace (pp); @@ -2194,7 +2183,6 @@ case POSTINCREMENT_EXPR: case POSTDECREMENT_EXPR: case ARRAY_REF: - case ARRAY_NOTATION_REF: case CALL_EXPR: case COMPONENT_REF: case BIT_FIELD_REF: @@ -2295,6 +2283,7 @@ case POINTER_PLUS_EXPR: case PLUS_EXPR: + case POINTER_DIFF_EXPR: case MINUS_EXPR: pp_c_additive_expression (this, e); break; @@ -2351,7 +2340,7 @@ if (pp_needs_newline (this)) pp_newline_and_indent (this, 0); - dump_generic_node (this, stmt, pp_indentation (this), 0, true); + dump_generic_node (this, stmt, pp_indentation (this), TDF_NONE, true); } @@ -2412,3 +2401,65 @@ pp_c_identifier (pp, name); } + +#if CHECKING_P + +namespace selftest { + +/* Selftests for pretty-printing trees. */ + +/* Verify that EXPR printed by c_pretty_printer is EXPECTED, using + LOC as the effective location for any failures. */ + +static void +assert_c_pretty_printer_output (const location &loc, const char *expected, + tree expr) +{ + c_pretty_printer pp; + pp.expression (expr); + ASSERT_STREQ_AT (loc, expected, pp_formatted_text (&pp)); +} + +/* Helper function for calling assert_c_pretty_printer_output. + This is to avoid having to write SELFTEST_LOCATION. */ + +#define ASSERT_C_PRETTY_PRINTER_OUTPUT(EXPECTED, EXPR) \ + SELFTEST_BEGIN_STMT \ + assert_c_pretty_printer_output ((SELFTEST_LOCATION), \ + (EXPECTED), \ + (EXPR)); \ + SELFTEST_END_STMT + +/* Verify that location wrappers don't show up in pretty-printed output. */ + +static void +test_location_wrappers () +{ + /* VAR_DECL. */ + tree id = get_identifier ("foo"); + tree decl = build_decl (UNKNOWN_LOCATION, VAR_DECL, id, + integer_type_node); + tree wrapped_decl = maybe_wrap_with_location (decl, BUILTINS_LOCATION); + ASSERT_NE (wrapped_decl, decl); + ASSERT_C_PRETTY_PRINTER_OUTPUT ("foo", decl); + ASSERT_C_PRETTY_PRINTER_OUTPUT ("foo", wrapped_decl); + + /* INTEGER_CST. */ + tree int_cst = build_int_cst (integer_type_node, 42); + tree wrapped_cst = maybe_wrap_with_location (int_cst, BUILTINS_LOCATION); + ASSERT_NE (wrapped_cst, int_cst); + ASSERT_C_PRETTY_PRINTER_OUTPUT ("42", int_cst); + ASSERT_C_PRETTY_PRINTER_OUTPUT ("42", wrapped_cst); +} + +/* Run all of the selftests within this file. */ + +void +c_pretty_print_c_tests () +{ + test_location_wrappers (); +} + +} // namespace selftest + +#endif /* CHECKING_P */