diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2022-02-25 12:09:43 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-02-25 12:09:43 +0000 |
commit | b695eb8f0bae01e00dfb9e9bf2554d1b48b76a9a (patch) | |
tree | df10f5102aef7d31d306753511b381e79e002363 /gcc/rust/expand/rust-macro-builtins.cc | |
parent | d3a4cf93b73fb32ab8d18541cc4fa5ff7b74c8e8 (diff) | |
parent | 8cc50f2d23fc085801ea21237b68b5cb27efd291 (diff) | |
download | gcc-b695eb8f0bae01e00dfb9e9bf2554d1b48b76a9a.zip gcc-b695eb8f0bae01e00dfb9e9bf2554d1b48b76a9a.tar.gz gcc-b695eb8f0bae01e00dfb9e9bf2554d1b48b76a9a.tar.bz2 |
Merge #970
970: Add file!() builtin r=CohenArthur a=CohenArthur
Co-authored-by: Arthur Cohen <arthur.cohen@embecosm.com>
Diffstat (limited to 'gcc/rust/expand/rust-macro-builtins.cc')
-rw-r--r-- | gcc/rust/expand/rust-macro-builtins.cc | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/gcc/rust/expand/rust-macro-builtins.cc b/gcc/rust/expand/rust-macro-builtins.cc index b7bbd32..ce0be92 100644 --- a/gcc/rust/expand/rust-macro-builtins.cc +++ b/gcc/rust/expand/rust-macro-builtins.cc @@ -18,8 +18,20 @@ #include "rust-macro-builtins.h" #include "rust-diagnostics.h" +#include "rust-expr.h" +#include "rust-session-manager.h" namespace Rust { +namespace { +std::unique_ptr<AST::Expr> +make_string (Location locus, std::string value) +{ + return std::unique_ptr<AST::Expr> ( + new AST::LiteralExpr (value, AST::Literal::STRING, + PrimitiveCoreType::CORETYPE_STR, {}, locus)); +} +} // namespace + AST::ASTFragment MacroBuiltin::assert (Location invoc_locus, AST::MacroInvocData &invoc) { @@ -27,4 +39,14 @@ MacroBuiltin::assert (Location invoc_locus, AST::MacroInvocData &invoc) return AST::ASTFragment::create_empty (); } + +AST::ASTFragment +MacroBuiltin::file (Location invoc_locus, AST::MacroInvocData &invoc) +{ + auto current_file + = Session::get_instance ().linemap->location_file (invoc_locus); + auto file_str = AST::SingleASTNode (make_string (invoc_locus, current_file)); + + return AST::ASTFragment ({file_str}); +} } // namespace Rust |