Skip to content

Commit 7574d78

Browse files
committed
---
yaml --- r: 145379 b: refs/heads/try2 c: 15ce791 h: refs/heads/master i: 145377: cda7413 145375: 6b59e8f v: v3
1 parent 4710e9a commit 7574d78

File tree

4 files changed

+144
-99
lines changed

4 files changed

+144
-99
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: 33993535efb490ddb0e3afb6e08e4f945ec28a04
8+
refs/heads/try2: 15ce791ff5b5756b1455c65708782bc8028de56f
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/src/librustc/driver/driver.rs

Lines changed: 75 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -439,15 +439,70 @@ pub fn compile_input(sess: Session, cfg: ast::CrateConfig, input: &input,
439439
phase_6_link_output(sess, &trans, outputs);
440440
}
441441

442-
pub fn pretty_print_input(sess: Session, cfg: ast::CrateConfig, input: &input,
443-
ppm: PpMode) {
442+
struct IdentifiedAnnotation {
443+
contents: (),
444+
}
444445

445-
fn ann_paren_for_expr(node: pprust::ann_node) {
446+
impl pprust::pp_ann for IdentifiedAnnotation {
447+
fn pre(&self, node: pprust::ann_node) {
446448
match node {
447-
pprust::node_expr(s, _) => pprust::popen(s),
448-
_ => ()
449+
pprust::node_expr(s, _) => pprust::popen(s),
450+
_ => ()
451+
}
452+
}
453+
fn post(&self, node: pprust::ann_node) {
454+
match node {
455+
pprust::node_item(s, item) => {
456+
pp::space(s.s);
457+
pprust::synth_comment(s, item.id.to_str());
458+
}
459+
pprust::node_block(s, ref blk) => {
460+
pp::space(s.s);
461+
pprust::synth_comment(s, ~"block " + blk.id.to_str());
462+
}
463+
pprust::node_expr(s, expr) => {
464+
pp::space(s.s);
465+
pprust::synth_comment(s, expr.id.to_str());
466+
pprust::pclose(s);
467+
}
468+
pprust::node_pat(s, pat) => {
469+
pp::space(s.s);
470+
pprust::synth_comment(s, ~"pat " + pat.id.to_str());
471+
}
449472
}
450473
}
474+
}
475+
476+
struct TypedAnnotation {
477+
analysis: CrateAnalysis,
478+
}
479+
480+
impl pprust::pp_ann for TypedAnnotation {
481+
fn pre(&self, node: pprust::ann_node) {
482+
match node {
483+
pprust::node_expr(s, _) => pprust::popen(s),
484+
_ => ()
485+
}
486+
}
487+
fn post(&self, node: pprust::ann_node) {
488+
let tcx = self.analysis.ty_cx;
489+
match node {
490+
pprust::node_expr(s, expr) => {
491+
pp::space(s.s);
492+
pp::word(s.s, "as");
493+
pp::space(s.s);
494+
pp::word(s.s, ppaux::ty_to_str(tcx, ty::expr_ty(tcx, expr)));
495+
pprust::pclose(s);
496+
}
497+
_ => ()
498+
}
499+
}
500+
}
501+
502+
pub fn pretty_print_input(sess: Session,
503+
cfg: ast::CrateConfig,
504+
input: &input,
505+
ppm: PpMode) {
451506
fn ann_typed_post(tcx: ty::ctxt, node: pprust::ann_node) {
452507
match node {
453508
pprust::node_expr(s, expr) => {
@@ -460,28 +515,6 @@ pub fn pretty_print_input(sess: Session, cfg: ast::CrateConfig, input: &input,
460515
_ => ()
461516
}
462517
}
463-
fn ann_identified_post(node: pprust::ann_node) {
464-
match node {
465-
pprust::node_item(s, item) => {
466-
pp::space(s.s);
467-
pprust::synth_comment(s, item.id.to_str());
468-
}
469-
pprust::node_block(s, ref blk) => {
470-
pp::space(s.s);
471-
pprust::synth_comment(
472-
s, ~"block " + blk.id.to_str());
473-
}
474-
pprust::node_expr(s, expr) => {
475-
pp::space(s.s);
476-
pprust::synth_comment(s, expr.id.to_str());
477-
pprust::pclose(s);
478-
}
479-
pprust::node_pat(s, pat) => {
480-
pp::space(s.s);
481-
pprust::synth_comment(s, ~"pat " + pat.id.to_str());
482-
}
483-
}
484-
}
485518

486519
let crate = phase_1_parse_input(sess, cfg.clone(), input);
487520

@@ -494,28 +527,30 @@ pub fn pretty_print_input(sess: Session, cfg: ast::CrateConfig, input: &input,
494527

495528
let annotation = match ppm {
496529
PpmIdentified | PpmExpandedIdentified => {
497-
pprust::pp_ann {
498-
pre: ann_paren_for_expr,
499-
post: ann_identified_post
500-
}
530+
@IdentifiedAnnotation {
531+
contents: (),
532+
} as @pprust::pp_ann
501533
}
502534
PpmTyped => {
503535
let analysis = phase_3_run_analysis_passes(sess, crate);
504-
pprust::pp_ann {
505-
pre: ann_paren_for_expr,
506-
post: |a| ann_typed_post(analysis.ty_cx, a)
507-
}
536+
@TypedAnnotation {
537+
analysis: analysis
538+
} as @pprust::pp_ann
508539
}
509-
_ => pprust::no_ann()
540+
_ => @pprust::no_ann::new() as @pprust::pp_ann,
510541
};
511542

512543
let src = sess.codemap.get_filemap(source_name(input)).src;
513544
do io::with_str_reader(src) |rdr| {
514-
pprust::print_crate(sess.codemap, token::get_ident_interner(),
515-
sess.span_diagnostic, crate,
545+
pprust::print_crate(sess.codemap,
546+
token::get_ident_interner(),
547+
sess.span_diagnostic,
548+
crate,
516549
source_name(input),
517-
rdr, io::stdout(),
518-
annotation, is_expanded);
550+
rdr,
551+
io::stdout(),
552+
annotation,
553+
is_expanded);
519554
}
520555
}
521556

branches/try2/src/librustc/middle/dataflow.rs

Lines changed: 39 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,42 @@ struct LoopScope<'self> {
8787
break_bits: ~[uint]
8888
}
8989

90+
impl<O:DataFlowOperator> pprust::pp_ann for DataFlowContext<O> {
91+
fn pre(&self, node: pprust::ann_node) {
92+
let (ps, id) = match node {
93+
pprust::node_expr(ps, expr) => (ps, expr.id),
94+
pprust::node_block(ps, blk) => (ps, blk.id),
95+
pprust::node_item(ps, _) => (ps, 0),
96+
pprust::node_pat(ps, pat) => (ps, pat.id)
97+
};
98+
99+
if self.nodeid_to_bitset.contains_key(&id) {
100+
let (start, end) = self.compute_id_range_frozen(id);
101+
let on_entry = self.on_entry.slice(start, end);
102+
let entry_str = bits_to_str(on_entry);
103+
104+
let gens = self.gens.slice(start, end);
105+
let gens_str = if gens.iter().any(|&u| u != 0) {
106+
fmt!(" gen: %s", bits_to_str(gens))
107+
} else {
108+
~""
109+
};
110+
111+
let kills = self.kills.slice(start, end);
112+
let kills_str = if kills.iter().any(|&u| u != 0) {
113+
fmt!(" kill: %s", bits_to_str(kills))
114+
} else {
115+
~""
116+
};
117+
118+
let comment_str = fmt!("id %d: %s%s%s",
119+
id, entry_str, gens_str, kills_str);
120+
pprust::synth_comment(ps, comment_str);
121+
pp::space(ps.s);
122+
}
123+
}
124+
}
125+
90126
impl<O:DataFlowOperator> DataFlowContext<O> {
91127
pub fn new(tcx: ty::ctxt,
92128
method_map: typeck::method_map,
@@ -319,46 +355,9 @@ impl<O:DataFlowOperator+Clone+'static> DataFlowContext<O> {
319355
}
320356

321357
fn pretty_print_to(@self, wr: @io::Writer, blk: &ast::Block) {
322-
let pre: @fn(pprust::ann_node) = |node| {
323-
let (ps, id) = match node {
324-
pprust::node_expr(ps, expr) => (ps, expr.id),
325-
pprust::node_block(ps, blk) => (ps, blk.id),
326-
pprust::node_item(ps, _) => (ps, 0),
327-
pprust::node_pat(ps, pat) => (ps, pat.id)
328-
};
329-
330-
if self.nodeid_to_bitset.contains_key(&id) {
331-
let (start, end) = self.compute_id_range_frozen(id);
332-
let on_entry = self.on_entry.slice(start, end);
333-
let entry_str = bits_to_str(on_entry);
334-
335-
let gens = self.gens.slice(start, end);
336-
let gens_str = if gens.iter().any(|&u| u != 0) {
337-
fmt!(" gen: %s", bits_to_str(gens))
338-
} else {
339-
~""
340-
};
341-
342-
let kills = self.kills.slice(start, end);
343-
let kills_str = if kills.iter().any(|&u| u != 0) {
344-
fmt!(" kill: %s", bits_to_str(kills))
345-
} else {
346-
~""
347-
};
348-
349-
let comment_str = fmt!("id %d: %s%s%s",
350-
id, entry_str, gens_str, kills_str);
351-
pprust::synth_comment(ps, comment_str);
352-
pp::space(ps.s);
353-
}
354-
};
355-
356-
let post: @fn(pprust::ann_node) = |_| {
357-
};
358-
359-
let ps = pprust::rust_printer_annotated(
360-
wr, self.tcx.sess.intr(),
361-
pprust::pp_ann {pre:pre, post:post});
358+
let ps = pprust::rust_printer_annotated(wr,
359+
self.tcx.sess.intr(),
360+
self as @pprust::pp_ann);
362361
pprust::cbox(ps, pprust::indent_unit);
363362
pprust::ibox(ps, 0u);
364363
pprust::print_block(ps, blk);

branches/try2/src/libsyntax/print/pprust.rs

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,26 @@ pub enum ann_node<'self> {
3737
node_expr(@ps, &'self ast::Expr),
3838
node_pat(@ps, &'self ast::Pat),
3939
}
40-
pub struct pp_ann {
41-
pre: @fn(ann_node),
42-
post: @fn(ann_node)
40+
41+
pub trait pp_ann {
42+
fn pre(&self, _node: ann_node) {}
43+
fn post(&self, _node: ann_node) {}
44+
}
45+
46+
pub struct no_ann {
47+
contents: (),
4348
}
4449

45-
pub fn no_ann() -> pp_ann {
46-
fn ignore(_node: ann_node) { }
47-
return pp_ann {pre: ignore, post: ignore};
50+
impl no_ann {
51+
pub fn new() -> no_ann {
52+
no_ann {
53+
contents: (),
54+
}
55+
}
4856
}
4957

58+
impl pp_ann for no_ann {}
59+
5060
pub struct CurrentCommentAndLiteral {
5161
cur_cmnt: uint,
5262
cur_lit: uint,
@@ -60,7 +70,7 @@ pub struct ps {
6070
literals: Option<~[comments::lit]>,
6171
cur_cmnt_and_lit: @mut CurrentCommentAndLiteral,
6272
boxes: @mut ~[pp::breaks],
63-
ann: pp_ann
73+
ann: @pp_ann
6474
}
6575

6676
pub fn ibox(s: @ps, u: uint) {
@@ -74,12 +84,13 @@ pub fn end(s: @ps) {
7484
}
7585

7686
pub fn rust_printer(writer: @io::Writer, intr: @ident_interner) -> @ps {
77-
return rust_printer_annotated(writer, intr, no_ann());
87+
return rust_printer_annotated(writer, intr, @no_ann::new() as @pp_ann);
7888
}
7989

8090
pub fn rust_printer_annotated(writer: @io::Writer,
8191
intr: @ident_interner,
82-
ann: pp_ann) -> @ps {
92+
ann: @pp_ann)
93+
-> @ps {
8394
return @ps {
8495
s: pp::mk_printer(writer, default_columns),
8596
cm: None::<@CodeMap>,
@@ -109,7 +120,7 @@ pub fn print_crate(cm: @CodeMap,
109120
filename: @str,
110121
input: @io::Reader,
111122
out: @io::Writer,
112-
ann: pp_ann,
123+
ann: @pp_ann,
113124
is_expanded: bool) {
114125
let (cmnts, lits) = comments::gather_comments_and_literals(
115126
span_diagnostic,
@@ -484,7 +495,7 @@ pub fn print_item(s: @ps, item: &ast::item) {
484495
maybe_print_comment(s, item.span.lo);
485496
print_outer_attributes(s, item.attrs);
486497
let ann_node = node_item(s, item);
487-
(s.ann.pre)(ann_node);
498+
s.ann.pre(ann_node);
488499
match item.node {
489500
ast::item_static(ref ty, m, expr) => {
490501
head(s, visibility_qualified(item.vis, "static"));
@@ -635,7 +646,7 @@ pub fn print_item(s: @ps, item: &ast::item) {
635646
end(s);
636647
}
637648
}
638-
(s.ann.post)(ann_node);
649+
s.ann.post(ann_node);
639650
}
640651

641652
fn print_trait_ref(s: @ps, t: &ast::trait_ref) {
@@ -958,7 +969,7 @@ pub fn print_possibly_embedded_block_(s: @ps,
958969
}
959970
maybe_print_comment(s, blk.span.lo);
960971
let ann_node = node_block(s, blk);
961-
(s.ann.pre)(ann_node);
972+
s.ann.pre(ann_node);
962973
match embedded {
963974
block_block_fn => end(s),
964975
block_normal => bopen(s)
@@ -979,7 +990,7 @@ pub fn print_possibly_embedded_block_(s: @ps,
979990
_ => ()
980991
}
981992
bclose_maybe_open(s, blk.span, indented, close_box);
982-
(s.ann.post)(ann_node);
993+
s.ann.post(ann_node);
983994
}
984995

985996
pub fn print_if(s: @ps, test: &ast::Expr, blk: &ast::Block,
@@ -1121,7 +1132,7 @@ pub fn print_expr(s: @ps, expr: &ast::Expr) {
11211132
maybe_print_comment(s, expr.span.lo);
11221133
ibox(s, indent_unit);
11231134
let ann_node = node_expr(s, expr);
1124-
(s.ann.pre)(ann_node);
1135+
s.ann.pre(ann_node);
11251136
match expr.node {
11261137
ast::ExprVstore(e, v) => {
11271138
print_expr_vstore(s, v);
@@ -1456,7 +1467,7 @@ pub fn print_expr(s: @ps, expr: &ast::Expr) {
14561467
pclose(s);
14571468
}
14581469
}
1459-
(s.ann.post)(ann_node);
1470+
s.ann.post(ann_node);
14601471
end(s);
14611472
}
14621473

@@ -1578,7 +1589,7 @@ pub fn print_bounded_path(s: @ps, path: &ast::Path,
15781589
pub fn print_pat(s: @ps, pat: &ast::Pat) {
15791590
maybe_print_comment(s, pat.span.lo);
15801591
let ann_node = node_pat(s, pat);
1581-
(s.ann.pre)(ann_node);
1592+
s.ann.pre(ann_node);
15821593
/* Pat isn't normalized, but the beauty of it
15831594
is that it doesn't matter */
15841595
match pat.node {
@@ -1678,7 +1689,7 @@ pub fn print_pat(s: @ps, pat: &ast::Pat) {
16781689
word(s.s, "]");
16791690
}
16801691
}
1681-
(s.ann.post)(ann_node);
1692+
s.ann.post(ann_node);
16821693
}
16831694

16841695
pub fn explicit_self_to_str(explicit_self: &ast::explicit_self_, intr: @ident_interner) -> ~str {

0 commit comments

Comments
 (0)