From dffe188991325b4e803fdd0da7c1563ce0fa27f4 Mon Sep 17 00:00:00 2001 From: Graydon Hoare Date: Fri, 21 Sep 2012 18:10:45 -0700 Subject: Install new pub/priv/export rules as defaults, old rules accessible under #[legacy_exports]; --- src/libsyntax/ext/auto_serialize.rs | 1 + src/libsyntax/ext/pipes/ast_builder.rs | 1 + src/libsyntax/ext/pipes/pipec.rs | 3 +- src/libsyntax/parse/token.rs | 1 + src/libsyntax/print/pprust.rs | 70 +++++++++++++++++++++++++--------- src/libsyntax/syntax.rc | 52 +++++++++++++++++++++++++ 6 files changed, 109 insertions(+), 19 deletions(-) (limited to 'src/libsyntax') diff --git a/src/libsyntax/ext/auto_serialize.rs b/src/libsyntax/ext/auto_serialize.rs index f4ad277b908..28d47087ccc 100644 --- a/src/libsyntax/ext/auto_serialize.rs +++ b/src/libsyntax/ext/auto_serialize.rs @@ -78,6 +78,7 @@ export expand; // Transitional reexports so qquote can find the paths it is looking for mod syntax { + #[legacy_exports]; pub use ext; pub use parse; } diff --git a/src/libsyntax/ext/pipes/ast_builder.rs b/src/libsyntax/ext/pipes/ast_builder.rs index a4512b7b098..01046dded26 100644 --- a/src/libsyntax/ext/pipes/ast_builder.rs +++ b/src/libsyntax/ext/pipes/ast_builder.rs @@ -10,6 +10,7 @@ use ext::base::mk_ctxt; // Transitional reexports so qquote can find the paths it is looking for mod syntax { + #[legacy_exports]; pub use ext; pub use parse; } diff --git a/src/libsyntax/ext/pipes/pipec.rs b/src/libsyntax/ext/pipes/pipec.rs index e2b08d089a7..913d69d391f 100644 --- a/src/libsyntax/ext/pipes/pipec.rs +++ b/src/libsyntax/ext/pipes/pipec.rs @@ -16,6 +16,7 @@ use ast_builder::{append_types, path, empty_span}; // Transitional reexports so qquote can find the paths it is looking for mod syntax { + #[legacy_exports]; pub use ext; pub use parse; } @@ -318,7 +319,7 @@ impl protocol: gen_init { } }; - cx.parse_item(fmt!("fn init%s() -> (client::%s, server::%s)\ + cx.parse_item(fmt!("pub fn init%s() -> (client::%s, server::%s)\ { use pipes::HasBuffer; %s }", start_state.ty_params.to_source(cx), start_state.to_ty(cx).to_source(cx), diff --git a/src/libsyntax/parse/token.rs b/src/libsyntax/parse/token.rs index d04a65fd2db..9bf612c588a 100644 --- a/src/libsyntax/parse/token.rs +++ b/src/libsyntax/parse/token.rs @@ -279,6 +279,7 @@ pure fn is_bar(t: token) -> bool { mod special_idents { + #[legacy_exports]; use ast::ident; const underscore : ident = 0u; const anon : ident = 1u; diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index f41cdae7e03..561e2ecd0b4 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -127,7 +127,7 @@ fn fun_to_str(decl: ast::fn_decl, name: ast::ident, params: ~[ast::ty_param], intr: ident_interner) -> ~str { do io::with_str_writer |wr| { let s = rust_printer(wr, intr); - print_fn(s, decl, None, name, params, None); + print_fn(s, decl, None, name, params, None, ast::inherited); end(s); // Close the head box end(s); // Close the outer box eof(s.s); @@ -420,7 +420,8 @@ fn print_foreign_item(s: ps, item: @ast::foreign_item) { print_outer_attributes(s, item.attrs); match item.node { ast::foreign_item_fn(decl, purity, typarams) => { - print_fn(s, decl, Some(purity), item.ident, typarams, None); + print_fn(s, decl, Some(purity), item.ident, typarams, None, + ast::inherited); end(s); // end head-ibox word(s.s, ~";"); end(s); // end the outer fn box @@ -444,7 +445,7 @@ fn print_item(s: ps, &&item: @ast::item) { s.ann.pre(ann_node); match item.node { ast::item_const(ty, expr) => { - head(s, ~"const"); + head(s, visibility_qualified(item.vis, ~"const")); print_ident(s, item.ident); word_space(s, ~":"); print_type(s, ty); @@ -458,12 +459,13 @@ fn print_item(s: ps, &&item: @ast::item) { } ast::item_fn(decl, purity, typarams, body) => { - print_fn(s, decl, Some(purity), item.ident, typarams, None); + print_fn(s, decl, Some(purity), item.ident, typarams, None, + item.vis); word(s.s, ~" "); print_block_with_attrs(s, body, item.attrs); } ast::item_mod(_mod) => { - head(s, ~"mod"); + head(s, visibility_qualified(item.vis, ~"mod")); print_ident(s, item.ident); nbsp(s); bopen(s); @@ -471,7 +473,7 @@ fn print_item(s: ps, &&item: @ast::item) { bclose(s, item.span); } ast::item_foreign_mod(nmod) => { - head(s, ~"extern"); + head(s, visibility_qualified(item.vis, ~"extern")); match nmod.sort { ast::named => { word_nbsp(s, ~"mod"); @@ -614,6 +616,30 @@ fn print_variants(s: ps, variants: ~[ast::variant], span: ast::span) { bclose(s, span); } +fn visibility_to_str(vis: ast::visibility) -> ~str { + match vis { + ast::private => ~"priv", + ast::public => ~"pub", + ast::inherited => ~"" + } +} + +fn visibility_qualified(vis: ast::visibility, s: ~str) -> ~str { + match vis { + ast::private | ast::public => + visibility_to_str(vis) + " " + s, + ast::inherited => s + } +} + +fn print_visibility(s: ps, vis: ast::visibility) { + match vis { + ast::private | ast::public => + word_nbsp(s, visibility_to_str(vis)), + ast::inherited => () + } +} + fn print_struct(s: ps, struct_def: @ast::struct_def, tps: ~[ast::ty_param], ident: ast::ident, span: ast::span) { print_ident(s, ident); @@ -651,9 +677,7 @@ fn print_struct(s: ps, struct_def: @ast::struct_def, tps: ~[ast::ty_param], ast::named_field(ident, mutability, visibility) => { hardbreak_if_not_bol(s); maybe_print_comment(s, field.span.lo); - if visibility == ast::private { - word_nbsp(s, ~"priv"); - } + print_visibility(s, visibility); if mutability == ast::class_mutable { word_nbsp(s, ~"mut"); } @@ -710,6 +734,7 @@ fn print_tt(s: ps, tt: ast::token_tree) { } fn print_variant(s: ps, v: ast::variant) { + print_visibility(s, v.node.vis); match v.node.kind { ast::tuple_variant_kind(args) => { print_ident(s, v.node.name); @@ -762,7 +787,8 @@ fn print_method(s: ps, meth: @ast::method) { maybe_print_comment(s, meth.span.lo); print_outer_attributes(s, meth.attrs); print_fn(s, meth.decl, Some(meth.purity), - meth.ident, meth.tps, Some(meth.self_ty.node)); + meth.ident, meth.tps, Some(meth.self_ty.node), + meth.vis); word(s.s, ~" "); print_block_with_attrs(s, meth.body, meth.attrs); } @@ -1224,7 +1250,8 @@ fn print_expr(s: ps, &&expr: @ast::expr) { cbox(s, indent_unit); // head-box, will be closed by print-block at start ibox(s, 0u); - word(s.s, fn_header_info_to_str(None, None, Some(proto))); + word(s.s, fn_header_info_to_str(None, None, Some(proto), + ast::inherited)); print_fn_args_and_ret(s, decl, *cap_clause, None); space(s.s); print_block(s, body); @@ -1587,8 +1614,9 @@ fn print_self_ty(s: ps, self_ty: ast::self_ty_) -> bool { fn print_fn(s: ps, decl: ast::fn_decl, purity: Option, name: ast::ident, typarams: ~[ast::ty_param], - opt_self_ty: Option) { - head(s, fn_header_info_to_str(opt_self_ty, purity, None)); + opt_self_ty: Option, + vis: ast::visibility) { + head(s, fn_header_info_to_str(opt_self_ty, purity, None, vis)); print_ident(s, name); print_type_params(s, typarams); print_fn_args_and_ret(s, decl, ~[], opt_self_ty); @@ -1758,6 +1786,7 @@ fn print_view_item(s: ps, item: @ast::view_item) { hardbreak_if_not_bol(s); maybe_print_comment(s, item.span.lo); print_outer_attributes(s, item.attrs); + print_visibility(s, item.vis); match item.node { ast::view_item_use(id, mta, _) => { head(s, ~"extern mod"); @@ -1827,7 +1856,8 @@ fn print_ty_fn(s: ps, opt_proto: Option, purity: ast::purity, tps: Option<~[ast::ty_param]>, opt_self_ty: Option) { ibox(s, indent_unit); - word(s.s, fn_header_info_to_str(opt_self_ty, Some(purity), opt_proto)); + word(s.s, fn_header_info_to_str(opt_self_ty, Some(purity), opt_proto, + ast::inherited)); print_bounds(s, bounds); match id { Some(id) => { word(s.s, ~" "); print_ident(s, id); } _ => () } match tps { Some(tps) => print_type_params(s, tps), _ => () } @@ -2050,10 +2080,14 @@ fn next_comment(s: ps) -> Option { fn fn_header_info_to_str(opt_sty: Option, opt_purity: Option, - opt_p: Option) -> ~str { - let mut s = match opt_sty { - Some(ast::sty_static) => ~"static ", - _ => ~ "" + opt_p: Option, + vis: ast::visibility) -> ~str { + + let mut s = visibility_qualified(vis, ~""); + + match opt_sty { + Some(ast::sty_static) => str::push_str(s, ~"static "), + _ => () }; match opt_purity { diff --git a/src/libsyntax/syntax.rc b/src/libsyntax/syntax.rc index 6ce8ef11d91..c62ec28f359 100644 --- a/src/libsyntax/syntax.rc +++ b/src/libsyntax/syntax.rc @@ -9,6 +9,7 @@ #[no_core]; #[legacy_modes]; +#[legacy_exports]; #[allow(vecs_implicitly_copyable)]; #[allow(non_camel_case_types)]; @@ -18,19 +19,31 @@ extern mod std(vers = "0.4"); use core::*; +#[legacy_exports] mod attr; +#[legacy_exports] mod diagnostic; +#[legacy_exports] mod codemap; +#[legacy_exports] mod ast; +#[legacy_exports] mod ast_util; +#[legacy_exports] mod ast_map; +#[legacy_exports] mod visit; +#[legacy_exports] mod fold; +#[legacy_exports] mod util { + #[legacy_exports]; + #[legacy_exports] mod interner; } mod parse { + #[legacy_exports]; export parser; export common; export lexer; @@ -40,61 +53,100 @@ mod parse { export classify; export attr; + #[legacy_exports] mod eval; + #[legacy_exports] mod lexer; + #[legacy_exports] mod parser; + #[legacy_exports] mod token; + #[legacy_exports] mod comments; + #[legacy_exports] mod attr; + #[legacy_exports] /// Common routines shared by parser mods + #[legacy_exports] mod common; /// Functions dealing with operator precedence + #[legacy_exports] mod prec; /// Routines the parser uses to classify AST nodes + #[legacy_exports] mod classify; /// Reporting obsolete syntax + #[legacy_exports] mod obsolete; } mod print { + #[legacy_exports]; + #[legacy_exports] mod pp; + #[legacy_exports] mod pprust; } mod ext { + #[legacy_exports]; + #[legacy_exports] mod base; + #[legacy_exports] mod expand; + #[legacy_exports] mod qquote; + #[legacy_exports] mod build; mod tt { + #[legacy_exports]; + #[legacy_exports] mod transcribe; + #[legacy_exports] mod macro_parser; + #[legacy_exports] mod macro_rules; } + #[legacy_exports] mod simplext; + #[legacy_exports] mod fmt; + #[legacy_exports] mod env; + #[legacy_exports] mod concat_idents; + #[legacy_exports] mod ident_to_str; + #[legacy_exports] mod log_syntax; + #[legacy_exports] mod auto_serialize; + #[legacy_exports] mod source_util; mod pipes { + #[legacy_exports]; + #[legacy_exports] mod ast_builder; + #[legacy_exports] mod parse_proto; + #[legacy_exports] mod pipec; + #[legacy_exports] mod proto; + #[legacy_exports] mod check; + #[legacy_exports] mod liveness; } + #[legacy_exports] mod trace_macros; } -- cgit 1.4.1-3-g733a5