Skip to content

Commit ffa7c76

Browse files
committed
rustc: Change print_file to print_crate
The pretty-printer needs access to the crate attributes in order to reproduce inner crate attributes in standalone .rs files Issue #487
1 parent e83a115 commit ffa7c76

File tree

4 files changed

+16
-11
lines changed

4 files changed

+16
-11
lines changed

src/comp/driver/rustc.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,8 @@ fn pretty_print_input(session::session sess, eval::env env, str input,
117117
case (ppm_normal) { mode = ppaux::mo_untyped; }
118118
case (ppm_identified) { mode = ppaux::mo_identified; }
119119
}
120-
pprust::print_file(sess, crate.node.module, input, std::io::stdout(),
121-
mode);
120+
pprust::print_crate(sess, crate, input, std::io::stdout(),
121+
mode);
122122
}
123123

124124
fn version(str argv0) {

src/comp/front/ast.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,9 @@ fn def_id_of_def(def d) -> def_id {
7676

7777
type crate = spanned[crate_];
7878

79-
type crate_ = rec(vec[@crate_directive] directives, _mod module);
79+
type crate_ = rec(vec[@crate_directive] directives,
80+
_mod module,
81+
vec[attribute] attrs);
8082

8183
tag meta_visibility { export_meta; local_meta; }
8284

src/comp/front/parser.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2285,13 +2285,14 @@ fn parse_native_view(&parser p) -> vec[@ast::view_item] {
22852285

22862286
fn parse_crate_from_source_file(&parser p) -> @ast::crate {
22872287
auto lo = p.get_lo_pos();
2288-
// FIXME (issue #487): Do something with these attrs
22892288
auto crate_attrs = parse_inner_attrs_and_next(p);
22902289
auto first_item_outer_attrs = crate_attrs._1;
22912290
auto m = parse_mod_items(p, token::EOF,
22922291
first_item_outer_attrs);
22932292
let vec[@ast::crate_directive] cdirs = [];
2294-
ret @spanned(lo, p.get_lo_pos(), rec(directives=cdirs, module=m));
2293+
ret @spanned(lo, p.get_lo_pos(), rec(directives=cdirs,
2294+
module=m,
2295+
attrs=crate_attrs._0));
22952296
}
22962297

22972298

@@ -2381,8 +2382,7 @@ fn parse_crate_directives(&parser p, token::token term) ->
23812382
fn parse_crate_from_crate_file(&parser p) -> @ast::crate {
23822383
auto lo = p.get_lo_pos();
23832384
auto prefix = std::fs::dirname(p.get_filemap().name);
2384-
// FIXME (issue #487): Do something with these attrs
2385-
auto attrs = parse_inner_attrs(p);
2385+
auto crate_attrs = parse_inner_attrs(p);
23862386
auto cdirs = parse_crate_directives(p, token::EOF);
23872387
let vec[str] deps = [];
23882388
auto cx =
@@ -2396,7 +2396,9 @@ fn parse_crate_from_crate_file(&parser p) -> @ast::crate {
23962396
eval::eval_crate_directives_to_mod(cx, p.get_env(), cdirs, prefix);
23972397
auto hi = p.get_hi_pos();
23982398
expect(p, token::EOF);
2399-
ret @spanned(lo, hi, rec(directives=cdirs, module=m));
2399+
ret @spanned(lo, hi, rec(directives=cdirs,
2400+
module=m,
2401+
attrs=crate_attrs));
24002402
}
24012403
//
24022404
// Local Variables:

src/comp/pretty/pprust.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ import pp::inconsistent;
2727
import pp::eof;
2828
import ppaux::*;
2929

30-
fn print_file(session sess, ast::_mod _mod, str filename, io::writer out,
31-
mode mode) {
30+
fn print_crate(session sess, @ast::crate crate, str filename,
31+
io::writer out, mode mode) {
3232
let vec[pp::breaks] boxes = [];
3333
auto r = lexer::gather_comments_and_literals(sess, filename);
3434
auto s =
@@ -40,7 +40,8 @@ fn print_file(session sess, ast::_mod _mod, str filename, io::writer out,
4040
mutable cur_lit=0u,
4141
mutable boxes=boxes,
4242
mode=mode);
43-
print_mod(s, _mod);
43+
print_inner_attributes(s, crate.node.attrs);
44+
print_mod(s, crate.node.module);
4445
eof(s.s);
4546
}
4647

0 commit comments

Comments
 (0)