aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp
diff options
context:
space:
mode:
authorWill Wray <wjwray@gmail.com>2018-10-12 03:35:48 +0000
committerJeff Law <law@gcc.gnu.org>2018-10-11 21:35:48 -0600
commit79371671cb49d19c41a75d203420f65c39c12b21 (patch)
treeba6b0fbe86184862b329e056b407eb62eab5ee58 /gcc/cp
parent0b8c3649a512c4cd1a846a2f3e86150e824cbb41 (diff)
downloadgcc-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
Diffstat (limited to 'gcc/cp')
-rw-r--r--gcc/cp/ChangeLog6
-rw-r--r--gcc/cp/cxx-pretty-print.c38
2 files changed, 44 insertions, 0 deletions
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: