Skip to content

Add view items to the ast map #20963

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 13, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/librustc/metadata/filesearch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ impl<'a> FileSearch<'a> {

debug!("filesearch: searching lib path");
let tlib_path = make_target_lib_path(self.sysroot,
self.triple);
self.triple);
if !visited_dirs.contains(tlib_path.as_vec()) {
match f(&tlib_path) {
FileMatches => found = true,
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/session/search_paths.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

use std::slice;

#[derive(Clone)]
#[derive(Clone, Show)]
pub struct SearchPaths {
paths: Vec<(PathKind, Path)>,
}
Expand All @@ -20,7 +20,7 @@ pub struct Iter<'a> {
iter: slice::Iter<'a, (PathKind, Path)>,
}

#[derive(Eq, PartialEq, Clone, Copy)]
#[derive(Eq, PartialEq, Clone, Copy, Show)]
pub enum PathKind {
Native,
Crate,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_driver/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ fn run_compiler(args: &[String]) {
list_metadata(&sess, &(*ifile), &mut stdout).unwrap();
}
Input::Str(_) => {
early_error("can not list metadata for stdin");
early_error("cannot list metadata for stdin");
}
}
return;
Expand Down
1 change: 1 addition & 0 deletions src/librustc_trans/trans/monomorphize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ pub fn monomorphic_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
ast_map::NodeArg(..) |
ast_map::NodeBlock(..) |
ast_map::NodePat(..) |
ast_map::NodeViewItem(..) |
ast_map::NodeLocal(..) => {
ccx.sess().bug(&format!("can't monomorphize a {:?}",
map_node)[])
Expand Down
13 changes: 13 additions & 0 deletions src/libsyntax/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1528,6 +1528,19 @@ pub struct ViewItem {
pub span: Span,
}

impl ViewItem {
pub fn id(&self) -> NodeId {
match self.node {
ViewItemExternCrate(_, _, id) => id,
ViewItemUse(ref vp) => match vp.node {
ViewPathSimple(_, _, id) => id,
ViewPathGlob(_, id) => id,
ViewPathList(_, _, id) => id,
}
}
}
}

#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
pub enum ViewItem_ {
/// Ident: name used to refer to this crate in the code
Expand Down
22 changes: 22 additions & 0 deletions src/libsyntax/ast_map/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ pub fn path_to_string<PI: Iterator<Item=PathElem>>(path: PI) -> String {
#[derive(Copy, Show)]
pub enum Node<'ast> {
NodeItem(&'ast Item),
NodeViewItem(&'ast ViewItem),
NodeForeignItem(&'ast ForeignItem),
NodeTraitItem(&'ast TraitItem),
NodeImplItem(&'ast ImplItem),
Expand All @@ -133,6 +134,7 @@ enum MapEntry<'ast> {

/// All the node types, with a parent ID.
EntryItem(NodeId, &'ast Item),
EntryViewItem(NodeId, &'ast ViewItem),
EntryForeignItem(NodeId, &'ast ForeignItem),
EntryTraitItem(NodeId, &'ast TraitItem),
EntryImplItem(NodeId, &'ast ImplItem),
Expand Down Expand Up @@ -167,6 +169,7 @@ impl<'ast> MapEntry<'ast> {
fn from_node(p: NodeId, node: Node<'ast>) -> MapEntry<'ast> {
match node {
NodeItem(n) => EntryItem(p, n),
NodeViewItem(n) => EntryViewItem(p, n),
NodeForeignItem(n) => EntryForeignItem(p, n),
NodeTraitItem(n) => EntryTraitItem(p, n),
NodeImplItem(n) => EntryImplItem(p, n),
Expand All @@ -185,6 +188,7 @@ impl<'ast> MapEntry<'ast> {
fn parent(self) -> Option<NodeId> {
Some(match self {
EntryItem(id, _) => id,
EntryViewItem(id, _) => id,
EntryForeignItem(id, _) => id,
EntryTraitItem(id, _) => id,
EntryImplItem(id, _) => id,
Expand All @@ -204,6 +208,7 @@ impl<'ast> MapEntry<'ast> {
fn to_node(self) -> Option<Node<'ast>> {
Some(match self {
EntryItem(_, n) => NodeItem(n),
EntryViewItem(_, n) => NodeViewItem(n),
EntryForeignItem(_, n) => NodeForeignItem(n),
EntryTraitItem(_, n) => NodeTraitItem(n),
EntryImplItem(_, n) => NodeImplItem(n),
Expand Down Expand Up @@ -336,6 +341,13 @@ impl<'ast> Map<'ast> {
}
}

pub fn expect_view_item(&self, id: NodeId) -> &'ast ViewItem {
match self.find(id) {
Some(NodeViewItem(view_item)) => view_item,
_ => panic!("expected view item, found {}", self.node_to_string(id))
}
}

pub fn expect_struct(&self, id: NodeId) -> &'ast StructDef {
match self.find(id) {
Some(NodeItem(i)) => {
Expand Down Expand Up @@ -521,6 +533,7 @@ impl<'ast> Map<'ast> {
pub fn opt_span(&self, id: NodeId) -> Option<Span> {
let sp = match self.find(id) {
Some(NodeItem(item)) => item.span,
Some(NodeViewItem(item)) => item.span,
Some(NodeForeignItem(foreign_item)) => foreign_item.span,
Some(NodeTraitItem(trait_method)) => {
match *trait_method {
Expand Down Expand Up @@ -813,6 +826,11 @@ impl<'ast> Visitor<'ast> for NodeCollector<'ast> {
self.parent = parent;
}

fn visit_view_item(&mut self, item: &'ast ViewItem) {
self.insert(item.id(), NodeViewItem(item));
visit::walk_view_item(self, item);
}

fn visit_pat(&mut self, pat: &'ast Pat) {
self.insert(pat.id, match pat.node {
// Note: this is at least *potentially* a pattern...
Expand Down Expand Up @@ -1018,6 +1036,7 @@ impl<'a> NodePrinter for pprust::State<'a> {
fn print_node(&mut self, node: &Node) -> IoResult<()> {
match *node {
NodeItem(a) => self.print_item(&*a),
NodeViewItem(a) => self.print_view_item(&*a),
NodeForeignItem(a) => self.print_foreign_item(&*a),
NodeTraitItem(a) => self.print_trait_method(&*a),
NodeImplItem(a) => self.print_impl_item(&*a),
Expand Down Expand Up @@ -1060,6 +1079,9 @@ fn node_id_to_string(map: &Map, id: NodeId, include_id: bool) -> String {
};
format!("{} {}{}", item_str, path_str, id_str)
}
Some(NodeViewItem(item)) => {
format!("view item {}{}", pprust::view_item_to_string(&*item), id_str)
}
Some(NodeForeignItem(item)) => {
let path_str = map.path_to_str_with_ident(id, item.ident);
format!("foreign item {}{}", path_str, id_str)
Expand Down