ast_pretty: Pass some token streams and trees by reference
This commit is contained in:
parent
394e1b40d2
commit
7055c23d2c
5 changed files with 24 additions and 24 deletions
|
|
@ -9,7 +9,7 @@ use rustc_ast::ast::{InlineAsmOptions, InlineAsmTemplatePiece};
|
|||
use rustc_ast::attr;
|
||||
use rustc_ast::ptr::P;
|
||||
use rustc_ast::token::{self, BinOpToken, DelimToken, Nonterminal, Token, TokenKind};
|
||||
use rustc_ast::tokenstream::{self, TokenStream, TokenTree};
|
||||
use rustc_ast::tokenstream::{TokenStream, TokenTree};
|
||||
use rustc_ast::util::parser::{self, AssocOp, Fixity};
|
||||
use rustc_ast::util::{classify, comments};
|
||||
use rustc_span::edition::Edition;
|
||||
|
|
@ -293,7 +293,7 @@ pub fn nonterminal_to_string(nt: &Nonterminal) -> String {
|
|||
token::NtIdent(e, is_raw) => IdentPrinter::for_ast_ident(e, is_raw).to_string(),
|
||||
token::NtLifetime(e) => e.to_string(),
|
||||
token::NtLiteral(ref e) => expr_to_string(e),
|
||||
token::NtTT(ref tree) => tt_to_string(tree.clone()),
|
||||
token::NtTT(ref tree) => tt_to_string(tree),
|
||||
token::NtVis(ref e) => vis_to_string(e),
|
||||
}
|
||||
}
|
||||
|
|
@ -314,11 +314,11 @@ pub fn expr_to_string(e: &ast::Expr) -> String {
|
|||
to_string(|s| s.print_expr(e))
|
||||
}
|
||||
|
||||
pub fn tt_to_string(tt: tokenstream::TokenTree) -> String {
|
||||
pub fn tt_to_string(tt: &TokenTree) -> String {
|
||||
to_string(|s| s.print_tt(tt, false))
|
||||
}
|
||||
|
||||
pub fn tts_to_string(tokens: TokenStream) -> String {
|
||||
pub fn tts_to_string(tokens: &TokenStream) -> String {
|
||||
to_string(|s| s.print_tts(tokens, false))
|
||||
}
|
||||
|
||||
|
|
@ -585,7 +585,7 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
|
|||
false,
|
||||
None,
|
||||
delim.to_token(),
|
||||
tokens.clone(),
|
||||
tokens,
|
||||
true,
|
||||
span,
|
||||
),
|
||||
|
|
@ -594,7 +594,7 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
|
|||
if let MacArgs::Eq(_, tokens) = &item.args {
|
||||
self.space();
|
||||
self.word_space("=");
|
||||
self.print_tts(tokens.clone(), true);
|
||||
self.print_tts(tokens, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -635,9 +635,9 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
|
|||
/// appropriate macro, transcribe back into the grammar we just parsed from,
|
||||
/// and then pretty-print the resulting AST nodes (so, e.g., we print
|
||||
/// expression arguments as expressions). It can be done! I think.
|
||||
fn print_tt(&mut self, tt: tokenstream::TokenTree, convert_dollar_crate: bool) {
|
||||
fn print_tt(&mut self, tt: &TokenTree, convert_dollar_crate: bool) {
|
||||
match tt {
|
||||
TokenTree::Token(ref token) => {
|
||||
TokenTree::Token(token) => {
|
||||
self.word(token_to_string_ext(&token, convert_dollar_crate));
|
||||
if let token::DocComment(..) = token.kind {
|
||||
self.hardbreak()
|
||||
|
|
@ -648,7 +648,7 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
|
|||
None,
|
||||
false,
|
||||
None,
|
||||
delim,
|
||||
*delim,
|
||||
tts,
|
||||
convert_dollar_crate,
|
||||
dspan.entire(),
|
||||
|
|
@ -657,14 +657,14 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
|
|||
}
|
||||
}
|
||||
|
||||
fn print_tts(&mut self, tts: tokenstream::TokenStream, convert_dollar_crate: bool) {
|
||||
let mut iter = tts.into_trees().peekable();
|
||||
fn print_tts(&mut self, tts: &TokenStream, convert_dollar_crate: bool) {
|
||||
let mut iter = tts.trees().peekable();
|
||||
while let Some(tt) = iter.next() {
|
||||
let show_space =
|
||||
if let Some(next) = iter.peek() { tt_prepend_space(next, &tt) } else { false };
|
||||
self.print_tt(tt, convert_dollar_crate);
|
||||
if show_space {
|
||||
self.space();
|
||||
self.print_tt(&tt, convert_dollar_crate);
|
||||
if let Some(next) = iter.peek() {
|
||||
if tt_prepend_space(next, &tt) {
|
||||
self.space();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -675,7 +675,7 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
|
|||
has_bang: bool,
|
||||
ident: Option<Ident>,
|
||||
delim: DelimToken,
|
||||
tts: TokenStream,
|
||||
tts: &TokenStream,
|
||||
convert_dollar_crate: bool,
|
||||
span: Span,
|
||||
) {
|
||||
|
|
@ -1253,7 +1253,7 @@ impl<'a> State<'a> {
|
|||
has_bang,
|
||||
Some(item.ident),
|
||||
macro_def.body.delim(),
|
||||
macro_def.body.inner_tokens(),
|
||||
¯o_def.body.inner_tokens(),
|
||||
true,
|
||||
item.span,
|
||||
);
|
||||
|
|
@ -1577,7 +1577,7 @@ impl<'a> State<'a> {
|
|||
true,
|
||||
None,
|
||||
m.args.delim(),
|
||||
m.args.inner_tokens(),
|
||||
&m.args.inner_tokens(),
|
||||
true,
|
||||
m.span(),
|
||||
);
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ pub fn expand_log_syntax<'cx>(
|
|||
sp: rustc_span::Span,
|
||||
tts: TokenStream,
|
||||
) -> Box<dyn base::MacResult + 'cx> {
|
||||
println!("{}", pprust::tts_to_string(tts));
|
||||
println!("{}", pprust::tts_to_string(&tts));
|
||||
|
||||
// any so that `log_syntax` can be invoked as an expression and item.
|
||||
base::DummyResult::any_valid(sp)
|
||||
|
|
|
|||
|
|
@ -71,7 +71,7 @@ pub fn expand_stringify(
|
|||
tts: TokenStream,
|
||||
) -> Box<dyn base::MacResult + 'static> {
|
||||
let sp = cx.with_def_site_ctxt(sp);
|
||||
let s = pprust::tts_to_string(tts);
|
||||
let s = pprust::tts_to_string(&tts);
|
||||
base::MacEager::expr(cx.expr_str(sp, Symbol::intern(&s)))
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -224,7 +224,7 @@ fn generic_extension<'cx>(
|
|||
let sess = cx.parse_sess;
|
||||
|
||||
if cx.trace_macros() {
|
||||
let msg = format!("expanding `{}! {{ {} }}`", name, pprust::tts_to_string(arg.clone()));
|
||||
let msg = format!("expanding `{}! {{ {} }}`", name, pprust::tts_to_string(&arg));
|
||||
trace_macros_note(&mut cx.expansions, sp, msg);
|
||||
}
|
||||
|
||||
|
|
@ -300,7 +300,7 @@ fn generic_extension<'cx>(
|
|||
}
|
||||
|
||||
if cx.trace_macros() {
|
||||
let msg = format!("to `{}`", pprust::tts_to_string(tts.clone()));
|
||||
let msg = format!("to `{}`", pprust::tts_to_string(&tts));
|
||||
trace_macros_note(&mut cx.expansions, sp, msg);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -413,7 +413,7 @@ impl server::TokenStream for Rustc<'_> {
|
|||
)
|
||||
}
|
||||
fn to_string(&mut self, stream: &Self::TokenStream) -> String {
|
||||
pprust::tts_to_string(stream.clone())
|
||||
pprust::tts_to_string(stream)
|
||||
}
|
||||
fn from_token_tree(
|
||||
&mut self,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue