aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorPierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>2023-06-15 13:49:43 +0200
committerP-E-P <32375388+P-E-P@users.noreply.github.com>2023-07-21 09:06:09 +0000
commitd2e353637897b091bed59d6bb98c1e5f98022a6c (patch)
tree6b8f4ec3dec931927d15fcb0d4926491ba9c68f3 /gcc
parent3dab250b5e28dd9ad3370a2f0a642ee71a6e6474 (diff)
downloadgcc-d2e353637897b091bed59d6bb98c1e5f98022a6c.zip
gcc-d2e353637897b091bed59d6bb98c1e5f98022a6c.tar.gz
gcc-d2e353637897b091bed59d6bb98c1e5f98022a6c.tar.bz2
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>
Diffstat (limited to 'gcc')
-rw-r--r--gcc/rust/metadata/rust-imports.cc20
-rw-r--r--gcc/rust/metadata/rust-imports.h9
-rw-r--r--gcc/rust/rust-session-manager.cc6
3 files changed, 19 insertions, 16 deletions
diff --git a/gcc/rust/metadata/rust-imports.cc b/gcc/rust/metadata/rust-imports.cc
index 45b3832..31d8afb 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 c728adb..37727f5 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 7a9e3bd..47ec515 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)
{