[gcc r14-7814] gccrs: import: Change package opening prototypes

Arthur Cohen cohenarthur@gcc.gnu.org
Tue Jan 16 18:00:51 GMT 2024


https://gcc.gnu.org/g:d31b401c8cd72a1c81c9be489a1f4f54bd6850dc

commit r14-7814-gd31b401c8cd72a1c81c9be489a1f4f54bd6850dc
Author: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Date:   Thu Jun 15 13:49:43 2023 +0200

    gccrs: import: Change package opening prototypes
    
    Also return a vector of proc macros when trying to open an external
    crate.
    
    gcc/rust/ChangeLog:
    
            * metadata/rust-imports.cc (add_search_path): Change prototype,
            now return a pair of Stream and procedural macro vector.
            (Import::open_package): Likewise.
            (Import::try_package_in_directory): Likewise.
            * metadata/rust-imports.h: Likewise.
            * rust-session-manager.cc (Session::load_extern_crate):
            Likewise.
    
    Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>

Diff:
---
 gcc/rust/metadata/rust-imports.cc | 20 ++++++++++----------
 gcc/rust/metadata/rust-imports.h  |  9 ++++++---
 gcc/rust/rust-session-manager.cc  |  6 +++---
 3 files changed, 19 insertions(+), 16 deletions(-)

diff --git a/gcc/rust/metadata/rust-imports.cc b/gcc/rust/metadata/rust-imports.cc
index a0d4123a64e..fc3a588f816 100644
--- a/gcc/rust/metadata/rust-imports.cc
+++ b/gcc/rust/metadata/rust-imports.cc
@@ -62,7 +62,7 @@ add_search_path (const std::string &path)
 // stop; we do not keep looking for another file with the same name
 // later in the search path.
 
-Import::Stream *
+std::pair<Import::Stream *, std::vector<ProcMacro::Procmacro>>
 Import::open_package (const std::string &filename, Location location,
 		      const std::string &relative_import_path)
 {
@@ -120,22 +120,22 @@ Import::open_package (const std::string &filename, Location location,
 	  if (!indir.empty () && indir[indir.size () - 1] != '/')
 	    indir += '/';
 	  indir += fn;
-	  Stream *s = Import::try_package_in_directory (indir, location);
-	  if (s != NULL)
+	  auto s = Import::try_package_in_directory (indir, location);
+	  if (s.first != NULL)
 	    return s;
 	}
     }
 
-  Stream *s = Import::try_package_in_directory (fn, location);
-  if (s != NULL)
+  auto s = Import::try_package_in_directory (fn, location);
+  if (s.first != NULL)
     return s;
 
-  return NULL;
+  return std::make_pair (NULL, std::vector<ProcMacro::Procmacro>{});
 }
 
 // Try to find the export data for FILENAME.
 
-Import::Stream *
+std::pair<Import::Stream *, std::vector<ProcMacro::Procmacro>>
 Import::try_package_in_directory (const std::string &filename,
 				  Location location)
 {
@@ -160,13 +160,13 @@ Import::try_package_in_directory (const std::string &filename,
 
       fd = Import::try_suffixes (&found_filename);
       if (fd < 0)
-	return NULL;
+	return std::make_pair (NULL, std::vector<ProcMacro::Procmacro>{});
     }
 
   // The export data may not be in this file.
   Stream *s = Import::find_export_data (found_filename, fd, location);
   if (s != NULL)
-    return s;
+    return std::make_pair (s, std::vector<ProcMacro::Procmacro>{});
 
   close (fd);
 
@@ -174,7 +174,7 @@ Import::try_package_in_directory (const std::string &filename,
 		 "%s exists but does not contain any Rust export data",
 		 found_filename.c_str ());
 
-  return NULL;
+  return std::make_pair (NULL, std::vector<ProcMacro::Procmacro>{});
 }
 
 // Given import "*PFILENAME", where *PFILENAME does not exist, try
diff --git a/gcc/rust/metadata/rust-imports.h b/gcc/rust/metadata/rust-imports.h
index c728adbbbd1..37727f5ab15 100644
--- a/gcc/rust/metadata/rust-imports.h
+++ b/gcc/rust/metadata/rust-imports.h
@@ -7,6 +7,7 @@
 
 #include "rust-system.h"
 #include "rust-location.h"
+#include "rust-proc-macro.h"
 
 namespace Rust {
 
@@ -109,10 +110,12 @@ public:
   // returns a pointer to a Stream object to read the data that it
   // exports.  LOCATION is the location of the import statement.
   // RELATIVE_IMPORT_PATH is used as a prefix for a relative import.
-  static Stream *open_package (const std::string &filename, Location location,
-			       const std::string &relative_import_path);
+  static std::pair<Stream *, std::vector<ProcMacro::Procmacro>>
+  open_package (const std::string &filename, Location location,
+		const std::string &relative_import_path);
 
-  static Stream *try_package_in_directory (const std::string &, Location);
+  static std::pair<Stream *, std::vector<ProcMacro::Procmacro>>
+  try_package_in_directory (const std::string &, Location);
 
   // Constructor.
   Import (Stream *, Location);
diff --git a/gcc/rust/rust-session-manager.cc b/gcc/rust/rust-session-manager.cc
index cc3a2089c1e..9806cfcb268 100644
--- a/gcc/rust/rust-session-manager.cc
+++ b/gcc/rust/rust-session-manager.cc
@@ -979,7 +979,7 @@ Session::load_extern_crate (const std::string &crate_name, location_t locus)
   // -frust-extern
   auto cli_extern_crate = extern_crates.find (crate_name);
 
-  Import::Stream *s;
+  std::pair<Import::Stream *, std::vector<ProcMacro::Procmacro>> s;
   if (cli_extern_crate != extern_crates.end ())
     {
       auto path = cli_extern_crate->second;
@@ -989,14 +989,14 @@ Session::load_extern_crate (const std::string &crate_name, location_t locus)
     {
       s = Import::open_package (import_name, locus, relative_import_path);
     }
-  if (s == NULL)
+  if (s.first == NULL)
     {
       rust_error_at (locus, "failed to locate crate %<%s%>",
 		     import_name.c_str ());
       return UNKNOWN_NODEID;
     }
 
-  Imports::ExternCrate extern_crate (*s);
+  Imports::ExternCrate extern_crate (*s.first);
   bool ok = extern_crate.load (locus);
   if (!ok)
     {


More information about the Gcc-cvs mailing list