Skip to content

Commit

Permalink
Rust-GCC#1806 I wrote up a better version, but eagar expansion doesn…
Browse files Browse the repository at this point in the history
…'t work
  • Loading branch information
liamnaddell committed Jul 20, 2024
1 parent 753b95b commit ab1e012
Showing 1 changed file with 2 additions and 13 deletions.
15 changes: 2 additions & 13 deletions gcc/rust/expand/rust-macro-builtins-utility.cc
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,6 @@ tl::optional<AST::Fragment>
MacroBuiltin::option_env_handler (location_t invoc_locus, AST::MacroInvocData &invoc,
AST::InvocKind semicolon)
{
//TODO: Use ast/rust-ast-builder.h instead.
auto invoc_token_tree = invoc.get_delim_tok_tree ();
MacroInvocLexer lex (invoc_token_tree.to_token_stream ());
Parser<MacroInvocLexer> parser (lex);
Expand Down Expand Up @@ -268,19 +267,13 @@ MacroBuiltin::option_env_handler (location_t invoc_locus, AST::MacroInvocData &i
return AST::Fragment::create_error ();
}

//TODO: Fix {}
if (expanded_expr.size () > 0)
{
if (!(lit_expr
= try_extract_string_literal_from_fragment (invoc_locus,
expanded_expr[0])))
{
return AST::Fragment::create_error ();
}
}

//TODO: Comments
//TODO: Pass tokens through
parser.skip_token (last_token_id);

auto env_value = getenv (lit_expr->as_string ().c_str ());
Expand All @@ -289,8 +282,6 @@ MacroBuiltin::option_env_handler (location_t invoc_locus, AST::MacroInvocData &i

if (env_value == nullptr)
{
//TODO: Fix token
auto tok = make_token (Token::make_string (invoc_locus, std::move ("DELETE ME")));

std::string none = "None";
std::unique_ptr<AST::Expr> none_expr = std::unique_ptr<AST::Expr>(new AST::PathInExpression(b.path_in_expression(std::vector({option,none}))));
Expand All @@ -299,7 +290,7 @@ MacroBuiltin::option_env_handler (location_t invoc_locus, AST::MacroInvocData &i
std::vector<AST::SingleASTNode> nodes;
nodes.push_back(node);

return AST::Fragment (nodes, std::move (tok));
return AST::Fragment (nodes, std::vector<std::unique_ptr<AST::Token>> ());
}
std::string some = "Some";
//TODO: Vector constructors
Expand All @@ -310,13 +301,11 @@ MacroBuiltin::option_env_handler (location_t invoc_locus, AST::MacroInvocData &i

auto node = AST::SingleASTNode (std::move(some_expr));

//TODO: Fix
auto tok = make_token (Token::make_string (invoc_locus, std::move (env_value)));

std::vector<AST::SingleASTNode> nodes;
nodes.push_back(node);

return AST::Fragment (nodes, std::move (tok));
return AST::Fragment (nodes, std::vector<std::unique_ptr<AST::Token>> ());
}

tl::optional<AST::Fragment>
Expand Down

0 comments on commit ab1e012

Please sign in to comment.