From: Pierre-Emmanuel Patry Date: Thu, 15 Jun 2023 11:49:43 +0000 (+0200) Subject: gccrs: import: Change package opening prototypes X-Git-Tag: basepoints/gcc-15~2325 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d31b401c8cd72a1c81c9be489a1f4f54bd6850dc;p=thirdparty%2Fgcc.git 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 --- diff --git a/gcc/rust/metadata/rust-imports.cc b/gcc/rust/metadata/rust-imports.cc index a0d4123a64e1..fc3a588f816a 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::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{}); } // Try to find the export data for FILENAME. -Import::Stream * +std::pair> 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{}); } // 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{}); 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{}); } // 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 c728adbbbd19..37727f5ab15f 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> + 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> + 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 cc3a2089c1ec..9806cfcb268f 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> 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) {