libsyntax: Update view_item_use/import to reflect actual usage
This commit is contained in:
parent
a6945f2a45
commit
0f09c106f0
11 changed files with 43 additions and 41 deletions
|
@ -45,7 +45,8 @@ fn inject_libcore_ref(sess: Session,
|
||||||
fold_crate: |crate, span, fld| {
|
fold_crate: |crate, span, fld| {
|
||||||
let n1 = sess.next_node_id();
|
let n1 = sess.next_node_id();
|
||||||
let vi1 = @ast::view_item {
|
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: ~[
|
attrs: ~[
|
||||||
spanned(ast::attribute_ {
|
spanned(ast::attribute_ {
|
||||||
style: ast::attr_inner,
|
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 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: ~[],
|
attrs: ~[],
|
||||||
vis: ast::private,
|
vis: ast::private,
|
||||||
span: dummy_sp() };
|
span: dummy_sp() };
|
||||||
|
|
|
@ -266,13 +266,13 @@ fn mk_std(cx: &TestCtxt) -> @ast::view_item {
|
||||||
let mi = nospan(mi);
|
let mi = nospan(mi);
|
||||||
let id_std = cx.sess.ident_of(~"std");
|
let id_std = cx.sess.ident_of(~"std");
|
||||||
let vi = if is_std(cx) {
|
let vi = if is_std(cx) {
|
||||||
ast::view_item_import(
|
ast::view_item_use(
|
||||||
~[@nospan(ast::view_path_simple(id_std,
|
~[@nospan(ast::view_path_simple(id_std,
|
||||||
path_node(~[id_std]),
|
path_node(~[id_std]),
|
||||||
ast::type_value_ns,
|
ast::type_value_ns,
|
||||||
cx.sess.next_node_id()))])
|
cx.sess.next_node_id()))])
|
||||||
} else {
|
} else {
|
||||||
ast::view_item_use(id_std, ~[@mi],
|
ast::view_item_extern_mod(id_std, ~[@mi],
|
||||||
cx.sess.next_node_id())
|
cx.sess.next_node_id())
|
||||||
};
|
};
|
||||||
let vi = ast::view_item {
|
let vi = ast::view_item {
|
||||||
|
|
|
@ -127,10 +127,11 @@ struct Env {
|
||||||
|
|
||||||
fn visit_view_item(e: @mut Env, i: @ast::view_item) {
|
fn visit_view_item(e: @mut Env, i: @ast::view_item) {
|
||||||
match /*bad*/copy i.node {
|
match /*bad*/copy i.node {
|
||||||
ast::view_item_use(ident, meta_items, id) => {
|
ast::view_item_extern_mod(ident, meta_items, id) => {
|
||||||
debug!("resolving use stmt. ident: %?, meta: %?", ident, meta_items);
|
debug!("resolving extern mod stmt. ident: %?, meta: %?",
|
||||||
|
ident, meta_items);
|
||||||
let cnum = resolve_crate(e, ident, meta_items, ~"", i.span);
|
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 {
|
pub struct CStore {
|
||||||
priv metas: oldmap::HashMap<ast::crate_num, crate_metadata>,
|
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_crate_files: ~[Path],
|
||||||
priv used_libraries: ~[~str],
|
priv used_libraries: ~[~str],
|
||||||
priv used_link_args: ~[~str],
|
priv used_link_args: ~[~str],
|
||||||
intr: @ident_interner
|
intr: @ident_interner
|
||||||
}
|
}
|
||||||
|
|
||||||
// Map from node_id's of local use statements to crate numbers
|
// Map from node_id's of local extern mod statements to crate numbers
|
||||||
type use_crate_map = oldmap::HashMap<ast::node_id, ast::crate_num>;
|
type extern_mod_crate_map = oldmap::HashMap<ast::node_id, ast::crate_num>;
|
||||||
|
|
||||||
pub fn mk_cstore(intr: @ident_interner) -> CStore {
|
pub fn mk_cstore(intr: @ident_interner) -> CStore {
|
||||||
let meta_cache = oldmap::HashMap();
|
let meta_cache = oldmap::HashMap();
|
||||||
let crate_map = oldmap::HashMap();
|
let crate_map = oldmap::HashMap();
|
||||||
return CStore {
|
return CStore {
|
||||||
metas: meta_cache,
|
metas: meta_cache,
|
||||||
use_crate_map: crate_map,
|
extern_mod_crate_map: crate_map,
|
||||||
used_crate_files: ~[],
|
used_crate_files: ~[],
|
||||||
used_libraries: ~[],
|
used_libraries: ~[],
|
||||||
used_link_args: ~[],
|
used_link_args: ~[],
|
||||||
|
@ -127,18 +127,18 @@ pub fn get_used_link_args(cstore: @mut CStore) -> ~[~str] {
|
||||||
return /*bad*/copy cstore.used_link_args;
|
return /*bad*/copy cstore.used_link_args;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_use_stmt_cnum(cstore: @mut CStore,
|
pub fn add_extern_mod_stmt_cnum(cstore: @mut CStore,
|
||||||
use_id: ast::node_id,
|
emod_id: ast::node_id,
|
||||||
cnum: ast::crate_num) {
|
cnum: ast::crate_num) {
|
||||||
let use_crate_map = cstore.use_crate_map;
|
let extern_mod_crate_map = cstore.extern_mod_crate_map;
|
||||||
use_crate_map.insert(use_id, cnum);
|
extern_mod_crate_map.insert(emod_id, cnum);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn find_use_stmt_cnum(cstore: @mut CStore,
|
pub fn find_extern_mod_stmt_cnum(cstore: @mut CStore,
|
||||||
use_id: ast::node_id)
|
emod_id: ast::node_id)
|
||||||
-> Option<ast::crate_num> {
|
-> Option<ast::crate_num> {
|
||||||
let use_crate_map = cstore.use_crate_map;
|
let extern_mod_crate_map = cstore.extern_mod_crate_map;
|
||||||
use_crate_map.find(&use_id)
|
extern_mod_crate_map.find(&emod_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
// returns hashes of crates directly used by this crate. Hashes are
|
// 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};
|
type crate_hash = {name: ~str, hash: ~str};
|
||||||
let mut result = ~[];
|
let mut result = ~[];
|
||||||
|
|
||||||
let use_crate_map = cstore.use_crate_map;
|
let extern_mod_crate_map = cstore.extern_mod_crate_map;
|
||||||
for use_crate_map.each_value |&cnum| {
|
for extern_mod_crate_map.each_value |&cnum| {
|
||||||
let cdata = cstore::get_crate_data(cstore, cnum);
|
let cdata = cstore::get_crate_data(cstore, cnum);
|
||||||
let hash = decoder::get_crate_hash(cdata.data);
|
let hash = decoder::get_crate_hash(cdata.data);
|
||||||
debug!("Add hash[%s]: %s", cdata.name, hash);
|
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::{each_path, get_method_names_if_trait};
|
||||||
use metadata::csearch::{get_static_methods_if_impl, get_struct_fields};
|
use metadata::csearch::{get_static_methods_if_impl, get_struct_fields};
|
||||||
use metadata::csearch::{get_type_name_if_impl};
|
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 metadata::decoder::{def_like, dl_def, dl_field, dl_impl};
|
||||||
use middle::lang_items::LanguageItems;
|
use middle::lang_items::LanguageItems;
|
||||||
use middle::lint::{deny, allow, forbid, level, unused_imports, warn};
|
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_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::{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::{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_item_use, view_path_glob, view_path_list};
|
||||||
use syntax::ast::{view_path_simple, visibility, anonymous, named, not};
|
use syntax::ast::{view_path_simple, visibility, anonymous, named, not};
|
||||||
use syntax::ast::{unsafe_fn};
|
use syntax::ast::{unsafe_fn};
|
||||||
|
@ -1388,7 +1388,7 @@ pub impl Resolver {
|
||||||
&&_visitor: vt<ReducedGraphParent>) {
|
&&_visitor: vt<ReducedGraphParent>) {
|
||||||
let privacy = visibility_to_privacy(view_item.vis);
|
let privacy = visibility_to_privacy(view_item.vis);
|
||||||
match /*bad*/copy view_item.node {
|
match /*bad*/copy view_item.node {
|
||||||
view_item_import(view_paths) => {
|
view_item_use(view_paths) => {
|
||||||
for view_paths.each |view_path| {
|
for view_paths.each |view_path| {
|
||||||
// Extract and intern the module part of the path. For
|
// Extract and intern the module part of the path. For
|
||||||
// globs and lists, the path is found directly in the AST;
|
// globs and lists, the path is found directly in the AST;
|
||||||
|
@ -1462,8 +1462,8 @@ pub impl Resolver {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
view_item_use(name, _, node_id) => {
|
view_item_extern_mod(name, _, node_id) => {
|
||||||
match find_use_stmt_cnum(self.session.cstore, node_id) {
|
match find_extern_mod_stmt_cnum(self.session.cstore, node_id) {
|
||||||
Some(crate_id) => {
|
Some(crate_id) => {
|
||||||
let (child_name_bindings, new_parent) =
|
let (child_name_bindings, new_parent) =
|
||||||
self.add_child(name, parent, ForbidDuplicateTypes,
|
self.add_child(name, parent, ForbidDuplicateTypes,
|
||||||
|
|
|
@ -1121,8 +1121,8 @@ pub struct view_item {
|
||||||
#[auto_decode]
|
#[auto_decode]
|
||||||
#[deriving_eq]
|
#[deriving_eq]
|
||||||
pub enum view_item_ {
|
pub enum view_item_ {
|
||||||
view_item_use(ident, ~[@meta_item], node_id),
|
view_item_extern_mod(ident, ~[@meta_item], node_id),
|
||||||
view_item_import(~[@view_path]),
|
view_item_use(~[@view_path]),
|
||||||
}
|
}
|
||||||
|
|
||||||
// Meta-data associated with an item
|
// 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) {
|
visit_view_item: fn@(vi: @view_item) {
|
||||||
match vi.node {
|
match vi.node {
|
||||||
view_item_use(_, _, id) => vfn(id),
|
view_item_extern_mod(_, _, id) => vfn(id),
|
||||||
view_item_import(vps) => {
|
view_item_use(vps) => {
|
||||||
for vec::each(vps) |vp| {
|
for vec::each(vps) |vp| {
|
||||||
match vp.node {
|
match vp.node {
|
||||||
view_path_simple(_, _, _, id) => vfn(id),
|
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()),
|
node: ast::view_path_glob(mk_raw_path(sp, path), cx.next_id()),
|
||||||
span: sp,
|
span: sp,
|
||||||
};
|
};
|
||||||
@ast::view_item { node: ast::view_item_import(~[glob]),
|
@ast::view_item { node: ast::view_item_use(~[glob]),
|
||||||
attrs: ~[],
|
attrs: ~[],
|
||||||
vis: ast::private,
|
vis: ast::private,
|
||||||
span: sp }
|
span: sp }
|
||||||
|
|
|
@ -310,7 +310,7 @@ pub impl ext_ctxt_ast_builder for ext_ctxt {
|
||||||
+items: ~[@ast::item]) -> @ast::item {
|
+items: ~[@ast::item]) -> @ast::item {
|
||||||
// XXX: Total hack: import `core::kinds::Owned` to work around a
|
// XXX: Total hack: import `core::kinds::Owned` to work around a
|
||||||
// parser bug whereby `fn f<T: ::kinds::Owned>` doesn't parse.
|
// 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 {
|
@codemap::spanned {
|
||||||
node: ast::view_path_simple(
|
node: ast::view_path_simple(
|
||||||
self.ident_of(~"Owned"),
|
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_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::{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::{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::{view_path, view_path_glob, view_path_list, view_path_simple};
|
||||||
use ast::{visibility, vstore, vstore_box, vstore_fixed, vstore_slice};
|
use ast::{visibility, vstore, vstore_box, vstore_fixed, vstore_slice};
|
||||||
use ast::{vstore_uniq};
|
use ast::{vstore_uniq};
|
||||||
|
@ -3503,7 +3503,7 @@ pub impl Parser {
|
||||||
let metadata = self.parse_optional_meta();
|
let metadata = self.parse_optional_meta();
|
||||||
self.expect(token::SEMI);
|
self.expect(token::SEMI);
|
||||||
iovi_view_item(@ast::view_item {
|
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,
|
attrs: attrs,
|
||||||
vis: visibility,
|
vis: visibility,
|
||||||
span: mk_sp(lo, self.last_span.hi)
|
span: mk_sp(lo, self.last_span.hi)
|
||||||
|
@ -3884,7 +3884,7 @@ pub impl Parser {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_use() -> view_item_ {
|
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 {
|
fn parse_view_path() -> @view_path {
|
||||||
|
@ -4006,7 +4006,7 @@ pub impl Parser {
|
||||||
self.expect_keyword(~"mod");
|
self.expect_keyword(~"mod");
|
||||||
let ident = self.parse_ident();
|
let ident = self.parse_ident();
|
||||||
let metadata = self.parse_optional_meta();
|
let metadata = self.parse_optional_meta();
|
||||||
view_item_use(ident, metadata, self.get_id())
|
view_item_extern_mod(ident, metadata, self.get_id())
|
||||||
} else {
|
} else {
|
||||||
fail!();
|
fail!();
|
||||||
};
|
};
|
||||||
|
@ -4053,8 +4053,8 @@ pub impl Parser {
|
||||||
iovi_view_item(view_item) => {
|
iovi_view_item(view_item) => {
|
||||||
if restricted_to_imports {
|
if restricted_to_imports {
|
||||||
match view_item.node {
|
match view_item.node {
|
||||||
view_item_import(_) => {}
|
view_item_use(*) => {}
|
||||||
view_item_use(*) =>
|
view_item_extern_mod(*) =>
|
||||||
self.fatal(~"\"extern mod\" \
|
self.fatal(~"\"extern mod\" \
|
||||||
declarations are not \
|
declarations are not \
|
||||||
allowed here")
|
allowed here")
|
||||||
|
|
|
@ -1859,7 +1859,7 @@ pub fn print_view_item(s: @ps, item: @ast::view_item) {
|
||||||
print_outer_attributes(s, item.attrs);
|
print_outer_attributes(s, item.attrs);
|
||||||
print_visibility(s, item.vis);
|
print_visibility(s, item.vis);
|
||||||
match item.node {
|
match item.node {
|
||||||
ast::view_item_use(id, mta, _) => {
|
ast::view_item_extern_mod(id, mta, _) => {
|
||||||
head(s, ~"extern mod");
|
head(s, ~"extern mod");
|
||||||
print_ident(s, id);
|
print_ident(s, id);
|
||||||
if !mta.is_empty() {
|
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");
|
head(s, ~"use");
|
||||||
print_view_paths(s, vps);
|
print_view_paths(s, vps);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue