Patchwork New command line switch -fada-spec-parent

login
register
mail settings
Submitter Thomas Quinot
Date Sept. 7, 2012, 3:10 p.m.
Message ID <20120907151034.GB84237@melamine.cuivre.fr.eu.org>
Download mbox | patch
Permalink /patch/182405/
State New
Headers show

Comments

Thomas Quinot - Sept. 7, 2012, 3:10 p.m.
* Steven Bosscher, 2012-08-24 :

> Why here instead of in c-family/c.opt?

Good point. Here is a new version of the patch:

        * c-family/c.opt (-fada-spec-parent): Define new command line switch.
        * c-family/c-ada-spec.c (get_ada_package): When -fada-spec-parent
        is specified, generate binding spec as a child of the specified unit.
        * doc/invoke.texi: Document -fada-spec-parent.
Joseph S. Myers - Sept. 7, 2012, 6:54 p.m.
On Fri, 7 Sep 2012, Thomas Quinot wrote:

>         * c-family/c.opt (-fada-spec-parent): Define new command line switch.
>         * c-family/c-ada-spec.c (get_ada_package): When -fada-spec-parent
>         is specified, generate binding spec as a child of the specified unit.

c-family has its own ChangeLog.

> +  int plen;

Use size_t rather than int for this length.

> +    plen = strlen(ada_specs_parent) + 1;

Missing space before '('.

> +    strcpy(res, ada_specs_parent);

Likewise.

> +    res [plen - 1] = '.';

Stray space before '['.

OK with those issues fixed.

Patch

diff --git a/gcc/c-family/c-ada-spec.c b/gcc/c-family/c-ada-spec.c
index c666667..d3974f3 100644
--- a/gcc/c-family/c-ada-spec.c
+++ b/gcc/c-family/c-ada-spec.c
@@ -818,15 +818,26 @@  get_ada_package (const char *file)
   char *res;
   const char *s;
   int i;
+  int plen;
 
   s = strstr (file, "/include/");
   if (s)
     base = s + 9;
   else
     base = lbasename (file);
-  res = XNEWVEC (char, strlen (base) + 1);
 
-  for (i = 0; *base; base++, i++)
+  if (ada_specs_parent == NULL)
+    plen = 0;
+  else
+    plen = strlen(ada_specs_parent) + 1;
+
+  res = XNEWVEC (char, plen + strlen (base) + 1);
+  if (ada_specs_parent != NULL) {
+    strcpy(res, ada_specs_parent);
+    res [plen - 1] = '.';
+  }
+
+  for (i = plen; *base; base++, i++)
     switch (*base)
       {
 	case '+':
@@ -838,7 +849,7 @@  get_ada_package (const char *file)
 	case '_':
 	case '/':
 	case '\\':
-	  res [i] = (i == 0 || res [i - 1] == '_') ? 'u' : '_';
+	  res [i] = (i == 0 || res [i - 1] == '.' || res [i - 1] == '_') ? 'u' : '_';
 	  break;
 
 	default:
@@ -3238,7 +3249,10 @@  dump_ads (const char *source_file,
   ads_name = xstrdup (pkg_name);
 
   for (s = ads_name; *s; s++)
-    *s = TOLOWER (*s);
+    if (*s == '.')
+      *s = '-';
+    else
+      *s = TOLOWER (*s);
 
   ads_name = reconcat (ads_name, ads_name, ".ads", NULL);
 
diff --git a/gcc/c-family/c.opt b/gcc/c-family/c.opt
index 40ff96c..4e64fce 100644
--- a/gcc/c-family/c.opt
+++ b/gcc/c-family/c.opt
@@ -709,6 +709,10 @@  faccess-control
 C++ ObjC++ Var(flag_access_control) Init(1)
 Enforce class member access control semantics
 
+fada-spec-parent=
+C ObjC C++ ObjC++ RejectNegative Joined Var(ada_specs_parent)
+-fada-spec-parent=unit  Dump Ada specs as child units of given parent
+
 fall-virtual
 C++ ObjC++ Ignore Warn(switch %qs is no longer supported)
 
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index 98959be..ad42eca 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -166,7 +166,7 @@  in the following sections.
 -pipe  -pass-exit-codes  @gol
 -x @var{language}  -v  -###  --help@r{[}=@var{class}@r{[},@dots{}@r{]]}  --target-help  @gol
 --version -wrapper @@@var{file} -fplugin=@var{file} -fplugin-arg-@var{name}=@var{arg}  @gol
--fdump-ada-spec@r{[}-slim@r{]} -fdump-go-spec=@var{file}}
+-fdump-ada-spec@r{[}-slim@r{]} -fada-spec-parent=@var{arg} -fdump-go-spec=@var{file}}
 
 @item C Language Options
 @xref{C Dialect Options,,Options Controlling C Dialect}.