use TokenStream rather than &[TokenTree] for built-in macros
That way, we don't loose the jointness info
This commit is contained in:
parent
b3146549ab
commit
fa893a3225
20 changed files with 109 additions and 113 deletions
|
@ -8,13 +8,12 @@ use errors::DiagnosticBuilder;
|
|||
|
||||
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 {
|
||||
|
@ -43,7 +42,7 @@ const OPTIONS: &[Symbol] = &[sym::volatile, sym::alignstack, sym::intel];
|
|||
|
||||
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,
|
||||
|
@ -71,20 +70,20 @@ pub fn expand_asm<'cx>(cx: &'cx mut ExtCtxt<'_>,
|
|||
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();
|
||||
|
@ -110,7 +109,8 @@ fn parse_inline_asm<'a>(
|
|||
));
|
||||
}
|
||||
// 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 =
|
||||
|
@ -129,12 +129,8 @@ fn parse_inline_asm<'a>(
|
|||
// 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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue