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
This commit is contained in:
parent
e83a115d79
commit
ffa7c76ed2
4 changed files with 16 additions and 11 deletions
|
@ -117,7 +117,7 @@ fn pretty_print_input(session::session sess, eval::env env, str input,
|
|||
case (ppm_normal) { mode = ppaux::mo_untyped; }
|
||||
case (ppm_identified) { mode = ppaux::mo_identified; }
|
||||
}
|
||||
pprust::print_file(sess, crate.node.module, input, std::io::stdout(),
|
||||
pprust::print_crate(sess, crate, input, std::io::stdout(),
|
||||
mode);
|
||||
}
|
||||
|
||||
|
|
|
@ -76,7 +76,9 @@ fn def_id_of_def(def d) -> def_id {
|
|||
|
||||
type crate = spanned[crate_];
|
||||
|
||||
type crate_ = rec(vec[@crate_directive] directives, _mod module);
|
||||
type crate_ = rec(vec[@crate_directive] directives,
|
||||
_mod module,
|
||||
vec[attribute] attrs);
|
||||
|
||||
tag meta_visibility { export_meta; local_meta; }
|
||||
|
||||
|
|
|
@ -2285,13 +2285,14 @@ fn parse_native_view(&parser p) -> vec[@ast::view_item] {
|
|||
|
||||
fn parse_crate_from_source_file(&parser p) -> @ast::crate {
|
||||
auto lo = p.get_lo_pos();
|
||||
// FIXME (issue #487): Do something with these attrs
|
||||
auto crate_attrs = parse_inner_attrs_and_next(p);
|
||||
auto first_item_outer_attrs = crate_attrs._1;
|
||||
auto m = parse_mod_items(p, token::EOF,
|
||||
first_item_outer_attrs);
|
||||
let vec[@ast::crate_directive] cdirs = [];
|
||||
ret @spanned(lo, p.get_lo_pos(), rec(directives=cdirs, module=m));
|
||||
ret @spanned(lo, p.get_lo_pos(), rec(directives=cdirs,
|
||||
module=m,
|
||||
attrs=crate_attrs._0));
|
||||
}
|
||||
|
||||
|
||||
|
@ -2381,8 +2382,7 @@ fn parse_crate_directives(&parser p, token::token term) ->
|
|||
fn parse_crate_from_crate_file(&parser p) -> @ast::crate {
|
||||
auto lo = p.get_lo_pos();
|
||||
auto prefix = std::fs::dirname(p.get_filemap().name);
|
||||
// FIXME (issue #487): Do something with these attrs
|
||||
auto attrs = parse_inner_attrs(p);
|
||||
auto crate_attrs = parse_inner_attrs(p);
|
||||
auto cdirs = parse_crate_directives(p, token::EOF);
|
||||
let vec[str] deps = [];
|
||||
auto cx =
|
||||
|
@ -2396,7 +2396,9 @@ fn parse_crate_from_crate_file(&parser p) -> @ast::crate {
|
|||
eval::eval_crate_directives_to_mod(cx, p.get_env(), cdirs, prefix);
|
||||
auto hi = p.get_hi_pos();
|
||||
expect(p, token::EOF);
|
||||
ret @spanned(lo, hi, rec(directives=cdirs, module=m));
|
||||
ret @spanned(lo, hi, rec(directives=cdirs,
|
||||
module=m,
|
||||
attrs=crate_attrs));
|
||||
}
|
||||
//
|
||||
// Local Variables:
|
||||
|
|
|
@ -27,8 +27,8 @@ import pp::inconsistent;
|
|||
import pp::eof;
|
||||
import ppaux::*;
|
||||
|
||||
fn print_file(session sess, ast::_mod _mod, str filename, io::writer out,
|
||||
mode mode) {
|
||||
fn print_crate(session sess, @ast::crate crate, str filename,
|
||||
io::writer out, mode mode) {
|
||||
let vec[pp::breaks] boxes = [];
|
||||
auto r = lexer::gather_comments_and_literals(sess, filename);
|
||||
auto s =
|
||||
|
@ -40,7 +40,8 @@ fn print_file(session sess, ast::_mod _mod, str filename, io::writer out,
|
|||
mutable cur_lit=0u,
|
||||
mutable boxes=boxes,
|
||||
mode=mode);
|
||||
print_mod(s, _mod);
|
||||
print_inner_attributes(s, crate.node.attrs);
|
||||
print_mod(s, crate.node.module);
|
||||
eof(s.s);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue