diff options
author | Eric Botcazou <ebotcazou@adacore.com> | 2024-05-23 18:26:12 +0200 |
---|---|---|
committer | Eric Botcazou <ebotcazou@adacore.com> | 2024-05-23 18:28:01 +0200 |
commit | 0b3b6a8df77b0ae15078402ea5fb933d6fccd585 (patch) | |
tree | 711fd18ab9c2fed6a97a2eaecbe7612f7f6d9737 /gcc | |
parent | dca3e6b9049ff3c1432d4717ca2309e7aad20447 (diff) | |
download | gcc-0b3b6a8df77b0ae15078402ea5fb933d6fccd585.zip gcc-0b3b6a8df77b0ae15078402ea5fb933d6fccd585.tar.gz gcc-0b3b6a8df77b0ae15078402ea5fb933d6fccd585.tar.bz2 |
Another small fix to implementation of -fdump-ada-spec
This avoids generating invalid Ada code for function with a multidimensional
array parameter and also cleans things up left and right.
gcc/c-family/
* c-ada-spec.cc (check_type_name_conflict): Add guard.
(is_char_array): Simplify.
(dump_ada_array_type): Use strip_array_types.
(dump_ada_node) <POINTER_TYPE>: Deal with anonymous array types.
(dump_nested_type): Use strip_array_types.
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/c-family/c-ada-spec.cc | 30 |
1 files changed, 11 insertions, 19 deletions
diff --git a/gcc/c-family/c-ada-spec.cc b/gcc/c-family/c-ada-spec.cc index 46fee30..8f0849b 100644 --- a/gcc/c-family/c-ada-spec.cc +++ b/gcc/c-family/c-ada-spec.cc @@ -1558,7 +1558,7 @@ check_type_name_conflict (pretty_printer *buffer, tree t) while (TREE_CODE (tmp) == POINTER_TYPE && !TYPE_NAME (tmp)) tmp = TREE_TYPE (tmp); - if (TREE_CODE (tmp) != FUNCTION_TYPE) + if (TREE_CODE (tmp) != FUNCTION_TYPE && tmp != error_mark_node) { const char *s; @@ -1788,17 +1788,9 @@ dump_sloc (pretty_printer *buffer, tree node) static bool is_char_array (tree t) { - int num_dim = 0; - - while (TREE_CODE (t) == ARRAY_TYPE) - { - num_dim++; - t = TREE_TYPE (t); - } - - return num_dim == 1 - && TREE_CODE (t) == INTEGER_TYPE - && id_equal (DECL_NAME (TYPE_NAME (t)), "char"); + return TREE_CODE (t) == ARRAY_TYPE + && TREE_CODE (TREE_TYPE (t)) == INTEGER_TYPE + && id_equal (DECL_NAME (TYPE_NAME (TREE_TYPE (t))), "char"); } /* Dump in BUFFER an array type NODE in Ada syntax. SPC is the indentation @@ -1821,9 +1813,7 @@ dump_ada_array_type (pretty_printer *buffer, tree node, int spc) /* Print the component type. */ if (!char_array) { - tree tmp = node; - while (TREE_CODE (tmp) == ARRAY_TYPE) - tmp = TREE_TYPE (tmp); + tree tmp = strip_array_types (node); pp_string (buffer, " of "); @@ -2350,6 +2340,11 @@ dump_ada_node (pretty_printer *buffer, tree node, tree type, int spc, && DECL_ORIGINAL_TYPE (DECL_CHAIN (stub)) == ref_type) ref_type = TREE_TYPE (DECL_CHAIN (stub)); + /* If this is a pointer to an anonymous array type, then use + the name of the component type. */ + else if (!type_name && is_access) + ref_type = strip_array_types (ref_type); + /* Generate "access <type>" instead of "access <subtype>" if the subtype comes from another file, because subtype declarations do not contribute to the limited view of a @@ -2639,10 +2634,7 @@ dump_nested_type (pretty_printer *buffer, tree field, tree t, int spc) if (!bitmap_set_bit (dumped_anonymous_types, TYPE_UID (field_type))) return; - /* Recurse on the element type if need be. */ - tmp = TREE_TYPE (field_type); - while (TREE_CODE (tmp) == ARRAY_TYPE) - tmp = TREE_TYPE (tmp); + tmp = strip_array_types (field_type); decl = get_underlying_decl (tmp); if (decl && !DECL_NAME (decl) |