public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc/devel/rust/master] builtins: Add file!() macro
@ 2022-06-08 12:11 Thomas Schwinge
0 siblings, 0 replies; only message in thread
From: Thomas Schwinge @ 2022-06-08 12:11 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:986b8c3c6024409beedc662fbe08345450a60cc2
commit 986b8c3c6024409beedc662fbe08345450a60cc2
Author: Arthur Cohen <arthur.cohen@embecosm.com>
Date: Wed Feb 23 10:48:49 2022 +0100
builtins: Add file!() macro
Diff:
---
gcc/rust/expand/rust-macro-builtins.cc | 15 +++++++++++++++
gcc/rust/expand/rust-macro-builtins.h | 3 +++
gcc/rust/util/rust-hir-map.cc | 1 +
3 files changed, 19 insertions(+)
diff --git a/gcc/rust/expand/rust-macro-builtins.cc b/gcc/rust/expand/rust-macro-builtins.cc
index b7bbd32c322..2678fe43a1e 100644
--- a/gcc/rust/expand/rust-macro-builtins.cc
+++ b/gcc/rust/expand/rust-macro-builtins.cc
@@ -18,6 +18,8 @@
#include "rust-macro-builtins.h"
#include "rust-diagnostics.h"
+#include "rust-expr.h"
+#include "rust-session-manager.h"
namespace Rust {
AST::ASTFragment
@@ -27,4 +29,17 @@ 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 (std::unique_ptr<AST::Expr> (
+ new AST::LiteralExpr (current_file, AST::Literal::STRING,
+ PrimitiveCoreType::CORETYPE_STR,
+ std::vector<AST::Attribute> (), invoc_locus)));
+
+ return AST::ASTFragment ({file_str});
+}
} // namespace Rust
diff --git a/gcc/rust/expand/rust-macro-builtins.h b/gcc/rust/expand/rust-macro-builtins.h
index f279d390ffe..ee42fe1dcc6 100644
--- a/gcc/rust/expand/rust-macro-builtins.h
+++ b/gcc/rust/expand/rust-macro-builtins.h
@@ -28,6 +28,9 @@ class MacroBuiltin
public:
static AST::ASTFragment assert (Location invoc_locus,
AST::MacroInvocData &invoc);
+
+ static AST::ASTFragment file (Location invoc_locus,
+ AST::MacroInvocData &invoc);
};
} // namespace Rust
diff --git a/gcc/rust/util/rust-hir-map.cc b/gcc/rust/util/rust-hir-map.cc
index 1c0e8fcb9ca..d154a8aab2b 100644
--- a/gcc/rust/util/rust-hir-map.cc
+++ b/gcc/rust/util/rust-hir-map.cc
@@ -746,6 +746,7 @@ Mappings::insert_macro_def (AST::MacroRulesDefinition *macro)
Location, AST::MacroInvocData &)>>
builtin_macros = {
{"assert", MacroBuiltin::assert},
+ {"file", MacroBuiltin::file},
};
auto builtin = builtin_macros.find (macro->get_rule_name ());
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2022-06-08 12:11 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-08 12:11 [gcc/devel/rust/master] builtins: Add file!() macro Thomas Schwinge
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).