@@ -1676,7 +1676,7 @@ dump_ada_array_domains (pretty_printer *
pp_character (buffer, ')');
}
-/* Dump in BUFFER file:line:col information related to NODE. */
+/* Dump in BUFFER file:line information related to NODE. */
static void
dump_sloc (pretty_printer *buffer, tree node)
@@ -1695,8 +1695,6 @@ dump_sloc (pretty_printer *buffer, tree
pp_string (buffer, xloc.file);
pp_string (buffer, ":");
pp_decimal_int (buffer, xloc.line);
- pp_string (buffer, ":");
- pp_decimal_int (buffer, xloc.column);
}
}
@@ -1848,6 +1846,33 @@ dump_ada_template (pretty_printer *buffe
return num_inst > 0;
}
+/* Return true if NODE is a simple enum types, that can be mapped to an
+ Ada enum type directly. */
+
+static bool
+is_simple_enum (tree node)
+{
+ unsigned count = 0;
+ tree value;
+
+ for (value = TYPE_VALUES (node); value; value = TREE_CHAIN (value))
+ {
+ tree int_val = TREE_VALUE (value);
+
+ if (TREE_CODE (int_val) != INTEGER_CST)
+ int_val = DECL_INITIAL (int_val);
+
+ if (! host_integerp (int_val, 0))
+ return false;
+ else if (TREE_INT_CST_LOW (int_val) != count)
+ return false;
+
+ count++;
+ }
+
+ return true;
+}
+
static bool in_function = true;
static bool bitfield_used = false;
@@ -1912,30 +1937,59 @@ dump_generic_ada_node (pretty_printer *b
(buffer, TYPE_NAME (node), node, cpp_check, spc, 0, true);
else
{
- tree value;
+ tree value = TYPE_VALUES (node);
- pp_string (buffer, "unsigned");
-
- for (value = TYPE_VALUES (node); value; value = TREE_CHAIN (value))
+ if (is_simple_enum (node))
{
- pp_semicolon (buffer);
- newline_and_indent (buffer, spc);
-
- pp_ada_tree_identifier
- (buffer, TREE_PURPOSE (value), node, false);
- pp_string (buffer, " : constant ");
+ bool first = true;
+ spc += INDENT_INCR;
+ newline_and_indent (buffer, spc - 1);
+ pp_string (buffer, "(");
+ for (; value; value = TREE_CHAIN (value))
+ {
+ if (first)
+ first = false;
+ else
+ {
+ pp_string (buffer, ",");
+ newline_and_indent (buffer, spc);
+ }
+ pp_ada_tree_identifier
+ (buffer, TREE_PURPOSE (value), node, false);
+ }
+ pp_string (buffer, ");");
+ spc -= INDENT_INCR;
+ newline_and_indent (buffer, spc);
+ pp_string (buffer, "pragma Convention (C, ");
dump_generic_ada_node
(buffer, DECL_NAME (type) ? type : TYPE_NAME (node), type,
cpp_check, spc, 0, true);
+ pp_string (buffer, ")");
+ }
+ else
+ {
+ pp_string (buffer, "unsigned");
+ for (; value; value = TREE_CHAIN (value))
+ {
+ pp_semicolon (buffer);
+ newline_and_indent (buffer, spc);
- pp_string (buffer, " := ");
- dump_generic_ada_node
- (buffer,
- TREE_CODE (TREE_VALUE (value)) == INTEGER_CST ?
- TREE_VALUE (value) : DECL_INITIAL (TREE_VALUE (value)),
- node,
- cpp_check, spc, false, true);
+ pp_ada_tree_identifier
+ (buffer, TREE_PURPOSE (value), node, false);
+ pp_string (buffer, " : constant ");
+
+ dump_generic_ada_node
+ (buffer, DECL_NAME (type) ? type : TYPE_NAME (node), type,
+ cpp_check, spc, 0, true);
+
+ pp_string (buffer, " := ");
+ dump_generic_ada_node
+ (buffer,
+ TREE_CODE (TREE_VALUE (value)) == INTEGER_CST ?
+ TREE_VALUE (value) : DECL_INITIAL (TREE_VALUE (value)),
+ node, cpp_check, spc, false, true);
+ }
}
}
break;
@@ -2702,6 +2756,11 @@ print_ada_declaration (pretty_printer *b
return 1;
break;
+ case ENUMERAL_TYPE:
+ pp_string
+ (buffer, is_simple_enum (TREE_TYPE (t)) ? "type " : "subtype ");
+ break;
+
default:
pp_string (buffer, "subtype ");
}