aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/ast
diff options
context:
space:
mode:
authorCohenArthur <arthur.cohen@epita.fr>2021-08-31 00:47:44 +0200
committerCohenArthur <arthur.cohen@epita.fr>2021-09-06 16:25:13 +0200
commit6aff3e33a03eaef2ff0d0a89def25abdf36c5b5f (patch)
treecf1535e1ca97f71f121b5e723d0f139c6e23d605 /gcc/rust/ast
parent2fe5d6c32a959c4a2958459a70effa03dab51e0d (diff)
downloadgcc-6aff3e33a03eaef2ff0d0a89def25abdf36c5b5f.zip
gcc-6aff3e33a03eaef2ff0d0a89def25abdf36c5b5f.tar.gz
gcc-6aff3e33a03eaef2ff0d0a89def25abdf36c5b5f.tar.bz2
module: Load items if module is unloaded and not marked for strip
Diffstat (limited to 'gcc/rust/ast')
-rw-r--r--gcc/rust/ast/rust-ast-full-test.cc30
-rw-r--r--gcc/rust/ast/rust-item.h9
2 files changed, 24 insertions, 15 deletions
diff --git a/gcc/rust/ast/rust-ast-full-test.cc b/gcc/rust/ast/rust-ast-full-test.cc
index 888a834d..89b24c1 100644
--- a/gcc/rust/ast/rust-ast-full-test.cc
+++ b/gcc/rust/ast/rust-ast-full-test.cc
@@ -4027,14 +4027,15 @@ filename_from_path_attribute (std::vector<Attribute> &outer_attrs)
return path_attr.get_attr_input ().as_string ();
}
-std::string
+void
Module::get_filename ()
{
rust_assert (kind == Module::ModuleKind::UNLOADED);
+ rust_assert (module_file.empty ());
auto path_string = filename_from_path_attribute (get_outer_attrs ());
if (!path_string.empty ())
- return path_string;
+ return;
// This corresponds to the path of the file 'including' the module. So the
// file that contains the 'mod <file>;' directive
@@ -4080,38 +4081,41 @@ Module::get_filename ()
rust_error_at (locus, "no candidate found for module %s",
module_name.c_str ());
- return file_mod_found ? expected_file_path
- : current_directory_name + expected_dir_path;
+ module_file = file_mod_found ? expected_file_path
+ : current_directory_name + expected_dir_path;
}
void
Module::load_items ()
{
- std::string mod_file = get_filename ();
+ get_filename ();
// We will already have errored out appropriately in the get_filename ()
// method
- if (mod_file.empty ())
+ if (module_file.empty ())
return;
- RAIIFile file_wrap (mod_file.c_str ());
+ RAIIFile file_wrap (module_file.c_str ());
Linemap *linemap = Session::get_instance ().linemap;
if (file_wrap.get_raw () == nullptr)
- rust_fatal_error (Location (), "cannot open module file %s: %m",
- mod_file.c_str ());
+ {
+ rust_error_at (Location (), "cannot open module file %s: %m",
+ module_file.c_str ());
+ return;
+ }
- rust_debug ("Attempting to parse file %s", mod_file.c_str ());
+ rust_debug ("Attempting to parse file %s", module_file.c_str ());
- Lexer lex (mod_file.c_str (), std::move (file_wrap), linemap);
+ Lexer lex (module_file.c_str (), std::move (file_wrap), linemap);
Parser<Lexer> parser (std::move (lex));
- auto items = parser.parse_items ();
+ auto parsed_items = parser.parse_items ();
for (const auto &error : parser.get_errors ())
error.emit_error ();
- items = std::move(items);
+ items = std::move (parsed_items);
kind = ModuleKind::LOADED;
}
diff --git a/gcc/rust/ast/rust-item.h b/gcc/rust/ast/rust-item.h
index 112ca28..4886992 100644
--- a/gcc/rust/ast/rust-item.h
+++ b/gcc/rust/ast/rust-item.h
@@ -982,6 +982,10 @@ private:
// bool has_items;
std::vector<std::unique_ptr<Item>> items;
+ // Filename the module refers to. Empty string on LOADED modules or if an
+ // error occured when dealing with UNLOADED modules
+ std::string module_file;
+
void clone_items (const std::vector<std::unique_ptr<Item>> &other_items)
{
items.reserve (other_items.size ());
@@ -1051,8 +1055,9 @@ public:
return *this;
}
- // Search for the filename associated with an external module
- std::string get_filename ();
+ // Search for the filename associated with an external module, storing it in
+ // module_file
+ void get_filename ();
// Load the items contained in an external module
void load_items ();