diff options
author | Will Wray <wjwray@gmail.com> | 2018-10-12 03:35:48 +0000 |
---|---|---|
committer | Jeff Law <law@gcc.gnu.org> | 2018-10-11 21:35:48 -0600 |
commit | 79371671cb49d19c41a75d203420f65c39c12b21 (patch) | |
tree | ba6b0fbe86184862b329e056b407eb62eab5ee58 | |
parent | 0b8c3649a512c4cd1a846a2f3e86150e824cbb41 (diff) | |
download | gcc-79371671cb49d19c41a75d203420f65c39c12b21.zip gcc-79371671cb49d19c41a75d203420f65c39c12b21.tar.gz gcc-79371671cb49d19c41a75d203420f65c39c12b21.tar.bz2 |
re PR c++/87364 (Pretty print of enumerator never prints the id, always falls back to C-style cast output)
PR c++/87364
* c-pretty-print.h (pp_c_type_cast): Prototype.
(pp_c_integer_constant): Likewise.
* c-pretty-print.c (pp_c_type_cast): No longer static.
(pp_c_integer_constant): Likewise.
(pp_c_enumeration_constant): Fix loop termination when finding
name of constant. No longer returns a value. Call
pp_c_integer_constant.
(c_pretty_printer::constant): Update for changes to
pp_c_enumeration_constant.
PR c++/87364
* cxx-pretty-print.c (pp_cxx_enumeration_constant): New function.
(cxx_pretty_printer::constant): Use it.
From-SVN: r265077
-rw-r--r-- | gcc/c-family/ChangeLog | 13 | ||||
-rw-r--r-- | gcc/c-family/c-pretty-print.c | 26 | ||||
-rw-r--r-- | gcc/c-family/c-pretty-print.h | 2 | ||||
-rw-r--r-- | gcc/cp/ChangeLog | 6 | ||||
-rw-r--r-- | gcc/cp/cxx-pretty-print.c | 38 |
5 files changed, 70 insertions, 15 deletions
diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog index 71251b9..3d5fd4f 100644 --- a/gcc/c-family/ChangeLog +++ b/gcc/c-family/ChangeLog @@ -1,3 +1,16 @@ +2018-10-11 Will Wray <wjwray@gmail.com> + + PR c++/87364 + * c-pretty-print.h (pp_c_type_cast): Prototype. + (pp_c_integer_constant): Likewise. + * c-pretty-print.c (pp_c_type_cast): No longer static. + (pp_c_integer_constant): Likewise. + (pp_c_enumeration_constant): Fix loop termination when finding + name of constant. No longer returns a value. Call + pp_c_integer_constant. + (c_pretty_printer::constant): Update for changes to + pp_c_enumeration_constant. + 2018-10-11 Jakub Jelinek <jakub@redhat.com> * c-lex.c (c_common_has_attribute): Return 201803 instead of 20180312 diff --git a/gcc/c-family/c-pretty-print.c b/gcc/c-family/c-pretty-print.c index efb41c5..bdd5567 100644 --- a/gcc/c-family/c-pretty-print.c +++ b/gcc/c-family/c-pretty-print.c @@ -192,7 +192,7 @@ pp_c_cv_qualifiers (c_pretty_printer *pp, int qualifiers, bool func_type) /* 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); @@ -908,7 +908,7 @@ pp_c_void_constant (c_pretty_printer *pp) /* Pretty-print an INTEGER literal. */ -static void +void pp_c_integer_constant (c_pretty_printer *pp, tree i) { if (tree_fits_shwi_p (i)) @@ -968,21 +968,20 @@ pp_c_bool_constant (c_pretty_printer *pp, tree b) 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)) ; @@ -992,10 +991,8 @@ pp_c_enumeration_constant (c_pretty_printer *pp, tree e) { /* 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. */ @@ -1140,9 +1137,8 @@ c_pretty_printer::constant (tree e) 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); } diff --git a/gcc/c-family/c-pretty-print.h b/gcc/c-family/c-pretty-print.h index c012b8c..ac824a3 100644 --- a/gcc/c-family/c-pretty-print.h +++ b/gcc/c-family/c-pretty-print.h @@ -128,11 +128,13 @@ void pp_c_logical_or_expression (c_pretty_printer *, tree); void pp_c_expression_list (c_pretty_printer *, tree); void pp_c_constructor_elts (c_pretty_printer *, vec<constructor_elt, va_gc> *); void pp_c_call_argument_list (c_pretty_printer *, tree); +void pp_c_type_cast (c_pretty_printer *, tree); void pp_c_cast_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 *); void pp_c_string_literal (c_pretty_printer *, tree); +void pp_c_integer_constant (c_pretty_printer *, tree); void print_c_tree (FILE *file, tree t); diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index a3d29d7..bbeb45c 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2018-10-11 Will Wray <wjwray@gmail.com> + + PR c++/87364 + * cxx-pretty-print.c (pp_cxx_enumeration_constant): New function. + (cxx_pretty_printer::constant): Use it. + 2018-10-11 David Malcolm <dmalcolm@redhat.com> PR c++/84993 diff --git a/gcc/cp/cxx-pretty-print.c b/gcc/cp/cxx-pretty-print.c index 8426c72..c138c50 100644 --- a/gcc/cp/cxx-pretty-print.c +++ b/gcc/cp/cxx-pretty-print.c @@ -294,6 +294,39 @@ pp_cxx_qualified_id (cxx_pretty_printer *pp, tree t) } } +/* Given a value e of ENUMERAL_TYPE: + Print out the first ENUMERATOR id with value e, if one is found, + (including nested names but excluding the enum name if unscoped) + else print out the value as a C-style cast (type-id)value. */ + +static void +pp_cxx_enumeration_constant (cxx_pretty_printer *pp, 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 (DECL_INITIAL (TREE_VALUE (value)), e); + value = TREE_CHAIN (value)) + ; + + if (value != NULL_TREE) + { + if (!ENUM_IS_SCOPED (type)) + type = get_containing_scope (type); + pp_cxx_nested_name_specifier (pp, type); + pp->id_expression (TREE_PURPOSE (value)); + } + else + { + /* Value must have been cast. */ + pp_c_type_cast (pp, type); + pp_c_integer_constant (pp, e); + } +} + void cxx_pretty_printer::constant (tree t) @@ -317,6 +350,11 @@ cxx_pretty_printer::constant (tree t) pp_string (this, "nullptr"); break; } + else if (TREE_CODE (TREE_TYPE (t)) == ENUMERAL_TYPE) + { + pp_cxx_enumeration_constant (this, t); + break; + } /* fall through. */ default: |