From: Eric Botcazou Date: Tue, 1 Aug 2017 22:15:32 +0000 (+0000) Subject: c-ada-spec.c (has_static_fields): Look only into fields. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=9f2cb25e3f332d2f409455e818a2046fa6089b2d;p=gcc.git c-ada-spec.c (has_static_fields): Look only into fields. * c-ada-spec.c (has_static_fields): Look only into fields. (dump_generic_ada_node): Small tweak. (dump_nested_types): Look only into fields. (print_ada_declaration): Look only into methods. Small tweak. (print_ada_struct_decl): Look only into fields. Use DECL_VIRTUAL_P. From-SVN: r250802 --- diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog index 54c7d82c968..84ef2147d7b 100644 --- a/gcc/c-family/ChangeLog +++ b/gcc/c-family/ChangeLog @@ -1,3 +1,11 @@ +2017-08-01 Eric Botcazou + + * c-ada-spec.c (has_static_fields): Look only into fields. + (dump_generic_ada_node): Small tweak. + (dump_nested_types): Look only into fields. + (print_ada_declaration): Look only into methods. Small tweak. + (print_ada_struct_decl): Look only into fields. Use DECL_VIRTUAL_P. + 2017-08-01 Eric Botcazou * c-ada-spec.c (print_generic_ada_decl): Pass correctly-typed constant. diff --git a/gcc/c-family/c-ada-spec.c b/gcc/c-family/c-ada-spec.c index 1f1c7e2f5d0..761e518d965 100644 --- a/gcc/c-family/c-ada-spec.c +++ b/gcc/c-family/c-ada-spec.c @@ -1052,13 +1052,11 @@ get_underlying_decl (tree type) static bool has_static_fields (const_tree type) { - tree tmp; - if (!type || !RECORD_OR_UNION_TYPE_P (type)) return false; - for (tmp = TYPE_FIELDS (type); tmp; tmp = TREE_CHAIN (tmp)) - if (DECL_NAME (tmp) && TREE_STATIC (tmp)) + for (tree fld = TYPE_FIELDS (type); fld; fld = TREE_CHAIN (fld)) + if (TREE_CODE (fld) == FIELD_DECL && DECL_NAME (fld) && TREE_STATIC (fld)) return true; return false; @@ -2384,13 +2382,14 @@ dump_generic_ada_node (pretty_printer *buffer, tree node, tree type, int spc, { if (is_tagged_type (TREE_TYPE (node))) { - tree tmp = TYPE_FIELDS (TREE_TYPE (node)); int first = 1; /* Look for ancestors. */ - for (; tmp; tmp = TREE_CHAIN (tmp)) + for (tree fld = TYPE_FIELDS (TREE_TYPE (node)); + fld; + fld = TREE_CHAIN (fld)) { - if (!DECL_NAME (tmp) && is_tagged_type (TREE_TYPE (tmp))) + if (!DECL_NAME (fld) && is_tagged_type (TREE_TYPE (fld))) { if (first) { @@ -2400,8 +2399,8 @@ dump_generic_ada_node (pretty_printer *buffer, tree node, tree type, int spc, else pp_string (buffer, " and "); - dump_ada_decl_name - (buffer, TYPE_NAME (TREE_TYPE (tmp)), false); + dump_ada_decl_name (buffer, TYPE_NAME (TREE_TYPE (fld)), + false); } } @@ -2504,7 +2503,7 @@ dump_nested_types (pretty_printer *buffer, tree t, tree parent, bool forward, dump_nested_type (buffer, field, t, parent, spc); for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field)) - if (!TYPE_NAME (TREE_TYPE (field))) + if (TREE_CODE (field) == FIELD_DECL && !TYPE_NAME (TREE_TYPE (field))) dump_nested_type (buffer, field, t, parent, spc); TREE_VISITED (t) = 1; @@ -2955,7 +2954,8 @@ print_ada_declaration (pretty_printer *buffer, tree t, tree type, int spc) if (is_constructor && RECORD_OR_UNION_TYPE_P (type)) for (tree fld = TYPE_FIELDS (type); fld; fld = DECL_CHAIN (fld)) - if (cpp_check (fld, IS_ABSTRACT)) + if (TREE_CODE (TREE_TYPE (fld)) == METHOD_TYPE + && cpp_check (fld, IS_ABSTRACT)) { is_abstract_class = true; break; @@ -3020,18 +3020,20 @@ print_ada_declaration (pretty_printer *buffer, tree t, tree type, int spc) if (cpp_check && RECORD_OR_UNION_TYPE_P (TREE_TYPE (t))) { - is_interface = -1; + bool has_fields = false; /* Check that there are no fields other than the virtual table. */ for (tree fld = TYPE_FIELDS (TREE_TYPE (t)); - fld; fld = TREE_CHAIN (fld)) + fld; + fld = TREE_CHAIN (fld)) { if (TREE_CODE (fld) == FIELD_DECL) { - if (is_interface < 0 && DECL_VIRTUAL_P (fld)) + if (!has_fields && DECL_VIRTUAL_P (fld)) is_interface = 1; else is_interface = 0; + has_fields = true; } else if (TREE_CODE (TREE_TYPE (fld)) == METHOD_TYPE && !DECL_ARTIFICIAL (fld)) @@ -3212,10 +3214,10 @@ print_ada_struct_decl (pretty_printer *buffer, tree node, tree type, int spc, field_num++; } } - else if (TREE_CODE (tmp) != TYPE_DECL && !TREE_STATIC (tmp)) + else if (TREE_CODE (tmp) == FIELD_DECL && !TREE_STATIC (tmp)) { /* Skip internal virtual table field. */ - if (strncmp (IDENTIFIER_POINTER (DECL_NAME (tmp)), "_vptr", 5)) + if (!DECL_VIRTUAL_P (tmp)) { if (is_union) { @@ -3306,7 +3308,9 @@ print_ada_struct_decl (pretty_printer *buffer, tree node, tree type, int spc, /* Print the static fields of the structure, if any. */ for (tmp = TYPE_FIELDS (node); tmp; tmp = TREE_CHAIN (tmp)) { - if (DECL_NAME (tmp) && TREE_STATIC (tmp)) + if (TREE_CODE (tmp) == FIELD_DECL + && DECL_NAME (tmp) + && TREE_STATIC (tmp)) { if (need_semicolon) {