aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorCohenArthur <arthur.cohen@epita.fr>2021-08-09 17:14:46 +0200
committerCohenArthur <arthur.cohen@epita.fr>2021-09-06 16:18:34 +0200
commit2fe5d6c32a959c4a2958459a70effa03dab51e0d (patch)
treeffd763bfb6eb4a9da51d38cc1ff47d0ec61b4f76 /gcc
parentb6f69bf1369826e52919d4342cc5f89b1f10aa64 (diff)
downloadgcc-2fe5d6c32a959c4a2958459a70effa03dab51e0d.zip
gcc-2fe5d6c32a959c4a2958459a70effa03dab51e0d.tar.gz
gcc-2fe5d6c32a959c4a2958459a70effa03dab51e0d.tar.bz2
module: Add load_items() function
Diffstat (limited to 'gcc')
-rw-r--r--gcc/rust/ast/rust-ast-full-test.cc33
-rw-r--r--gcc/rust/ast/rust-item.h2
2 files changed, 35 insertions, 0 deletions
diff --git a/gcc/rust/ast/rust-ast-full-test.cc b/gcc/rust/ast/rust-ast-full-test.cc
index 6241710..888a834d 100644
--- a/gcc/rust/ast/rust-ast-full-test.cc
+++ b/gcc/rust/ast/rust-ast-full-test.cc
@@ -24,6 +24,8 @@ along with GCC; see the file COPYING3. If not see
#include "rust-diagnostics.h"
#include "rust-ast-visitor.h"
#include "rust-session-manager.h"
+#include "rust-lex.h"
+#include "rust-parse.h"
#include "operator.h"
/* Compilation unit used for various AST-related functions that would make
@@ -4083,6 +4085,37 @@ Module::get_filename ()
}
void
+Module::load_items ()
+{
+ std::string mod_file = get_filename ();
+
+ // We will already have errored out appropriately in the get_filename ()
+ // method
+ if (mod_file.empty ())
+ return;
+
+ RAIIFile file_wrap (mod_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_debug ("Attempting to parse file %s", mod_file.c_str ());
+
+ Lexer lex (mod_file.c_str (), std::move (file_wrap), linemap);
+ Parser<Lexer> parser (std::move (lex));
+
+ auto items = parser.parse_items ();
+
+ for (const auto &error : parser.get_errors ())
+ error.emit_error ();
+
+ items = std::move(items);
+ kind = ModuleKind::LOADED;
+}
+
+void
Attribute::parse_attr_to_meta_item ()
{
// only parse if has attribute input and not already parsed
diff --git a/gcc/rust/ast/rust-item.h b/gcc/rust/ast/rust-item.h
index 0578329..112ca28 100644
--- a/gcc/rust/ast/rust-item.h
+++ b/gcc/rust/ast/rust-item.h
@@ -1053,6 +1053,8 @@ public:
// Search for the filename associated with an external module
std::string get_filename ();
+ // Load the items contained in an external module
+ void load_items ();
void accept_vis (ASTVisitor &vis) override;