Skip to content

Commit

Permalink
Store parse result of parse_format_string(s)
Browse files Browse the repository at this point in the history
gcc/rust/ChangeLog:

	* ast/rust-expr.h (struct TupleTemplateStr):
	Store parse result of parse_format_string(s)
	* expand/rust-macro-builtins-asm.cc (parse_format_strings):
	Likewise

Signed-off-by: badumbatish <tanghocle456@gmail.com>
  • Loading branch information
badumbatish authored and CohenArthur committed Jul 1, 2024
1 parent 7fd14aa commit b657fa0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
7 changes: 5 additions & 2 deletions gcc/rust/ast/rust-expr.h
Original file line number Diff line number Diff line change
Expand Up @@ -5057,9 +5057,12 @@ struct TupleClobber
struct TupleTemplateStr
{
// as gccrs still doesn't contain a symbol class I have put them as strings
std::string symbol;
std::string optional_symbol;
location_t loc;
std::string symbol;

TupleTemplateStr (location_t loc, const std::string &symbol)
: loc (loc), symbol (symbol)
{}
};

// Inline Assembly Node
Expand Down
17 changes: 16 additions & 1 deletion gcc/rust/expand/rust-macro-builtins-asm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -784,12 +784,20 @@ parse_format_strings (InlineAsmContext inline_asm_ctx)
auto last_token_id = inline_asm_ctx.last_token_id;
auto fm_string = parse_format_string (inline_asm_ctx);

auto &inline_asm = inline_asm_ctx.inline_asm;
auto token = parser.peek_current_token ();
if (fm_string == tl::nullopt)
{
rust_error_at (parser.peek_current_token ()->get_locus (),
"%s template must be a string literal", "asm");
return tl::unexpected<InlineAsmParseError> (COMMITTED);
}
else
{
auto template_str
= AST::TupleTemplateStr (token->get_locus (), fm_string.value ());
inline_asm.template_strs.push_back (template_str);
}

// formatted string stream

Expand All @@ -803,15 +811,22 @@ parse_format_strings (InlineAsmContext inline_asm_ctx)
// in here, which is formatted string in ABNF
inline_asm_ctx.consumed_comma_without_formatted_string = false;

token = parser.peek_current_token ();
fm_string = parse_format_string (inline_asm_ctx);
if (fm_string == tl::nullopt)
{
inline_asm_ctx.consumed_comma_without_formatted_string = true;
break;
}
else
{
auto template_str
= AST::TupleTemplateStr (token->get_locus (), fm_string.value ());
inline_asm.template_strs.push_back (template_str);
}
}

return tl::expected<InlineAsmContext, InlineAsmParseError> (inline_asm_ctx);
return inline_asm_ctx;
}

// bool
Expand Down

0 comments on commit b657fa0

Please sign in to comment.