auto merge of #5004 : luqmana/rust/rename-use-import, r=catamorphism
Seems like my previous pull request got lost along the way somehow. So here it is updated.
This commit is contained in:
commit
9ba2e65fd6
@ -45,7 +45,8 @@ fn inject_libcore_ref(sess: Session,
|
||||
fold_crate: |crate, span, fld| {
|
||||
let n1 = sess.next_node_id();
|
||||
let vi1 = @ast::view_item {
|
||||
node: ast::view_item_use(sess.ident_of(~"core"), ~[], n1),
|
||||
node: ast::view_item_extern_mod(
|
||||
sess.ident_of(~"core"), ~[], n1),
|
||||
attrs: ~[
|
||||
spanned(ast::attribute_ {
|
||||
style: ast::attr_inner,
|
||||
@ -86,7 +87,7 @@ fn inject_libcore_ref(sess: Session,
|
||||
};
|
||||
|
||||
let vp = @spanned(ast::view_path_glob(prelude_path, n2));
|
||||
let vi2 = @ast::view_item { node: ast::view_item_import(~[vp]),
|
||||
let vi2 = @ast::view_item { node: ast::view_item_use(~[vp]),
|
||||
attrs: ~[],
|
||||
vis: ast::private,
|
||||
span: dummy_sp() };
|
||||
|
@ -266,13 +266,13 @@ fn mk_std(cx: &TestCtxt) -> @ast::view_item {
|
||||
let mi = nospan(mi);
|
||||
let id_std = cx.sess.ident_of(~"std");
|
||||
let vi = if is_std(cx) {
|
||||
ast::view_item_import(
|
||||
ast::view_item_use(
|
||||
~[@nospan(ast::view_path_simple(id_std,
|
||||
path_node(~[id_std]),
|
||||
ast::type_value_ns,
|
||||
cx.sess.next_node_id()))])
|
||||
} else {
|
||||
ast::view_item_use(id_std, ~[@mi],
|
||||
ast::view_item_extern_mod(id_std, ~[@mi],
|
||||
cx.sess.next_node_id())
|
||||
};
|
||||
let vi = ast::view_item {
|
||||
|
@ -142,10 +142,11 @@ fn visit_crate(e: @mut Env, c: ast::crate) {
|
||||
|
||||
fn visit_view_item(e: @mut Env, i: @ast::view_item) {
|
||||
match /*bad*/copy i.node {
|
||||
ast::view_item_use(ident, meta_items, id) => {
|
||||
debug!("resolving use stmt. ident: %?, meta: %?", ident, meta_items);
|
||||
ast::view_item_extern_mod(ident, meta_items, id) => {
|
||||
debug!("resolving extern mod stmt. ident: %?, meta: %?",
|
||||
ident, meta_items);
|
||||
let cnum = resolve_crate(e, ident, meta_items, ~"", i.span);
|
||||
cstore::add_use_stmt_cnum(e.cstore, id, cnum);
|
||||
cstore::add_extern_mod_stmt_cnum(e.cstore, id, cnum);
|
||||
}
|
||||
_ => ()
|
||||
}
|
||||
|
@ -40,22 +40,22 @@ pub type crate_metadata = @{name: ~str,
|
||||
|
||||
pub struct CStore {
|
||||
priv metas: oldmap::HashMap<ast::crate_num, crate_metadata>,
|
||||
priv use_crate_map: use_crate_map,
|
||||
priv extern_mod_crate_map: extern_mod_crate_map,
|
||||
priv used_crate_files: ~[Path],
|
||||
priv used_libraries: ~[~str],
|
||||
priv used_link_args: ~[~str],
|
||||
intr: @ident_interner
|
||||
}
|
||||
|
||||
// Map from node_id's of local use statements to crate numbers
|
||||
type use_crate_map = oldmap::HashMap<ast::node_id, ast::crate_num>;
|
||||
// Map from node_id's of local extern mod statements to crate numbers
|
||||
type extern_mod_crate_map = oldmap::HashMap<ast::node_id, ast::crate_num>;
|
||||
|
||||
pub fn mk_cstore(intr: @ident_interner) -> CStore {
|
||||
let meta_cache = oldmap::HashMap();
|
||||
let crate_map = oldmap::HashMap();
|
||||
return CStore {
|
||||
metas: meta_cache,
|
||||
use_crate_map: crate_map,
|
||||
extern_mod_crate_map: crate_map,
|
||||
used_crate_files: ~[],
|
||||
used_libraries: ~[],
|
||||
used_link_args: ~[],
|
||||
@ -127,18 +127,18 @@ pub fn get_used_link_args(cstore: @mut CStore) -> ~[~str] {
|
||||
return /*bad*/copy cstore.used_link_args;
|
||||
}
|
||||
|
||||
pub fn add_use_stmt_cnum(cstore: @mut CStore,
|
||||
use_id: ast::node_id,
|
||||
cnum: ast::crate_num) {
|
||||
let use_crate_map = cstore.use_crate_map;
|
||||
use_crate_map.insert(use_id, cnum);
|
||||
pub fn add_extern_mod_stmt_cnum(cstore: @mut CStore,
|
||||
emod_id: ast::node_id,
|
||||
cnum: ast::crate_num) {
|
||||
let extern_mod_crate_map = cstore.extern_mod_crate_map;
|
||||
extern_mod_crate_map.insert(emod_id, cnum);
|
||||
}
|
||||
|
||||
pub fn find_use_stmt_cnum(cstore: @mut CStore,
|
||||
use_id: ast::node_id)
|
||||
pub fn find_extern_mod_stmt_cnum(cstore: @mut CStore,
|
||||
emod_id: ast::node_id)
|
||||
-> Option<ast::crate_num> {
|
||||
let use_crate_map = cstore.use_crate_map;
|
||||
use_crate_map.find(&use_id)
|
||||
let extern_mod_crate_map = cstore.extern_mod_crate_map;
|
||||
extern_mod_crate_map.find(&emod_id)
|
||||
}
|
||||
|
||||
// returns hashes of crates directly used by this crate. Hashes are
|
||||
@ -147,8 +147,8 @@ pub fn get_dep_hashes(cstore: @mut CStore) -> ~[~str] {
|
||||
type crate_hash = {name: ~str, hash: ~str};
|
||||
let mut result = ~[];
|
||||
|
||||
let use_crate_map = cstore.use_crate_map;
|
||||
for use_crate_map.each_value |&cnum| {
|
||||
let extern_mod_crate_map = cstore.extern_mod_crate_map;
|
||||
for extern_mod_crate_map.each_value |&cnum| {
|
||||
let cdata = cstore::get_crate_data(cstore, cnum);
|
||||
let hash = decoder::get_crate_hash(cdata.data);
|
||||
debug!("Add hash[%s]: %s", cdata.name, hash);
|
||||
|
@ -15,7 +15,7 @@ use driver::session::Session;
|
||||
use metadata::csearch::{each_path, get_method_names_if_trait};
|
||||
use metadata::csearch::{get_static_methods_if_impl, get_struct_fields};
|
||||
use metadata::csearch::{get_type_name_if_impl};
|
||||
use metadata::cstore::find_use_stmt_cnum;
|
||||
use metadata::cstore::find_extern_mod_stmt_cnum;
|
||||
use metadata::decoder::{def_like, dl_def, dl_field, dl_impl};
|
||||
use middle::lang_items::LanguageItems;
|
||||
use middle::lint::{deny, allow, forbid, level, unused_imports, warn};
|
||||
@ -55,7 +55,7 @@ use syntax::ast::{ty_bool, ty_char, ty_f, ty_f32, ty_f64, ty_float, ty_i};
|
||||
use syntax::ast::{ty_i16, ty_i32, ty_i64, ty_i8, ty_int, ty_param, ty_path};
|
||||
use syntax::ast::{ty_str, ty_u, ty_u16, ty_u32, ty_u64, ty_u8, ty_uint};
|
||||
use syntax::ast::{type_value_ns, ty_param_bound, unnamed_field};
|
||||
use syntax::ast::{variant, view_item, view_item_import};
|
||||
use syntax::ast::{variant, view_item, view_item_extern_mod};
|
||||
use syntax::ast::{view_item_use, view_path_glob, view_path_list};
|
||||
use syntax::ast::{view_path_simple, visibility, anonymous, named, not};
|
||||
use syntax::ast::{unsafe_fn};
|
||||
@ -1388,7 +1388,7 @@ pub impl Resolver {
|
||||
&&_visitor: vt<ReducedGraphParent>) {
|
||||
let privacy = visibility_to_privacy(view_item.vis);
|
||||
match /*bad*/copy view_item.node {
|
||||
view_item_import(view_paths) => {
|
||||
view_item_use(view_paths) => {
|
||||
for view_paths.each |view_path| {
|
||||
// Extract and intern the module part of the path. For
|
||||
// globs and lists, the path is found directly in the AST;
|
||||
@ -1462,8 +1462,9 @@ pub impl Resolver {
|
||||
}
|
||||
}
|
||||
|
||||
view_item_use(name, _, node_id) => {
|
||||
match find_use_stmt_cnum(self.session.cstore, node_id) {
|
||||
view_item_extern_mod(name, _, node_id) => {
|
||||
match find_extern_mod_stmt_cnum(self.session.cstore,
|
||||
node_id) {
|
||||
Some(crate_id) => {
|
||||
let (child_name_bindings, new_parent) =
|
||||
self.add_child(name, parent, ForbidDuplicateTypes,
|
||||
|
@ -1121,8 +1121,8 @@ pub struct view_item {
|
||||
#[auto_decode]
|
||||
#[deriving_eq]
|
||||
pub enum view_item_ {
|
||||
view_item_use(ident, ~[@meta_item], node_id),
|
||||
view_item_import(~[@view_path]),
|
||||
view_item_extern_mod(ident, ~[@meta_item], node_id),
|
||||
view_item_use(~[@view_path]),
|
||||
}
|
||||
|
||||
// Meta-data associated with an item
|
||||
|
@ -395,8 +395,8 @@ 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_extern_mod(_, _, id) => vfn(id),
|
||||
view_item_use(vps) => {
|
||||
for vec::each(vps) |vp| {
|
||||
match vp.node {
|
||||
view_path_simple(_, _, _, id) => vfn(id),
|
||||
|
@ -192,7 +192,7 @@ pub fn mk_glob_use(cx: ext_ctxt,
|
||||
node: ast::view_path_glob(mk_raw_path(sp, path), cx.next_id()),
|
||||
span: sp,
|
||||
};
|
||||
@ast::view_item { node: ast::view_item_import(~[glob]),
|
||||
@ast::view_item { node: ast::view_item_use(~[glob]),
|
||||
attrs: ~[],
|
||||
vis: ast::private,
|
||||
span: sp }
|
||||
|
@ -319,7 +319,7 @@ pub impl ext_ctxt_ast_builder for ext_ctxt {
|
||||
|
||||
// XXX: Total hack: import `core::kinds::Owned` to work around a
|
||||
// parser bug whereby `fn f<T: ::kinds::Owned>` doesn't parse.
|
||||
let vi = ast::view_item_import(~[
|
||||
let vi = ast::view_item_use(~[
|
||||
@codemap::spanned {
|
||||
node: ast::view_path_simple(
|
||||
self.ident_of(~"Owned"),
|
||||
|
@ -54,7 +54,7 @@ use ast::{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_import, view_item_use};
|
||||
use ast::{view_item_, view_item_extern_mod, 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};
|
||||
@ -3503,7 +3503,7 @@ pub impl Parser {
|
||||
let metadata = self.parse_optional_meta();
|
||||
self.expect(token::SEMI);
|
||||
iovi_view_item(@ast::view_item {
|
||||
node: view_item_use(ident, metadata, self.get_id()),
|
||||
node: view_item_extern_mod(ident, metadata, self.get_id()),
|
||||
attrs: attrs,
|
||||
vis: visibility,
|
||||
span: mk_sp(lo, self.last_span.hi)
|
||||
@ -3884,7 +3884,7 @@ pub impl Parser {
|
||||
}
|
||||
|
||||
fn parse_use() -> view_item_ {
|
||||
return view_item_import(self.parse_view_paths());
|
||||
return view_item_use(self.parse_view_paths());
|
||||
}
|
||||
|
||||
fn parse_view_path() -> @view_path {
|
||||
@ -4006,7 +4006,7 @@ pub impl Parser {
|
||||
self.expect_keyword(~"mod");
|
||||
let ident = self.parse_ident();
|
||||
let metadata = self.parse_optional_meta();
|
||||
view_item_use(ident, metadata, self.get_id())
|
||||
view_item_extern_mod(ident, metadata, self.get_id())
|
||||
} else {
|
||||
fail!();
|
||||
};
|
||||
@ -4053,8 +4053,8 @@ pub impl Parser {
|
||||
iovi_view_item(view_item) => {
|
||||
if restricted_to_imports {
|
||||
match view_item.node {
|
||||
view_item_import(_) => {}
|
||||
view_item_use(*) =>
|
||||
view_item_use(*) => {}
|
||||
view_item_extern_mod(*) =>
|
||||
self.fatal(~"\"extern mod\" \
|
||||
declarations are not \
|
||||
allowed here")
|
||||
|
@ -1859,7 +1859,7 @@ pub fn print_view_item(s: @ps, item: @ast::view_item) {
|
||||
print_outer_attributes(s, item.attrs);
|
||||
print_visibility(s, item.vis);
|
||||
match item.node {
|
||||
ast::view_item_use(id, mta, _) => {
|
||||
ast::view_item_extern_mod(id, mta, _) => {
|
||||
head(s, ~"extern mod");
|
||||
print_ident(s, id);
|
||||
if !mta.is_empty() {
|
||||
@ -1869,7 +1869,7 @@ pub fn print_view_item(s: @ps, item: @ast::view_item) {
|
||||
}
|
||||
}
|
||||
|
||||
ast::view_item_import(vps) => {
|
||||
ast::view_item_use(vps) => {
|
||||
head(s, ~"use");
|
||||
print_view_paths(s, vps);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user