]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: import: Change package opening prototypes
authorPierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Thu, 15 Jun 2023 11:49:43 +0000 (13:49 +0200)
committerArthur Cohen <arthur.cohen@embecosm.com>
Tue, 16 Jan 2024 17:55:58 +0000 (18:55 +0100)
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>
gcc/rust/metadata/rust-imports.cc
gcc/rust/metadata/rust-imports.h
gcc/rust/rust-session-manager.cc

index a0d4123a64e14e12ec246588ba0d77cf1035c1b0..fc3a588f816adbd8bccdc861764187d2ae32c9b6 100644 (file)
@@ -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
index c728adbbbd1976d8be86959da684a7c2b6b2be08..37727f5ab15fa6eb85dd01c39e0b29fcf402f814 100644 (file)
@@ -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);
index cc3a2089c1ec7359ba0573bddf5368923ccf5e3b..9806cfcb268f7bd7a36bb033b851026deb99c331 100644 (file)
@@ -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)
     {