1
Fork 0

Start parsing pub/priv on regular items

Issue #1893
This commit is contained in:
Marijn Haverbeke 2012-05-08 16:06:24 +02:00
parent df3bf7c2a0
commit b619954457
15 changed files with 100 additions and 77 deletions

View file

@ -557,7 +557,7 @@ enum ret_style {
type method = {ident: ident, attrs: [attribute], type method = {ident: ident, attrs: [attribute],
tps: [ty_param], decl: fn_decl, body: blk, tps: [ty_param], decl: fn_decl, body: blk,
id: node_id, span: span, self_id: node_id, id: node_id, span: span, self_id: node_id,
privacy: privacy}; // privacy is always public, unless it's a vis: visibility}; // always public, unless it's a
// class method // class method
#[auto_serialize] #[auto_serialize]
@ -580,7 +580,7 @@ type variant_arg = {ty: @ty, id: node_id};
#[auto_serialize] #[auto_serialize]
type variant_ = {name: ident, attrs: [attribute], args: [variant_arg], type variant_ = {name: ident, attrs: [attribute], args: [variant_arg],
id: node_id, disr_expr: option<@expr>}; id: node_id, disr_expr: option<@expr>, vis: visibility};
#[auto_serialize] #[auto_serialize]
type variant = spanned<variant_>; type variant = spanned<variant_>;
@ -641,9 +641,13 @@ type attribute_ = {style: attr_style, value: meta_item};
#[auto_serialize] #[auto_serialize]
type iface_ref = {path: @path, id: node_id}; type iface_ref = {path: @path, id: node_id};
#[auto_serialize]
enum visibility { public, private }
#[auto_serialize] #[auto_serialize]
type item = {ident: ident, attrs: [attribute], type item = {ident: ident, attrs: [attribute],
id: node_id, node: item_, span: span}; id: node_id, node: item_,
vis: visibility, span: span};
#[auto_serialize] #[auto_serialize]
enum region_param { enum region_param {
@ -679,16 +683,13 @@ type class_member = spanned<class_member_>;
#[auto_serialize] #[auto_serialize]
enum class_member_ { enum class_member_ {
instance_var(ident, @ty, class_mutability, node_id, privacy), instance_var(ident, @ty, class_mutability, node_id, visibility),
class_method(@method) class_method(@method)
} }
#[auto_serialize] #[auto_serialize]
enum class_mutability { class_mutable, class_immutable } enum class_mutability { class_mutable, class_immutable }
#[auto_serialize]
enum privacy { priv, pub }
#[auto_serialize] #[auto_serialize]
type class_ctor = spanned<class_ctor_>; type class_ctor = spanned<class_ctor_>;

View file

@ -276,11 +276,11 @@ pure fn class_item_ident(ci: @class_member) -> ident {
} }
type ivar = {ident: ident, ty: @ty, cm: class_mutability, type ivar = {ident: ident, ty: @ty, cm: class_mutability,
id: node_id, privacy: privacy}; id: node_id, vis: visibility};
fn public_methods(ms: [@method]) -> [@method] { fn public_methods(ms: [@method]) -> [@method] {
vec::filter(ms, {|m| alt m.privacy { vec::filter(ms, {|m| alt m.vis {
pub { true } public { true }
_ { false }}}) _ { false }}})
} }
@ -288,8 +288,8 @@ fn split_class_items(cs: [@class_member]) -> ([ivar], [@method]) {
let mut vs = [], ms = []; let mut vs = [], ms = [];
for cs.each {|c| for cs.each {|c|
alt c.node { alt c.node {
instance_var(i, t, cm, id, privacy) { instance_var(i, t, cm, id, vis) {
vs += [{ident: i, ty: t, cm: cm, id: id, privacy: privacy}]; vs += [{ident: i, ty: t, cm: cm, id: id, vis: vis}];
} }
class_method(m) { ms += [m]; } class_method(m) { ms += [m]; }
} }
@ -297,10 +297,10 @@ fn split_class_items(cs: [@class_member]) -> ([ivar], [@method]) {
(vs, ms) (vs, ms)
} }
pure fn class_member_privacy(ci: @class_member) -> privacy { pure fn class_member_visibility(ci: @class_member) -> visibility {
alt ci.node { alt ci.node {
instance_var(_, _, _, _, p) { p } instance_var(_, _, _, _, vis) { vis }
class_method(m) { m.privacy } class_method(m) { m.vis }
} }
} }

View file

@ -546,6 +546,7 @@ fn mk_ser_fn(cx: ext_ctxt, span: span, name: str, tps: [ast::ty_param],
constraints: []}, constraints: []},
ser_tps, ser_tps,
ser_blk), ser_blk),
vis: ast::public,
span: span} span: span}
} }
@ -744,6 +745,7 @@ fn mk_deser_fn(cx: ext_ctxt, span: span, name: str, tps: [ast::ty_param],
constraints: []}, constraints: []},
deser_tps, deser_tps,
deser_blk), deser_blk),
vis: ast::public,
span: span} span: span}
} }

View file

@ -173,7 +173,7 @@ fn parse_stmt(p: parser) -> @ast::stmt {
} }
fn parse_item(p: parser) -> @ast::item { fn parse_item(p: parser) -> @ast::item {
alt (parser::parse_item(p, [])) { alt parser::parse_item(p, [], ast::public) {
some(item) { item } some(item) { item }
none { fail "parse_item: parsing an item failed"; } none { fail "parse_item: parsing an item failed"; }
} }

View file

@ -241,6 +241,7 @@ fn noop_fold_item(&&i: @item, fld: ast_fold) -> @item {
attrs: vec::map(i.attrs, fold_attribute), attrs: vec::map(i.attrs, fold_attribute),
id: fld.new_id(i.id), id: fld.new_id(i.id),
node: fld.fold_item_underscore(i.node), node: fld.fold_item_underscore(i.node),
vis: i.vis,
span: fld.new_span(i.span)}; span: fld.new_span(i.span)};
} }
@ -323,7 +324,7 @@ fn noop_fold_method(&&m: @method, fld: ast_fold) -> @method {
id: fld.new_id(m.id), id: fld.new_id(m.id),
span: fld.new_span(m.span), span: fld.new_span(m.span),
self_id: fld.new_id(m.self_id), self_id: fld.new_id(m.self_id),
privacy: m.privacy}; vis: m.vis};
} }
@ -564,7 +565,8 @@ fn noop_fold_variant(v: variant_, fld: ast_fold) -> variant_ {
ret {name: v.name, ret {name: v.name,
attrs: attrs, attrs: attrs,
args: args, id: fld.new_id(v.id), args: args, id: fld.new_id(v.id),
disr_expr: de}; disr_expr: de,
vis: v.vis};
} }
fn noop_fold_ident(&&i: ident, _fld: ast_fold) -> ident { ret i; } fn noop_fold_ident(&&i: ident, _fld: ast_fold) -> ident { ret i; }

View file

@ -107,7 +107,7 @@ fn eval_crate_directive(cx: ctx, cdir: @ast::crate_directive, prefix: str,
let i = let i =
parser::mk_item(p0, cdir.span.lo, cdir.span.hi, id, parser::mk_item(p0, cdir.span.lo, cdir.span.hi, id,
ast::item_mod(m0), mod_attrs); ast::item_mod(m0), ast::public, mod_attrs);
// Thread defids, chpos and byte_pos through the parsers // Thread defids, chpos and byte_pos through the parsers
cx.sess.chpos = p0.reader.chpos; cx.sess.chpos = p0.reader.chpos;
cx.sess.byte_pos = cx.sess.byte_pos + p0.reader.pos; cx.sess.byte_pos = cx.sess.byte_pos + p0.reader.pos;
@ -126,6 +126,7 @@ fn eval_crate_directive(cx: ctx, cdir: @ast::crate_directive, prefix: str,
attrs: attrs + a0, attrs: attrs + a0,
id: cx.sess.next_id, id: cx.sess.next_id,
node: ast::item_mod(m0), node: ast::item_mod(m0),
vis: ast::public,
span: cdir.span}; span: cdir.span};
cx.sess.next_id += 1; cx.sess.next_id += 1;
items += [i]; items += [i];

View file

@ -1485,7 +1485,7 @@ fn parse_let(p: parser) -> @ast::decl {
} }
/* assumes "let" token has already been consumed */ /* assumes "let" token has already been consumed */
fn parse_instance_var(p:parser, pr: ast::privacy) -> @ast::class_member { fn parse_instance_var(p:parser, pr: ast::visibility) -> @ast::class_member {
let mut is_mutbl = ast::class_immutable; let mut is_mutbl = ast::class_immutable;
let lo = p.span.lo; let lo = p.span.lo;
if eat_keyword(p, "mut") { if eat_keyword(p, "mut") {
@ -1527,7 +1527,7 @@ fn parse_stmt(p: parser, +first_item_attrs: [ast::attribute]) -> @ast::stmt {
let item_attrs = first_item_attrs + item_attrs; let item_attrs = first_item_attrs + item_attrs;
alt parse_item(p, item_attrs) { alt parse_item(p, item_attrs, ast::public) {
some(i) { some(i) {
let mut hi = i.span.hi; let mut hi = i.span.hi;
let decl = @spanned(lo, hi, ast::decl_item(i)); let decl = @spanned(lo, hi, ast::decl_item(i));
@ -1789,11 +1789,13 @@ fn parse_fn_header(p: parser) -> {ident: ast::ident, tps: [ast::ty_param]} {
} }
fn mk_item(p: parser, lo: uint, hi: uint, +ident: ast::ident, fn mk_item(p: parser, lo: uint, hi: uint, +ident: ast::ident,
+node: ast::item_, +attrs: [ast::attribute]) -> @ast::item { +node: ast::item_, vis: ast::visibility,
+attrs: [ast::attribute]) -> @ast::item {
ret @{ident: ident, ret @{ident: ident,
attrs: attrs, attrs: attrs,
id: p.get_id(), id: p.get_id(),
node: node, node: node,
vis: vis,
span: mk_sp(lo, hi)}; span: mk_sp(lo, hi)};
} }
@ -1819,7 +1821,7 @@ fn parse_method_name(p: parser) -> ast::ident {
} }
} }
fn parse_method(p: parser, pr: ast::privacy) -> @ast::method { fn parse_method(p: parser, pr: ast::visibility) -> @ast::method {
let attrs = parse_outer_attributes(p); let attrs = parse_outer_attributes(p);
let lo = p.span.lo, pur = parse_fn_purity(p); let lo = p.span.lo, pur = parse_fn_purity(p);
let ident = parse_method_name(p); let ident = parse_method_name(p);
@ -1829,7 +1831,7 @@ fn parse_method(p: parser, pr: ast::privacy) -> @ast::method {
let attrs = attrs + inner_attrs; let attrs = attrs + inner_attrs;
@{ident: ident, attrs: attrs, tps: tps, decl: decl, body: body, @{ident: ident, attrs: attrs, tps: tps, decl: decl, body: body,
id: p.get_id(), span: mk_sp(lo, body.span.hi), id: p.get_id(), span: mk_sp(lo, body.span.hi),
self_id: p.get_id(), privacy: pr} self_id: p.get_id(), vis: pr}
} }
fn parse_item_iface(p: parser) -> item_info { fn parse_item_iface(p: parser) -> item_info {
@ -1877,7 +1879,7 @@ fn parse_item_impl(p: parser) -> item_info {
let ty = parse_ty(p, false); let ty = parse_ty(p, false);
let mut meths = []; let mut meths = [];
expect(p, token::LBRACE); expect(p, token::LBRACE);
while !eat(p, token::RBRACE) { meths += [parse_method(p, ast::pub)]; } while !eat(p, token::RBRACE) { meths += [parse_method(p, ast::public)]; }
(ident, ast::item_impl(tps, rp, ifce, ty, meths), none) (ident, ast::item_impl(tps, rp, ifce, ty, meths), none)
} }
@ -1978,15 +1980,15 @@ fn parse_item_class(p: parser) -> item_info {
} }
} }
fn parse_single_class_item(p: parser, privcy: ast::privacy) fn parse_single_class_item(p: parser, vis: ast::visibility)
-> @ast::class_member { -> @ast::class_member {
if eat_keyword(p, "let") { if eat_keyword(p, "let") {
let a_var = parse_instance_var(p, privcy); let a_var = parse_instance_var(p, vis);
expect(p, token::SEMI); expect(p, token::SEMI);
ret a_var; ret a_var;
} }
else { else {
let m = parse_method(p, privcy); let m = parse_method(p, vis);
ret @{node: ast::class_method(m), span: m.span}; ret @{node: ast::class_method(m), span: m.span};
} }
} }
@ -2014,17 +2016,23 @@ fn parse_class_item(p:parser, class_name_with_tps: @ast::path)
expect(p, token::LBRACE); expect(p, token::LBRACE);
let mut results = []; let mut results = [];
while p.token != token::RBRACE { while p.token != token::RBRACE {
results += [parse_single_class_item(p, ast::priv)]; results += [parse_single_class_item(p, ast::private)];
} }
p.bump(); p.bump();
ret members(results); ret members(results);
} }
else { else {
// Probably need to parse attrs // Probably need to parse attrs
ret members([parse_single_class_item(p, ast::pub)]); ret members([parse_single_class_item(p, ast::public)]);
} }
} }
fn parse_visibility(p: parser, def: ast::visibility) -> ast::visibility {
if eat_keyword(p, "pub") { ast::public }
else if eat_keyword(p, "priv") { ast::private }
else { def }
}
fn parse_mod_items(p: parser, term: token::token, fn parse_mod_items(p: parser, term: token::token,
+first_item_attrs: [ast::attribute]) -> ast::_mod { +first_item_attrs: [ast::attribute]) -> ast::_mod {
// Shouldn't be any view items since we've already parsed an item attr // Shouldn't be any view items since we've already parsed an item attr
@ -2035,7 +2043,8 @@ fn parse_mod_items(p: parser, term: token::token,
let mut attrs = parse_outer_attributes(p); let mut attrs = parse_outer_attributes(p);
if first { attrs = first_item_attrs + attrs; first = false; } if first { attrs = first_item_attrs + attrs; first = false; }
#debug["parse_mod_items: parse_item(attrs=%?)", attrs]; #debug["parse_mod_items: parse_item(attrs=%?)", attrs];
alt parse_item(p, attrs) { let vis = parse_visibility(p, ast::private);
alt parse_item(p, attrs, vis) {
some(i) { items += [i]; } some(i) { items += [i]; }
_ { _ {
p.fatal("expected item but found '" + p.fatal("expected item but found '" +
@ -2154,7 +2163,7 @@ fn parse_region_param(p: parser) -> ast::region_param {
} }
} }
fn parse_item_enum(p: parser) -> item_info { fn parse_item_enum(p: parser, default_vis: ast::visibility) -> item_info {
let id = parse_ident(p); let id = parse_ident(p);
let rp = parse_region_param(p); let rp = parse_region_param(p);
let ty_params = parse_ty_params(p); let ty_params = parse_ty_params(p);
@ -2171,7 +2180,8 @@ fn parse_item_enum(p: parser) -> item_info {
attrs: [], attrs: [],
args: [{ty: ty, id: p.get_id()}], args: [{ty: ty, id: p.get_id()}],
id: p.get_id(), id: p.get_id(),
disr_expr: none}); disr_expr: none,
vis: ast::public});
ret (id, ast::item_enum([variant], ty_params, rp), none); ret (id, ast::item_enum([variant], ty_params, rp), none);
} }
expect(p, token::LBRACE); expect(p, token::LBRACE);
@ -2181,6 +2191,7 @@ fn parse_item_enum(p: parser) -> item_info {
while p.token != token::RBRACE { while p.token != token::RBRACE {
let variant_attrs = parse_outer_attributes(p); let variant_attrs = parse_outer_attributes(p);
let vlo = p.span.lo; let vlo = p.span.lo;
let vis = parse_visibility(p, default_vis);
let ident = parse_value_ident(p); let ident = parse_value_ident(p);
let mut args = [], disr_expr = none; let mut args = [], disr_expr = none;
if p.token == token::LPAREN { if p.token == token::LPAREN {
@ -2198,7 +2209,7 @@ fn parse_item_enum(p: parser) -> item_info {
let vr = {name: ident, attrs: variant_attrs, let vr = {name: ident, attrs: variant_attrs,
args: args, id: p.get_id(), args: args, id: p.get_id(),
disr_expr: disr_expr}; disr_expr: disr_expr, vis: vis};
variants += [spanned(vlo, p.last_span.hi, vr)]; variants += [spanned(vlo, p.last_span.hi, vr)];
if !eat(p, token::COMMA) { break; } if !eat(p, token::COMMA) { break; }
@ -2241,7 +2252,8 @@ fn fn_expr_lookahead(tok: token::token) -> bool {
} }
} }
fn parse_item(p: parser, +attrs: [ast::attribute]) -> option<@ast::item> { fn parse_item(p: parser, +attrs: [ast::attribute], vis: ast::visibility)
-> option<@ast::item> {
let lo = p.span.lo; let lo = p.span.lo;
let (ident, item_, extra_attrs) = if eat_keyword(p, "const") { let (ident, item_, extra_attrs) = if eat_keyword(p, "const") {
parse_item_const(p) parse_item_const(p)
@ -2265,7 +2277,7 @@ fn parse_item(p: parser, +attrs: [ast::attribute]) -> option<@ast::item> {
} else if eat_keyword(p, "type") { } else if eat_keyword(p, "type") {
parse_item_type(p) parse_item_type(p)
} else if eat_keyword(p, "enum") { } else if eat_keyword(p, "enum") {
parse_item_enum(p) parse_item_enum(p, vis)
} else if eat_keyword(p, "iface") { } else if eat_keyword(p, "iface") {
parse_item_iface(p) parse_item_iface(p)
} else if eat_keyword(p, "impl") { } else if eat_keyword(p, "impl") {
@ -2275,7 +2287,8 @@ fn parse_item(p: parser, +attrs: [ast::attribute]) -> option<@ast::item> {
} else if eat_keyword(p, "class") { } else if eat_keyword(p, "class") {
parse_item_class(p) parse_item_class(p)
} else { ret none; }; } else { ret none; };
some(mk_item(p, lo, p.last_span.hi, ident, item_, alt extra_attrs { some(mk_item(p, lo, p.last_span.hi, ident, item_, vis,
alt extra_attrs {
some(as) { attrs + as } some(as) { attrs + as }
none { attrs } none { attrs }
})) }))

View file

@ -229,7 +229,7 @@ fn contextual_keyword_table() -> hashmap<str, ()> {
"implements", "implements",
"move", "move",
"of", "of",
"priv", "priv", "pub",
"self", "send", "static", "self", "send", "static",
"to", "to",
"use", "use",

View file

@ -533,9 +533,9 @@ fn print_item(s: ps, &&item: @ast::item) {
*/ */
hardbreak_if_not_bol(s); hardbreak_if_not_bol(s);
maybe_print_comment(s, ci.span.lo); maybe_print_comment(s, ci.span.lo);
let pr = ast_util::class_member_privacy(ci); let pr = ast_util::class_member_visibility(ci);
alt pr { alt pr {
ast::priv { ast::private {
head(s, "priv"); head(s, "priv");
bopen(s); bopen(s);
hardbreak_if_not_bol(s); hardbreak_if_not_bol(s);
@ -559,7 +559,7 @@ fn print_item(s: ps, &&item: @ast::item) {
} }
} }
alt pr { alt pr {
ast::priv { bclose(s, ci.span); } ast::private { bclose(s, ci.span); }
_ {} _ {}
} }
} }

View file

@ -195,6 +195,7 @@ fn mk_test_module(cx: test_ctxt) -> @ast::item {
attrs: [resolve_unexported_attr], attrs: [resolve_unexported_attr],
id: cx.sess.next_node_id(), id: cx.sess.next_node_id(),
node: item_, node: item_,
vis: ast::public,
span: dummy_sp()}; span: dummy_sp()};
#debug("Synthetic test module:\n%s\n", pprust::item_to_str(@item)); #debug("Synthetic test module:\n%s\n", pprust::item_to_str(@item));
@ -233,6 +234,7 @@ fn mk_tests(cx: test_ctxt) -> @ast::item {
attrs: [], attrs: [],
id: cx.sess.next_node_id(), id: cx.sess.next_node_id(),
node: item_, node: item_,
vis: ast::public,
span: dummy_sp()}; span: dummy_sp()};
ret @item; ret @item;
} }
@ -415,6 +417,7 @@ fn mk_main(cx: test_ctxt) -> @ast::item {
attrs: [], attrs: [],
id: cx.sess.next_node_id(), id: cx.sess.next_node_id(),
node: item_, node: item_,
vis: ast::public,
span: dummy_sp()}; span: dummy_sp()};
ret @item; ret @item;
} }

View file

@ -454,7 +454,7 @@ fn get_iface_methods(cdata: cmd, id: ast::node_id, tcx: ty::ctxt)
'u' { ast::unsafe_fn } 'u' { ast::unsafe_fn }
'f' { ast::impure_fn } 'f' { ast::impure_fn }
'p' { ast::pure_fn } 'p' { ast::pure_fn }
}, privacy: ast::pub}]; }, vis: ast::public}];
} }
@result @result
} }
@ -471,17 +471,17 @@ fn get_class_members(cdata: cmd, id: ast::node_id,
let name = item_name(an_item); let name = item_name(an_item);
let did = class_member_id(an_item, cdata); let did = class_member_id(an_item, cdata);
let mt = field_mutability(an_item); let mt = field_mutability(an_item);
result += [{ident: name, id: did, privacy: result += [{ident: name, id: did, vis:
family_to_privacy(f), mutability: mt}]; family_to_visibility(f), mutability: mt}];
} }
} }
result result
} }
pure fn family_to_privacy(family: char) -> ast::privacy { pure fn family_to_visibility(family: char) -> ast::visibility {
alt family { alt family {
'g' { ast::pub } 'g' { ast::public }
_ { ast::priv } _ { ast::private }
} }
} }

View file

@ -99,9 +99,9 @@ fn encode_native_module_item_paths(ebml_w: ebml::writer, nmod: native_mod,
fn encode_class_item_paths(ebml_w: ebml::writer, fn encode_class_item_paths(ebml_w: ebml::writer,
items: [@class_member], path: [str], &index: [entry<str>]) { items: [@class_member], path: [str], &index: [entry<str>]) {
for items.each {|it| for items.each {|it|
alt ast_util::class_member_privacy(it) { alt ast_util::class_member_visibility(it) {
priv { cont; } private { cont; }
pub { public {
let (id, ident) = alt it.node { let (id, ident) = alt it.node {
instance_var(v, _, _, vid, _) { (vid, v) } instance_var(v, _, _, vid, _) { (vid, v) }
class_method(it) { (it.id, it.ident) } class_method(it) { (it.id, it.ident) }
@ -399,9 +399,10 @@ fn encode_info_for_mod(ecx: @encode_ctxt, ebml_w: ebml::writer, md: _mod,
ebml_w.end_tag(); ebml_w.end_tag();
} }
fn encode_privacy(ebml_w: ebml::writer, privacy: privacy) { fn encode_visibility(ebml_w: ebml::writer, visibility: visibility) {
encode_family(ebml_w, alt privacy { encode_family(ebml_w, alt visibility {
pub { 'g' } priv { 'j' }}); public { 'g' } private { 'j' }
});
} }
/* Returns an index of items in this class */ /* Returns an index of items in this class */
@ -417,11 +418,11 @@ fn encode_info_for_class(ecx: @encode_ctxt, ebml_w: ebml::writer,
/* We encode both private and public fields -- need to include /* We encode both private and public fields -- need to include
private fields to get the offsets right */ private fields to get the offsets right */
alt ci.node { alt ci.node {
instance_var(nm, _, mt, id, pr) { instance_var(nm, _, mt, id, vis) {
*index += [{val: id, pos: ebml_w.writer.tell()}]; *index += [{val: id, pos: ebml_w.writer.tell()}];
ebml_w.start_tag(tag_items_data_item); ebml_w.start_tag(tag_items_data_item);
#debug("encode_info_for_class: doing %s %d", nm, id); #debug("encode_info_for_class: doing %s %d", nm, id);
encode_privacy(ebml_w, pr); encode_visibility(ebml_w, vis);
encode_name(ebml_w, nm); encode_name(ebml_w, nm);
encode_path(ebml_w, path, ast_map::path_name(nm)); encode_path(ebml_w, path, ast_map::path_name(nm));
encode_type(ecx, ebml_w, node_id_to_type(tcx, id)); encode_type(ecx, ebml_w, node_id_to_type(tcx, id));
@ -430,8 +431,8 @@ fn encode_info_for_class(ecx: @encode_ctxt, ebml_w: ebml::writer,
ebml_w.end_tag(); ebml_w.end_tag();
} }
class_method(m) { class_method(m) {
alt m.privacy { alt m.vis {
pub { public {
*index += [{val: m.id, pos: ebml_w.writer.tell()}]; *index += [{val: m.id, pos: ebml_w.writer.tell()}];
/* Not sure whether we really need to have two indices, /* Not sure whether we really need to have two indices,
but it works for now -- tjc */ but it works for now -- tjc */
@ -625,15 +626,15 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: ebml::writer, item: @item,
let (fs,ms) = ast_util::split_class_items(items); let (fs,ms) = ast_util::split_class_items(items);
for fs.each {|f| for fs.each {|f|
ebml_w.start_tag(tag_item_field); ebml_w.start_tag(tag_item_field);
encode_privacy(ebml_w, f.privacy); encode_visibility(ebml_w, f.vis);
encode_name(ebml_w, f.ident); encode_name(ebml_w, f.ident);
encode_def_id(ebml_w, local_def(f.id)); encode_def_id(ebml_w, local_def(f.id));
ebml_w.end_tag(); ebml_w.end_tag();
} }
for ms.each {|m| for ms.each {|m|
alt m.privacy { alt m.vis {
priv { /* do nothing */ } private { /* do nothing */ }
pub { public {
/* Write the info that's needed when viewing this class /* Write the info that's needed when viewing this class
as an iface */ as an iface */
ebml_w.start_tag(tag_item_iface_method); ebml_w.start_tag(tag_item_iface_method);
@ -648,7 +649,6 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: ebml::writer, item: @item,
ebml_w.start_tag(tag_item_impl_method); ebml_w.start_tag(tag_item_impl_method);
ebml_w.writer.write(str::bytes(def_to_str(local_def(m.id)))); ebml_w.writer.write(str::bytes(def_to_str(local_def(m.id))));
ebml_w.end_tag(); ebml_w.end_tag();
} }
} }
} }

View file

@ -1642,6 +1642,7 @@ fn index_mod(md: ast::_mod) -> mod_index {
id: ctor.node.id, id: ctor.node.id,
node: node:
item_fn(ctor.node.dec, tps, ctor.node.body), item_fn(ctor.node.dec, tps, ctor.node.body),
vis: ast::public,
span: ctor.node.body.span})); span: ctor.node.body.span}));
} }
} }

View file

@ -165,7 +165,7 @@ type method = {ident: ast::ident,
tps: @[param_bounds], tps: @[param_bounds],
fty: fn_ty, fty: fn_ty,
purity: ast::purity, purity: ast::purity,
privacy: ast::privacy}; vis: ast::visibility};
type constr_table = hashmap<ast::node_id, [constr]>; type constr_table = hashmap<ast::node_id, [constr]>;
@ -181,7 +181,7 @@ enum vstore {
type field_ty = { type field_ty = {
ident: ident, ident: ident,
id: def_id, id: def_id,
privacy: ast::privacy, vis: ast::visibility,
mutability: ast::class_mutability mutability: ast::class_mutability
}; };
@ -2540,21 +2540,21 @@ fn lookup_public_fields(cx: ctxt, did: ast::def_id) -> [field_ty] {
} }
pure fn is_public(f: field_ty) -> bool { pure fn is_public(f: field_ty) -> bool {
alt f.privacy { alt f.vis {
pub { true } public { true }
priv { false } private { false }
} }
} }
// Look up the list of method names and IDs for a given class // Look up the list of method names and IDs for a given class
// Fails if the id is not bound to a class. // Fails if the id is not bound to a class.
fn lookup_class_method_ids(cx: ctxt, did: ast::def_id) fn lookup_class_method_ids(cx: ctxt, did: ast::def_id)
: is_local(did) -> [{name: ident, id: node_id, privacy: privacy}] { : is_local(did) -> [{name: ident, id: node_id, vis: visibility}] {
alt cx.items.find(did.node) { alt cx.items.find(did.node) {
some(ast_map::node_item(@{node: item_class(_,_,items,_,_), _}, _)) { some(ast_map::node_item(@{node: item_class(_,_,items,_,_), _}, _)) {
let (_,ms) = split_class_items(items); let (_,ms) = split_class_items(items);
vec::map(ms, {|m| {name: m.ident, id: m.id, vec::map(ms, {|m| {name: m.ident, id: m.id,
privacy: m.privacy}}) vis: m.vis}})
} }
_ { _ {
cx.sess.bug("lookup_class_method_ids: id not bound to a class"); cx.sess.bug("lookup_class_method_ids: id not bound to a class");
@ -2588,9 +2588,9 @@ fn class_field_tys(items: [@class_member]) -> [field_ty] {
let mut rslt = []; let mut rslt = [];
for items.each {|it| for items.each {|it|
alt it.node { alt it.node {
instance_var(nm, _, cm, id, privacy) { instance_var(nm, _, cm, id, vis) {
rslt += [{ident: nm, id: ast_util::local_def(id), rslt += [{ident: nm, id: ast_util::local_def(id),
privacy: privacy, mutability: cm}]; vis: vis, mutability: cm}];
} }
class_method(_) { } class_method(_) { }
} }

View file

@ -1176,7 +1176,7 @@ fn ty_of_method(ccx: @crate_ctxt,
fty: ty_of_fn_decl(ccx, type_rscope(rp), ast::proto_bare, fty: ty_of_fn_decl(ccx, type_rscope(rp), ast::proto_bare,
m.decl, none), m.decl, none),
purity: m.decl.purity, purity: m.decl.purity,
privacy: m.privacy} vis: m.vis}
} }
fn ty_of_ty_method(self: @crate_ctxt, fn ty_of_ty_method(self: @crate_ctxt,
@ -1187,7 +1187,7 @@ fn ty_of_ty_method(self: @crate_ctxt,
fty: ty_of_fn_decl(self, type_rscope(rp), ast::proto_bare, fty: ty_of_fn_decl(self, type_rscope(rp), ast::proto_bare,
m.decl, none), m.decl, none),
// assume public, because this is only invoked on iface methods // assume public, because this is only invoked on iface methods
purity: m.decl.purity, privacy: ast::pub} purity: m.decl.purity, vis: ast::public}
} }
// Functions that write types into the node type table // Functions that write types into the node type table
@ -2705,7 +2705,7 @@ impl methods for lookup {
for ms.each {|m| for ms.each {|m|
if m.ident != self.m_name { cont; } if m.ident != self.m_name { cont; }
if m.privacy == ast::priv && !self.include_private { if m.vis == ast::private && !self.include_private {
self.tcx().sess.span_fatal( self.tcx().sess.span_fatal(
self.expr.span, self.expr.span,
"Call to private method not allowed outside \ "Call to private method not allowed outside \