Skip to content

syntax: Don't parameterize the the pretty printer #12993

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/librustc/driver/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -596,15 +596,15 @@ struct IdentifiedAnnotation;

impl pprust::PpAnn for IdentifiedAnnotation {
fn pre(&self,
s: &mut pprust::State<IdentifiedAnnotation>,
s: &mut pprust::State,
node: pprust::AnnNode) -> io::IoResult<()> {
match node {
pprust::NodeExpr(_) => s.popen(),
_ => Ok(())
}
}
fn post(&self,
s: &mut pprust::State<IdentifiedAnnotation>,
s: &mut pprust::State,
node: pprust::AnnNode) -> io::IoResult<()> {
match node {
pprust::NodeItem(item) => {
Expand Down Expand Up @@ -634,15 +634,15 @@ struct TypedAnnotation {

impl pprust::PpAnn for TypedAnnotation {
fn pre(&self,
s: &mut pprust::State<TypedAnnotation>,
s: &mut pprust::State,
node: pprust::AnnNode) -> io::IoResult<()> {
match node {
pprust::NodeExpr(_) => s.popen(),
_ => Ok(())
}
}
fn post(&self,
s: &mut pprust::State<TypedAnnotation>,
s: &mut pprust::State,
node: pprust::AnnNode) -> io::IoResult<()> {
let tcx = &self.analysis.ty_cx;
match node {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/dataflow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ struct LoopScope<'a> {

impl<'a, O:DataFlowOperator> pprust::PpAnn for DataFlowContext<'a, O> {
fn pre(&self,
ps: &mut pprust::State<DataFlowContext<'a, O>>,
ps: &mut pprust::State,
node: pprust::AnnNode) -> io::IoResult<()> {
let id = match node {
pprust::NodeExpr(expr) => expr.id,
Expand Down
4 changes: 2 additions & 2 deletions src/libsyntax/fold.rs
Original file line number Diff line number Diff line change
Expand Up @@ -880,8 +880,8 @@ mod test {
use super::*;

// this version doesn't care about getting comments or docstrings in.
fn fake_print_crate<A: pprust::PpAnn>(s: &mut pprust::State<A>,
krate: &ast::Crate) -> io::IoResult<()> {
fn fake_print_crate(s: &mut pprust::State,
krate: &ast::Crate) -> io::IoResult<()> {
s.print_mod(&krate.module, krate.attrs.as_slice())
}

Expand Down
37 changes: 19 additions & 18 deletions src/libsyntax/print/pprust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ pub enum AnnNode<'a> {
}

pub trait PpAnn {
fn pre(&self, _state: &mut State<Self>, _node: AnnNode) -> IoResult<()> { Ok(()) }
fn post(&self, _state: &mut State<Self>, _node: AnnNode) -> IoResult<()> { Ok(()) }
fn pre(&self, _state: &mut State, _node: AnnNode) -> IoResult<()> { Ok(()) }
fn post(&self, _state: &mut State, _node: AnnNode) -> IoResult<()> { Ok(()) }
}

pub struct NoAnn;
Expand All @@ -56,23 +56,24 @@ pub struct CurrentCommentAndLiteral {
cur_lit: uint,
}

pub struct State<'a, A> {
pub struct State<'a> {
s: pp::Printer,
cm: Option<&'a CodeMap>,
intr: @token::IdentInterner,
comments: Option<Vec<comments::Comment> >,
literals: Option<Vec<comments::Literal> >,
cur_cmnt_and_lit: CurrentCommentAndLiteral,
boxes: RefCell<Vec<pp::Breaks> >,
ann: &'a A
ann: &'a PpAnn
}

pub fn rust_printer(writer: ~io::Writer) -> State<'static, NoAnn> {
pub fn rust_printer(writer: ~io::Writer) -> State<'static> {
static NO_ANN: NoAnn = NoAnn;
rust_printer_annotated(writer, &NO_ANN)
}

pub fn rust_printer_annotated<'a, A: PpAnn>(writer: ~io::Writer, ann: &'a A) -> State<'a, A> {
pub fn rust_printer_annotated<'a>(writer: ~io::Writer,
ann: &'a PpAnn) -> State<'a> {
State {
s: pp::mk_printer(writer, default_columns),
cm: None,
Expand All @@ -95,14 +96,14 @@ pub static default_columns: uint = 78u;
// Requires you to pass an input filename and reader so that
// it can scan the input text for comments and literals to
// copy forward.
pub fn print_crate<'a, A: PpAnn>(cm: &'a CodeMap,
span_diagnostic: &diagnostic::SpanHandler,
krate: &ast::Crate,
filename: ~str,
input: &mut io::Reader,
out: ~io::Writer,
ann: &'a A,
is_expanded: bool) -> IoResult<()> {
pub fn print_crate<'a>(cm: &'a CodeMap,
span_diagnostic: &diagnostic::SpanHandler,
krate: &ast::Crate,
filename: ~str,
input: &mut io::Reader,
out: ~io::Writer,
ann: &'a PpAnn,
is_expanded: bool) -> IoResult<()> {
let (cmnts, lits) = comments::gather_comments_and_literals(
span_diagnostic,
filename,
Expand Down Expand Up @@ -133,7 +134,7 @@ pub fn print_crate<'a, A: PpAnn>(cm: &'a CodeMap,
eof(&mut s.s)
}

pub fn to_str(f: |&mut State<NoAnn>| -> IoResult<()>) -> ~str {
pub fn to_str(f: |&mut State| -> IoResult<()>) -> ~str {
let mut s = rust_printer(~MemWriter::new());
f(&mut s).unwrap();
eof(&mut s.s).unwrap();
Expand Down Expand Up @@ -237,7 +238,7 @@ pub fn visibility_qualified(vis: ast::Visibility, s: &str) -> ~str {
}
}

impl<'a, A: PpAnn> State<'a, A> {
impl<'a> State<'a> {
pub fn ibox(&mut self, u: uint) -> IoResult<()> {
self.boxes.borrow_mut().get().push(pp::Inconsistent);
pp::ibox(&mut self.s, u)
Expand Down Expand Up @@ -365,7 +366,7 @@ impl<'a, A: PpAnn> State<'a, A> {
}

pub fn commasep<T>(&mut self, b: Breaks, elts: &[T],
op: |&mut State<A>, &T| -> IoResult<()>)
op: |&mut State, &T| -> IoResult<()>)
-> IoResult<()> {
try!(self.rbox(0u, b));
let mut first = true;
Expand All @@ -381,7 +382,7 @@ impl<'a, A: PpAnn> State<'a, A> {
&mut self,
b: Breaks,
elts: &[T],
op: |&mut State<A>, &T| -> IoResult<()>,
op: |&mut State, &T| -> IoResult<()>,
get_span: |&T| -> codemap::Span) -> IoResult<()> {
try!(self.rbox(0u, b));
let len = elts.len();
Expand Down