c-ada-spec.c (has_static_fields): Look only into fields.
authorEric Botcazou <ebotcazou@adacore.com>
Tue, 1 Aug 2017 22:15:32 +0000 (22:15 +0000)
committerEric Botcazou <ebotcazou@gcc.gnu.org>
Tue, 1 Aug 2017 22:15:32 +0000 (22:15 +0000)
* 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

gcc/c-family/ChangeLog
gcc/c-family/c-ada-spec.c

index 54c7d82c96852bdd2623d540f8eff69db9382492..84ef2147d7b9ce748c144958376f29bbf52a0c47 100644 (file)
@@ -1,3 +1,11 @@
+2017-08-01  Eric Botcazou  <ebotcazou@adacore.com>
+
+       * 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  <ebotcazou@adacore.com>
 
        * c-ada-spec.c (print_generic_ada_decl): Pass correctly-typed constant.
index 1f1c7e2f5d0e0e799d14f0a730e4f248d5ef4c84..761e518d96571c581a44317831a005d44f64d6f1 100644 (file)
@@ -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)
            {