Patchwork -fdump-ada-spec: misc small fixes

login
register
mail settings
Submitter Arnaud Charlet
Date Aug. 23, 2012, 10:47 a.m.
Message ID <20120823104731.GA23827@adacore.com>
Download mbox | patch
Permalink /patch/179662/
State New
Headers show

Comments

Arnaud Charlet - Aug. 23, 2012, 10:47 a.m.
The following patch fixes various small "obvious" glitches in -fdump-ada-spec:

- It adds a missing pragma Ada_2005; in the generate Ada files
  since the generated code expects Ada 2005 syntax
- It adds a pragma Style_Checks (Off); to disable style checks on auto
  generated files
- It fixes generation of bindings for the following construct:
   typedef void (*__sighandler_t) (int);
   typedef __sighandler_t sig_t;

  Before this patch, we were wrongly generating:

   subtype sig_t is access procedure (arg1 : int);

  instead of:

   subtype sig_t is uu_sighandler_t;

- It adds missing aliased keyword on some record fields, which is needed
  to be able to take the 'Access of such fields in Ada

Tested on x86_64-unknown-linux-gnu, OK to commit on trunk?

	* c-ada-spec.c (dump_generic_ada_node): Fix handling of name_only
	for pointers, and add missing Convention C pragma.
	(print_ada_struct_decl): Add missing aliased keyword.
	(dump_ads): Add pragma Ada_2005 and Style_Checks (Off).
Joseph S. Myers - Aug. 23, 2012, 2:42 p.m.
On Thu, 23 Aug 2012, Arnaud Charlet wrote:

> 	* c-ada-spec.c (dump_generic_ada_node): Fix handling of name_only
> 	for pointers, and add missing Convention C pragma.
> 	(print_ada_struct_decl): Add missing aliased keyword.
> 	(dump_ads): Add pragma Ada_2005 and Style_Checks (Off).

OK.

Patch

Index: c-ada-spec.c
===================================================================
--- c-ada-spec.c	(revision 190616)
+++ c-ada-spec.c	(working copy)
@@ -1947,7 +1947,12 @@  dump_generic_ada_node (pretty_printer *b
 
     case POINTER_TYPE:
     case REFERENCE_TYPE:
-      if (TREE_CODE (TREE_TYPE (node)) == FUNCTION_TYPE)
+      if (name_only && TYPE_NAME (node))
+	dump_generic_ada_node
+	  (buffer, TYPE_NAME (node), node, cpp_check,
+	   spc, limited_access, true);
+
+      else if (TREE_CODE (TREE_TYPE (node)) == FUNCTION_TYPE)
 	{
 	  tree fnode = TREE_TYPE (node);
 	  bool is_function;
@@ -1975,17 +1980,25 @@  dump_generic_ada_node (pretty_printer *b
 	      dump_generic_ada_node
 		(buffer, TREE_TYPE (fnode), type, cpp_check, spc, 0, true);
 	    }
+
+	    /* If we are dumping the full type, it means we are part of a
+	       type definition and need also a Convention C pragma.  */
+	    if (!name_only)
+	      {
+		pp_semicolon (buffer);
+		newline_and_indent (buffer, spc);
+		pp_string (buffer, "pragma Convention (C, ");
+		dump_generic_ada_node
+		  (buffer, type, 0, cpp_check, spc, false, true);
+		pp_string (buffer, ")");
+	      }
 	}
       else
 	{
 	  int is_access = false;
 	  unsigned int quals = TYPE_QUALS (TREE_TYPE (node));
 
-	  if (name_only && TYPE_NAME (node))
-	    dump_generic_ada_node
-	      (buffer, TYPE_NAME (node), node, cpp_check,
-	       spc, limited_access, true);
-	  else if (VOID_TYPE_P (TREE_TYPE (node)))
+	  if (VOID_TYPE_P (TREE_TYPE (node)))
 	    {
 	      if (!name_only)
 		pp_string (buffer, "new ");
@@ -3087,10 +3100,10 @@  print_ada_struct_decl (pretty_printer *b
 		      INDENT (field_spc);
 
 		      if (field_num == 0)
-			pp_string (buffer, "parent : ");
+			pp_string (buffer, "parent : aliased ");
 		      else
 			{
-			  sprintf (buf, "field_%d : ", field_num + 1);
+			  sprintf (buf, "field_%d : aliased ", field_num + 1);
 			  pp_string (buffer, buf);
 			}
 		      dump_ada_decl_name
@@ -3262,6 +3275,10 @@  dump_ads (const char *source_file,
       /* Dump all references.  */
       dump_ada_nodes (&pp, source_file, cpp_check);
 
+      /* Requires Ada 2005 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");
+
       /* Dump withs.  */
       dump_ada_withs (f);