Skip to content

Commit 62ab4d6

Browse files
committed
builtin_macros: Add make_string helper
1 parent 986b8c3 commit 62ab4d6

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

gcc/rust/expand/rust-macro-builtins.cc

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,16 @@
2222
#include "rust-session-manager.h"
2323

2424
namespace Rust {
25+
namespace {
26+
std::unique_ptr<AST::Expr>
27+
make_string (Location locus, std::string value)
28+
{
29+
return std::unique_ptr<AST::Expr> (
30+
new AST::LiteralExpr (value, AST::Literal::STRING,
31+
PrimitiveCoreType::CORETYPE_STR, {}, locus));
32+
}
33+
} // namespace
34+
2535
AST::ASTFragment
2636
MacroBuiltin::assert (Location invoc_locus, AST::MacroInvocData &invoc)
2737
{
@@ -35,10 +45,7 @@ MacroBuiltin::file (Location invoc_locus, AST::MacroInvocData &invoc)
3545
{
3646
auto current_file
3747
= Session::get_instance ().linemap->location_file (invoc_locus);
38-
auto file_str = AST::SingleASTNode (std::unique_ptr<AST::Expr> (
39-
new AST::LiteralExpr (current_file, AST::Literal::STRING,
40-
PrimitiveCoreType::CORETYPE_STR,
41-
std::vector<AST::Attribute> (), invoc_locus)));
48+
auto file_str = AST::SingleASTNode (make_string (invoc_locus, current_file));
4249

4350
return AST::ASTFragment ({file_str});
4451
}

0 commit comments

Comments
 (0)