use syntax::ast;
use syntax::ext::base::{self, *};
-use syntax::parse;
use syntax::parse::token::{self, Token};
use syntax::ptr::P;
use syntax::symbol::{kw, sym, Symbol};
use syntax::ast::AsmDialect;
use syntax_pos::Span;
-use syntax::tokenstream;
+use syntax::tokenstream::{self, TokenStream};
use syntax::{span_err, struct_span_err};
enum State {
pub fn expand_asm<'cx>(cx: &'cx mut ExtCtxt<'_>,
sp: Span,
- tts: &[tokenstream::TokenTree])
+ tts: TokenStream)
-> Box<dyn base::MacResult + 'cx> {
let mut inline_asm = match parse_inline_asm(cx, sp, tts) {
Ok(Some(inline_asm)) => inline_asm,
MacEager::expr(P(ast::Expr {
id: ast::DUMMY_NODE_ID,
node: ast::ExprKind::InlineAsm(P(inline_asm)),
- span: cx.with_legacy_ctxt(sp),
+ span: cx.with_def_site_ctxt(sp),
attrs: ThinVec::new(),
}))
}
fn parse_inline_asm<'a>(
cx: &mut ExtCtxt<'a>,
sp: Span,
- tts: &[tokenstream::TokenTree],
+ tts: TokenStream,
) -> Result<Option<ast::InlineAsm>, DiagnosticBuilder<'a>> {
// Split the tts before the first colon, to avoid `asm!("x": y)` being
// parsed as `asm!(z)` with `z = "x": y` which is type ascription.
- let first_colon = tts.iter()
+ let first_colon = tts.trees()
.position(|tt| {
- match *tt {
+ match tt {
tokenstream::TokenTree::Token(Token { kind: token::Colon, .. }) |
tokenstream::TokenTree::Token(Token { kind: token::ModSep, .. }) => true,
_ => false,
}
})
.unwrap_or(tts.len());
- let mut p = cx.new_parser_from_tts(&tts[first_colon..]);
+ let mut p = cx.new_parser_from_tts(tts.trees().skip(first_colon).collect());
let mut asm = kw::Invalid;
let mut asm_str_style = None;
let mut outputs = Vec::new();
));
}
// Nested parser, stop before the first colon (see above).
- let mut p2 = cx.new_parser_from_tts(&tts[..first_colon]);
+ let mut p2 =
+ cx.new_parser_from_tts(tts.trees().take(first_colon).collect());
if p2.token == token::Eof {
let mut err =
// This is most likely malformed.
if p2.token != token::Eof {
let mut extra_tts = p2.parse_all_token_trees()?;
- extra_tts.extend(tts[first_colon..].iter().cloned());
- p = parse::stream_to_parser(
- cx.parse_sess,
- extra_tts.into_iter().collect(),
- Some("inline assembly"),
- );
+ extra_tts.extend(tts.trees().skip(first_colon));
+ p = cx.new_parser_from_tts(extra_tts.into_iter().collect());
}
asm = s;