{AST::InlineAsmOption::RAW, "raw"},
};
-int
-parseDirSpec (Parser<MacroInvocLexer> &parser, TokenId last_token_id)
-{
- return 0;
-}
-
-int
-parse_clobber_abi (InlineAsmContext &inline_asm_ctx)
+tl::expected<InlineAsmContext, std::string>
+parse_clobber_abi (InlineAsmContext inline_asm_ctx)
{
// clobber_abi := "clobber_abi(" <abi> *("," <abi>) [","] ")"
// PARSE EVERYTHING COMMITTEDLY IN THIS FUNCTION, WE CONFIRMED VIA clobber_abi
{
rust_error_at (token->get_locus (),
"expected %<(%>, found end of macro arguments");
- return -1;
+ return tl::unexpected<std::string> (
+ "Expected something else instead of end of macro arguments");
}
else
{
rust_error_at (token->get_locus (), "expected %<(%>, found %qs",
token->get_token_description ());
}
- return -1;
+ return tl::unexpected<std::string> (
+ "Expected left parenthesis instead of something else");
}
if (parser.skip_token (RIGHT_PAREN))
rust_error_at (
parser.peek_current_token ()->get_locus (),
"at least one abi must be provided as an argument to %<clobber_abi%>");
- return -1;
+ return tl::unexpected<std::string> (
+ "at least one abi must be provided as an argument to %<clobber_abi%>");
}
std::vector<AST::TupleClobber> new_abis;
// TODO: If the skip of comma is unsuccessful, which should be
// illegal, pleaes emit the correct error.
rust_unreachable ();
- return -1;
+ return tl::unexpected<std::string> ("SKIP OF COMMA UNSUCCESSFUL");
}
token = parser.peek_current_token ();
inline_asm.clobber_abi.push_back (abi);
}
- return 0;
+ return inline_asm_ctx;
}
tl::optional<AST::InlineAsmRegOrRegClass>
return reg_class;
}
-int
-parse_operand (InlineAsmContext &inline_asm_ctx)
-{
- return 0;
-}
-
// From rustc
-tl::optional<AST::InlineAsmOperand>
-parse_reg_operand (InlineAsmContext &inline_asm_ctx)
+tl::expected<InlineAsmContext, std::string>
+parse_reg_operand (InlineAsmContext inline_asm_ctx)
{
// let name = if p.token.is_ident() && p.look_ahead(1, |t| *t == token::Eq) {
// let (ident, _) = p.token.ident().unwrap();
// };
auto &parser = inline_asm_ctx.parser;
AST::InlineAsmOperand reg_operand;
- rust_debug ("Enter parse_reg_operand");
auto token = parser.peek_current_token ();
auto iden_token = parser.peek_current_token ();
auto &inline_asm = inline_asm_ctx.inline_asm;
if (check_identifier (parser, ""))
{
- rust_debug ("Didn't get passed identifier checking, %s",
- token->as_string ().c_str ());
-
auto equal_token = parser.peek_current_token ();
if (!parser.skip_token (EQUAL))
{
// Rust::IN search for #define RS_TOKEN_LIST in code base.
if (!is_global_asm && parser.skip_token (IN))
{
- rust_debug ("Enter parse_reg_operand in");
-
auto reg = parse_reg (inline_asm_ctx);
if (parser.skip_token (UNDERSCORE))
// instead of nullptr
struct AST::InlineAsmOperand::In in (reg, nullptr);
reg_operand.set_in (in);
-
- return reg_operand;
+ inline_asm_ctx.inline_asm.operands.push_back (reg_operand);
+ return inline_asm_ctx;
}
else if (!is_global_asm && check_identifier (parser, "out"))
{
- rust_debug ("Enter parse_reg_operand out");
-
auto reg = parse_reg (inline_asm_ctx);
auto expr = parse_format_string (inline_asm_ctx);
// instead of nullptr
struct AST::InlineAsmOperand::Out out (reg, false, nullptr);
reg_operand.set_out (out);
+ inline_asm_ctx.inline_asm.operands.push_back (reg_operand);
- return reg_operand;
+ return inline_asm_ctx;
}
else if (!is_global_asm && check_identifier (parser, "lateout"))
{
rust_unreachable ();
- return tl::nullopt;
+ return inline_asm_ctx;
}
else if (!is_global_asm && check_identifier (parser, "inout"))
{
- rust_debug ("Enter parse_reg_operand inout");
-
auto reg = parse_reg (inline_asm_ctx);
if (parser.skip_token (UNDERSCORE))
if (parser.skip_token (MATCH_ARROW))
{
- rust_debug ("Matched MATCH_ARROW");
if (!parser.skip_token (UNDERSCORE))
{
parse_format_string (inline_asm_ctx);
nullptr,
nullptr);
reg_operand.set_split_in_out (split_in_out);
+ inline_asm_ctx.inline_asm.operands.push_back (reg_operand);
- return reg_operand;
+ return inline_asm_ctx;
}
else
{
// }
struct AST::InlineAsmOperand::InOut inout (reg, false, nullptr);
reg_operand.set_in_out (inout);
-
- return reg_operand;
+ inline_asm_ctx.inline_asm.operands.push_back (reg_operand);
+ return inline_asm_ctx;
}
}
else if (!is_global_asm && check_identifier (parser, "inlateout"))
// For reviewers, the parsing of inout and inlateout is exactly the same,
// Except here, the late flag is set to true.
{
- rust_debug ("Enter parse_reg_operand inout");
-
auto reg = parse_reg (inline_asm_ctx);
if (parser.skip_token (UNDERSCORE))
if (parser.skip_token (MATCH_ARROW))
{
- rust_debug ("Matched MATCH_ARROW");
if (!parser.skip_token (UNDERSCORE))
{
parse_format_string (inline_asm_ctx);
nullptr,
nullptr);
reg_operand.set_split_in_out (split_in_out);
-
- return reg_operand;
+ inline_asm_ctx.inline_asm.operands.push_back (reg_operand);
+ return inline_asm_ctx;
}
else
{
// }
struct AST::InlineAsmOperand::InOut inout (reg, true, nullptr);
reg_operand.set_in_out (inout);
-
- return reg_operand;
+ inline_asm_ctx.inline_asm.operands.push_back (reg_operand);
+ return inline_asm_ctx;
}
}
else if (parser.peek_current_token ()->get_id () == CONST)
// TODO: Please handle const with parse_expr instead.
auto anon_const = parse_format_string (inline_asm_ctx);
reg_operand.set_cnst (tl::nullopt);
- return reg_operand;
+ rust_unreachable ();
+ return inline_asm_ctx;
}
else if (check_identifier (parser, "sym"))
{
// TODO: Please handle sym, which needs ExprKind::Path in Rust's asm.rs
rust_unreachable ();
- return tl::nullopt;
+ return inline_asm_ctx;
}
else
{
// something must be wrong. consult compiler code in asm.rs or rust online
// compiler.
rust_unreachable ();
- return tl::nullopt;
+ return inline_asm_ctx;
}
- return reg_operand;
+ return inline_asm_ctx;
}
void
check_and_set (InlineAsmContext &inline_asm_ctx, AST::InlineAsmOption option)
}
// And if that token comma is also the trailing comma, we break
- // TODO: Check with mentor see what last_token_id means
token = parser.peek_current_token ();
if (token->get_id () == COMMA && token->get_id () == last_token_id)
{
parser (parser), last_token_id (last_token_id)
{}
- // InlineAsmContext (InlineAsmContext && inline_asm_ctx)
- // : allow_templates(inline_asm_ctx.allow_templates),
- // is_explicit(inline_asm_ctx.is_explicit),
- // consumed_comma_without_formatted_string(inline_asm_ctx.consumed_comma_without_formatted_string),
- // inline_asm(inline_asm_ctx.inline_asm),
- // parser(inline_asm_ctx.parser),
- // last_token_id(inline_asm_ctx.last_token_id) {}
-
bool is_global_asm () { return inline_asm.is_global_asm; }
bool allows_templates () { return allow_templates; }
tl::expected<InlineAsmContext, std::string>
parse_format_strings (InlineAsmContext inline_asm_ctx);
+tl::expected<InlineAsmContext, std::string>
+parse_clobber_abi (InlineAsmContext inline_asm_ctx);
+
+// From rustc
+tl::expected<InlineAsmContext, std::string>
+parse_reg_operand (InlineAsmContext inline_asm_ctx);
+
tl::optional<AST::Fragment>
parse_asm (location_t invoc_locus, AST::MacroInvocData &invoc,
bool is_global_asm);
void
check_and_set (InlineAsmContext &inline_asm_ctx, AST::InlineAsmOption option);
-// From rustc
-int
-parse_operand (InlineAsmContext &inline_asm_ctx);
-
-// From rustc
-tl::optional<AST::InlineAsmOperand>
-parse_reg_operand (InlineAsmContext &inline_asm_ctx);
// From rustc
int
tl::optional<AST::InlineAsmRegOrRegClass>
parse_reg (InlineAsmContext &inline_asm_ctx);
-int
-parse_clobber_abi (InlineAsmContext &inline_asm_ctx);
-
tl::optional<std::string>
parse_format_string (InlineAsmContext &inline_asm_ctx);