Support visibility qualifiers in crate directives properly.

This commit is contained in:
Graydon Hoare 2012-09-24 12:53:32 -07:00
parent c675cd396d
commit 9c6ae65865
5 changed files with 16 additions and 14 deletions

View File

@ -265,8 +265,8 @@ type crate_ =
config: crate_cfg};
enum crate_directive_ {
cdir_src_mod(ident, ~[attribute]),
cdir_dir_mod(ident, ~[@crate_directive], ~[attribute]),
cdir_src_mod(visibility, ident, ~[attribute]),
cdir_dir_mod(visibility, ident, ~[@crate_directive], ~[attribute]),
// NB: cdir_view_item is *not* processed by the rest of the compiler, the
// attached view_items are sunk into the crate's module during parsing,

View File

@ -162,11 +162,12 @@ fn noop_fold_crate(c: crate_, fld: ast_fold) -> crate_ {
fn noop_fold_crate_directive(cd: crate_directive_, fld: ast_fold) ->
crate_directive_ {
return match cd {
cdir_src_mod(id, attrs) => {
cdir_src_mod(fld.fold_ident(id), /* FIXME (#2543) */ copy attrs)
cdir_src_mod(vis, id, attrs) => {
cdir_src_mod(vis, fld.fold_ident(id),
/* FIXME (#2543) */ copy attrs)
}
cdir_dir_mod(id, cds, attrs) => {
cdir_dir_mod(fld.fold_ident(id),
cdir_dir_mod(vis, id, cds, attrs) => {
cdir_dir_mod(vis, fld.fold_ident(id),
vec::map(cds, |x| fld.fold_crate_directive(*x)),
/* FIXME (#2543) */ copy attrs)
}

View File

@ -85,7 +85,7 @@ fn eval_crate_directive(cx: ctx, cdir: @ast::crate_directive, prefix: &Path,
&view_items: ~[@ast::view_item],
&items: ~[@ast::item]) {
match cdir.node {
ast::cdir_src_mod(id, attrs) => {
ast::cdir_src_mod(vis, id, attrs) => {
let file_path = Path(cdir_path_opt(
cx.sess.interner.get(id) + ~".rs", attrs));
let full_path = if file_path.is_absolute {
@ -103,13 +103,13 @@ fn eval_crate_directive(cx: ctx, cdir: @ast::crate_directive, prefix: &Path,
let i = p0.mk_item(cdir.span.lo, cdir.span.hi,
/* FIXME (#2543) */ copy id,
ast::item_mod(m0), ast::public, mod_attrs);
ast::item_mod(m0), vis, mod_attrs);
// Thread defids, chpos and byte_pos through the parsers
cx.sess.chpos = r0.chpos;
cx.sess.byte_pos = cx.sess.byte_pos + r0.pos;
vec::push(items, i);
}
ast::cdir_dir_mod(id, cdirs, attrs) => {
ast::cdir_dir_mod(vis, id, cdirs, attrs) => {
let path = Path(cdir_path_opt(*cx.sess.interner.get(id), attrs));
let full_path = if path.is_absolute {
copy path
@ -123,7 +123,7 @@ fn eval_crate_directive(cx: ctx, cdir: @ast::crate_directive, prefix: &Path,
attrs: vec::append(attrs, a0),
id: cx.sess.next_id,
node: ast::item_mod(m0),
vis: ast::public,
vis: vis,
span: cdir.span};
cx.sess.next_id += 1;
vec::push(items, i);

View File

@ -3601,6 +3601,7 @@ impl parser {
let expect_mod = vec::len(outer_attrs) > 0u;
let lo = self.span.lo;
let vis = self.parse_visibility();
if expect_mod || self.is_keyword(~"mod") {
self.expect_keyword(~"mod");
@ -3611,7 +3612,7 @@ impl parser {
token::SEMI => {
let mut hi = self.span.hi;
self.bump();
return spanned(lo, hi, cdir_src_mod(id, outer_attrs));
return spanned(lo, hi, cdir_src_mod(vis, id, outer_attrs));
}
// mod x = "foo_dir" { ...directives... }
token::LBRACE => {
@ -3624,7 +3625,7 @@ impl parser {
let mut hi = self.span.hi;
self.expect(token::RBRACE);
return spanned(lo, hi,
cdir_dir_mod(id, cdirs, mod_attrs));
cdir_dir_mod(vis, id, cdirs, mod_attrs));
}
_ => self.unexpected()
}

View File

@ -96,8 +96,8 @@ fn visit_crate<E>(c: crate, e: E, v: vt<E>) {
fn visit_crate_directive<E>(cd: @crate_directive, e: E, v: vt<E>) {
match cd.node {
cdir_src_mod(_, _) => (),
cdir_dir_mod(_, cdirs, _) => for cdirs.each |cdir| {
cdir_src_mod(_, _, _) => (),
cdir_dir_mod(_, _, cdirs, _) => for cdirs.each |cdir| {
visit_crate_directive(*cdir, e, v);
},
cdir_view_item(vi) => v.visit_view_item(vi, e, v),