public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Thomas Schwinge <tschwinge@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc/devel/rust/master] builtins: Add file!() macro
Date: Wed,  8 Jun 2022 12:11:53 +0000 (GMT)	[thread overview]
Message-ID: <20220608121153.AE01F3816674@sourceware.org> (raw)

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 ());


                 reply	other threads:[~2022-06-08 12:11 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220608121153.AE01F3816674@sourceware.org \
    --to=tschwinge@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).