From aacb92ffe6191f260430e8ad2a7c22808d3222a4 Mon Sep 17 00:00:00 2001 From: Luqman Aden Date: Thu, 31 Jan 2013 21:32:07 -0500 Subject: [PATCH] libsyntax: update view_item_use/import to reflect actual usage --- src/libcargo/cargo.rc | 2 +- src/librustc/front/core_inject.rs | 5 +++-- src/librustc/front/test.rs | 7 ++++--- src/librustc/metadata/creader.rs | 6 +++--- src/librustc/metadata/cstore.rs | 22 +++++++++++----------- src/librustc/middle/resolve.rs | 10 +++++----- src/libsyntax/ast.rs | 4 ++-- src/libsyntax/ast_util.rs | 4 ++-- src/libsyntax/ext/build.rs | 2 +- src/libsyntax/ext/pipes/ast_builder.rs | 2 +- src/libsyntax/parse/parser.rs | 12 ++++++------ src/libsyntax/print/pprust.rs | 4 ++-- 12 files changed, 41 insertions(+), 39 deletions(-) diff --git a/src/libcargo/cargo.rc b/src/libcargo/cargo.rc index bb5e3f9f74d7e..7dd21923da43e 100644 --- a/src/libcargo/cargo.rc +++ b/src/libcargo/cargo.rc @@ -345,7 +345,7 @@ pub fn load_crate(filename: &Path) -> Option { fn goto_view_item(ps: syntax::parse::parse_sess, e: @Env, i: @ast::view_item) { match i.node { - ast::view_item_use(ident, metas, _) => { + ast::view_item_extern_mod(ident, metas, _) => { let name_items = attr::find_meta_items_by_name(metas, ~"name"); let m = if name_items.is_empty() { diff --git a/src/librustc/front/core_inject.rs b/src/librustc/front/core_inject.rs index 835203f4efe17..77bb039856172 100644 --- a/src/librustc/front/core_inject.rs +++ b/src/librustc/front/core_inject.rs @@ -44,7 +44,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, @@ -85,7 +86,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() }; diff --git a/src/librustc/front/test.rs b/src/librustc/front/test.rs index a33d78c3b585a..d46cbaa1d74ba 100644 --- a/src/librustc/front/test.rs +++ b/src/librustc/front/test.rs @@ -262,9 +262,10 @@ fn mk_std(cx: test_ctxt) -> @ast::view_item { let vers = nospan(vers); let mi = ast::meta_name_value(~"vers", vers); let mi = nospan(mi); - let vi = ast::view_item_use(cx.sess.ident_of(~"std"), - ~[@mi], - cx.sess.next_node_id()); + let vi = ast::view_item_extern_mod( + cx.sess.ident_of(~"std"), + ~[@mi], + cx.sess.next_node_id()); let vi = ast::view_item { node: vi, attrs: ~[], diff --git a/src/librustc/metadata/creader.rs b/src/librustc/metadata/creader.rs index e91c4f938640c..1ae43de7362d1 100644 --- a/src/librustc/metadata/creader.rs +++ b/src/librustc/metadata/creader.rs @@ -123,10 +123,10 @@ type env = @{diag: span_handler, fn visit_view_item(e: 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); } _ => () } diff --git a/src/librustc/metadata/cstore.rs b/src/librustc/metadata/cstore.rs index f2bd998b55706..2891dd854babe 100644 --- a/src/librustc/metadata/cstore.rs +++ b/src/librustc/metadata/cstore.rs @@ -47,14 +47,14 @@ pub enum CStore { private(cstore_private), } type cstore_private = @{metas: map::HashMap, - use_crate_map: use_crate_map, + extern_mod_crate_map: extern_mod_crate_map, mut used_crate_files: ~[Path], mut used_libraries: ~[~str], mut used_link_args: ~[~str], intr: @ident_interner}; -// Map from node_id's of local use statements to crate numbers -type use_crate_map = map::HashMap; +// Map from node_id's of local extern mod statements to crate numbers +type extern_mod_crate_map = map::HashMap; // Internal method to retrieve the data from the cstore pure fn p(cstore: CStore) -> cstore_private { @@ -65,7 +65,7 @@ pub fn mk_cstore(intr: @ident_interner) -> CStore { let meta_cache = map::HashMap(); let crate_map = map::HashMap(); return private(@{metas: meta_cache, - use_crate_map: crate_map, + extern_mod_crate_map: crate_map, mut used_crate_files: ~[], mut used_libraries: ~[], mut used_link_args: ~[], @@ -132,14 +132,14 @@ pub fn get_used_link_args(cstore: CStore) -> ~[~str] { return /*bad*/copy p(cstore).used_link_args; } -pub fn add_use_stmt_cnum(cstore: CStore, use_id: ast::node_id, - cnum: ast::crate_num) { - p(cstore).use_crate_map.insert(use_id, cnum); +pub fn add_extern_mod_stmt_cnum( + cstore: CStore, emod_id: ast::node_id, cnum: ast::crate_num) { + p(cstore).extern_mod_crate_map.insert(emod_id, cnum); } -pub fn find_use_stmt_cnum(cstore: CStore, - use_id: ast::node_id) -> Option { - p(cstore).use_crate_map.find(use_id) +pub fn find_extern_mod_stmt_cnum( + cstore: CStore, emod_id: ast::node_id) -> Option { + p(cstore).extern_mod_crate_map.find(emod_id) } // returns hashes of crates directly used by this crate. Hashes are @@ -148,7 +148,7 @@ pub fn get_dep_hashes(cstore: CStore) -> ~[~str] { type crate_hash = {name: ~str, hash: ~str}; let mut result = ~[]; - for p(cstore).use_crate_map.each_value |cnum| { + for p(cstore).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); diff --git a/src/librustc/middle/resolve.rs b/src/librustc/middle/resolve.rs index f748815620434..afedc9ac6bf7f 100644 --- a/src/librustc/middle/resolve.rs +++ b/src/librustc/middle/resolve.rs @@ -14,7 +14,7 @@ use driver::session; use driver::session::Session; use metadata::csearch::{each_path, get_method_names_if_trait}; use metadata::csearch::{get_static_methods_if_impl, 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}; @@ -54,7 +54,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}; @@ -1386,7 +1386,7 @@ pub impl Resolver { &&_visitor: vt) { 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; @@ -1456,8 +1456,8 @@ 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, diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index e85f41c54a22a..a8f9cd8967db0 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -1456,8 +1456,8 @@ pub struct view_item { #[auto_encode] #[auto_decode] 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 diff --git a/src/libsyntax/ast_util.rs b/src/libsyntax/ast_util.rs index 1ae232404048e..f5e3832337a98 100644 --- a/src/libsyntax/ast_util.rs +++ b/src/libsyntax/ast_util.rs @@ -417,8 +417,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), diff --git a/src/libsyntax/ext/build.rs b/src/libsyntax/ext/build.rs index 6d44a412742e0..d488fabe0a6b3 100644 --- a/src/libsyntax/ext/build.rs +++ b/src/libsyntax/ext/build.rs @@ -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 } diff --git a/src/libsyntax/ext/pipes/ast_builder.rs b/src/libsyntax/ext/pipes/ast_builder.rs index 8abca3d97f955..7b67fc3fb2d46 100644 --- a/src/libsyntax/ext/pipes/ast_builder.rs +++ b/src/libsyntax/ext/pipes/ast_builder.rs @@ -309,7 +309,7 @@ pub impl ext_ctxt: ext_ctxt_ast_builder { +items: ~[@ast::item]) -> @ast::item { // XXX: Total hack: import `core::kinds::Owned` to work around a // parser bug whereby `fn f` doesn't parse. - let vi = ast::view_item_import(~[ + let vi = ast::view_item_use(~[ @ast::spanned { node: ast::view_path_simple( self.ident_of(~"Owned"), diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 48f38092f88c1..145badc62f31c 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -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_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}; @@ -3387,7 +3387,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) @@ -3768,7 +3768,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 { @@ -3890,7 +3890,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; }; @@ -3937,8 +3937,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") diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 6661f5e810a33..7ff747ecf42ff 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -1846,7 +1846,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() { @@ -1856,7 +1856,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); }