This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Restore proper operation of -fdump-ada-spec in C++


It was broken by the recent removal of TYPE_METHODS.

Bootstrapped/regtested on x86_64-suse-linux, applied on the mainline.


2017-08-01  Eric Botcazou  <ebotcazou@adacore.com>

c-family/
	* 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.

-- 
Eric Botcazou
Index: c-ada-spec.c
===================================================================
--- c-ada-spec.c	(revision 250797)
+++ c-ada-spec.c	(working copy)
@@ -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, tre
 	{
 	  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, tre
 		      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,
       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, tre
 
       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, tre
       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, tre
 		  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, tre
   /* 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)
 	    {

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]