attempt to have rustfmt use the new logic
apparently it doesn't really use the asm parsing at present, so this may work?
This commit is contained in:
@@ -4,7 +4,7 @@ use rustc_ast::ptr::P;
|
|||||||
use rustc_ast::tokenstream::TokenStream;
|
use rustc_ast::tokenstream::TokenStream;
|
||||||
use rustc_ast::{AsmMacro, token};
|
use rustc_ast::{AsmMacro, token};
|
||||||
use rustc_data_structures::fx::{FxHashMap, FxIndexMap};
|
use rustc_data_structures::fx::{FxHashMap, FxIndexMap};
|
||||||
use rustc_errors::{DiagCtxtHandle, PResult};
|
use rustc_errors::PResult;
|
||||||
use rustc_expand::base::*;
|
use rustc_expand::base::*;
|
||||||
use rustc_index::bit_set::GrowableBitSet;
|
use rustc_index::bit_set::GrowableBitSet;
|
||||||
use rustc_parse::exp;
|
use rustc_parse::exp;
|
||||||
@@ -33,7 +33,7 @@ pub enum RawAsmArgKind {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Validated assembly arguments, ready for macro expansion.
|
/// Validated assembly arguments, ready for macro expansion.
|
||||||
pub struct AsmArgs {
|
struct AsmArgs {
|
||||||
pub templates: Vec<P<ast::Expr>>,
|
pub templates: Vec<P<ast::Expr>>,
|
||||||
pub operands: Vec<(ast::InlineAsmOperand, Span)>,
|
pub operands: Vec<(ast::InlineAsmOperand, Span)>,
|
||||||
named_args: FxIndexMap<Symbol, usize>,
|
named_args: FxIndexMap<Symbol, usize>,
|
||||||
@@ -261,26 +261,17 @@ fn parse_args<'a>(
|
|||||||
tts: TokenStream,
|
tts: TokenStream,
|
||||||
asm_macro: AsmMacro,
|
asm_macro: AsmMacro,
|
||||||
) -> PResult<'a, AsmArgs> {
|
) -> PResult<'a, AsmArgs> {
|
||||||
let mut p = ecx.new_parser_from_tts(tts);
|
let raw_args = parse_raw_asm_args(&mut ecx.new_parser_from_tts(tts), sp, asm_macro)?;
|
||||||
parse_asm_args(&mut p, sp, asm_macro)
|
validate_raw_asm_args(ecx, asm_macro, raw_args)
|
||||||
}
|
}
|
||||||
|
|
||||||
// public for use in rustfmt
|
fn validate_raw_asm_args<'a>(
|
||||||
// FIXME: use `RawAsmArg` in the formatting code instead.
|
ecx: &ExtCtxt<'a>,
|
||||||
pub fn parse_asm_args<'a>(
|
|
||||||
p: &mut Parser<'a>,
|
|
||||||
sp: Span,
|
|
||||||
asm_macro: AsmMacro,
|
|
||||||
) -> PResult<'a, AsmArgs> {
|
|
||||||
let raw_args = parse_raw_asm_args(p, sp, asm_macro)?;
|
|
||||||
validate_raw_asm_args(p.dcx(), asm_macro, raw_args)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn validate_raw_asm_args<'a>(
|
|
||||||
dcx: DiagCtxtHandle<'a>,
|
|
||||||
asm_macro: AsmMacro,
|
asm_macro: AsmMacro,
|
||||||
raw_args: Vec<RawAsmArg>,
|
raw_args: Vec<RawAsmArg>,
|
||||||
) -> PResult<'a, AsmArgs> {
|
) -> PResult<'a, AsmArgs> {
|
||||||
|
let dcx = ecx.dcx();
|
||||||
|
|
||||||
let mut args = AsmArgs {
|
let mut args = AsmArgs {
|
||||||
templates: vec![],
|
templates: vec![],
|
||||||
operands: vec![],
|
operands: vec![],
|
||||||
|
|||||||
@@ -1,11 +1,14 @@
|
|||||||
use rustc_ast::ast;
|
use rustc_ast::ast;
|
||||||
use rustc_builtin_macros::asm::{AsmArgs, parse_asm_args};
|
use rustc_builtin_macros::asm::{RawAsmArg, parse_raw_asm_args};
|
||||||
|
|
||||||
use crate::rewrite::RewriteContext;
|
use crate::rewrite::RewriteContext;
|
||||||
|
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
pub(crate) fn parse_asm(context: &RewriteContext<'_>, mac: &ast::MacCall) -> Option<AsmArgs> {
|
pub(crate) fn parse_asm(
|
||||||
|
context: &RewriteContext<'_>,
|
||||||
|
mac: &ast::MacCall,
|
||||||
|
) -> Option<Vec<RawAsmArg>> {
|
||||||
let ts = mac.args.tokens.clone();
|
let ts = mac.args.tokens.clone();
|
||||||
let mut parser = super::build_parser(context, ts);
|
let mut parser = super::build_parser(context, ts);
|
||||||
parse_asm_args(&mut parser, mac.span(), ast::AsmMacro::Asm).ok()
|
parse_raw_asm_args(&mut parser, mac.span(), ast::AsmMacro::Asm).ok()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user