aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust
diff options
context:
space:
mode:
authorArthur Cohen <arthur.cohen@embecosm.com>2022-02-23 15:41:48 +0100
committerArthur Cohen <arthur.cohen@embecosm.com>2022-02-23 15:53:15 +0100
commit62ab4d6bf10181de2e354095ad9780d11fd4dd8b (patch)
tree53092724cc99650108968e43423b83444f28e90c /gcc/rust
parent986b8c3c6024409beedc662fbe08345450a60cc2 (diff)
downloadgcc-62ab4d6bf10181de2e354095ad9780d11fd4dd8b.zip
gcc-62ab4d6bf10181de2e354095ad9780d11fd4dd8b.tar.gz
gcc-62ab4d6bf10181de2e354095ad9780d11fd4dd8b.tar.bz2
builtin_macros: Add make_string helper
Diffstat (limited to 'gcc/rust')
-rw-r--r--gcc/rust/expand/rust-macro-builtins.cc15
1 files changed, 11 insertions, 4 deletions
diff --git a/gcc/rust/expand/rust-macro-builtins.cc b/gcc/rust/expand/rust-macro-builtins.cc
index 2678fe4..ce0be92 100644
--- a/gcc/rust/expand/rust-macro-builtins.cc
+++ b/gcc/rust/expand/rust-macro-builtins.cc
@@ -22,6 +22,16 @@
#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)
{
@@ -35,10 +45,7 @@ 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)));
+ auto file_str = AST::SingleASTNode (make_string (invoc_locus, current_file));
return AST::ASTFragment ({file_str});
}