public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* Restore proper operation of -fdump-ada-spec in C++
@ 2017-08-01 22:16 Eric Botcazou
  2017-08-05 22:00 ` Eric Botcazou
  2017-08-07 15:09 ` Eric Botcazou
  0 siblings, 2 replies; 3+ messages in thread
From: Eric Botcazou @ 2017-08-01 22:16 UTC (permalink / raw)
  To: gcc-patches

[-- Attachment #1: Type: text/plain, Size: 484 bytes --]

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

[-- Attachment #2: p.diff --]
[-- Type: text/x-patch, Size: 3843 bytes --]

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)
 	    {

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Restore proper operation of -fdump-ada-spec in C++
  2017-08-01 22:16 Restore proper operation of -fdump-ada-spec in C++ Eric Botcazou
@ 2017-08-05 22:00 ` Eric Botcazou
  2017-08-07 15:09 ` Eric Botcazou
  1 sibling, 0 replies; 3+ messages in thread
From: Eric Botcazou @ 2017-08-05 22:00 UTC (permalink / raw)
  To: gcc-patches

[-- Attachment #1: Type: text/plain, Size: 702 bytes --]

> It was broken by the recent removal of TYPE_METHODS.

It turns out that the support for constructors/destructors also needs to be 
adjusted after the recent changes.

Tested on x86_64-suse-linux, applied on the mainline.


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

c-family/
	* c-ada-spec.c (has_static_fields): Look only into variables.
	(print_constructor): Add TYPE parameter and use it for the name.
	(print_destructor): Likewise.
	(print_ada_declaration): Adjust to new constructor/destructor names.
	Adjust calls to print_constructor and print_destructor.
	(print_ada_struct_decl): Do not test TREE_STATIC on FIELD_DECL.
	Look only into variables in the final loop.

-- 
Eric Botcazou

[-- Attachment #2: p.diff --]
[-- Type: text/x-patch, Size: 3506 bytes --]

Index: c-ada-spec.c
===================================================================
--- c-ada-spec.c	(revision 250802)
+++ c-ada-spec.c	(working copy)
@@ -1056,7 +1056,7 @@ has_static_fields (const_tree type)
     return false;
 
   for (tree fld = TYPE_FIELDS (type); fld; fld = TREE_CHAIN (fld))
-    if (TREE_CODE (fld) == FIELD_DECL && DECL_NAME (fld) && TREE_STATIC (fld))
+    if (TREE_CODE (fld) == VAR_DECL && DECL_NAME (fld))
       return true;
 
   return false;
@@ -2635,12 +2634,12 @@ dump_nested_type (pretty_printer *buffer, tree fie
     }
 }
 
-/* Dump in BUFFER constructor spec corresponding to T.  */
+/* Dump in BUFFER constructor spec corresponding to T for TYPE.  */
 
 static void
-print_constructor (pretty_printer *buffer, tree t)
+print_constructor (pretty_printer *buffer, tree t, tree type)
 {
-  tree decl_name = DECL_NAME (DECL_ORIGIN (t));
+  tree decl_name = DECL_NAME (TYPE_NAME (type));
 
   pp_string (buffer, "New_");
   pp_ada_tree_identifier (buffer, decl_name, t, false);
@@ -2649,9 +2648,9 @@ static void
 /* Dump in BUFFER destructor spec corresponding to T.  */
 
 static void
-print_destructor (pretty_printer *buffer, tree t)
+print_destructor (pretty_printer *buffer, tree t, tree type)
 {
-  tree decl_name = DECL_NAME (DECL_ORIGIN (t));
+  tree decl_name = DECL_NAME (TYPE_NAME (type));
 
   pp_string (buffer, "Delete_");
   pp_ada_tree_identifier (buffer, decl_name, t, false);
@@ -2907,7 +2906,8 @@ print_ada_declaration (pretty_printer *buffer, tre
 	    return 0;
 
 	  /* Only consider constructors/destructors for complete objects.  */
-	  if (strncmp (IDENTIFIER_POINTER (decl_name), "__comp", 6) != 0)
+	  if (strncmp (IDENTIFIER_POINTER (decl_name), "__ct_comp", 9) != 0
+	      && strncmp (IDENTIFIER_POINTER (decl_name), "__dt_comp", 9) != 0)
 	    return 0;
 	}
 
@@ -2935,9 +2935,9 @@ print_ada_declaration (pretty_printer *buffer, tre
 	}
 
       if (is_constructor)
-	print_constructor (buffer, t);
+	print_constructor (buffer, t, type);
       else if (is_destructor)
-	print_destructor (buffer, t);
+	print_destructor (buffer, t, type);
       else
 	dump_ada_decl_name (buffer, t, false);
 
@@ -2976,7 +2976,7 @@ print_ada_declaration (pretty_printer *buffer, tre
       if (is_constructor)
 	{
 	  pp_string (buffer, "pragma CPP_Constructor (");
-	  print_constructor (buffer, t);
+	  print_constructor (buffer, t, type);
 	  pp_string (buffer, ", \"");
 	  pp_asm_name (buffer, t);
 	  pp_string (buffer, "\");");
@@ -2984,7 +2984,7 @@ print_ada_declaration (pretty_printer *buffer, tre
       else if (is_destructor)
 	{
 	  pp_string (buffer, "pragma Import (CPP, ");
-	  print_destructor (buffer, t);
+	  print_destructor (buffer, t, type);
 	  pp_string (buffer, ", \"");
 	  pp_asm_name (buffer, t);
 	  pp_string (buffer, "\");");
@@ -3214,7 +3208,7 @@ print_ada_struct_decl (pretty_printer *buffer, tre
 		  field_num++;
 		}
 	    }
-	  else if (TREE_CODE (tmp) == FIELD_DECL && !TREE_STATIC (tmp))
+	  else if (TREE_CODE (tmp) == FIELD_DECL)
 	    {
 	      /* Skip internal virtual table field.  */
 	      if (!DECL_VIRTUAL_P (tmp))
@@ -3308,9 +3302,7 @@ 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 (TREE_CODE (tmp) == FIELD_DECL
-	  && DECL_NAME (tmp)
-	  && TREE_STATIC (tmp))
+      if (TREE_CODE (tmp) == VAR_DECL && DECL_NAME (tmp))
 	{
 	  if (need_semicolon)
 	    {

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Restore proper operation of -fdump-ada-spec in C++
  2017-08-01 22:16 Restore proper operation of -fdump-ada-spec in C++ Eric Botcazou
  2017-08-05 22:00 ` Eric Botcazou
@ 2017-08-07 15:09 ` Eric Botcazou
  1 sibling, 0 replies; 3+ messages in thread
From: Eric Botcazou @ 2017-08-07 15:09 UTC (permalink / raw)
  To: gcc-patches

[-- Attachment #1: Type: text/plain, Size: 351 bytes --]

> It was broken by the recent removal of TYPE_METHODS.

Hopefully last tweak...

Tested on x86_64-suse-linux, applied on the mainline.


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

c-family/
	* c-ada-spec.c (has_nontrivial_methods): Test for FUNCTION_DECL.
	(print_ada_methods): Likewise.
	(print_ada_declaration): Likewise.

-- 
Eric Botcazou

[-- Attachment #2: p.diff --]
[-- Type: text/x-patch, Size: 1567 bytes --]

Index: c-ada-spec.c
===================================================================
--- c-ada-spec.c	(revision 250890)
+++ c-ada-spec.c	(working copy)
@@ -1099,7 +1099,7 @@ has_nontrivial_methods (tree type)
 
   /* If there are user-defined methods, they are deemed non-trivial.  */
   for (tree fld = TYPE_FIELDS (type); fld; fld = DECL_CHAIN (fld))
-    if (TREE_CODE (TREE_TYPE (fld)) == METHOD_TYPE && !DECL_ARTIFICIAL (fld))
+    if (TREE_CODE (fld) == FUNCTION_DECL && !DECL_ARTIFICIAL (fld))
       return true;
 
   return false;
@@ -2442,7 +2442,7 @@ print_ada_methods (pretty_printer *buffer, tree no
 
   int res = 1;
   for (tree fld = TYPE_FIELDS (node); fld; fld = DECL_CHAIN (fld))
-    if (TREE_CODE (TREE_TYPE (fld)) == METHOD_TYPE)
+    if (TREE_CODE (fld) == FUNCTION_DECL)
       {
 	if (res)
 	  {
@@ -2955,8 +2955,7 @@ 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 (TREE_CODE (TREE_TYPE (fld)) == METHOD_TYPE
-	      && cpp_check (fld, IS_ABSTRACT))
+	  if (TREE_CODE (fld) == FUNCTION_DECL && cpp_check (fld, IS_ABSTRACT))
 	    {
 	      is_abstract_class = true;
 	      break;
@@ -3036,7 +3035,7 @@ print_ada_declaration (pretty_printer *buffer, tre
 		    is_interface = 0;
 		  has_fields = true;
 		}
-	      else if (TREE_CODE (TREE_TYPE (fld)) == METHOD_TYPE
+	      else if (TREE_CODE (fld) == FUNCTION_DECL
 		       && !DECL_ARTIFICIAL (fld))
 		{
 		  if (cpp_check (fld, IS_ABSTRACT))

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-08-07 15:09 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-08-01 22:16 Restore proper operation of -fdump-ada-spec in C++ Eric Botcazou
2017-08-05 22:00 ` Eric Botcazou
2017-08-07 15:09 ` Eric Botcazou

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).