aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorliushuyu <liushuyu011@gmail.com>2022-04-18 03:36:02 -0600
committerliushuyu <liushuyu011@gmail.com>2022-04-19 01:46:26 -0600
commitf876cba554fcc2d4c71f7ccec55555894a005ab2 (patch)
treeb2d0cb6fbe29b3e38b29557b9090464bea927168 /gcc
parente753fa4e3633c6e6158ca26d930f0d1aaca15a6a (diff)
downloadgcc-f876cba554fcc2d4c71f7ccec55555894a005ab2.zip
gcc-f876cba554fcc2d4c71f7ccec55555894a005ab2.tar.gz
gcc-f876cba554fcc2d4c71f7ccec55555894a005ab2.tar.bz2
macros: save included filename into session manager
Diffstat (limited to 'gcc')
-rw-r--r--gcc/rust/expand/rust-macro-builtins.cc14
-rw-r--r--gcc/rust/rust-session-manager.h13
2 files changed, 21 insertions, 6 deletions
diff --git a/gcc/rust/expand/rust-macro-builtins.cc b/gcc/rust/expand/rust-macro-builtins.cc
index e4beb95..fb30241 100644
--- a/gcc/rust/expand/rust-macro-builtins.cc
+++ b/gcc/rust/expand/rust-macro-builtins.cc
@@ -425,22 +425,24 @@ MacroBuiltin::include (Location invoc_locus, AST::MacroInvocData &invoc)
if (lit_expr == nullptr)
return AST::ASTFragment::create_error ();
- std::string target_filename
+ std::string filename
= source_relative_path (lit_expr->as_string (), invoc_locus);
+ auto target_filename
+ = Rust::Session::get_instance ().include_extra_file (std::move (filename));
- RAIIFile target_file (target_filename.c_str ());
+ RAIIFile target_file (target_filename);
Linemap *linemap = Session::get_instance ().linemap;
if (target_file.get_raw () == nullptr)
{
- rust_error_at (lit_expr->get_locus (), "cannot open included file %s: %m",
- target_filename.c_str ());
+ rust_error_at (lit_expr->get_locus (),
+ "cannot open included file %qs: %m", target_filename);
return AST::ASTFragment::create_error ();
}
- rust_debug ("Attempting to parse included file %s", target_filename.c_str ());
+ rust_debug ("Attempting to parse included file %s", target_filename);
- Lexer lex (target_filename.c_str (), std::move (target_file), linemap);
+ Lexer lex (target_filename, std::move (target_file), linemap);
Parser<Lexer> parser (std::move (lex));
auto parsed_items = parser.parse_items ();
diff --git a/gcc/rust/rust-session-manager.h b/gcc/rust/rust-session-manager.h
index 6fa83d9..0c15711 100644
--- a/gcc/rust/rust-session-manager.h
+++ b/gcc/rust/rust-session-manager.h
@@ -235,6 +235,10 @@ struct Session
* every file so eh. */
std::string injected_crate_name;
+ /* extra files get included during late stages of compilation (e.g. macro
+ * expansion) */
+ std::vector<std::string> extra_files;
+
// backend wrapper to GCC GENERIC
Backend *backend;
@@ -267,6 +271,15 @@ public:
void parse_files (int num_files, const char **files);
void init_options ();
+ /* This function saves the filename data into the session manager using the
+ * `move` semantics, and returns a C-style string referencing the input
+ * std::string */
+ inline const char *include_extra_file (std::string filename)
+ {
+ extra_files.push_back (std::move (filename));
+ return extra_files.back ().c_str ();
+ }
+
private:
Session () = default;
void parse_file (const char *filename);