Rename Printer constructor from mk_printer() to Printer::new()
This commit is contained in:
parent
de9b573eed
commit
953da9832d
3 changed files with 27 additions and 27 deletions
|
@ -222,29 +222,6 @@ struct PrintStackElem {
|
||||||
|
|
||||||
const SIZE_INFINITY: isize = 0xffff;
|
const SIZE_INFINITY: isize = 0xffff;
|
||||||
|
|
||||||
pub fn mk_printer() -> Printer {
|
|
||||||
let linewidth = 78;
|
|
||||||
// Yes 55, it makes the ring buffers big enough to never fall behind.
|
|
||||||
let n: usize = 55 * linewidth;
|
|
||||||
debug!("mk_printer {}", linewidth);
|
|
||||||
Printer {
|
|
||||||
out: String::new(),
|
|
||||||
buf_max_len: n,
|
|
||||||
margin: linewidth as isize,
|
|
||||||
space: linewidth as isize,
|
|
||||||
left: 0,
|
|
||||||
right: 0,
|
|
||||||
// Initialize a single entry; advance_right() will extend it on demand
|
|
||||||
// up to `buf_max_len` elements.
|
|
||||||
buf: vec![BufEntry::default()],
|
|
||||||
left_total: 0,
|
|
||||||
right_total: 0,
|
|
||||||
scan_stack: VecDeque::new(),
|
|
||||||
print_stack: Vec::new(),
|
|
||||||
pending_indentation: 0,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct Printer {
|
pub struct Printer {
|
||||||
out: String,
|
out: String,
|
||||||
buf_max_len: usize,
|
buf_max_len: usize,
|
||||||
|
@ -288,6 +265,29 @@ impl Default for BufEntry {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Printer {
|
impl Printer {
|
||||||
|
pub fn new() -> Self {
|
||||||
|
let linewidth = 78;
|
||||||
|
// Yes 55, it makes the ring buffers big enough to never fall behind.
|
||||||
|
let n: usize = 55 * linewidth;
|
||||||
|
debug!("Printer::new {}", linewidth);
|
||||||
|
Printer {
|
||||||
|
out: String::new(),
|
||||||
|
buf_max_len: n,
|
||||||
|
margin: linewidth as isize,
|
||||||
|
space: linewidth as isize,
|
||||||
|
left: 0,
|
||||||
|
right: 0,
|
||||||
|
// Initialize a single entry; advance_right() will extend it on demand
|
||||||
|
// up to `buf_max_len` elements.
|
||||||
|
buf: vec![BufEntry::default()],
|
||||||
|
left_total: 0,
|
||||||
|
right_total: 0,
|
||||||
|
scan_stack: VecDeque::new(),
|
||||||
|
print_stack: Vec::new(),
|
||||||
|
pending_indentation: 0,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn last_token(&self) -> Token {
|
pub fn last_token(&self) -> Token {
|
||||||
self.buf[self.right].token.clone()
|
self.buf[self.right].token.clone()
|
||||||
}
|
}
|
||||||
|
|
|
@ -103,7 +103,7 @@ pub fn print_crate<'a>(
|
||||||
edition: Edition,
|
edition: Edition,
|
||||||
) -> String {
|
) -> String {
|
||||||
let mut s =
|
let mut s =
|
||||||
State { s: pp::mk_printer(), comments: Some(Comments::new(sm, filename, input)), ann };
|
State { s: pp::Printer::new(), comments: Some(Comments::new(sm, filename, input)), ann };
|
||||||
|
|
||||||
if is_expanded && !krate.attrs.iter().any(|attr| attr.has_name(sym::no_core)) {
|
if is_expanded && !krate.attrs.iter().any(|attr| attr.has_name(sym::no_core)) {
|
||||||
// We need to print `#![no_std]` (and its feature gate) so that
|
// We need to print `#![no_std]` (and its feature gate) so that
|
||||||
|
@ -910,7 +910,7 @@ impl<'a> PrintState<'a> for State<'a> {
|
||||||
|
|
||||||
impl<'a> State<'a> {
|
impl<'a> State<'a> {
|
||||||
pub fn new() -> State<'a> {
|
pub fn new() -> State<'a> {
|
||||||
State { s: pp::mk_printer(), comments: None, ann: &NoAnn }
|
State { s: pp::Printer::new(), comments: None, ann: &NoAnn }
|
||||||
}
|
}
|
||||||
|
|
||||||
crate fn commasep_cmnt<T, F, G>(&mut self, b: Breaks, elts: &[T], mut op: F, mut get_span: G)
|
crate fn commasep_cmnt<T, F, G>(&mut self, b: Breaks, elts: &[T], mut op: F, mut get_span: G)
|
||||||
|
|
|
@ -170,7 +170,7 @@ impl<'a> State<'a> {
|
||||||
ann: &'a dyn PpAnn,
|
ann: &'a dyn PpAnn,
|
||||||
) -> State<'a> {
|
) -> State<'a> {
|
||||||
State {
|
State {
|
||||||
s: pp::mk_printer(),
|
s: pp::Printer::new(),
|
||||||
comments: Some(Comments::new(sm, filename, input)),
|
comments: Some(Comments::new(sm, filename, input)),
|
||||||
attrs,
|
attrs,
|
||||||
ann,
|
ann,
|
||||||
|
@ -186,7 +186,7 @@ pub fn to_string<F>(ann: &dyn PpAnn, f: F) -> String
|
||||||
where
|
where
|
||||||
F: FnOnce(&mut State<'_>),
|
F: FnOnce(&mut State<'_>),
|
||||||
{
|
{
|
||||||
let mut printer = State { s: pp::mk_printer(), comments: None, attrs: &|_| &[], ann };
|
let mut printer = State { s: pp::Printer::new(), comments: None, attrs: &|_| &[], ann };
|
||||||
f(&mut printer);
|
f(&mut printer);
|
||||||
printer.s.eof()
|
printer.s.eof()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue