mirror of
https://github.com/rust-lang/rust.git
synced 2025-01-26 14:43:24 +00:00
auto merge of #20963 : nick29581/rust/ast_map, r=eddyb
This commit is contained in:
commit
6ba9acd8ab
@ -54,7 +54,7 @@ impl<'a> FileSearch<'a> {
|
|||||||
|
|
||||||
debug!("filesearch: searching lib path");
|
debug!("filesearch: searching lib path");
|
||||||
let tlib_path = make_target_lib_path(self.sysroot,
|
let tlib_path = make_target_lib_path(self.sysroot,
|
||||||
self.triple);
|
self.triple);
|
||||||
if !visited_dirs.contains(tlib_path.as_vec()) {
|
if !visited_dirs.contains(tlib_path.as_vec()) {
|
||||||
match f(&tlib_path) {
|
match f(&tlib_path) {
|
||||||
FileMatches => found = true,
|
FileMatches => found = true,
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
|
|
||||||
use std::slice;
|
use std::slice;
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone, Show)]
|
||||||
pub struct SearchPaths {
|
pub struct SearchPaths {
|
||||||
paths: Vec<(PathKind, Path)>,
|
paths: Vec<(PathKind, Path)>,
|
||||||
}
|
}
|
||||||
@ -20,7 +20,7 @@ pub struct Iter<'a> {
|
|||||||
iter: slice::Iter<'a, (PathKind, Path)>,
|
iter: slice::Iter<'a, (PathKind, Path)>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Eq, PartialEq, Clone, Copy)]
|
#[derive(Eq, PartialEq, Clone, Copy, Show)]
|
||||||
pub enum PathKind {
|
pub enum PathKind {
|
||||||
Native,
|
Native,
|
||||||
Crate,
|
Crate,
|
||||||
|
@ -186,7 +186,7 @@ fn run_compiler(args: &[String]) {
|
|||||||
list_metadata(&sess, &(*ifile), &mut stdout).unwrap();
|
list_metadata(&sess, &(*ifile), &mut stdout).unwrap();
|
||||||
}
|
}
|
||||||
Input::Str(_) => {
|
Input::Str(_) => {
|
||||||
early_error("can not list metadata for stdin");
|
early_error("cannot list metadata for stdin");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
|
@ -274,6 +274,7 @@ pub fn monomorphic_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
|
|||||||
ast_map::NodeArg(..) |
|
ast_map::NodeArg(..) |
|
||||||
ast_map::NodeBlock(..) |
|
ast_map::NodeBlock(..) |
|
||||||
ast_map::NodePat(..) |
|
ast_map::NodePat(..) |
|
||||||
|
ast_map::NodeViewItem(..) |
|
||||||
ast_map::NodeLocal(..) => {
|
ast_map::NodeLocal(..) => {
|
||||||
ccx.sess().bug(&format!("can't monomorphize a {:?}",
|
ccx.sess().bug(&format!("can't monomorphize a {:?}",
|
||||||
map_node)[])
|
map_node)[])
|
||||||
|
@ -1528,6 +1528,19 @@ pub struct ViewItem {
|
|||||||
pub span: Span,
|
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)]
|
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
|
||||||
pub enum ViewItem_ {
|
pub enum ViewItem_ {
|
||||||
/// Ident: name used to refer to this crate in the code
|
/// Ident: name used to refer to this crate in the code
|
||||||
|
@ -107,6 +107,7 @@ pub fn path_to_string<PI: Iterator<Item=PathElem>>(path: PI) -> String {
|
|||||||
#[derive(Copy, Show)]
|
#[derive(Copy, Show)]
|
||||||
pub enum Node<'ast> {
|
pub enum Node<'ast> {
|
||||||
NodeItem(&'ast Item),
|
NodeItem(&'ast Item),
|
||||||
|
NodeViewItem(&'ast ViewItem),
|
||||||
NodeForeignItem(&'ast ForeignItem),
|
NodeForeignItem(&'ast ForeignItem),
|
||||||
NodeTraitItem(&'ast TraitItem),
|
NodeTraitItem(&'ast TraitItem),
|
||||||
NodeImplItem(&'ast ImplItem),
|
NodeImplItem(&'ast ImplItem),
|
||||||
@ -133,6 +134,7 @@ enum MapEntry<'ast> {
|
|||||||
|
|
||||||
/// All the node types, with a parent ID.
|
/// All the node types, with a parent ID.
|
||||||
EntryItem(NodeId, &'ast Item),
|
EntryItem(NodeId, &'ast Item),
|
||||||
|
EntryViewItem(NodeId, &'ast ViewItem),
|
||||||
EntryForeignItem(NodeId, &'ast ForeignItem),
|
EntryForeignItem(NodeId, &'ast ForeignItem),
|
||||||
EntryTraitItem(NodeId, &'ast TraitItem),
|
EntryTraitItem(NodeId, &'ast TraitItem),
|
||||||
EntryImplItem(NodeId, &'ast ImplItem),
|
EntryImplItem(NodeId, &'ast ImplItem),
|
||||||
@ -167,6 +169,7 @@ impl<'ast> MapEntry<'ast> {
|
|||||||
fn from_node(p: NodeId, node: Node<'ast>) -> MapEntry<'ast> {
|
fn from_node(p: NodeId, node: Node<'ast>) -> MapEntry<'ast> {
|
||||||
match node {
|
match node {
|
||||||
NodeItem(n) => EntryItem(p, n),
|
NodeItem(n) => EntryItem(p, n),
|
||||||
|
NodeViewItem(n) => EntryViewItem(p, n),
|
||||||
NodeForeignItem(n) => EntryForeignItem(p, n),
|
NodeForeignItem(n) => EntryForeignItem(p, n),
|
||||||
NodeTraitItem(n) => EntryTraitItem(p, n),
|
NodeTraitItem(n) => EntryTraitItem(p, n),
|
||||||
NodeImplItem(n) => EntryImplItem(p, n),
|
NodeImplItem(n) => EntryImplItem(p, n),
|
||||||
@ -185,6 +188,7 @@ impl<'ast> MapEntry<'ast> {
|
|||||||
fn parent(self) -> Option<NodeId> {
|
fn parent(self) -> Option<NodeId> {
|
||||||
Some(match self {
|
Some(match self {
|
||||||
EntryItem(id, _) => id,
|
EntryItem(id, _) => id,
|
||||||
|
EntryViewItem(id, _) => id,
|
||||||
EntryForeignItem(id, _) => id,
|
EntryForeignItem(id, _) => id,
|
||||||
EntryTraitItem(id, _) => id,
|
EntryTraitItem(id, _) => id,
|
||||||
EntryImplItem(id, _) => id,
|
EntryImplItem(id, _) => id,
|
||||||
@ -204,6 +208,7 @@ impl<'ast> MapEntry<'ast> {
|
|||||||
fn to_node(self) -> Option<Node<'ast>> {
|
fn to_node(self) -> Option<Node<'ast>> {
|
||||||
Some(match self {
|
Some(match self {
|
||||||
EntryItem(_, n) => NodeItem(n),
|
EntryItem(_, n) => NodeItem(n),
|
||||||
|
EntryViewItem(_, n) => NodeViewItem(n),
|
||||||
EntryForeignItem(_, n) => NodeForeignItem(n),
|
EntryForeignItem(_, n) => NodeForeignItem(n),
|
||||||
EntryTraitItem(_, n) => NodeTraitItem(n),
|
EntryTraitItem(_, n) => NodeTraitItem(n),
|
||||||
EntryImplItem(_, n) => NodeImplItem(n),
|
EntryImplItem(_, n) => NodeImplItem(n),
|
||||||
@ -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 {
|
pub fn expect_struct(&self, id: NodeId) -> &'ast StructDef {
|
||||||
match self.find(id) {
|
match self.find(id) {
|
||||||
Some(NodeItem(i)) => {
|
Some(NodeItem(i)) => {
|
||||||
@ -521,6 +533,7 @@ impl<'ast> Map<'ast> {
|
|||||||
pub fn opt_span(&self, id: NodeId) -> Option<Span> {
|
pub fn opt_span(&self, id: NodeId) -> Option<Span> {
|
||||||
let sp = match self.find(id) {
|
let sp = match self.find(id) {
|
||||||
Some(NodeItem(item)) => item.span,
|
Some(NodeItem(item)) => item.span,
|
||||||
|
Some(NodeViewItem(item)) => item.span,
|
||||||
Some(NodeForeignItem(foreign_item)) => foreign_item.span,
|
Some(NodeForeignItem(foreign_item)) => foreign_item.span,
|
||||||
Some(NodeTraitItem(trait_method)) => {
|
Some(NodeTraitItem(trait_method)) => {
|
||||||
match *trait_method {
|
match *trait_method {
|
||||||
@ -813,6 +826,11 @@ impl<'ast> Visitor<'ast> for NodeCollector<'ast> {
|
|||||||
self.parent = parent;
|
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) {
|
fn visit_pat(&mut self, pat: &'ast Pat) {
|
||||||
self.insert(pat.id, match pat.node {
|
self.insert(pat.id, match pat.node {
|
||||||
// Note: this is at least *potentially* a pattern...
|
// Note: this is at least *potentially* a pattern...
|
||||||
@ -1018,6 +1036,7 @@ impl<'a> NodePrinter for pprust::State<'a> {
|
|||||||
fn print_node(&mut self, node: &Node) -> IoResult<()> {
|
fn print_node(&mut self, node: &Node) -> IoResult<()> {
|
||||||
match *node {
|
match *node {
|
||||||
NodeItem(a) => self.print_item(&*a),
|
NodeItem(a) => self.print_item(&*a),
|
||||||
|
NodeViewItem(a) => self.print_view_item(&*a),
|
||||||
NodeForeignItem(a) => self.print_foreign_item(&*a),
|
NodeForeignItem(a) => self.print_foreign_item(&*a),
|
||||||
NodeTraitItem(a) => self.print_trait_method(&*a),
|
NodeTraitItem(a) => self.print_trait_method(&*a),
|
||||||
NodeImplItem(a) => self.print_impl_item(&*a),
|
NodeImplItem(a) => self.print_impl_item(&*a),
|
||||||
@ -1060,6 +1079,9 @@ fn node_id_to_string(map: &Map, id: NodeId, include_id: bool) -> String {
|
|||||||
};
|
};
|
||||||
format!("{} {}{}", item_str, path_str, id_str)
|
format!("{} {}{}", item_str, path_str, id_str)
|
||||||
}
|
}
|
||||||
|
Some(NodeViewItem(item)) => {
|
||||||
|
format!("view item {}{}", pprust::view_item_to_string(&*item), id_str)
|
||||||
|
}
|
||||||
Some(NodeForeignItem(item)) => {
|
Some(NodeForeignItem(item)) => {
|
||||||
let path_str = map.path_to_str_with_ident(id, item.ident);
|
let path_str = map.path_to_str_with_ident(id, item.ident);
|
||||||
format!("foreign item {}{}", path_str, id_str)
|
format!("foreign item {}{}", path_str, id_str)
|
||||||
|
Loading…
Reference in New Issue
Block a user