From: Eric Botcazou Date: Sat, 7 Jul 2018 10:46:10 +0000 (+0000) Subject: c-ada-spec.c (to_ada_name): Remove index parameter. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=e730a0ef11a788bb00034e007b320c6608c17e66;p=gcc.git c-ada-spec.c (to_ada_name): Remove index parameter. * c-ada-spec.c (to_ada_name): Remove index parameter. (pp_ada_tree_identifier): Likewise. (dump_ada_macros): Adjust call to to_ada_name. (struct overloaded_name_hash): Delete. (struct overloaded_name_hasher): Likewise. (overloaded_names): Likewise. (compute_overloading_index): Likewise. (dump_ada_decl_name): Do not call compute_overloading_index and adjust calls to pp_ada_tree_identifier. (dump_ada_double_name): Adjust calls to pp_ada_tree_identifier. (dump_ada_import): Add spc parameter and switch to aspect syntax. (dump_ada_function_declaration): Adjust call to pp_ada_tree_identifier. (dump_ada_enum_type): Remove type and display_convention parameters. Adjust calls to pp_ada_tree_identifier. (dump_ada_node): Likewise and for dump_ada_structure. (dump_nested_type) : Adjust call to dump_ada_enum_type and tidy up. : Adjust call to dump_ada_structure and switch to aspect syntax. (print_constructor): Adjust call to pp_ada_tree_identifier. (print_destructor): Likewise. (dump_ada_declaration): Switch to aspect syntax. (dump_ada_structure): Likewise and tidy up. Replace display_convention parameter with nested parameter. (dump_ads): Emit pragma Ada_2012 in lieu of pragma Ada_2005. (dump_ada_specs): Do not delete overloaded_names table. From-SVN: r262499 --- diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog index 4193200895f..bf4e7e9bd89 100644 --- a/gcc/c-family/ChangeLog +++ b/gcc/c-family/ChangeLog @@ -1,7 +1,36 @@ +2018-07-07 Eric Botcazou + + * c-ada-spec.c (to_ada_name): Remove index parameter. + (pp_ada_tree_identifier): Likewise. + (dump_ada_macros): Adjust call to to_ada_name. + (struct overloaded_name_hash): Delete. + (struct overloaded_name_hasher): Likewise. + (overloaded_names): Likewise. + (compute_overloading_index): Likewise. + (dump_ada_decl_name): Do not call compute_overloading_index and + adjust calls to pp_ada_tree_identifier. + (dump_ada_double_name): Adjust calls to pp_ada_tree_identifier. + (dump_ada_import): Add spc parameter and switch to aspect syntax. + (dump_ada_function_declaration): Adjust call to pp_ada_tree_identifier. + (dump_ada_enum_type): Remove type and display_convention parameters. + Adjust calls to pp_ada_tree_identifier. + (dump_ada_node): Likewise and for dump_ada_structure. + (dump_nested_type) : Adjust call to dump_ada_enum_type + and tidy up. + : Adjust call to dump_ada_structure and switch to aspect + syntax. + (print_constructor): Adjust call to pp_ada_tree_identifier. + (print_destructor): Likewise. + (dump_ada_declaration): Switch to aspect syntax. + (dump_ada_structure): Likewise and tidy up. Replace display_convention + parameter with nested parameter. + (dump_ads): Emit pragma Ada_2012 in lieu of pragma Ada_2005. + (dump_ada_specs): Do not delete overloaded_names table. + 2018-07-06 Peter Bergner PR target/86324 - * c-attribs.c (handle_mode_attribute): Call new translate_mode_attribute + * c-attribs.c (handle_mode_attribute): Call translate_mode_attribute target hook. 2018-07-05 Nathan Sidwell diff --git a/gcc/c-family/c-ada-spec.c b/gcc/c-family/c-ada-spec.c index 30fdb59d55c..9c7de23a04e 100644 --- a/gcc/c-family/c-ada-spec.c +++ b/gcc/c-family/c-ada-spec.c @@ -34,8 +34,8 @@ along with GCC; see the file COPYING3. If not see /* Local functions, macros and variables. */ static int dump_ada_node (pretty_printer *, tree, tree, int, bool, bool); static int dump_ada_declaration (pretty_printer *, tree, tree, int); -static void dump_ada_structure (pretty_printer *, tree, tree, int, bool); -static char *to_ada_name (const char *, unsigned int, bool *); +static void dump_ada_structure (pretty_printer *, tree, tree, bool, int); +static char *to_ada_name (const char *, bool *); #define INDENT(SPACE) \ do { int i; for (i = 0; i homonyms; -}; - -struct overloaded_name_hasher : delete_ptr_hash -{ - static inline hashval_t hash (overloaded_name_hash *t) - { return t->hash; } - static inline bool equal (overloaded_name_hash *a, overloaded_name_hash *b) - { return a->name == b->name && a->context == b->context; } -}; - -static hash_table *overloaded_names; - -/* Compute the overloading index of function DECL in its context. */ - -static unsigned int -compute_overloading_index (tree decl) -{ - const hashval_t hashcode - = iterative_hash_hashval_t (htab_hash_pointer (DECL_NAME (decl)), - htab_hash_pointer (DECL_CONTEXT (decl))); - struct overloaded_name_hash in, *h, **slot; - unsigned int index, *iter; - - if (!overloaded_names) - overloaded_names = new hash_table (512); - - /* Look up the list of homonyms in the table. */ - in.hash = hashcode; - in.name = DECL_NAME (decl); - in.context = DECL_CONTEXT (decl); - slot = overloaded_names->find_slot_with_hash (&in, hashcode, INSERT); - if (*slot) - h = *slot; - else - { - h = new overloaded_name_hash; - h->hash = hashcode; - h->name = DECL_NAME (decl); - h->context = DECL_CONTEXT (decl); - h->homonyms.create (0); - *slot = h; - } - - /* Look up the function in the list of homonyms. */ - FOR_EACH_VEC_ELT (h->homonyms, index, iter) - if (*iter == DECL_UID (decl)) - break; - - /* If it is not present, push it onto the list. */ - if (!iter) - h->homonyms.safe_push (DECL_UID (decl)); - - return index; -} - /* Dump in BUFFER the name of a DECL node if set, in Ada syntax. LIMITED_ACCESS indicates whether NODE can be accessed via a limited 'with' clause rather than a regular 'with' clause. */ @@ -1519,13 +1450,7 @@ static void dump_ada_decl_name (pretty_printer *buffer, tree decl, bool limited_access) { if (DECL_NAME (decl)) - { - const unsigned int index - = (TREE_CODE (decl) == FUNCTION_DECL && cpp_check) - ? compute_overloading_index (decl) : 0; - pp_ada_tree_identifier (buffer, DECL_NAME (decl), decl, index, - limited_access); - } + pp_ada_tree_identifier (buffer, DECL_NAME (decl), decl, limited_access); else { tree type_name = TYPE_NAME (TREE_TYPE (decl)); @@ -1539,7 +1464,7 @@ dump_ada_decl_name (pretty_printer *buffer, tree decl, bool limited_access) pp_scalar (buffer, "%d", TYPE_UID (TREE_TYPE (decl))); } else if (TREE_CODE (type_name) == IDENTIFIER_NODE) - pp_ada_tree_identifier (buffer, type_name, decl, 0, limited_access); + pp_ada_tree_identifier (buffer, type_name, decl, limited_access); } } @@ -1549,7 +1474,7 @@ static void dump_ada_double_name (pretty_printer *buffer, tree t1, tree t2) { if (DECL_NAME (t1)) - pp_ada_tree_identifier (buffer, DECL_NAME (t1), t1, 0, false); + pp_ada_tree_identifier (buffer, DECL_NAME (t1), t1, false); else { pp_string (buffer, "anon"); @@ -1559,7 +1484,7 @@ dump_ada_double_name (pretty_printer *buffer, tree t1, tree t2) pp_underscore (buffer); if (DECL_NAME (t2)) - pp_ada_tree_identifier (buffer, DECL_NAME (t2), t2, 0, false); + pp_ada_tree_identifier (buffer, DECL_NAME (t2), t2, false); else { pp_string (buffer, "anon"); @@ -1586,32 +1511,38 @@ dump_ada_double_name (pretty_printer *buffer, tree t1, tree t2) } } -/* Dump in BUFFER pragma Import C/CPP on a given node T. */ +/* Dump in BUFFER aspect Import on a given node T. SPC is the current + indentation level. */ static void -dump_ada_import (pretty_printer *buffer, tree t) +dump_ada_import (pretty_printer *buffer, tree t, int spc) { const char *name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (t)); const bool is_stdcall = TREE_CODE (t) == FUNCTION_DECL && lookup_attribute ("stdcall", TYPE_ATTRIBUTES (TREE_TYPE (t))); + pp_string (buffer, "with Import => True, "); + + newline_and_indent (buffer, spc + 5); + if (is_stdcall) - pp_string (buffer, "pragma Import (Stdcall, "); + pp_string (buffer, "Convention => Stdcall, "); else if (name[0] == '_' && name[1] == 'Z') - pp_string (buffer, "pragma Import (CPP, "); + pp_string (buffer, "Convention => CPP, "); else - pp_string (buffer, "pragma Import (C, "); + pp_string (buffer, "Convention => C, "); - dump_ada_decl_name (buffer, t, false); - pp_string (buffer, ", \""); + newline_and_indent (buffer, spc + 5); + + pp_string (buffer, "External_Name => \""); if (is_stdcall) pp_string (buffer, IDENTIFIER_POINTER (DECL_NAME (t))); else pp_asm_name (buffer, t); - pp_string (buffer, "\");"); + pp_string (buffer, "\";"); } /* Check whether T and its type have different names, and append "the_" @@ -1717,7 +1648,7 @@ dump_ada_function_declaration (pretty_printer *buffer, tree func, if (DECL_NAME (arg)) { check_name (buffer, arg); - pp_ada_tree_identifier (buffer, DECL_NAME (arg), NULL_TREE, 0, + pp_ada_tree_identifier (buffer, DECL_NAME (arg), NULL_TREE, false); pp_string (buffer, " : "); } @@ -2022,13 +1953,11 @@ is_simple_enum (tree node) return true; } -/* Dump in BUFFER an enumeral type NODE of type TYPE in Ada syntax. SPC is - the indentation level. If DISPLAY_CONVENTION is true, also print the - pragma Convention for NODE. */ +/* Dump in BUFFER an enumeral type NODE in Ada syntax. SPC is the indentation + level. */ static void -dump_ada_enum_type (pretty_printer *buffer, tree node, tree type, int spc, - bool display_convention) +dump_ada_enum_type (pretty_printer *buffer, tree node, int spc) { if (is_simple_enum (node)) { @@ -2046,19 +1975,12 @@ dump_ada_enum_type (pretty_printer *buffer, tree node, tree type, int spc, newline_and_indent (buffer, spc); } - pp_ada_tree_identifier (buffer, TREE_PURPOSE (value), node, 0, false); + pp_ada_tree_identifier (buffer, TREE_PURPOSE (value), node, false); } - pp_string (buffer, ");"); + pp_string (buffer, ")"); spc -= INDENT_INCR; newline_and_indent (buffer, spc); - - if (display_convention) - { - pp_string (buffer, "pragma Convention (C, "); - dump_ada_node (buffer, DECL_NAME (type) ? type : TYPE_NAME (node), - type, spc, false, true); - pp_right_paren (buffer); - } + pp_string (buffer, "with Convention => C"); } else { @@ -2071,7 +1993,7 @@ dump_ada_enum_type (pretty_printer *buffer, tree node, tree type, int spc, pp_semicolon (buffer); newline_and_indent (buffer, spc); - pp_ada_tree_identifier (buffer, TREE_PURPOSE (value), node, 0, false); + pp_ada_tree_identifier (buffer, TREE_PURPOSE (value), node, false); pp_string (buffer, " : constant "); if (TYPE_UNSIGNED (node)) @@ -2110,7 +2032,7 @@ dump_ada_node (pretty_printer *buffer, tree node, tree type, int spc, return 0; case IDENTIFIER_NODE: - pp_ada_tree_identifier (buffer, node, type, 0, limited_access); + pp_ada_tree_identifier (buffer, node, type, limited_access); break; case TREE_LIST: @@ -2149,7 +2071,7 @@ dump_ada_node (pretty_printer *buffer, tree node, tree type, int spc, if (name_only) dump_ada_node (buffer, TYPE_NAME (node), node, spc, false, true); else - dump_ada_enum_type (buffer, node, type, spc, true); + dump_ada_enum_type (buffer, node, spc); break; case REAL_TYPE: @@ -2171,7 +2093,7 @@ dump_ada_node (pretty_printer *buffer, tree node, tree type, int spc, if (TYPE_NAME (node)) { if (TREE_CODE (TYPE_NAME (node)) == IDENTIFIER_NODE) - pp_ada_tree_identifier (buffer, TYPE_NAME (node), node, 0, + pp_ada_tree_identifier (buffer, TYPE_NAME (node), node, limited_access); else if (TREE_CODE (TYPE_NAME (node)) == TYPE_DECL && DECL_NAME (TYPE_NAME (node))) @@ -2215,14 +2137,11 @@ dump_ada_node (pretty_printer *buffer, tree node, tree type, int spc, spc + INDENT_INCR); /* If we are dumping the full type, it means we are part of a - type definition and need also a Convention C pragma. */ + type definition and need also a Convention C aspect. */ if (!name_only) { - pp_semicolon (buffer); newline_and_indent (buffer, spc); - pp_string (buffer, "pragma Convention (C, "); - dump_ada_node (buffer, type, NULL_TREE, spc, false, true); - pp_right_paren (buffer); + pp_string (buffer, "with Convention => C"); } } else @@ -2336,7 +2255,7 @@ dump_ada_node (pretty_printer *buffer, tree node, tree type, int spc, dump_ada_node (buffer, TYPE_NAME (node), node, spc, limited_access, true); else - dump_ada_structure (buffer, node, type, spc, true); + dump_ada_structure (buffer, node, type, false, spc); break; case INTEGER_CST: @@ -2607,23 +2526,9 @@ dump_nested_type (pretty_printer *buffer, tree field, tree t, tree parent, else dump_ada_double_name (buffer, parent, field); pp_string (buffer, " is "); - dump_ada_enum_type (buffer, field_type, t, spc, false); - - if (is_simple_enum (field_type)) - { - pp_string (buffer, "pragma Convention (C, "); - if (TYPE_NAME (field_type)) - dump_ada_node (buffer, field_type, NULL_TREE, spc, false, true); - else - dump_ada_double_name (buffer, parent, field); - pp_string (buffer, ");"); - newline_and_indent (buffer, spc); - } - else - { - pp_semicolon (buffer); - newline_and_indent (buffer, spc); - } + dump_ada_enum_type (buffer, field_type, spc); + pp_semicolon (buffer); + newline_and_indent (buffer, spc); break; case RECORD_TYPE: @@ -2641,25 +2546,19 @@ dump_nested_type (pretty_printer *buffer, tree field, tree t, tree parent, pp_string (buffer, " (discr : unsigned := 0)"); pp_string (buffer, " is "); - dump_ada_structure (buffer, field_type, t, spc, false); + dump_ada_structure (buffer, field_type, t, true, spc); - pp_string (buffer, "pragma Convention (C_Pass_By_Copy, "); - if (TYPE_NAME (field_type)) - dump_ada_node (buffer, field_type, NULL_TREE, spc, false, true); - else - dump_ada_double_name (buffer, parent, field); - pp_string (buffer, ");"); - newline_and_indent (buffer, spc); + pp_string (buffer, "with Convention => C_Pass_By_Copy"); if (TREE_CODE (field_type) == UNION_TYPE) { - pp_string (buffer, "pragma Unchecked_Union ("); - if (TYPE_NAME (field_type)) - dump_ada_node (buffer, field_type, NULL_TREE, spc, false, true); - else - dump_ada_double_name (buffer, parent, field); - pp_string (buffer, ");"); + pp_comma (buffer); + newline_and_indent (buffer, spc + 5); + pp_string (buffer, "Unchecked_Union => True"); } + + pp_semicolon (buffer); + newline_and_indent (buffer, spc); break; default: @@ -2675,7 +2574,7 @@ print_constructor (pretty_printer *buffer, tree t, tree type) tree decl_name = DECL_NAME (TYPE_NAME (type)); pp_string (buffer, "New_"); - pp_ada_tree_identifier (buffer, decl_name, t, 0, false); + pp_ada_tree_identifier (buffer, decl_name, t, false); } /* Dump in BUFFER destructor spec corresponding to T. */ @@ -2686,7 +2585,7 @@ print_destructor (pretty_printer *buffer, tree t, tree type) tree decl_name = DECL_NAME (TYPE_NAME (type)); pp_string (buffer, "Delete_"); - pp_ada_tree_identifier (buffer, decl_name, t, 0, false); + pp_ada_tree_identifier (buffer, decl_name, t, false); } /* Return the name of type T. */ @@ -2981,33 +2880,33 @@ dump_ada_declaration (pretty_printer *buffer, tree t, tree type, int spc) if (is_abstract || is_abstract_class) pp_string (buffer, " is abstract"); - pp_semicolon (buffer); - pp_string (buffer, " -- "); - dump_sloc (buffer, t); - if (is_abstract || !DECL_ASSEMBLER_NAME (t)) - return 1; - - newline_and_indent (buffer, spc); - - if (is_constructor) { + pp_semicolon (buffer); + pp_string (buffer, " -- "); + dump_sloc (buffer, t); + } + else if (is_constructor) + { + pp_semicolon (buffer); + pp_string (buffer, " -- "); + dump_sloc (buffer, t); + + newline_and_indent (buffer, spc); pp_string (buffer, "pragma CPP_Constructor ("); print_constructor (buffer, t, type); pp_string (buffer, ", \""); pp_asm_name (buffer, t); pp_string (buffer, "\");"); } - else if (is_destructor) + else { - pp_string (buffer, "pragma Import (CPP, "); - print_destructor (buffer, t, type); - pp_string (buffer, ", \""); - pp_asm_name (buffer, t); - pp_string (buffer, "\");"); + pp_string (buffer, " -- "); + dump_sloc (buffer, t); + + newline_and_indent (buffer, spc); + dump_ada_import (buffer, t, spc); } - else - dump_ada_import (buffer, t); return 1; } @@ -3062,13 +2961,12 @@ dump_ada_declaration (pretty_printer *buffer, tree t, tree type, int spc) TREE_VISITED (t) = 1; if (is_interface) { - pp_string (buffer, "limited interface; -- "); + pp_string (buffer, "limited interface -- "); dump_sloc (buffer, t); newline_and_indent (buffer, spc); - pp_string (buffer, "pragma Import (CPP, "); - dump_ada_node (buffer, TYPE_NAME (TREE_TYPE (t)), type, spc, false, - true); - pp_right_paren (buffer); + pp_string (buffer, "with Import => True,"); + newline_and_indent (buffer, spc + 5); + pp_string (buffer, "Convention => CPP"); dump_ada_methods (buffer, TREE_TYPE (t), spc); } @@ -3152,28 +3050,29 @@ dump_ada_declaration (pretty_printer *buffer, tree t, tree type, int spc) /* All needed indentation/newline performed already, so return 0. */ return 0; } - else + else if (is_var) { - pp_string (buffer, "; -- "); + pp_string (buffer, " -- "); dump_sloc (buffer, t); + newline_and_indent (buffer, spc); + dump_ada_import (buffer, t, spc); } - if (is_var) + else { - newline_and_indent (buffer, spc); - dump_ada_import (buffer, t); + pp_string (buffer, "; -- "); + dump_sloc (buffer, t); } return 1; } -/* Dump in BUFFER a structure NODE of type TYPE: name, fields, and methods - in Ada syntax. SPC is the indentation level. If DISPLAY_CONVENTION is - true, also print the pragma Convention for NODE. */ +/* Dump in BUFFER a structure NODE of type TYPE in Ada syntax. If NESTED is + true, it's an anonymous nested type. SPC is the indentation level. */ static void -dump_ada_structure (pretty_printer *buffer, tree node, tree type, int spc, - bool display_convention) +dump_ada_structure (pretty_printer *buffer, tree node, tree type, bool nested, + int spc) { const bool is_union = (TREE_CODE (node) == UNION_TYPE); char buf[32]; @@ -3268,45 +3167,35 @@ dump_ada_structure (pretty_printer *buffer, tree node, tree type, int spc, } INDENT (spc); - pp_string (buffer, "end record;"); + pp_string (buffer, "end record"); newline_and_indent (buffer, spc); - if (!display_convention) + /* We disregard the methods for anonymous nested types. */ + if (nested) return; - if (RECORD_OR_UNION_TYPE_P (TREE_TYPE (type))) + if (has_nontrivial_methods (node)) { - if (has_nontrivial_methods (TREE_TYPE (type))) - pp_string (buffer, "pragma Import (CPP, "); - else - pp_string (buffer, "pragma Convention (C_Pass_By_Copy, "); + pp_string (buffer, "with Import => True,"); + newline_and_indent (buffer, spc + 5); + pp_string (buffer, "Convention => CPP"); } else - pp_string (buffer, "pragma Convention (C, "); - - package_prefix = false; - dump_ada_node (buffer, TREE_TYPE (type), type, spc, false, true); - package_prefix = true; - pp_right_paren (buffer); + pp_string (buffer, "with Convention => C_Pass_By_Copy"); if (is_union) { - pp_semicolon (buffer); - newline_and_indent (buffer, spc); - pp_string (buffer, "pragma Unchecked_Union ("); - - dump_ada_node (buffer, TREE_TYPE (type), type, spc, false, true); - pp_right_paren (buffer); + pp_comma (buffer); + newline_and_indent (buffer, spc + 5); + pp_string (buffer, "Unchecked_Union => True"); } if (bitfield_used) { - pp_semicolon (buffer); - newline_and_indent (buffer, spc); - pp_string (buffer, "pragma Pack ("); - dump_ada_node (buffer, TREE_TYPE (type), type, spc, false, true); - pp_right_paren (buffer); + pp_comma (buffer); + newline_and_indent (buffer, spc + 5); + pp_string (buffer, "Pack => True"); bitfield_used = false; } @@ -3377,9 +3266,9 @@ dump_ads (const char *source_file, cpp_check = check; dump_ada_nodes (&pp, source_file); - /* Requires Ada 2005 syntax, so generate corresponding pragma. + /* We require Ada 2012 syntax, so generate corresponding pragma. Also, disable style checks since this file is auto-generated. */ - fprintf (f, "pragma Ada_2005;\npragma Style_Checks (Off);\n\n"); + fprintf (f, "pragma Ada_2012;\npragma Style_Checks (Off);\n\n"); /* Dump withs. */ dump_ada_withs (f); @@ -3445,5 +3334,4 @@ dump_ada_specs (void (*collect_all_refs)(const char *), /* Free various tables. */ free (source_refs); - delete overloaded_names; }