Skip to content
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
5 changes: 2 additions & 3 deletions src/librustc/metadata/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -331,12 +331,11 @@ fn encode_info_for_mod(ecx: @encode_ctxt, ebml_w: writer::Encoder,
item_impl(*) | item_struct(*) => {
let (ident, did) = (item.ident, item.id);
debug!("(encoding info for module) ... encoding impl %s \
(%?/%?), exported? %?",
(%?/%?)",
ecx.tcx.sess.str_of(ident),
did,
ast_map::node_id_to_str(ecx.tcx.items, did, ecx.tcx
.sess.parse_sess.interner),
ast_util::is_exported(ident, md));
.sess.parse_sess.interner));

ebml_w.start_tag(tag_mod_impl);
ebml_w.wr_str(def_to_str(local_def(did)));
Expand Down
17 changes: 8 additions & 9 deletions src/librustc/middle/privacy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,15 @@ use syntax::ast::{provided, required};
use syntax::ast;
use syntax::ast_map::{node_item, node_method};
use syntax::ast_map;
use syntax::ast_util::{Private, Public, has_legacy_export_attr, is_local};
use syntax::ast_util::{visibility_to_privacy};
use syntax::ast_util::{Private, Public, is_local};
use syntax::ast_util::{variant_visibility_to_privacy, visibility_to_privacy};
use syntax::codemap::span;
use syntax::visit;

pub fn check_crate(tcx: ty::ctxt,
method_map: &method_map,
crate: @ast::crate) {
let privileged_items = @DVec();
let legacy_exports = has_legacy_export_attr(crate.node.attrs);

// Adds structs that are privileged to this scope.
let add_privileged_items: @fn(&[@ast::item]) -> int = |items| {
Expand All @@ -65,20 +64,20 @@ pub fn check_crate(tcx: ty::ctxt,
|it| { it.vis },
~"unbound enum parent when checking \
dereference of enum type");
visibility_to_privacy(parent_vis, legacy_exports)
visibility_to_privacy(parent_vis)
}
else {
// WRONG
Public
};
debug!("parental_privacy = %?", parental_privacy);
debug!("vis = %?, priv = %?, legacy_exports = %?",
debug!("vis = %?, priv = %?",
variant_info.vis,
visibility_to_privacy(variant_info.vis, legacy_exports),
legacy_exports);
visibility_to_privacy(variant_info.vis))
// inherited => privacy of the enum item
if visibility_to_privacy(variant_info.vis,
parental_privacy == Public) == Private {
if variant_visibility_to_privacy(variant_info.vis,
parental_privacy == Public)
== Private {
tcx.sess.span_err(span,
~"can only dereference enums \
with a single, public variant");
Expand Down
237 changes: 28 additions & 209 deletions src/librustc/middle/resolve.rs

Large diffs are not rendered by default.

4 changes: 0 additions & 4 deletions src/librustc/middle/trans/monomorphize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,6 @@ pub fn monomorphic_fn(ccx: @crate_ctxt,
ast_map::node_stmt(*) => {
ccx.tcx.sess.bug(~"Can't monomorphize a stmt")
}
ast_map::node_export(*) => {
ccx.tcx.sess.bug(~"Can't monomorphize an export")
}
ast_map::node_arg(*) => ccx.tcx.sess.bug(~"Can't monomorphize an arg"),
ast_map::node_block(*) => {
ccx.tcx.sess.bug(~"Can't monomorphize a block")
Expand Down Expand Up @@ -255,7 +252,6 @@ pub fn monomorphic_fn(ccx: @crate_ctxt,
ast_map::node_expr(*) |
ast_map::node_stmt(*) |
ast_map::node_trait_method(*) |
ast_map::node_export(*) |
ast_map::node_arg(*) |
ast_map::node_block(*) |
ast_map::node_local(*) => {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3756,7 +3756,7 @@ pub fn item_path(cx: ctxt, id: ast::def_id) -> ast_map::path {

ast_map::node_stmt(*) | ast_map::node_expr(*) |
ast_map::node_arg(*) | ast_map::node_local(*) |
ast_map::node_export(*) | ast_map::node_block(*) => {
ast_map::node_block(*) => {
cx.sess.bug(fmt!("cannot find item_path for node %?", node));
}
}
Expand Down
1 change: 0 additions & 1 deletion src/librustc/middle/typeck/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ use std::map;
use std::smallintmap;
use syntax::ast::{provided, required, spanned};
use syntax::ast_map::node_id_to_str;
use syntax::ast_util::{has_legacy_export_attr};
use syntax::ast_util::{local_def, respan, split_trait_methods};
use syntax::codemap::span;
use syntax::print::pprust::*;
Expand Down
1 change: 0 additions & 1 deletion src/libsyntax/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1504,7 +1504,6 @@ pub struct view_item {
pub enum view_item_ {
view_item_use(ident, ~[@meta_item], node_id),
view_item_import(~[@view_path]),
view_item_export(~[@view_path])
}

// Meta-data associated with an item
Expand Down
24 changes: 0 additions & 24 deletions src/libsyntax/ast_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ pub enum ast_node {
node_variant(variant, @item, @path),
node_expr(@expr),
node_stmt(@stmt),
node_export(@view_path, @path),
// Locals are numbered, because the alias analysis needs to know in which
// order they are introduced.
node_arg(arg, uint),
Expand Down Expand Up @@ -128,7 +127,6 @@ pub fn mk_ast_map_visitor() -> vt {
visit_fn: map_fn,
visit_local: map_local,
visit_arm: map_arm,
visit_view_item: map_view_item,
visit_block: map_block,
.. *visit::default_visitor()
});
Expand Down Expand Up @@ -324,23 +322,6 @@ pub fn map_struct_def(struct_def: @ast::struct_def, parent_node: ast_node,
}
}

pub fn map_view_item(vi: @view_item, cx: ctx, _v: vt) {
match vi.node {
view_item_export(vps) => for vps.each |vp| {
let (id, name) = match vp.node {
view_path_simple(nm, _, _, id) => {
(id, /* FIXME (#2543) */ copy nm)
}
view_path_glob(pth, id) | view_path_list(pth, _, id) => {
(id, path_to_ident(pth))
}
};
cx.map.insert(id, node_export(*vp, extend(cx, name)));
},
_ => ()
}
}

pub fn map_expr(ex: @expr, cx: ctx, v: vt) {
cx.map.insert(ex.id, node_expr(ex));
visit::visit_expr(ex, cx, v);
Expand Down Expand Up @@ -396,11 +377,6 @@ pub fn node_id_to_str(map: map, id: node_id, itr: @ident_interner) -> ~str {
fmt!("stmt %s (id=%?)",
pprust::stmt_to_str(*stmt, itr), id)
}
// FIXMEs are as per #2410
Some(node_export(_, path)) => {
fmt!("export %s (id=%?)", // add more info here
path_to_str(*path, itr), id)
}
Some(node_arg(_, _)) => { // add more info here
fmt!("arg (id=%?)", id)
}
Expand Down
100 changes: 14 additions & 86 deletions src/libsyntax/ast_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,64 +215,6 @@ pub pure fn float_ty_to_str(t: float_ty) -> ~str {
match t { ty_f => ~"f", ty_f32 => ~"f32", ty_f64 => ~"f64" }
}

pub fn is_exported(i: ident, m: _mod) -> bool {
let mut local = false;
let mut parent_enum : Option<ident> = None;
for m.items.each |it| {
if it.ident == i { local = true; }
match it.node {
item_enum(ref enum_definition, _) =>
for (*enum_definition).variants.each |v| {
if v.node.name == i {
local = true;
parent_enum = Some(/* FIXME (#2543) */ copy it.ident);
}
},
_ => ()
}
if local { break; }
}
let mut has_explicit_exports = false;
for m.view_items.each |vi| {
match vi.node {
view_item_export(vps) => {
has_explicit_exports = true;
for vps.each |vp| {
match vp.node {
ast::view_path_simple(id, _, _, _) => {
if id == i { return true; }
match parent_enum {
Some(parent_enum_id) => {
if id == parent_enum_id { return true; }
}
_ => ()
}
}

ast::view_path_list(path, ref ids, _) => {
if vec::len(path.idents) == 1u {
if i == path.idents[0] { return true; }
for (*ids).each |id| {
if id.node.name == i { return true; }
}
} else {
fail ~"export of path-qualified list";
}
}

_ => ()
}
}
}
_ => ()
}
}
// If there are no declared exports then
// everything not imported is exported
// even if it's local (since it's explicit)
return !has_explicit_exports && local;
}

pub pure fn is_call_expr(e: @expr) -> bool {
match e.node { expr_call(_, _, _) => true, _ => false }
}
Expand Down Expand Up @@ -476,7 +418,7 @@ pub fn id_visitor(vfn: fn@(node_id)) -> visit::vt<()> {
visit_view_item: fn@(vi: @view_item) {
match vi.node {
view_item_use(_, _, id) => vfn(id),
view_item_import(vps) | view_item_export(vps) => {
view_item_import(vps) => {
for vec::each(vps) |vp| {
match vp.node {
view_path_simple(_, _, _, id) => vfn(id),
Expand Down Expand Up @@ -662,46 +604,32 @@ pub fn struct_def_is_tuple_like(struct_def: @ast::struct_def) -> bool {
struct_def.ctor_id.is_some()
}

pub fn visibility_to_privacy(visibility: visibility) -> Privacy {
match visibility {
public => Public,
inherited | private => Private
}
}

pub fn visibility_to_privacy(visibility: visibility,
legacy_exports: bool) -> Privacy {
if legacy_exports {
pub fn variant_visibility_to_privacy(visibility: visibility,
enclosing_is_public: bool)
-> Privacy {
if enclosing_is_public {
match visibility {
inherited | public => Public,
public | inherited => Public,
private => Private
}
} else {
match visibility {
public => Public,
inherited | private => Private
}
visibility_to_privacy(visibility)
}
}

#[deriving_eq]
pub enum Privacy {
Private,
Public
}

pub impl Privacy : cmp::Eq {
pure fn eq(&self, other: &Privacy) -> bool {
((*self) as uint) == ((*other) as uint)
}
pure fn ne(&self, other: &Privacy) -> bool { !(*self).eq(other) }
}

pub fn has_legacy_export_attr(attrs: &[attribute]) -> bool {
for attrs.each |attribute| {
match attribute.node.value.node {
meta_word(ref w) if (*w) == ~"legacy_exports" => {
return true;
}
_ => {}
}
}
return false;
}

// Local Variables:
// mode: rust
// fill-column: 78;
Expand Down
26 changes: 4 additions & 22 deletions src/libsyntax/parse/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ use ast::{ty_field, ty_fixed_length_vec, ty_fn, ty_infer, ty_mac, ty_method};
use ast::{ty_nil, ty_param, ty_param_bound, ty_path, ty_ptr, ty_rec, ty_rptr};
use ast::{ty_tup, ty_u32, ty_uniq, ty_vec, type_value_ns, uniq};
use ast::{unnamed_field, unsafe_blk, unsafe_fn, variant, view_item};
use ast::{view_item_, view_item_export, view_item_import, view_item_use};
use ast::{view_item_, view_item_import, view_item_use};
use ast::{view_path, view_path_glob, view_path_list, view_path_simple};
use ast::{visibility, vstore, vstore_box, vstore_fixed, vstore_slice};
use ast::{vstore_uniq};
Expand Down Expand Up @@ -88,6 +88,7 @@ use core::vec::push;
use core::vec;
use std::map::HashMap;

#[deriving_eq]
enum restriction {
UNRESTRICTED,
RESTRICT_STMT_EXPR,
Expand Down Expand Up @@ -3735,15 +3736,6 @@ pub impl Parser {
vis: visibility,
span: mk_sp(lo, self.last_span.hi)
});
} else if self.eat_keyword(~"export") {
let view_paths = self.parse_view_paths();
self.expect(token::SEMI);
return iovi_view_item(@ast::view_item {
node: view_item_export(view_paths),
attrs: attrs,
vis: visibility,
span: mk_sp(lo, self.last_span.hi)
});
} else if macros_allowed && !self.is_any_keyword(copy self.token)
&& self.look_ahead(1) == token::NOT
&& (is_plain_ident(self.look_ahead(2))
Expand Down Expand Up @@ -3916,7 +3908,6 @@ pub impl Parser {
next_tok = self.look_ahead(2);
};
self.token_is_keyword(~"use", tok)
|| self.token_is_keyword(~"export", tok)
|| (self.token_is_keyword(~"extern", tok) &&
self.token_is_keyword(~"mod", next_tok))
}
Expand All @@ -3925,8 +3916,6 @@ pub impl Parser {
let lo = self.span.lo;
let node = if self.eat_keyword(~"use") {
self.parse_use()
} else if self.eat_keyword(~"export") {
view_item_export(self.parse_view_paths())
} else if self.eat_keyword(~"extern") {
self.expect_keyword(~"mod");
let ident = self.parse_ident();
Expand Down Expand Up @@ -3979,8 +3968,8 @@ pub impl Parser {
if restricted_to_imports {
match view_item.node {
view_item_import(_) => {}
view_item_export(_) | view_item_use(*) =>
self.fatal(~"exports and \"extern mod\" \
view_item_use(*) =>
self.fatal(~"\"extern mod\" \
declarations are not \
allowed here")
}
Expand Down Expand Up @@ -4025,13 +4014,6 @@ pub impl Parser {
}
}

impl restriction : cmp::Eq {
pure fn eq(&self, other: &restriction) -> bool {
((*self) as uint) == ((*other) as uint)
}
pure fn ne(&self, other: &restriction) -> bool { !(*self).eq(other) }
}

//
// Local Variables:
// mode: rust
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/parse/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ pub fn strict_keyword_table() -> HashMap<~str, ()> {
~"break",
~"const", ~"copy",
~"do", ~"drop",
~"else", ~"enum", ~"export", ~"extern",
~"else", ~"enum", ~"extern",
~"fail", ~"false", ~"fn", ~"for",
~"if", ~"impl",
~"let", ~"log", ~"loop",
Expand Down
Loading