public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc/devel/c++-modules] Add control for default header translation rules
@ 2020-08-31 17:52 Nathan Sidwell
  0 siblings, 0 replies; only message in thread
From: Nathan Sidwell @ 2020-08-31 17:52 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:965e986d18842d8281a31e35dd3c82a0569e5a46

commit 965e986d18842d8281a31e35dd3c82a0569e5a46
Author: Nathan Sidwell <nathan@acm.org>
Date:   Mon Aug 31 10:52:10 2020 -0700

    Add control for default header translation rules
    
            gcc/cp/
            * mapper-client.cc (module_client::open_module_client): Better
            error reporting.
            * mapper-resolver.cc (module_resolver::module_resolver): Specify
            default translate behavior.
            (module_resolver::IncludeTranslateRequest): Check it.
            * mapper-server.cc (flag_xlate): New.
            (process_args): Rename -f->-m add -t
            (main): Adjust.
            * mapper.h (module_resolver): Add default_xlate field.
            gcc/testsuite/
            * g++.dg/modules/inc-xlate-1_e.C: Adjust.
            * g++.dg/modules/legacy-2_b.H: Adjust.
            * g++.dg/modules/legacy-6.map: Adjust.
            * g++.dg/modules/legacy-6_[cd].C: Adjust.
            * g++.dg/modules/map-2.C: Adjust.

Diff:
---
 ChangeLog.modules                            | 18 ++++++++++++++++
 gcc/cp/mapper-client.cc                      | 29 ++++++++++++++++----------
 gcc/cp/mapper-resolver.cc                    | 13 ++++++------
 gcc/cp/mapper-server.cc                      | 31 +++++++++++++++++-----------
 gcc/cp/mapper.h                              | 13 ++++++++----
 gcc/testsuite/g++.dg/modules/inc-xlate-1_e.C |  2 +-
 gcc/testsuite/g++.dg/modules/legacy-2_b.H    |  2 +-
 gcc/testsuite/g++.dg/modules/legacy-6.map    |  4 ++--
 gcc/testsuite/g++.dg/modules/legacy-6_c.C    |  2 +-
 gcc/testsuite/g++.dg/modules/legacy-6_d.C    |  2 +-
 gcc/testsuite/g++.dg/modules/map-2.C         |  1 +
 11 files changed, 77 insertions(+), 40 deletions(-)

diff --git a/ChangeLog.modules b/ChangeLog.modules
index 49bfdd8871a..5b1c355f909 100644
--- a/ChangeLog.modules
+++ b/ChangeLog.modules
@@ -1,5 +1,23 @@
 2020-08-31  Nathan Sidwell  <nathan@acm.org>
 
+	Add control for default header translation rules.
+	gcc/cp/
+	* mapper-client.cc (module_client::open_module_client): Better
+	error reporting.
+	* mapper-resolver.cc (module_resolver::module_resolver): Specify
+	default translate behavior.
+	(module_resolver::IncludeTranslateRequest): Check it.
+	* mapper-server.cc (flag_xlate): New.
+	(process_args): Rename -f->-m add -t
+	(main): Adjust.
+	* mapper.h (module_resolver): Add default_xlate field.
+	gcc/testsuite/
+	* g++.dg/modules/inc-xlate-1_e.C: Adjust.
+	* g++.dg/modules/legacy-2_b.H: Adjust.
+	* g++.dg/modules/legacy-6.map: Adjust.
+	* g++.dg/modules/legacy-6_[cd].C: Adjust.
+	* g++.dg/modules/map-2.C: Adjust.
+
 	gcc/cp/
 	* name-lookup.c (get_fixed_binding_slot): Don't stat-hack a
 	namespace.
diff --git a/gcc/cp/mapper-client.cc b/gcc/cp/mapper-client.cc
index f79244c746f..fb73838ca7c 100644
--- a/gcc/cp/mapper-client.cc
+++ b/gcc/cp/mapper-client.cc
@@ -25,6 +25,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "diagnostic-core.h"
 #define MAPPER_FOR_GCC 1
 #include "mapper.h"
+#include "intl.h"
 
 module_client::module_client (pex_obj *p, int fd_from, int fd_to)
   : Client (fd_from, fd_to), pex (p)
@@ -113,6 +114,7 @@ module_client::open_module_client (location_t loc, const char *o,
   std::string ident;
   std::string name;
   char const *errmsg = nullptr;
+  unsigned line = 0;
 
   if (o && o[0])
     {
@@ -203,27 +205,31 @@ module_client::open_module_client (location_t loc, const char *o,
   if (!c)
     {
       // Make a default in-process client
-      auto r = new module_resolver ();
-      auto *s = new Cody::Server (r);
-      c = new module_client (s);
-      if (!errmsg && !name.empty ())
+      bool file = !errmsg && !name.empty ();
+      auto r = new module_resolver (!file, true);
+
+      if (file)
 	{
 	int fd = open (name.c_str (), O_RDONLY | O_CLOEXEC);
 	if (fd < 0)
 	  errmsg = "opening";
 	else
 	  {
-	    if (r->read_tuple_file (fd, ident, false))
-	      errmsg = "reading";
+	    if (int l = r->read_tuple_file (fd, ident, false))
+	      {
+		if (l > 0)
+		  line = l;
+		errmsg = "reading";
+	      }
 	      
 	    close (fd);
 	  }
 	}
       else
-	{
-	  r->set_repo ("gcm.cache");
-	  r->set_default (true);
-	}
+	r->set_repo ("gcm.cache");
+
+      auto *s = new Cody::Server (r);
+      c = new module_client (s);
     }
 
 #ifdef SIGPIPE
@@ -233,7 +239,8 @@ module_client::open_module_client (location_t loc, const char *o,
 #endif
 
   if (errmsg)
-    error_at (loc, "failed %s mapper %qs", errmsg, name.c_str ());
+    error_at (loc, line ? G_("failed %s mapper %qs line %u")
+	      : G_("failed %s mapper %qs"), errmsg, name.c_str (), line);
 
   // now wave hello!
   c->Cork ();
diff --git a/gcc/cp/mapper-resolver.cc b/gcc/cp/mapper-resolver.cc
index de0279bb0fa..7b689ebfa16 100644
--- a/gcc/cp/mapper-resolver.cc
+++ b/gcc/cp/mapper-resolver.cc
@@ -1,4 +1,4 @@
-/* C++ modules.  Experimental!	-*- c++-mode -*-
+/* C++ modules.  Experimental!	-*- c++ -*-
    Copyright (C) 2017-2020 Free Software Foundation, Inc.
    Written by Nathan Sidwell <nathan@acm.org> while at FaceBook
 
@@ -30,8 +30,8 @@ along with GCC; see the file COPYING3.  If not see
 #include <sys/types.h>
 #include <sys/stat.h>
 
-module_resolver::module_resolver (bool def)
-  : provide_default (def)
+module_resolver::module_resolver (bool map, bool xlate)
+  : default_map (map), default_translate (xlate)
 {
 }
 
@@ -179,7 +179,7 @@ module_resolver::cmi_response (Cody::Server *s, std::string &module)
   if (iter == map.end ())
     {
       std::string file;
-      if (provide_default)
+      if (default_map)
 	file = std::move (GetCMIName (module));
       auto res = map.emplace (module, file);
       iter = res.first;
@@ -206,11 +206,10 @@ module_resolver::ModuleImportRequest (Cody::Server *s, std::string &module)
 }
 
 int
-module_resolver::IncludeTranslateRequest (Cody::Server *s,
-					      std::string &include)
+module_resolver::IncludeTranslateRequest (Cody::Server *s, std::string &include)
 {
   auto iter = map.find (include);
-  if (iter == map.end ())
+  if (iter == map.end () && default_translate)
     {
       // Not found, look for it
       if (fd_repo == -1 && !repo.empty ())
diff --git a/gcc/cp/mapper-server.cc b/gcc/cp/mapper-server.cc
index 323afb636ca..fe604de9839 100644
--- a/gcc/cp/mapper-server.cc
+++ b/gcc/cp/mapper-server.cc
@@ -137,7 +137,10 @@ static bool flag_one = false;
 static bool flag_sequential = false;
 
 /* Fallback to default if map file is unrewarding.  */
-static bool flag_fallback = false;
+static bool flag_map = false;
+
+/* Fallback to xlate if map file is unrewarding.  */
+static bool flag_xlate = false;
 
 /* Root binary directory.  */
 static const char *flag_root = "gcm.cache";
@@ -331,18 +334,19 @@ process_args (int argc, char **argv)
   static const struct option options[] =
     {
      { "accept", required_argument, NULL, 'a' },
-     { "fallback",no_argument,	NULL, 'f' },
      { "help",	no_argument,	NULL, 'h' },
+     { "map",   no_argument,	NULL, 'm' },
      { "noisy",	no_argument,	NULL, 'n' },
      { "one",	no_argument,	NULL, '1' },
      { "root",	required_argument, NULL, 'r' },
      { "sequential", no_argument, NULL, 's' },
+     { "translate",no_argument,	NULL, 't' },
      { "version", no_argument,	NULL, 'v' },
      { 0, 0, 0, 0 }
     };
   int opt;
   bool bad_accept = false;
-  const char *opts = "a:fhn1r:sv";
+  const char *opts = "a:fhmn1r:stv";
   while ((opt = getopt_long (argc, argv, opts, options, NULL)) != -1)
     {
       switch (opt)
@@ -351,12 +355,13 @@ process_args (int argc, char **argv)
 	  if (!accept_from (optarg))
 	    bad_accept = true;
 	  break;
-	case 'f':
-	  flag_fallback = true;
-	  break;
 	case 'h':
 	  print_usage (false);
 	  /* print_usage will exit.  */
+	case 'f': // deprecated alias
+	case 'm':
+	  flag_map = true;
+	  break;
 	case 'n':
 	  flag_noisy = true;
 	  break;
@@ -369,6 +374,9 @@ process_args (int argc, char **argv)
 	case 's':
 	  flag_sequential = true;
 	  break;
+	case 't':
+	  flag_xlate = true;
+	  break;
 	case 'v':
 	  print_version ();
 	  /* print_version will exit.  */
@@ -878,12 +886,9 @@ main (int argc, char *argv[])
 
   int argno = process_args (argc, argv);
 
-  module_resolver r;
-  if (flag_root)
-    r.set_repo (flag_root);
-
   std::string name;
   int sock_fd = -1; /* Socket fd, otherwise stdin/stdout.  */
+  module_resolver r (flag_map, flag_xlate);
 
   if (argno != argc)
     {
@@ -918,8 +923,10 @@ main (int argc, char *argv[])
 	  error ("failed reading '%s': %s", option.c_str (), xstrerror (err));
       }
   else
-    flag_fallback = true;
-  r.set_default (flag_fallback);
+    r.set_default_map (true);
+
+  if (flag_root)
+    r.set_repo (flag_root);
 
 #ifdef HAVE_AF_INET6
   netmask_set_t::iterator end = netmask_set.end ();
diff --git a/gcc/cp/mapper.h b/gcc/cp/mapper.h
index f7940126e49..8c46f8dfc58 100644
--- a/gcc/cp/mapper.h
+++ b/gcc/cp/mapper.h
@@ -36,16 +36,21 @@ private:
   std::string ident;
   module_map map;
   int fd_repo = -1;
-  bool provide_default = true;
+  bool default_map = true;
+  bool default_translate = true;
 
 public:
-  module_resolver (bool def = true);
+  module_resolver (bool map = true, bool xlate = true);
   virtual ~module_resolver () override;
 
 public:
-  void set_default (bool d)
+  void set_default_map (bool d)
   {
-    provide_default = d;
+    default_map = d;
+  }
+  void set_default_translate (bool d)
+  {
+    default_translate = d;
   }
   void set_ident (char const *i)
   {
diff --git a/gcc/testsuite/g++.dg/modules/inc-xlate-1_e.C b/gcc/testsuite/g++.dg/modules/inc-xlate-1_e.C
index 88c949465f1..eaa023c9e3b 100644
--- a/gcc/testsuite/g++.dg/modules/inc-xlate-1_e.C
+++ b/gcc/testsuite/g++.dg/modules/inc-xlate-1_e.C
@@ -1,4 +1,4 @@
-// { dg-additional-options "-fmodules-ts -fmodule-mapper=|mapper-server\\ -f\\ [srcdir]/inc-xlate-1.map" }
+// { dg-additional-options "-fmodules-ts -fmodule-mapper=|mapper-server\\ -t\\ [srcdir]/inc-xlate-1.map" }
 export module bad;
 #include "inc-xlate-1_a.H"  // { dg-error "not be include-translated" }
 
diff --git a/gcc/testsuite/g++.dg/modules/legacy-2_b.H b/gcc/testsuite/g++.dg/modules/legacy-2_b.H
index 0f7e26ec3bc..bff60b77a21 100644
--- a/gcc/testsuite/g++.dg/modules/legacy-2_b.H
+++ b/gcc/testsuite/g++.dg/modules/legacy-2_b.H
@@ -1,4 +1,4 @@
-// { dg-additional-options "-fmodule-header -fmodule-mapper=|mapper-server\\ -f\\ $srcdir/g++.dg/modules/legacy-2.map" }
+// { dg-additional-options "-fmodule-header -fmodule-mapper=|mapper-server\\ -mt\\ $srcdir/g++.dg/modules/legacy-2.map" }
 // { dg-module-cmi {} }
 
 #define frob FROB
diff --git a/gcc/testsuite/g++.dg/modules/legacy-6.map b/gcc/testsuite/g++.dg/modules/legacy-6.map
index 1d1a1ef4e58..8199bf9e190 100644
--- a/gcc/testsuite/g++.dg/modules/legacy-6.map
+++ b/gcc/testsuite/g++.dg/modules/legacy-6.map
@@ -1,2 +1,2 @@
-"legacy-6_a.H"
-"legacy-6_b.H"
+./legacy-6_a.H
+./legacy-6_b.H
diff --git a/gcc/testsuite/g++.dg/modules/legacy-6_c.C b/gcc/testsuite/g++.dg/modules/legacy-6_c.C
index c3df8c9a3e4..c8873e14c53 100644
--- a/gcc/testsuite/g++.dg/modules/legacy-6_c.C
+++ b/gcc/testsuite/g++.dg/modules/legacy-6_c.C
@@ -1,5 +1,5 @@
 // { dg-do preprocess }
-// { dg-additional-options "-fmodules-ts -fmodule-mapper=|mapper-server\\ -f\\ [srcdir]/legacy-6.map" }
+// { dg-additional-options "-fmodules-ts -fmodule-mapper=|mapper-server\\ -mt\\ [srcdir]/legacy-6.map" }
 
 #include "legacy-6_a.H"
 #include "legacy-6_b.H"
diff --git a/gcc/testsuite/g++.dg/modules/legacy-6_d.C b/gcc/testsuite/g++.dg/modules/legacy-6_d.C
index 850935f67fb..65b85d4d7e7 100644
--- a/gcc/testsuite/g++.dg/modules/legacy-6_d.C
+++ b/gcc/testsuite/g++.dg/modules/legacy-6_d.C
@@ -1,5 +1,5 @@
 // { dg-do preprocess }
-// { dg-additional-options "-fmodules-ts -fmodule-mapper=|mapper-server\\ -f\\ [srcdir]/legacy-6.map" }
+// { dg-additional-options "-fmodules-ts -fmodule-mapper=|mapper-server\\ -mt\\ [srcdir]/legacy-6.map" }
 
 #include "legacy-6_a.H"
 int i;
diff --git a/gcc/testsuite/g++.dg/modules/map-2.C b/gcc/testsuite/g++.dg/modules/map-2.C
index eb08971f77d..dceb1834196 100644
--- a/gcc/testsuite/g++.dg/modules/map-2.C
+++ b/gcc/testsuite/g++.dg/modules/map-2.C
@@ -5,6 +5,7 @@
 // { dg-additional-files map-2.map }
 
 export module foo;
+// { dg-error "Interface: no such module" "" { target *-*-* } .-1 }
 // { dg-error "failed reading mapper" "" { target *-*-* } 0 }
 
 // { dg-prune-output "not writing module" }


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2020-08-31 17:52 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-31 17:52 [gcc/devel/c++-modules] Add control for default header translation rules Nathan Sidwell

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