From b4928d13d8700e8d4890adad8cdc12fc9af2168d Mon Sep 17 00:00:00 2001 From: Ahmed Charles Date: Wed, 28 May 2014 09:27:36 -0700 Subject: [PATCH] Steps towards fixing #11983. --- src/libsyntax/ast.rs | 4 +- src/libsyntax/ast_map.rs | 226 +++++++-------- src/libsyntax/ast_util.rs | 366 ++++++++++++------------ src/libsyntax/codemap.rs | 2 - src/libsyntax/fold.rs | 572 +++++++++++++++++++------------------- src/libsyntax/visit.rs | 315 ++++++++++----------- 6 files changed, 741 insertions(+), 744 deletions(-) diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index 9cbe7e0b5fce5..de85d20fa7efc 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -1178,8 +1178,8 @@ pub enum InlinedItem { mod test { use serialize::json; use serialize; - use codemap::*; - use super::*; + use codemap::{Span, BytePos}; + use super::{Crate, Mod}; // are ASTs encodable? #[test] diff --git a/src/libsyntax/ast_map.rs b/src/libsyntax/ast_map.rs index 9a7b4f7d9497a..ec5a07703d3d3 100644 --- a/src/libsyntax/ast_map.rs +++ b/src/libsyntax/ast_map.rs @@ -9,7 +9,7 @@ // except according to those terms. use abi; -use ast::*; +use ast; use ast_util; use codemap::Span; use fold::Folder; @@ -26,12 +26,12 @@ use std::string::String; #[deriving(Clone, PartialEq)] pub enum PathElem { - PathMod(Name), - PathName(Name) + PathMod(ast::Name), + PathName(ast::Name) } impl PathElem { - pub fn name(&self) -> Name { + pub fn name(&self) -> ast::Name { match *self { PathMod(name) | PathName(name) => name } @@ -94,22 +94,22 @@ pub fn path_to_str>(mut path: PI) -> String { #[deriving(Clone)] pub enum Node { - NodeItem(@Item), - NodeForeignItem(@ForeignItem), - NodeTraitMethod(@TraitMethod), - NodeMethod(@Method), - NodeVariant(P), - NodeExpr(@Expr), - NodeStmt(@Stmt), - NodeArg(@Pat), - NodeLocal(@Pat), - NodePat(@Pat), - NodeBlock(P), + NodeItem(@ast::Item), + NodeForeignItem(@ast::ForeignItem), + NodeTraitMethod(@ast::TraitMethod), + NodeMethod(@ast::Method), + NodeVariant(ast::P), + NodeExpr(@ast::Expr), + NodeStmt(@ast::Stmt), + NodeArg(@ast::Pat), + NodeLocal(@ast::Pat), + NodePat(@ast::Pat), + NodeBlock(ast::P), /// NodeStructCtor represents a tuple struct. - NodeStructCtor(@StructDef), + NodeStructCtor(@ast::StructDef), - NodeLifetime(@Lifetime), + NodeLifetime(@ast::Lifetime), } // The odd layout is to bring down the total size. @@ -119,33 +119,33 @@ enum MapEntry { NotPresent, // All the node types, with a parent ID. - EntryItem(NodeId, @Item), - EntryForeignItem(NodeId, @ForeignItem), - EntryTraitMethod(NodeId, @TraitMethod), - EntryMethod(NodeId, @Method), - EntryVariant(NodeId, P), - EntryExpr(NodeId, @Expr), - EntryStmt(NodeId, @Stmt), - EntryArg(NodeId, @Pat), - EntryLocal(NodeId, @Pat), - EntryPat(NodeId, @Pat), - EntryBlock(NodeId, P), - EntryStructCtor(NodeId, @StructDef), - EntryLifetime(NodeId, @Lifetime), + EntryItem(ast::NodeId, @ast::Item), + EntryForeignItem(ast::NodeId, @ast::ForeignItem), + EntryTraitMethod(ast::NodeId, @ast::TraitMethod), + EntryMethod(ast::NodeId, @ast::Method), + EntryVariant(ast::NodeId, ast::P), + EntryExpr(ast::NodeId, @ast::Expr), + EntryStmt(ast::NodeId, @ast::Stmt), + EntryArg(ast::NodeId, @ast::Pat), + EntryLocal(ast::NodeId, @ast::Pat), + EntryPat(ast::NodeId, @ast::Pat), + EntryBlock(ast::NodeId, ast::P), + EntryStructCtor(ast::NodeId, @ast::StructDef), + EntryLifetime(ast::NodeId, @ast::Lifetime), // Roots for node trees. RootCrate, - RootInlinedParent(P) + RootInlinedParent(ast::P) } struct InlinedParent { path: Vec , // Required by NodeTraitMethod and NodeMethod. - def_id: DefId + def_id: ast::DefId } impl MapEntry { - fn parent(&self) -> Option { + fn parent(&self) -> Option { Some(match *self { EntryItem(id, _) => id, EntryForeignItem(id, _) => id, @@ -198,7 +198,7 @@ pub struct Map { } impl Map { - fn find_entry(&self, id: NodeId) -> Option { + fn find_entry(&self, id: ast::NodeId) -> Option { let map = self.map.borrow(); if map.len() > id as uint { Some(*map.get(id as uint)) @@ -209,7 +209,7 @@ impl Map { /// Retrieve the Node corresponding to `id`, failing if it cannot /// be found. - pub fn get(&self, id: NodeId) -> Node { + pub fn get(&self, id: ast::NodeId) -> Node { match self.find(id) { Some(node) => node, None => fail!("couldn't find node id {} in the AST map", id) @@ -218,17 +218,17 @@ impl Map { /// Retrieve the Node corresponding to `id`, returning None if /// cannot be found. - pub fn find(&self, id: NodeId) -> Option { + pub fn find(&self, id: ast::NodeId) -> Option { self.find_entry(id).and_then(|x| x.to_node()) } /// Retrieve the parent NodeId for `id`, or `id` itself if no /// parent is registered in this map. - pub fn get_parent(&self, id: NodeId) -> NodeId { + pub fn get_parent(&self, id: ast::NodeId) -> ast::NodeId { self.find_entry(id).and_then(|x| x.parent()).unwrap_or(id) } - pub fn get_parent_did(&self, id: NodeId) -> DefId { + pub fn get_parent_did(&self, id: ast::NodeId) -> ast::DefId { let parent = self.get_parent(id); match self.find_entry(parent) { Some(RootInlinedParent(data)) => data.def_id, @@ -236,11 +236,11 @@ impl Map { } } - pub fn get_foreign_abi(&self, id: NodeId) -> abi::Abi { + pub fn get_foreign_abi(&self, id: ast::NodeId) -> abi::Abi { let parent = self.get_parent(id); let abi = match self.find_entry(parent) { Some(EntryItem(_, i)) => match i.node { - ItemForeignMod(ref nm) => Some(nm.abi), + ast::ItemForeignMod(ref nm) => Some(nm.abi), _ => None }, // Wrong but OK, because the only inlined foreign items are intrinsics. @@ -254,7 +254,7 @@ impl Map { } } - pub fn get_foreign_vis(&self, id: NodeId) -> Visibility { + pub fn get_foreign_vis(&self, id: ast::NodeId) -> ast::Visibility { let vis = self.expect_foreign_item(id).vis; match self.find(self.get_parent(id)) { Some(NodeItem(i)) => vis.inherit_from(i.vis), @@ -262,24 +262,24 @@ impl Map { } } - pub fn expect_item(&self, id: NodeId) -> @Item { + pub fn expect_item(&self, id: ast::NodeId) -> @ast::Item { match self.find(id) { Some(NodeItem(item)) => item, _ => fail!("expected item, found {}", self.node_to_str(id)) } } - pub fn expect_struct(&self, id: NodeId) -> @StructDef { + pub fn expect_struct(&self, id: ast::NodeId) -> @ast::StructDef { match self.find(id) { Some(NodeItem(i)) => { match i.node { - ItemStruct(struct_def, _) => struct_def, + ast::ItemStruct(struct_def, _) => struct_def, _ => fail!("struct ID bound to non-struct") } } Some(NodeVariant(ref variant)) => { match (*variant).node.kind { - StructVariantKind(struct_def) => struct_def, + ast::StructVariantKind(struct_def) => struct_def, _ => fail!("struct ID bound to enum variant that isn't struct-like"), } } @@ -287,25 +287,25 @@ impl Map { } } - pub fn expect_variant(&self, id: NodeId) -> P { + pub fn expect_variant(&self, id: ast::NodeId) -> ast::P { match self.find(id) { Some(NodeVariant(variant)) => variant, _ => fail!(format!("expected variant, found {}", self.node_to_str(id))), } } - pub fn expect_foreign_item(&self, id: NodeId) -> @ForeignItem { + pub fn expect_foreign_item(&self, id: ast::NodeId) -> @ast::ForeignItem { match self.find(id) { Some(NodeForeignItem(item)) => item, _ => fail!("expected foreign item, found {}", self.node_to_str(id)) } } - pub fn get_path_elem(&self, id: NodeId) -> PathElem { + pub fn get_path_elem(&self, id: ast::NodeId) -> PathElem { match self.get(id) { NodeItem(item) => { match item.node { - ItemMod(_) | ItemForeignMod(_) => { + ast::ItemMod(_) | ast::ItemForeignMod(_) => { PathMod(item.ident.name) } _ => PathName(item.ident.name) @@ -314,29 +314,29 @@ impl Map { NodeForeignItem(i) => PathName(i.ident.name), NodeMethod(m) => PathName(m.ident.name), NodeTraitMethod(tm) => match *tm { - Required(ref m) => PathName(m.ident.name), - Provided(ref m) => PathName(m.ident.name) + ast::Required(ref m) => PathName(m.ident.name), + ast::Provided(ref m) => PathName(m.ident.name) }, NodeVariant(v) => PathName(v.node.name.name), node => fail!("no path elem for {:?}", node) } } - pub fn with_path(&self, id: NodeId, f: |PathElems| -> T) -> T { + pub fn with_path(&self, id: ast::NodeId, f: |PathElems| -> T) -> T { self.with_path_next(id, None, f) } - pub fn path_to_str(&self, id: NodeId) -> String { + pub fn path_to_str(&self, id: ast::NodeId) -> String { self.with_path(id, |path| path_to_str(path)) } - fn path_to_str_with_ident(&self, id: NodeId, i: Ident) -> String { + fn path_to_str_with_ident(&self, id: ast::NodeId, i: ast::Ident) -> String { self.with_path(id, |path| { path_to_str(path.chain(Some(PathName(i.name)).move_iter())) }) } - fn with_path_next(&self, id: NodeId, next: LinkedPath, f: |PathElems| -> T) -> T { + fn with_path_next(&self, id: ast::NodeId, next: LinkedPath, f: |PathElems| -> T) -> T { let parent = self.get_parent(id); let parent = match self.find_entry(id) { Some(EntryForeignItem(..)) | Some(EntryVariant(..)) => { @@ -366,14 +366,14 @@ impl Map { } } - pub fn with_attrs(&self, id: NodeId, f: |Option<&[Attribute]>| -> T) -> T { + pub fn with_attrs(&self, id: ast::NodeId, f: |Option<&[ast::Attribute]>| -> T) -> T { let node = self.get(id); let attrs = match node { NodeItem(ref i) => Some(i.attrs.as_slice()), NodeForeignItem(ref fi) => Some(fi.attrs.as_slice()), NodeTraitMethod(ref tm) => match **tm { - Required(ref type_m) => Some(type_m.attrs.as_slice()), - Provided(ref m) => Some(m.attrs.as_slice()) + ast::Required(ref type_m) => Some(type_m.attrs.as_slice()), + ast::Provided(ref m) => Some(m.attrs.as_slice()) }, NodeMethod(ref m) => Some(m.attrs.as_slice()), NodeVariant(ref v) => Some(v.node.attrs.as_slice()), @@ -388,14 +388,14 @@ impl Map { f(attrs) } - pub fn opt_span(&self, id: NodeId) -> Option { + pub fn opt_span(&self, id: ast::NodeId) -> Option { let sp = match self.find(id) { Some(NodeItem(item)) => item.span, Some(NodeForeignItem(foreign_item)) => foreign_item.span, Some(NodeTraitMethod(trait_method)) => { match *trait_method { - Required(ref type_method) => type_method.span, - Provided(ref method) => method.span, + ast::Required(ref type_method) => type_method.span, + ast::Provided(ref method) => method.span, } } Some(NodeMethod(method)) => method.span, @@ -411,18 +411,18 @@ impl Map { Some(sp) } - pub fn span(&self, id: NodeId) -> Span { + pub fn span(&self, id: ast::NodeId) -> Span { self.opt_span(id) .unwrap_or_else(|| fail!("AstMap.span: could not find span for id {}", id)) } - pub fn node_to_str(&self, id: NodeId) -> String { + pub fn node_to_str(&self, id: ast::NodeId) -> String { node_id_to_str(self, id) } } pub trait FoldOps { - fn new_id(&self, id: NodeId) -> NodeId { + fn new_id(&self, id: ast::NodeId) -> ast::NodeId { id } fn new_span(&self, span: Span) -> Span { @@ -434,20 +434,20 @@ pub struct Ctx<'a, F> { map: &'a Map, // The node in which we are currently mapping (an item or a method). // When equal to DUMMY_NODE_ID, the next mapped node becomes the parent. - parent: NodeId, + parent: ast::NodeId, fold_ops: F } impl<'a, F> Ctx<'a, F> { - fn insert(&self, id: NodeId, entry: MapEntry) { + fn insert(&self, id: ast::NodeId, entry: MapEntry) { (*self.map.map.borrow_mut()).grow_set(id as uint, &NotPresent, entry); } } impl<'a, F: FoldOps> Folder for Ctx<'a, F> { - fn new_id(&mut self, id: NodeId) -> NodeId { + fn new_id(&mut self, id: ast::NodeId) -> ast::NodeId { let id = self.fold_ops.new_id(id); - if self.parent == DUMMY_NODE_ID { + if self.parent == ast::DUMMY_NODE_ID { self.parent = id; } id @@ -457,30 +457,30 @@ impl<'a, F: FoldOps> Folder for Ctx<'a, F> { self.fold_ops.new_span(span) } - fn fold_item(&mut self, i: @Item) -> SmallVector<@Item> { + fn fold_item(&mut self, i: @ast::Item) -> SmallVector<@ast::Item> { let parent = self.parent; - self.parent = DUMMY_NODE_ID; + self.parent = ast::DUMMY_NODE_ID; let i = fold::noop_fold_item(i, self).expect_one("expected one item"); assert_eq!(self.parent, i.id); match i.node { - ItemImpl(_, _, _, ref ms) => { + ast::ItemImpl(_, _, _, ref ms) => { for &m in ms.iter() { self.insert(m.id, EntryMethod(self.parent, m)); } } - ItemEnum(ref enum_definition, _) => { + ast::ItemEnum(ref enum_definition, _) => { for &v in enum_definition.variants.iter() { self.insert(v.node.id, EntryVariant(self.parent, v)); } } - ItemForeignMod(ref nm) => { + ast::ItemForeignMod(ref nm) => { for &nitem in nm.items.iter() { self.insert(nitem.id, EntryForeignItem(self.parent, nitem)); } } - ItemStruct(struct_def, _) => { + ast::ItemStruct(struct_def, _) => { // If this is a tuple-like struct, register the constructor. match struct_def.ctor_id { Some(ctor_id) => { @@ -490,20 +490,20 @@ impl<'a, F: FoldOps> Folder for Ctx<'a, F> { None => {} } } - ItemTrait(_, _, ref traits, ref methods) => { + ast::ItemTrait(_, _, ref traits, ref methods) => { for t in traits.iter() { self.insert(t.ref_id, EntryItem(self.parent, i)); } for tm in methods.iter() { match *tm { - Required(ref m) => { + ast::Required(ref m) => { self.insert(m.id, EntryTraitMethod(self.parent, @(*tm).clone())); } - Provided(m) => { + ast::Provided(m) => { self.insert(m.id, EntryTraitMethod(self.parent, - @Provided(m))); + @ast::Provided(m))); } } } @@ -517,10 +517,10 @@ impl<'a, F: FoldOps> Folder for Ctx<'a, F> { SmallVector::one(i) } - fn fold_pat(&mut self, pat: @Pat) -> @Pat { + fn fold_pat(&mut self, pat: @ast::Pat) -> @ast::Pat { let pat = fold::noop_fold_pat(pat, self); match pat.node { - PatIdent(..) => { + ast::PatIdent(..) => { // Note: this is at least *potentially* a pattern... self.insert(pat.id, EntryLocal(self.parent, pat)); } @@ -532,7 +532,7 @@ impl<'a, F: FoldOps> Folder for Ctx<'a, F> { pat } - fn fold_expr(&mut self, expr: @Expr) -> @Expr { + fn fold_expr(&mut self, expr: @ast::Expr) -> @ast::Expr { let expr = fold::noop_fold_expr(expr, self); self.insert(expr.id, EntryExpr(self.parent, expr)); @@ -540,31 +540,31 @@ impl<'a, F: FoldOps> Folder for Ctx<'a, F> { expr } - fn fold_stmt(&mut self, stmt: &Stmt) -> SmallVector<@Stmt> { + fn fold_stmt(&mut self, stmt: &ast::Stmt) -> SmallVector<@ast::Stmt> { let stmt = fold::noop_fold_stmt(stmt, self).expect_one("expected one statement"); self.insert(ast_util::stmt_id(stmt), EntryStmt(self.parent, stmt)); SmallVector::one(stmt) } - fn fold_type_method(&mut self, m: &TypeMethod) -> TypeMethod { + fn fold_type_method(&mut self, m: &ast::TypeMethod) -> ast::TypeMethod { let parent = self.parent; - self.parent = DUMMY_NODE_ID; + self.parent = ast::DUMMY_NODE_ID; let m = fold::noop_fold_type_method(m, self); assert_eq!(self.parent, m.id); self.parent = parent; m } - fn fold_method(&mut self, m: @Method) -> @Method { + fn fold_method(&mut self, m: @ast::Method) -> @ast::Method { let parent = self.parent; - self.parent = DUMMY_NODE_ID; + self.parent = ast::DUMMY_NODE_ID; let m = fold::noop_fold_method(m, self); assert_eq!(self.parent, m.id); self.parent = parent; m } - fn fold_fn_decl(&mut self, decl: &FnDecl) -> P { + fn fold_fn_decl(&mut self, decl: &ast::FnDecl) -> ast::P { let decl = fold::noop_fold_fn_decl(decl, self); for a in decl.inputs.iter() { self.insert(a.id, EntryArg(self.parent, a.pat)); @@ -572,28 +572,28 @@ impl<'a, F: FoldOps> Folder for Ctx<'a, F> { decl } - fn fold_block(&mut self, block: P) -> P { + fn fold_block(&mut self, block: ast::P) -> ast::P { let block = fold::noop_fold_block(block, self); self.insert(block.id, EntryBlock(self.parent, block)); block } - fn fold_lifetime(&mut self, lifetime: &Lifetime) -> Lifetime { + fn fold_lifetime(&mut self, lifetime: &ast::Lifetime) -> ast::Lifetime { let lifetime = fold::noop_fold_lifetime(lifetime, self); self.insert(lifetime.id, EntryLifetime(self.parent, @lifetime)); lifetime } } -pub fn map_crate(krate: Crate, fold_ops: F) -> (Crate, Map) { +pub fn map_crate(krate: ast::Crate, fold_ops: F) -> (ast::Crate, Map) { let map = Map { map: RefCell::new(Vec::new()) }; let krate = { let mut cx = Ctx { map: &map, - parent: CRATE_NODE_ID, + parent: ast::CRATE_NODE_ID, fold_ops: fold_ops }; - cx.insert(CRATE_NODE_ID, RootCrate); + cx.insert(ast::CRATE_NODE_ID, RootCrate); cx.fold_crate(krate) }; @@ -623,39 +623,39 @@ pub fn map_crate(krate: Crate, fold_ops: F) -> (Crate, Map) { pub fn map_decoded_item(map: &Map, path: Vec , fold_ops: F, - fold: |&mut Ctx| -> InlinedItem) - -> InlinedItem { + fold: |&mut Ctx| -> ast::InlinedItem) + -> ast::InlinedItem { let mut cx = Ctx { map: map, - parent: DUMMY_NODE_ID, + parent: ast::DUMMY_NODE_ID, fold_ops: fold_ops }; // Generate a NodeId for the RootInlinedParent inserted below. - cx.new_id(DUMMY_NODE_ID); + cx.new_id(ast::DUMMY_NODE_ID); // Methods get added to the AST map when their impl is visited. Since we // don't decode and instantiate the impl, but just the method, we have to // add it to the table now. Likewise with foreign items. - let mut def_id = DefId { krate: LOCAL_CRATE, node: DUMMY_NODE_ID }; + let mut def_id = ast::DefId { krate: ast::LOCAL_CRATE, node: ast::DUMMY_NODE_ID }; let ii = fold(&mut cx); match ii { - IIItem(_) => {} - IIMethod(impl_did, is_provided, m) => { + ast::IIItem(_) => {} + ast::IIMethod(impl_did, is_provided, m) => { let entry = if is_provided { - EntryTraitMethod(cx.parent, @Provided(m)) + EntryTraitMethod(cx.parent, @ast::Provided(m)) } else { EntryMethod(cx.parent, m) }; cx.insert(m.id, entry); def_id = impl_did; } - IIForeign(i) => { + ast::IIForeign(i) => { cx.insert(i.id, EntryForeignItem(cx.parent, i)); } } - cx.insert(cx.parent, RootInlinedParent(P(InlinedParent { + cx.insert(cx.parent, RootInlinedParent(ast::P(InlinedParent { path: path, def_id: def_id }))); @@ -663,21 +663,21 @@ pub fn map_decoded_item(map: &Map, ii } -fn node_id_to_str(map: &Map, id: NodeId) -> String { +fn node_id_to_str(map: &Map, id: ast::NodeId) -> String { match map.find(id) { Some(NodeItem(item)) => { let path_str = map.path_to_str_with_ident(id, item.ident); let item_str = match item.node { - ItemStatic(..) => "static", - ItemFn(..) => "fn", - ItemMod(..) => "mod", - ItemForeignMod(..) => "foreign mod", - ItemTy(..) => "ty", - ItemEnum(..) => "enum", - ItemStruct(..) => "struct", - ItemTrait(..) => "trait", - ItemImpl(..) => "impl", - ItemMac(..) => "macro" + ast::ItemStatic(..) => "static", + ast::ItemFn(..) => "fn", + ast::ItemMod(..) => "mod", + ast::ItemForeignMod(..) => "foreign mod", + ast::ItemTy(..) => "ty", + ast::ItemEnum(..) => "enum", + ast::ItemStruct(..) => "struct", + ast::ItemTrait(..) => "trait", + ast::ItemImpl(..) => "impl", + ast::ItemMac(..) => "macro" }; (format!("{} {} (id={})", item_str, path_str, id)).to_string() } diff --git a/src/libsyntax/ast_util.rs b/src/libsyntax/ast_util.rs index e4f2f7f26cf0d..42c28b5850e09 100644 --- a/src/libsyntax/ast_util.rs +++ b/src/libsyntax/ast_util.rs @@ -8,7 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use ast::*; use ast; use ast_util; use codemap; @@ -21,10 +20,9 @@ use visit; use std::cell::Cell; use std::cmp; -use std::string::String; use std::u32; -pub fn path_name_i(idents: &[Ident]) -> String { +pub fn path_name_i(idents: &[ast::Ident]) -> String { // FIXME: Bad copies (#2543 -- same for everything else that says "bad") idents.iter().map(|i| { token::get_ident(*i).get().to_string() @@ -33,103 +31,103 @@ pub fn path_name_i(idents: &[Ident]) -> String { // totally scary function: ignores all but the last element, should have // a different name -pub fn path_to_ident(path: &Path) -> Ident { +pub fn path_to_ident(path: &ast::Path) -> ast::Ident { path.segments.last().unwrap().identifier } -pub fn local_def(id: NodeId) -> DefId { - ast::DefId { krate: LOCAL_CRATE, node: id } +pub fn local_def(id: ast::NodeId) -> ast::DefId { + ast::DefId { krate: ast::LOCAL_CRATE, node: id } } -pub fn is_local(did: ast::DefId) -> bool { did.krate == LOCAL_CRATE } +pub fn is_local(did: ast::DefId) -> bool { did.krate == ast::LOCAL_CRATE } -pub fn stmt_id(s: &Stmt) -> NodeId { +pub fn stmt_id(s: &ast::Stmt) -> ast::NodeId { match s.node { - StmtDecl(_, id) => id, - StmtExpr(_, id) => id, - StmtSemi(_, id) => id, - StmtMac(..) => fail!("attempted to analyze unexpanded stmt") + ast::StmtDecl(_, id) => id, + ast::StmtExpr(_, id) => id, + ast::StmtSemi(_, id) => id, + ast::StmtMac(..) => fail!("attempted to analyze unexpanded stmt") } } -pub fn variant_def_ids(d: Def) -> Option<(DefId, DefId)> { +pub fn variant_def_ids(d: ast::Def) -> Option<(ast::DefId, ast::DefId)> { match d { - DefVariant(enum_id, var_id, _) => { + ast::DefVariant(enum_id, var_id, _) => { Some((enum_id, var_id)) } _ => None } } -pub fn def_id_of_def(d: Def) -> DefId { +pub fn def_id_of_def(d: ast::Def) -> ast::DefId { match d { - DefFn(id, _) | DefStaticMethod(id, _, _) | DefMod(id) | - DefForeignMod(id) | DefStatic(id, _) | - DefVariant(_, id, _) | DefTy(id) | DefTyParam(id, _) | - DefUse(id) | DefStruct(id) | DefTrait(id) | DefMethod(id, _) => { + ast::DefFn(id, _) | ast::DefStaticMethod(id, _, _) | ast::DefMod(id) | + ast::DefForeignMod(id) | ast::DefStatic(id, _) | + ast::DefVariant(_, id, _) | ast::DefTy(id) | ast::DefTyParam(id, _) | + ast::DefUse(id) | ast::DefStruct(id) | ast::DefTrait(id) | ast::DefMethod(id, _) => { id } - DefArg(id, _) | DefLocal(id, _) | DefSelfTy(id) - | DefUpvar(id, _, _, _) | DefBinding(id, _) | DefRegion(id) - | DefTyParamBinder(id) | DefLabel(id) => { + ast::DefArg(id, _) | ast::DefLocal(id, _) | ast::DefSelfTy(id) | + ast::DefUpvar(id, _, _, _) | ast::DefBinding(id, _) | ast::DefRegion(id) | + ast::DefTyParamBinder(id) | ast::DefLabel(id) => { local_def(id) } - DefPrimTy(_) => fail!() + ast::DefPrimTy(_) => fail!() } } -pub fn binop_to_str(op: BinOp) -> &'static str { +pub fn binop_to_str(op: ast::BinOp) -> &'static str { match op { - BiAdd => "+", - BiSub => "-", - BiMul => "*", - BiDiv => "/", - BiRem => "%", - BiAnd => "&&", - BiOr => "||", - BiBitXor => "^", - BiBitAnd => "&", - BiBitOr => "|", - BiShl => "<<", - BiShr => ">>", - BiEq => "==", - BiLt => "<", - BiLe => "<=", - BiNe => "!=", - BiGe => ">=", - BiGt => ">" - } -} - -pub fn lazy_binop(b: BinOp) -> bool { + ast::BiAdd => "+", + ast::BiSub => "-", + ast::BiMul => "*", + ast::BiDiv => "/", + ast::BiRem => "%", + ast::BiAnd => "&&", + ast::BiOr => "||", + ast::BiBitXor => "^", + ast::BiBitAnd => "&", + ast::BiBitOr => "|", + ast::BiShl => "<<", + ast::BiShr => ">>", + ast::BiEq => "==", + ast::BiLt => "<", + ast::BiLe => "<=", + ast::BiNe => "!=", + ast::BiGe => ">=", + ast::BiGt => ">" + } +} + +pub fn lazy_binop(b: ast::BinOp) -> bool { match b { - BiAnd => true, - BiOr => true, + ast::BiAnd => true, + ast::BiOr => true, _ => false } } -pub fn is_shift_binop(b: BinOp) -> bool { +pub fn is_shift_binop(b: ast::BinOp) -> bool { match b { - BiShl => true, - BiShr => true, + ast::BiShl => true, + ast::BiShr => true, _ => false } } -pub fn unop_to_str(op: UnOp) -> &'static str { +pub fn unop_to_str(op: ast::UnOp) -> &'static str { match op { - UnBox => "@", - UnUniq => "box() ", - UnDeref => "*", - UnNot => "!", - UnNeg => "-", + ast::UnBox => "@", + ast::UnUniq => "box() ", + ast::UnDeref => "*", + ast::UnNot => "!", + ast::UnNeg => "-", } } -pub fn is_path(e: @Expr) -> bool { - return match e.node { ExprPath(_) => true, _ => false }; +pub fn is_path(e: @ast::Expr) -> bool { + return match e.node { ast::ExprPath(_) => true, _ => false }; } pub enum SuffixMode { @@ -139,17 +137,17 @@ pub enum SuffixMode { // Get a string representation of a signed int type, with its value. // We want to avoid "45int" and "-3int" in favor of "45" and "-3" -pub fn int_ty_to_str(t: IntTy, val: Option, mode: SuffixMode) -> String { +pub fn int_ty_to_str(t: ast::IntTy, val: Option, mode: SuffixMode) -> String { let s = match t { - TyI if val.is_some() => match mode { + ast::TyI if val.is_some() => match mode { AutoSuffix => "", ForceSuffix => "i", }, - TyI => "int", - TyI8 => "i8", - TyI16 => "i16", - TyI32 => "i32", - TyI64 => "i64" + ast::TyI => "int", + ast::TyI8 => "i8", + ast::TyI16 => "i16", + ast::TyI32 => "i32", + ast::TyI64 => "i64" }; match val { @@ -161,28 +159,28 @@ pub fn int_ty_to_str(t: IntTy, val: Option, mode: SuffixMode) -> String { } } -pub fn int_ty_max(t: IntTy) -> u64 { +pub fn int_ty_max(t: ast::IntTy) -> u64 { match t { - TyI8 => 0x80u64, - TyI16 => 0x8000u64, - TyI | TyI32 => 0x80000000u64, // actually ni about TyI - TyI64 => 0x8000000000000000u64 + ast::TyI8 => 0x80u64, + ast::TyI16 => 0x8000u64, + ast::TyI | ast::TyI32 => 0x80000000u64, // actually ni about TyI + ast::TyI64 => 0x8000000000000000u64 } } // Get a string representation of an unsigned int type, with its value. // We want to avoid "42uint" in favor of "42u" -pub fn uint_ty_to_str(t: UintTy, val: Option, mode: SuffixMode) -> String { +pub fn uint_ty_to_str(t: ast::UintTy, val: Option, mode: SuffixMode) -> String { let s = match t { - TyU if val.is_some() => match mode { + ast::TyU if val.is_some() => match mode { AutoSuffix => "", ForceSuffix => "u", }, - TyU => "uint", - TyU8 => "u8", - TyU16 => "u16", - TyU32 => "u32", - TyU64 => "u64" + ast::TyU => "uint", + ast::TyU8 => "u8", + ast::TyU16 => "u16", + ast::TyU32 => "u32", + ast::TyU64 => "u64" }; match val { @@ -191,39 +189,39 @@ pub fn uint_ty_to_str(t: UintTy, val: Option, mode: SuffixMode) -> String { } } -pub fn uint_ty_max(t: UintTy) -> u64 { +pub fn uint_ty_max(t: ast::UintTy) -> u64 { match t { - TyU8 => 0xffu64, - TyU16 => 0xffffu64, - TyU | TyU32 => 0xffffffffu64, // actually ni about TyU - TyU64 => 0xffffffffffffffffu64 + ast::TyU8 => 0xffu64, + ast::TyU16 => 0xffffu64, + ast::TyU | ast::TyU32 => 0xffffffffu64, // actually ni about TyU + ast::TyU64 => 0xffffffffffffffffu64 } } -pub fn float_ty_to_str(t: FloatTy) -> String { +pub fn float_ty_to_str(t: ast::FloatTy) -> String { match t { - TyF32 => "f32".to_string(), - TyF64 => "f64".to_string(), - TyF128 => "f128".to_string(), + ast::TyF32 => "f32".to_string(), + ast::TyF64 => "f64".to_string(), + ast::TyF128 => "f128".to_string(), } } -pub fn is_call_expr(e: @Expr) -> bool { - match e.node { ExprCall(..) => true, _ => false } +pub fn is_call_expr(e: @ast::Expr) -> bool { + match e.node { ast::ExprCall(..) => true, _ => false } } -pub fn block_from_expr(e: @Expr) -> P { - P(Block { +pub fn block_from_expr(e: @ast::Expr) -> ast::P { + ast::P(ast::Block { view_items: Vec::new(), stmts: Vec::new(), expr: Some(e), id: e.id, - rules: DefaultBlock, + rules: ast::DefaultBlock, span: e.span }) } -pub fn ident_to_path(s: Span, identifier: Ident) -> Path { +pub fn ident_to_path(s: Span, identifier: ast::Ident) -> ast::Path { ast::Path { span: s, global: false, @@ -237,26 +235,26 @@ pub fn ident_to_path(s: Span, identifier: Ident) -> Path { } } -pub fn ident_to_pat(id: NodeId, s: Span, i: Ident) -> @Pat { +pub fn ident_to_pat(id: ast::NodeId, s: Span, i: ast::Ident) -> @ast::Pat { @ast::Pat { id: id, - node: PatIdent(BindByValue(MutImmutable), ident_to_path(s, i), None), + node: ast::PatIdent(ast::BindByValue(ast::MutImmutable), ident_to_path(s, i), None), span: s } } -pub fn name_to_dummy_lifetime(name: Name) -> Lifetime { - Lifetime { id: DUMMY_NODE_ID, - span: codemap::DUMMY_SP, - name: name } +pub fn name_to_dummy_lifetime(name: ast::Name) -> ast::Lifetime { + ast::Lifetime { id: ast::DUMMY_NODE_ID, + span: codemap::DUMMY_SP, + name: name } } -pub fn is_unguarded(a: &Arm) -> bool { +pub fn is_unguarded(a: &ast::Arm) -> bool { match a.guard { None => true, _ => false } } -pub fn unguarded_pat(a: &Arm) -> Option > { +pub fn unguarded_pat(a: &ast::Arm) -> Option > { if is_unguarded(a) { Some(/* FIXME (#2543) */ a.pats.clone()) } else { @@ -269,7 +267,7 @@ pub fn unguarded_pat(a: &Arm) -> Option > { /// hint of where they came from, (previously they would all just be /// listed as `__extensions__::method_name::hash`, with no indication /// of the type). -pub fn impl_pretty_name(trait_ref: &Option, ty: &Ty) -> Ident { +pub fn impl_pretty_name(trait_ref: &Option, ty: &ast::Ty) -> ast::Ident { let mut pretty = pprust::ty_to_str(ty); match *trait_ref { Some(ref trait_ref) => { @@ -281,10 +279,10 @@ pub fn impl_pretty_name(trait_ref: &Option, ty: &Ty) -> Ident { token::gensym_ident(pretty.as_slice()) } -pub fn public_methods(ms: Vec<@Method> ) -> Vec<@Method> { +pub fn public_methods(ms: Vec<@ast::Method> ) -> Vec<@ast::Method> { ms.move_iter().filter(|m| { match m.vis { - Public => true, + ast::Public => true, _ => false } }).collect() @@ -292,11 +290,11 @@ pub fn public_methods(ms: Vec<@Method> ) -> Vec<@Method> { // extract a TypeMethod from a TraitMethod. if the TraitMethod is // a default, pull out the useful fields to make a TypeMethod -pub fn trait_method_to_ty_method(method: &TraitMethod) -> TypeMethod { +pub fn trait_method_to_ty_method(method: &ast::TraitMethod) -> ast::TypeMethod { match *method { - Required(ref m) => (*m).clone(), - Provided(ref m) => { - TypeMethod { + ast::Required(ref m) => (*m).clone(), + ast::Provided(ref m) => { + ast::TypeMethod { ident: m.ident, attrs: m.attrs.clone(), fn_style: m.fn_style, @@ -311,20 +309,20 @@ pub fn trait_method_to_ty_method(method: &TraitMethod) -> TypeMethod { } } -pub fn split_trait_methods(trait_methods: &[TraitMethod]) - -> (Vec , Vec<@Method> ) { +pub fn split_trait_methods(trait_methods: &[ast::TraitMethod]) + -> (Vec , Vec<@ast::Method> ) { let mut reqd = Vec::new(); let mut provd = Vec::new(); for trt_method in trait_methods.iter() { match *trt_method { - Required(ref tm) => reqd.push((*tm).clone()), - Provided(m) => provd.push(m) + ast::Required(ref tm) => reqd.push((*tm).clone()), + ast::Provided(m) => provd.push(m) } }; (reqd, provd) } -pub fn struct_field_visibility(field: ast::StructField) -> Visibility { +pub fn struct_field_visibility(field: ast::StructField) -> ast::Visibility { match field.node.kind { ast::NamedField(_, v) | ast::UnnamedField(v) => v } @@ -334,16 +332,16 @@ pub fn struct_field_visibility(field: ast::StructField) -> Visibility { pub fn operator_prec(op: ast::BinOp) -> uint { match op { // 'as' sits here with 12 - BiMul | BiDiv | BiRem => 11u, - BiAdd | BiSub => 10u, - BiShl | BiShr => 9u, - BiBitAnd => 8u, - BiBitXor => 7u, - BiBitOr => 6u, - BiLt | BiLe | BiGe | BiGt => 4u, - BiEq | BiNe => 3u, - BiAnd => 2u, - BiOr => 1u + ast::BiMul | ast::BiDiv | ast::BiRem => 11u, + ast::BiAdd | ast::BiSub => 10u, + ast::BiShl | ast::BiShr => 9u, + ast::BiBitAnd => 8u, + ast::BiBitXor => 7u, + ast::BiBitOr => 6u, + ast::BiLt | ast::BiLe | ast::BiGe | ast::BiGt => 4u, + ast::BiEq | ast::BiNe => 3u, + ast::BiAnd => 2u, + ast::BiOr => 1u } } @@ -351,8 +349,8 @@ pub fn operator_prec(op: ast::BinOp) -> uint { /// not appearing in the prior table. pub static as_prec: uint = 12u; -pub fn empty_generics() -> Generics { - Generics {lifetimes: Vec::new(), +pub fn empty_generics() -> ast::Generics { + ast::Generics {lifetimes: Vec::new(), ty_params: OwnedSlice::empty()} } @@ -361,8 +359,8 @@ pub fn empty_generics() -> Generics { #[deriving(Encodable, Decodable)] pub struct IdRange { - pub min: NodeId, - pub max: NodeId, + pub min: ast::NodeId, + pub max: ast::NodeId, } impl IdRange { @@ -377,14 +375,14 @@ impl IdRange { self.min >= self.max } - pub fn add(&mut self, id: NodeId) { + pub fn add(&mut self, id: ast::NodeId) { self.min = cmp::min(self.min, id); self.max = cmp::max(self.max, id + 1); } } pub trait IdVisitingOperation { - fn visit_id(&self, node_id: NodeId); + fn visit_id(&self, node_id: ast::NodeId); } pub struct IdVisitor<'a, O> { @@ -394,7 +392,7 @@ pub struct IdVisitor<'a, O> { } impl<'a, O: IdVisitingOperation> IdVisitor<'a, O> { - fn visit_generics_helper(&self, generics: &Generics) { + fn visit_generics_helper(&self, generics: &ast::Generics) { for type_parameter in generics.ty_params.iter() { self.operation.visit_id(type_parameter.id) } @@ -406,15 +404,15 @@ impl<'a, O: IdVisitingOperation> IdVisitor<'a, O> { impl<'a, O: IdVisitingOperation> Visitor<()> for IdVisitor<'a, O> { fn visit_mod(&mut self, - module: &Mod, + module: &ast::Mod, _: Span, - node_id: NodeId, + node_id: ast::NodeId, env: ()) { self.operation.visit_id(node_id); visit::walk_mod(self, module, env) } - fn visit_view_item(&mut self, view_item: &ViewItem, env: ()) { + fn visit_view_item(&mut self, view_item: &ast::ViewItem, env: ()) { if !self.pass_through_items { if self.visited_outermost { return; @@ -423,16 +421,16 @@ impl<'a, O: IdVisitingOperation> Visitor<()> for IdVisitor<'a, O> { } } match view_item.node { - ViewItemExternCrate(_, _, node_id) => { + ast::ViewItemExternCrate(_, _, node_id) => { self.operation.visit_id(node_id) } - ViewItemUse(ref view_path) => { + ast::ViewItemUse(ref view_path) => { match view_path.node { - ViewPathSimple(_, _, node_id) | - ViewPathGlob(_, node_id) => { + ast::ViewPathSimple(_, _, node_id) | + ast::ViewPathGlob(_, node_id) => { self.operation.visit_id(node_id) } - ViewPathList(_, ref paths, node_id) => { + ast::ViewPathList(_, ref paths, node_id) => { self.operation.visit_id(node_id); for path in paths.iter() { self.operation.visit_id(path.node.id) @@ -445,12 +443,12 @@ impl<'a, O: IdVisitingOperation> Visitor<()> for IdVisitor<'a, O> { self.visited_outermost = false; } - fn visit_foreign_item(&mut self, foreign_item: &ForeignItem, env: ()) { + fn visit_foreign_item(&mut self, foreign_item: &ast::ForeignItem, env: ()) { self.operation.visit_id(foreign_item.id); visit::walk_foreign_item(self, foreign_item, env) } - fn visit_item(&mut self, item: &Item, env: ()) { + fn visit_item(&mut self, item: &ast::Item, env: ()) { if !self.pass_through_items { if self.visited_outermost { return @@ -461,7 +459,7 @@ impl<'a, O: IdVisitingOperation> Visitor<()> for IdVisitor<'a, O> { self.operation.visit_id(item.id); match item.node { - ItemEnum(ref enum_definition, _) => { + ast::ItemEnum(ref enum_definition, _) => { for variant in enum_definition.variants.iter() { self.operation.visit_id(variant.node.id) } @@ -474,51 +472,51 @@ impl<'a, O: IdVisitingOperation> Visitor<()> for IdVisitor<'a, O> { self.visited_outermost = false } - fn visit_local(&mut self, local: &Local, env: ()) { + fn visit_local(&mut self, local: &ast::Local, env: ()) { self.operation.visit_id(local.id); visit::walk_local(self, local, env) } - fn visit_block(&mut self, block: &Block, env: ()) { + fn visit_block(&mut self, block: &ast::Block, env: ()) { self.operation.visit_id(block.id); visit::walk_block(self, block, env) } - fn visit_stmt(&mut self, statement: &Stmt, env: ()) { + fn visit_stmt(&mut self, statement: &ast::Stmt, env: ()) { self.operation.visit_id(ast_util::stmt_id(statement)); visit::walk_stmt(self, statement, env) } - fn visit_pat(&mut self, pattern: &Pat, env: ()) { + fn visit_pat(&mut self, pattern: &ast::Pat, env: ()) { self.operation.visit_id(pattern.id); visit::walk_pat(self, pattern, env) } - fn visit_expr(&mut self, expression: &Expr, env: ()) { + fn visit_expr(&mut self, expression: &ast::Expr, env: ()) { self.operation.visit_id(expression.id); visit::walk_expr(self, expression, env) } - fn visit_ty(&mut self, typ: &Ty, env: ()) { + fn visit_ty(&mut self, typ: &ast::Ty, env: ()) { self.operation.visit_id(typ.id); match typ.node { - TyPath(_, _, id) => self.operation.visit_id(id), + ast::TyPath(_, _, id) => self.operation.visit_id(id), _ => {} } visit::walk_ty(self, typ, env) } - fn visit_generics(&mut self, generics: &Generics, env: ()) { + fn visit_generics(&mut self, generics: &ast::Generics, env: ()) { self.visit_generics_helper(generics); visit::walk_generics(self, generics, env) } fn visit_fn(&mut self, function_kind: &visit::FnKind, - function_declaration: &FnDecl, - block: &Block, + function_declaration: &ast::FnDecl, + block: &ast::Block, span: Span, - node_id: NodeId, + node_id: ast::NodeId, env: ()) { if !self.pass_through_items { match *function_kind { @@ -557,16 +555,16 @@ impl<'a, O: IdVisitingOperation> Visitor<()> for IdVisitor<'a, O> { } } - fn visit_struct_field(&mut self, struct_field: &StructField, env: ()) { + fn visit_struct_field(&mut self, struct_field: &ast::StructField, env: ()) { self.operation.visit_id(struct_field.node.id); visit::walk_struct_field(self, struct_field, env) } fn visit_struct_def(&mut self, - struct_def: &StructDef, + struct_def: &ast::StructDef, _: ast::Ident, _: &ast::Generics, - id: NodeId, + id: ast::NodeId, _: ()) { self.operation.visit_id(id); struct_def.ctor_id.map(|ctor_id| self.operation.visit_id(ctor_id)); @@ -582,7 +580,7 @@ impl<'a, O: IdVisitingOperation> Visitor<()> for IdVisitor<'a, O> { } } -pub fn visit_ids_for_inlined_item(item: &InlinedItem, +pub fn visit_ids_for_inlined_item(item: &ast::InlinedItem, operation: &O) { let mut id_visitor = IdVisitor { operation: operation, @@ -598,14 +596,14 @@ struct IdRangeComputingVisitor { } impl IdVisitingOperation for IdRangeComputingVisitor { - fn visit_id(&self, id: NodeId) { + fn visit_id(&self, id: ast::NodeId) { let mut id_range = self.result.get(); id_range.add(id); self.result.set(id_range) } } -pub fn compute_id_range_for_inlined_item(item: &InlinedItem) -> IdRange { +pub fn compute_id_range_for_inlined_item(item: &ast::InlinedItem) -> IdRange { let visitor = IdRangeComputingVisitor { result: Cell::new(IdRange::max()) }; @@ -614,10 +612,10 @@ pub fn compute_id_range_for_inlined_item(item: &InlinedItem) -> IdRange { } pub fn compute_id_range_for_fn_body(fk: &visit::FnKind, - decl: &FnDecl, - body: &Block, + decl: &ast::FnDecl, + body: &ast::Block, sp: Span, - id: NodeId) + id: ast::NodeId) -> IdRange { /*! @@ -639,35 +637,35 @@ pub fn compute_id_range_for_fn_body(fk: &visit::FnKind, pub fn is_item_impl(item: @ast::Item) -> bool { match item.node { - ItemImpl(..) => true, - _ => false + ast::ItemImpl(..) => true, + _ => false } } -pub fn walk_pat(pat: &Pat, it: |&Pat| -> bool) -> bool { +pub fn walk_pat(pat: &ast::Pat, it: |&ast::Pat| -> bool) -> bool { if !it(pat) { return false; } match pat.node { - PatIdent(_, _, Some(p)) => walk_pat(p, it), - PatStruct(_, ref fields, _) => { + ast::PatIdent(_, _, Some(p)) => walk_pat(p, it), + ast::PatStruct(_, ref fields, _) => { fields.iter().advance(|f| walk_pat(f.pat, |p| it(p))) } - PatEnum(_, Some(ref s)) | PatTup(ref s) => { + ast::PatEnum(_, Some(ref s)) | ast::PatTup(ref s) => { s.iter().advance(|&p| walk_pat(p, |p| it(p))) } - PatBox(s) | PatRegion(s) => { + ast::PatBox(s) | ast::PatRegion(s) => { walk_pat(s, it) } - PatVec(ref before, ref slice, ref after) => { + ast::PatVec(ref before, ref slice, ref after) => { before.iter().advance(|&p| walk_pat(p, |p| it(p))) && slice.iter().advance(|&p| walk_pat(p, |p| it(p))) && after.iter().advance(|&p| walk_pat(p, |p| it(p))) } - PatMac(_) => fail!("attempted to analyze unexpanded pattern"), - PatWild | PatWildMulti | PatLit(_) | PatRange(_, _) | PatIdent(_, _, _) | - PatEnum(_, _) => { + ast::PatMac(_) => fail!("attempted to analyze unexpanded pattern"), + ast::PatWild | ast::PatWildMulti | ast::PatLit(_) | ast::PatRange(_, _) | + ast::PatIdent(_, _, _) | ast::PatEnum(_, _) => { true } } @@ -697,10 +695,10 @@ impl EachViewItem for ast::Crate { } } -pub fn view_path_id(p: &ViewPath) -> NodeId { +pub fn view_path_id(p: &ast::ViewPath) -> ast::NodeId { match p.node { - ViewPathSimple(_, _, id) | ViewPathGlob(_, id) - | ViewPathList(_, _, id) => id + ast::ViewPathSimple(_, _, id) | ast::ViewPathGlob(_, id) | + ast::ViewPathList(_, _, id) => id } } @@ -747,14 +745,14 @@ pub fn segments_name_eq(a : &[ast::PathSegment], b : &[ast::PathSegment]) -> boo } // Returns true if this literal is a string and false otherwise. -pub fn lit_is_str(lit: @Lit) -> bool { +pub fn lit_is_str(lit: @ast::Lit) -> bool { match lit.node { - LitStr(..) => true, + ast::LitStr(..) => true, _ => false, } } -pub fn get_inner_tys(ty: P) -> Vec> { +pub fn get_inner_tys(ty: ast::P) -> Vec> { match ty.node { ast::TyRptr(_, mut_ty) | ast::TyPtr(mut_ty) => { vec!(mut_ty.ty) @@ -771,11 +769,9 @@ pub fn get_inner_tys(ty: P) -> Vec> { #[cfg(test)] mod test { - use ast::*; - use super::*; use owned_slice::OwnedSlice; - fn ident_to_segment(id : &Ident) -> PathSegment { + fn ident_to_segment(id : &ast::Ident) -> PathSegment { PathSegment {identifier:id.clone(), lifetimes: Vec::new(), types: OwnedSlice::empty()} @@ -783,14 +779,14 @@ mod test { #[test] fn idents_name_eq_test() { assert!(segments_name_eq( - [Ident{name:3,ctxt:4}, Ident{name:78,ctxt:82}] + [ast::Ident{name:3,ctxt:4}, ast::Ident{name:78,ctxt:82}] .iter().map(ident_to_segment).collect::>().as_slice(), - [Ident{name:3,ctxt:104}, Ident{name:78,ctxt:182}] + [ast::Ident{name:3,ctxt:104}, ast::Ident{name:78,ctxt:182}] .iter().map(ident_to_segment).collect::>().as_slice())); assert!(!segments_name_eq( - [Ident{name:3,ctxt:4}, Ident{name:78,ctxt:82}] + [ast::Ident{name:3,ctxt:4}, ast::Ident{name:78,ctxt:82}] .iter().map(ident_to_segment).collect::>().as_slice(), - [Ident{name:3,ctxt:104}, Ident{name:77,ctxt:182}] + [ast::Ident{name:3,ctxt:104}, ast::Ident{name:77,ctxt:182}] .iter().map(ident_to_segment).collect::>().as_slice())); } } diff --git a/src/libsyntax/codemap.rs b/src/libsyntax/codemap.rs index f31d0d869404c..59cc841f44725 100644 --- a/src/libsyntax/codemap.rs +++ b/src/libsyntax/codemap.rs @@ -530,8 +530,6 @@ impl CodeMap { #[cfg(test)] mod test { - use super::*; - #[test] fn t1 () { let cm = CodeMap::new(); diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs index 8903eb80829b4..9cca2b4c5a97d 100644 --- a/src/libsyntax/fold.rs +++ b/src/libsyntax/fold.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use ast::*; +//use ast::*; use ast; use ast_util; use codemap::{respan, Span, Spanned}; @@ -20,44 +20,44 @@ use std::rc::Rc; // We may eventually want to be able to fold over type parameters, too. pub trait Folder { - fn fold_crate(&mut self, c: Crate) -> Crate { + fn fold_crate(&mut self, c: ast::Crate) -> ast::Crate { noop_fold_crate(c, self) } - fn fold_meta_items(&mut self, meta_items: &[@MetaItem]) -> Vec<@MetaItem> { + fn fold_meta_items(&mut self, meta_items: &[@ast::MetaItem]) -> Vec<@ast::MetaItem> { meta_items.iter().map(|x| fold_meta_item_(*x, self)).collect() } - fn fold_view_path(&mut self, view_path: @ViewPath) -> @ViewPath { + fn fold_view_path(&mut self, view_path: @ast::ViewPath) -> @ast::ViewPath { let inner_view_path = match view_path.node { - ViewPathSimple(ref ident, ref path, node_id) => { + ast::ViewPathSimple(ref ident, ref path, node_id) => { let id = self.new_id(node_id); - ViewPathSimple(ident.clone(), - self.fold_path(path), - id) + ast::ViewPathSimple(ident.clone(), + self.fold_path(path), + id) } - ViewPathGlob(ref path, node_id) => { + ast::ViewPathGlob(ref path, node_id) => { let id = self.new_id(node_id); - ViewPathGlob(self.fold_path(path), id) + ast::ViewPathGlob(self.fold_path(path), id) } - ViewPathList(ref path, ref path_list_idents, node_id) => { + ast::ViewPathList(ref path, ref path_list_idents, node_id) => { let id = self.new_id(node_id); - ViewPathList(self.fold_path(path), - path_list_idents.iter().map(|path_list_ident| { - let id = self.new_id(path_list_ident.node - .id); - Spanned { - node: PathListIdent_ { - name: path_list_ident.node - .name - .clone(), - id: id, - }, - span: self.new_span( - path_list_ident.span) - } - }).collect(), - id) + ast::ViewPathList(self.fold_path(path), + path_list_idents.iter().map(|path_list_ident| { + let id = self.new_id(path_list_ident.node + .id); + Spanned { + node: ast::PathListIdent_ { + name: path_list_ident.node + .name + .clone(), + id: id, + }, + span: self.new_span( + path_list_ident.span) + } + }).collect(), + id) } }; @Spanned { @@ -66,19 +66,19 @@ pub trait Folder { } } - fn fold_view_item(&mut self, vi: &ViewItem) -> ViewItem { + fn fold_view_item(&mut self, vi: &ast::ViewItem) -> ast::ViewItem { noop_fold_view_item(vi, self) } - fn fold_foreign_item(&mut self, ni: @ForeignItem) -> @ForeignItem { + fn fold_foreign_item(&mut self, ni: @ast::ForeignItem) -> @ast::ForeignItem { noop_fold_foreign_item(ni, self) } - fn fold_item(&mut self, i: @Item) -> SmallVector<@Item> { + fn fold_item(&mut self, i: @ast::Item) -> SmallVector<@ast::Item> { noop_fold_item(i, self) } - fn fold_struct_field(&mut self, sf: &StructField) -> StructField { + fn fold_struct_field(&mut self, sf: &ast::StructField) -> ast::StructField { let id = self.new_id(sf.node.id); Spanned { node: ast::StructField_ { @@ -91,32 +91,32 @@ pub trait Folder { } } - fn fold_item_underscore(&mut self, i: &Item_) -> Item_ { + fn fold_item_underscore(&mut self, i: &ast::Item_) -> ast::Item_ { noop_fold_item_underscore(i, self) } - fn fold_fn_decl(&mut self, d: &FnDecl) -> P { + fn fold_fn_decl(&mut self, d: &ast::FnDecl) -> ast::P { noop_fold_fn_decl(d, self) } - fn fold_type_method(&mut self, m: &TypeMethod) -> TypeMethod { + fn fold_type_method(&mut self, m: &ast::TypeMethod) -> ast::TypeMethod { noop_fold_type_method(m, self) } - fn fold_method(&mut self, m: @Method) -> @Method { + fn fold_method(&mut self, m: @ast::Method) -> @ast::Method { noop_fold_method(m, self) } - fn fold_block(&mut self, b: P) -> P { + fn fold_block(&mut self, b: ast::P) -> ast::P { noop_fold_block(b, self) } - fn fold_stmt(&mut self, s: &Stmt) -> SmallVector<@Stmt> { + fn fold_stmt(&mut self, s: &ast::Stmt) -> SmallVector<@ast::Stmt> { noop_fold_stmt(s, self) } - fn fold_arm(&mut self, a: &Arm) -> Arm { - Arm { + fn fold_arm(&mut self, a: &ast::Arm) -> ast::Arm { + ast::Arm { attrs: a.attrs.iter().map(|x| fold_attribute_(*x, self)).collect(), pats: a.pats.iter().map(|x| self.fold_pat(*x)).collect(), guard: a.guard.map(|x| self.fold_expr(x)), @@ -124,15 +124,15 @@ pub trait Folder { } } - fn fold_pat(&mut self, p: @Pat) -> @Pat { + fn fold_pat(&mut self, p: @ast::Pat) -> @ast::Pat { noop_fold_pat(p, self) } - fn fold_decl(&mut self, d: @Decl) -> SmallVector<@Decl> { + fn fold_decl(&mut self, d: @ast::Decl) -> SmallVector<@ast::Decl> { let node = match d.node { - DeclLocal(ref l) => SmallVector::one(DeclLocal(self.fold_local(*l))), - DeclItem(it) => { - self.fold_item(it).move_iter().map(|i| DeclItem(i)).collect() + ast::DeclLocal(ref l) => SmallVector::one(ast::DeclLocal(self.fold_local(*l))), + ast::DeclItem(it) => { + self.fold_item(it).move_iter().map(|i| ast::DeclItem(i)).collect() } }; @@ -144,23 +144,23 @@ pub trait Folder { }).collect() } - fn fold_expr(&mut self, e: @Expr) -> @Expr { + fn fold_expr(&mut self, e: @ast::Expr) -> @ast::Expr { noop_fold_expr(e, self) } - fn fold_ty(&mut self, t: P) -> P { + fn fold_ty(&mut self, t: ast::P) -> ast::P { let id = self.new_id(t.id); let node = match t.node { - TyNil | TyBot | TyInfer => t.node.clone(), - TyBox(ty) => TyBox(self.fold_ty(ty)), - TyUniq(ty) => TyUniq(self.fold_ty(ty)), - TyVec(ty) => TyVec(self.fold_ty(ty)), - TyPtr(ref mt) => TyPtr(fold_mt(mt, self)), - TyRptr(ref region, ref mt) => { - TyRptr(fold_opt_lifetime(region, self), fold_mt(mt, self)) + ast::TyNil | ast::TyBot | ast::TyInfer => t.node.clone(), + ast::TyBox(ty) => ast::TyBox(self.fold_ty(ty)), + ast::TyUniq(ty) => ast::TyUniq(self.fold_ty(ty)), + ast::TyVec(ty) => ast::TyVec(self.fold_ty(ty)), + ast::TyPtr(ref mt) => ast::TyPtr(fold_mt(mt, self)), + ast::TyRptr(ref region, ref mt) => { + ast::TyRptr(fold_opt_lifetime(region, self), fold_mt(mt, self)) } - TyClosure(ref f, ref region) => { - TyClosure(@ClosureTy { + ast::TyClosure(ref f, ref region) => { + ast::TyClosure(@ast::ClosureTy { fn_style: f.fn_style, onceness: f.onceness, bounds: fold_opt_bounds(&f.bounds, self), @@ -168,8 +168,8 @@ pub trait Folder { lifetimes: f.lifetimes.iter().map(|l| self.fold_lifetime(l)).collect(), }, fold_opt_lifetime(region, self)) } - TyProc(ref f) => { - TyProc(@ClosureTy { + ast::TyProc(ref f) => { + ast::TyProc(@ast::ClosureTy { fn_style: f.fn_style, onceness: f.onceness, bounds: fold_opt_bounds(&f.bounds, self), @@ -177,38 +177,38 @@ pub trait Folder { lifetimes: f.lifetimes.iter().map(|l| self.fold_lifetime(l)).collect(), }) } - TyBareFn(ref f) => { - TyBareFn(@BareFnTy { + ast::TyBareFn(ref f) => { + ast::TyBareFn(@ast::BareFnTy { lifetimes: f.lifetimes.iter().map(|l| self.fold_lifetime(l)).collect(), fn_style: f.fn_style, abi: f.abi, decl: self.fold_fn_decl(f.decl) }) } - TyTup(ref tys) => TyTup(tys.iter().map(|&ty| self.fold_ty(ty)).collect()), - TyPath(ref path, ref bounds, id) => { + ast::TyTup(ref tys) => ast::TyTup(tys.iter().map(|&ty| self.fold_ty(ty)).collect()), + ast::TyPath(ref path, ref bounds, id) => { let id = self.new_id(id); - TyPath(self.fold_path(path), - fold_opt_bounds(bounds, self), - id) + ast::TyPath(self.fold_path(path), + fold_opt_bounds(bounds, self), + id) } - TyFixedLengthVec(ty, e) => { - TyFixedLengthVec(self.fold_ty(ty), self.fold_expr(e)) + ast::TyFixedLengthVec(ty, e) => { + ast::TyFixedLengthVec(self.fold_ty(ty), self.fold_expr(e)) } - TyTypeof(expr) => TyTypeof(self.fold_expr(expr)), + ast::TyTypeof(expr) => ast::TyTypeof(self.fold_expr(expr)), }; - P(Ty { + ast::P(ast::Ty { id: id, span: self.new_span(t.span), node: node, }) } - fn fold_mod(&mut self, m: &Mod) -> Mod { + fn fold_mod(&mut self, m: &ast::Mod) -> ast::Mod { noop_fold_mod(m, self) } - fn fold_foreign_mod(&mut self, nm: &ForeignMod) -> ForeignMod { + fn fold_foreign_mod(&mut self, nm: &ast::ForeignMod) -> ast::ForeignMod { ast::ForeignMod { abi: nm.abi, view_items: nm.view_items @@ -222,16 +222,16 @@ pub trait Folder { } } - fn fold_variant(&mut self, v: &Variant) -> P { + fn fold_variant(&mut self, v: &ast::Variant) -> ast::P { let id = self.new_id(v.node.id); let kind; match v.node.kind { - TupleVariantKind(ref variant_args) => { - kind = TupleVariantKind(variant_args.iter().map(|x| + ast::TupleVariantKind(ref variant_args) => { + kind = ast::TupleVariantKind(variant_args.iter().map(|x| fold_variant_arg_(x, self)).collect()) } - StructVariantKind(ref struct_def) => { - kind = StructVariantKind(@ast::StructDef { + ast::StructVariantKind(ref struct_def) => { + kind = ast::StructVariantKind(@ast::StructDef { fields: struct_def.fields.iter() .map(|f| self.fold_struct_field(f)).collect(), ctor_id: struct_def.ctor_id.map(|c| self.new_id(c)), @@ -258,17 +258,17 @@ pub trait Folder { disr_expr: de, vis: v.node.vis, }; - P(Spanned { + ast::P(Spanned { node: node, span: self.new_span(v.span), }) } - fn fold_ident(&mut self, i: Ident) -> Ident { + fn fold_ident(&mut self, i: ast::Ident) -> ast::Ident { i } - fn fold_path(&mut self, p: &Path) -> Path { + fn fold_path(&mut self, p: &ast::Path) -> ast::Path { ast::Path { span: self.new_span(p.span), global: p.global, @@ -280,9 +280,9 @@ pub trait Folder { } } - fn fold_local(&mut self, l: @Local) -> @Local { + fn fold_local(&mut self, l: @ast::Local) -> @ast::Local { let id = self.new_id(l.id); // Needs to be first, for ast_map. - @Local { + @ast::Local { id: id, ty: self.fold_ty(l.ty), pat: self.fold_pat(l.pat), @@ -292,24 +292,24 @@ pub trait Folder { } } - fn fold_mac(&mut self, macro: &Mac) -> Mac { + fn fold_mac(&mut self, macro: &ast::Mac) -> ast::Mac { Spanned { node: match macro.node { - MacInvocTT(ref p, ref tts, ctxt) => { - MacInvocTT(self.fold_path(p), - fold_tts(tts.as_slice(), self), - ctxt) + ast::MacInvocTT(ref p, ref tts, ctxt) => { + ast::MacInvocTT(self.fold_path(p), + fold_tts(tts.as_slice(), self), + ctxt) } }, span: self.new_span(macro.span) } } - fn map_exprs(&self, f: |@Expr| -> @Expr, es: &[@Expr]) -> Vec<@Expr> { + fn map_exprs(&self, f: |@ast::Expr| -> @ast::Expr, es: &[@ast::Expr]) -> Vec<@ast::Expr> { es.iter().map(|x| f(*x)).collect() } - fn new_id(&mut self, i: NodeId) -> NodeId { + fn new_id(&mut self, i: ast::NodeId) -> ast::NodeId { i } @@ -317,23 +317,23 @@ pub trait Folder { sp } - fn fold_explicit_self(&mut self, es: &ExplicitSelf) -> ExplicitSelf { + fn fold_explicit_self(&mut self, es: &ast::ExplicitSelf) -> ast::ExplicitSelf { Spanned { span: self.new_span(es.span), node: self.fold_explicit_self_(&es.node) } } - fn fold_explicit_self_(&mut self, es: &ExplicitSelf_) -> ExplicitSelf_ { + fn fold_explicit_self_(&mut self, es: &ast::ExplicitSelf_) -> ast::ExplicitSelf_ { match *es { - SelfStatic | SelfValue | SelfUniq => *es, - SelfRegion(ref lifetime, m) => { - SelfRegion(fold_opt_lifetime(lifetime, self), m) + ast::SelfStatic | ast::SelfValue | ast::SelfUniq => *es, + ast::SelfRegion(ref lifetime, m) => { + ast::SelfRegion(fold_opt_lifetime(lifetime, self), m) } } } - fn fold_lifetime(&mut self, l: &Lifetime) -> Lifetime { + fn fold_lifetime(&mut self, l: &ast::Lifetime) -> ast::Lifetime { noop_fold_lifetime(l, self) } } @@ -341,23 +341,24 @@ pub trait Folder { /* some little folds that probably aren't useful to have in Folder itself*/ //used in noop_fold_item and noop_fold_crate and noop_fold_crate_directive -fn fold_meta_item_(mi: @MetaItem, fld: &mut T) -> @MetaItem { +fn fold_meta_item_(mi: @ast::MetaItem, fld: &mut T) -> @ast::MetaItem { @Spanned { node: match mi.node { - MetaWord(ref id) => MetaWord((*id).clone()), - MetaList(ref id, ref mis) => { - MetaList((*id).clone(), mis.iter().map(|e| fold_meta_item_(*e, fld)).collect()) + ast::MetaWord(ref id) => ast::MetaWord((*id).clone()), + ast::MetaList(ref id, ref mis) => { + ast::MetaList((*id).clone(), mis.iter() + .map(|e| fold_meta_item_(*e, fld)).collect()) } - MetaNameValue(ref id, ref s) => { - MetaNameValue((*id).clone(), (*s).clone()) + ast::MetaNameValue(ref id, ref s) => { + ast::MetaNameValue((*id).clone(), (*s).clone()) } }, span: fld.new_span(mi.span) } } //used in noop_fold_item and noop_fold_crate -fn fold_attribute_(at: Attribute, fld: &mut T) -> Attribute { +fn fold_attribute_(at: ast::Attribute, fld: &mut T) -> ast::Attribute { Spanned { span: fld.new_span(at.span), node: ast::Attribute_ { @@ -370,9 +371,9 @@ fn fold_attribute_(at: Attribute, fld: &mut T) -> Attribute { } //used in noop_fold_foreign_item and noop_fold_fn_decl -fn fold_arg_(a: &Arg, fld: &mut T) -> Arg { +fn fold_arg_(a: &ast::Arg, fld: &mut T) -> ast::Arg { let id = fld.new_id(a.id); // Needs to be first, for ast_map. - Arg { + ast::Arg { id: id, ty: fld.fold_ty(a.ty), pat: fld.fold_pat(a.pat), @@ -398,19 +399,19 @@ fn fold_arg_(a: &Arg, fld: &mut T) -> Arg { // since many token::IDENT are not necessary part of let bindings and most // token::LIFETIME are certainly not loop labels. But we can't tell in their // token form. So this is less ideal and hacky but it works. -pub fn fold_tts(tts: &[TokenTree], fld: &mut T) -> Vec { +pub fn fold_tts(tts: &[ast::TokenTree], fld: &mut T) -> Vec { tts.iter().map(|tt| { match *tt { - TTTok(span, ref tok) => - TTTok(span,maybe_fold_ident(tok,fld)), - TTDelim(ref tts) => TTDelim(Rc::new(fold_tts(tts.as_slice(), fld))), - TTSeq(span, ref pattern, ref sep, is_optional) => - TTSeq(span, + ast::TTTok(span, ref tok) => + ast::TTTok(span,maybe_fold_ident(tok,fld)), + ast::TTDelim(ref tts) => ast::TTDelim(Rc::new(fold_tts(tts.as_slice(), fld))), + ast::TTSeq(span, ref pattern, ref sep, is_optional) => + ast::TTSeq(span, Rc::new(fold_tts(pattern.as_slice(), fld)), sep.as_ref().map(|tok|maybe_fold_ident(tok,fld)), is_optional), - TTNonterminal(sp,ref ident) => - TTNonterminal(sp,fld.fold_ident(*ident)) + ast::TTNonterminal(sp,ref ident) => + ast::TTNonterminal(sp,fld.fold_ident(*ident)) } }).collect() } @@ -426,8 +427,8 @@ fn maybe_fold_ident(t: &token::Token, fld: &mut T) -> token::Token { } } -pub fn noop_fold_fn_decl(decl: &FnDecl, fld: &mut T) -> P { - P(FnDecl { +pub fn noop_fold_fn_decl(decl: &ast::FnDecl, fld: &mut T) -> ast::P { + ast::P(ast::FnDecl { inputs: decl.inputs.iter().map(|x| fold_arg_(x, fld)).collect(), // bad copy output: fld.fold_ty(decl.output), cf: decl.cf, @@ -435,18 +436,18 @@ pub fn noop_fold_fn_decl(decl: &FnDecl, fld: &mut T) -> P { }) } -fn fold_ty_param_bound(tpb: &TyParamBound, fld: &mut T) - -> TyParamBound { +fn fold_ty_param_bound(tpb: &ast::TyParamBound, fld: &mut T) + -> ast::TyParamBound { match *tpb { - TraitTyParamBound(ref ty) => TraitTyParamBound(fold_trait_ref(ty, fld)), - StaticRegionTyParamBound => StaticRegionTyParamBound, - OtherRegionTyParamBound(s) => OtherRegionTyParamBound(s) + ast::TraitTyParamBound(ref ty) => ast::TraitTyParamBound(fold_trait_ref(ty, fld)), + ast::StaticRegionTyParamBound => ast::StaticRegionTyParamBound, + ast::OtherRegionTyParamBound(s) => ast::OtherRegionTyParamBound(s) } } -pub fn fold_ty_param(tp: &TyParam, fld: &mut T) -> TyParam { +pub fn fold_ty_param(tp: &ast::TyParam, fld: &mut T) -> ast::TyParam { let id = fld.new_id(tp.id); - TyParam { + ast::TyParam { ident: tp.ident, id: id, sized: tp.sized, @@ -456,36 +457,36 @@ pub fn fold_ty_param(tp: &TyParam, fld: &mut T) -> TyParam { } } -pub fn fold_ty_params(tps: &OwnedSlice, fld: &mut T) - -> OwnedSlice { +pub fn fold_ty_params(tps: &OwnedSlice, fld: &mut T) + -> OwnedSlice { tps.map(|tp| fold_ty_param(tp, fld)) } -pub fn noop_fold_lifetime(l: &Lifetime, fld: &mut T) -> Lifetime { +pub fn noop_fold_lifetime(l: &ast::Lifetime, fld: &mut T) -> ast::Lifetime { let id = fld.new_id(l.id); - Lifetime { + ast::Lifetime { id: id, span: fld.new_span(l.span), name: l.name } } -pub fn fold_lifetimes(lts: &Vec, fld: &mut T) - -> Vec { +pub fn fold_lifetimes(lts: &Vec, fld: &mut T) + -> Vec { lts.iter().map(|l| fld.fold_lifetime(l)).collect() } -pub fn fold_opt_lifetime(o_lt: &Option, fld: &mut T) - -> Option { +pub fn fold_opt_lifetime(o_lt: &Option, fld: &mut T) + -> Option { o_lt.as_ref().map(|lt| fld.fold_lifetime(lt)) } -pub fn fold_generics(generics: &Generics, fld: &mut T) -> Generics { - Generics {ty_params: fold_ty_params(&generics.ty_params, fld), - lifetimes: fold_lifetimes(&generics.lifetimes, fld)} +pub fn fold_generics(generics: &ast::Generics, fld: &mut T) -> ast::Generics { + ast::Generics {ty_params: fold_ty_params(&generics.ty_params, fld), + lifetimes: fold_lifetimes(&generics.lifetimes, fld)} } -fn fold_struct_def(struct_def: @StructDef, fld: &mut T) -> @StructDef { +fn fold_struct_def(struct_def: @ast::StructDef, fld: &mut T) -> @ast::StructDef { @ast::StructDef { fields: struct_def.fields.iter().map(|f| fold_struct_field(f, fld)).collect(), ctor_id: struct_def.ctor_id.map(|cid| fld.new_id(cid)), @@ -497,7 +498,7 @@ fn fold_struct_def(struct_def: @StructDef, fld: &mut T) -> @StructDef } } -fn fold_trait_ref(p: &TraitRef, fld: &mut T) -> TraitRef { +fn fold_trait_ref(p: &ast::TraitRef, fld: &mut T) -> ast::TraitRef { let id = fld.new_id(p.ref_id); ast::TraitRef { path: fld.fold_path(&p.path), @@ -505,7 +506,7 @@ fn fold_trait_ref(p: &TraitRef, fld: &mut T) -> TraitRef { } } -fn fold_struct_field(f: &StructField, fld: &mut T) -> StructField { +fn fold_struct_field(f: &ast::StructField, fld: &mut T) -> ast::StructField { let id = fld.new_id(f.node.id); Spanned { node: ast::StructField_ { @@ -518,7 +519,7 @@ fn fold_struct_field(f: &StructField, fld: &mut T) -> StructField { } } -fn fold_field_(field: Field, folder: &mut T) -> Field { +fn fold_field_(field: ast::Field, folder: &mut T) -> ast::Field { ast::Field { ident: respan(field.ident.span, folder.fold_ident(field.ident.node)), expr: folder.fold_expr(field.expr), @@ -526,15 +527,15 @@ fn fold_field_(field: Field, folder: &mut T) -> Field { } } -fn fold_mt(mt: &MutTy, folder: &mut T) -> MutTy { - MutTy { +fn fold_mt(mt: &ast::MutTy, folder: &mut T) -> ast::MutTy { + ast::MutTy { ty: folder.fold_ty(mt.ty), mutbl: mt.mutbl, } } -fn fold_opt_bounds(b: &Option>, folder: &mut T) - -> Option> { +fn fold_opt_bounds(b: &Option>, folder: &mut T) + -> Option> { b.as_ref().map(|bounds| { bounds.map(|bound| { fold_ty_param_bound(bound, folder) @@ -542,7 +543,7 @@ fn fold_opt_bounds(b: &Option>, folder: &mut }) } -fn fold_variant_arg_(va: &VariantArg, folder: &mut T) -> VariantArg { +fn fold_variant_arg_(va: &ast::VariantArg, folder: &mut T) -> ast::VariantArg { let id = folder.new_id(va.id); ast::VariantArg { ty: folder.fold_ty(va.ty), @@ -550,19 +551,19 @@ fn fold_variant_arg_(va: &VariantArg, folder: &mut T) -> VariantArg { } } -pub fn noop_fold_view_item(vi: &ViewItem, folder: &mut T) - -> ViewItem{ +pub fn noop_fold_view_item(vi: &ast::ViewItem, folder: &mut T) + -> ast::ViewItem{ let inner_view_item = match vi.node { - ViewItemExternCrate(ref ident, ref string, node_id) => { - ViewItemExternCrate(ident.clone(), - (*string).clone(), - folder.new_id(node_id)) + ast::ViewItemExternCrate(ref ident, ref string, node_id) => { + ast::ViewItemExternCrate(ident.clone(), + (*string).clone(), + folder.new_id(node_id)) } - ViewItemUse(ref view_path) => { - ViewItemUse(folder.fold_view_path(*view_path)) + ast::ViewItemUse(ref view_path) => { + ast::ViewItemUse(folder.fold_view_path(*view_path)) } }; - ViewItem { + ast::ViewItem { node: inner_view_item, attrs: vi.attrs.iter().map(|a| fold_attribute_(*a, folder)).collect(), vis: vi.vis, @@ -570,11 +571,11 @@ pub fn noop_fold_view_item(vi: &ViewItem, folder: &mut T) } } -pub fn noop_fold_block(b: P, folder: &mut T) -> P { +pub fn noop_fold_block(b: ast::P, folder: &mut T) -> ast::P { let id = folder.new_id(b.id); // Needs to be first, for ast_map. let view_items = b.view_items.iter().map(|x| folder.fold_view_item(x)).collect(); let stmts = b.stmts.iter().flat_map(|s| folder.fold_stmt(*s).move_iter()).collect(); - P(Block { + ast::P(ast::Block { id: id, view_items: view_items, stmts: stmts, @@ -584,13 +585,13 @@ pub fn noop_fold_block(b: P, folder: &mut T) -> P { }) } -pub fn noop_fold_item_underscore(i: &Item_, folder: &mut T) -> Item_ { +pub fn noop_fold_item_underscore(i: &ast::Item_, folder: &mut T) -> ast::Item_ { match *i { - ItemStatic(t, m, e) => { - ItemStatic(folder.fold_ty(t), m, folder.fold_expr(e)) + ast::ItemStatic(t, m, e) => { + ast::ItemStatic(folder.fold_ty(t), m, folder.fold_expr(e)) } - ItemFn(decl, fn_style, abi, ref generics, body) => { - ItemFn( + ast::ItemFn(decl, fn_style, abi, ref generics, body) => { + ast::ItemFn( folder.fold_fn_decl(decl), fn_style, abi, @@ -598,13 +599,13 @@ pub fn noop_fold_item_underscore(i: &Item_, folder: &mut T) -> Item_ folder.fold_block(body) ) } - ItemMod(ref m) => ItemMod(folder.fold_mod(m)), - ItemForeignMod(ref nm) => ItemForeignMod(folder.fold_foreign_mod(nm)), - ItemTy(t, ref generics) => { - ItemTy(folder.fold_ty(t), fold_generics(generics, folder)) + ast::ItemMod(ref m) => ast::ItemMod(folder.fold_mod(m)), + ast::ItemForeignMod(ref nm) => ast::ItemForeignMod(folder.fold_foreign_mod(nm)), + ast::ItemTy(t, ref generics) => { + ast::ItemTy(folder.fold_ty(t), fold_generics(generics, folder)) } - ItemEnum(ref enum_definition, ref generics) => { - ItemEnum( + ast::ItemEnum(ref enum_definition, ref generics) => { + ast::ItemEnum( ast::EnumDef { variants: enum_definition.variants.iter().map(|&x| { folder.fold_variant(x) @@ -612,36 +613,36 @@ pub fn noop_fold_item_underscore(i: &Item_, folder: &mut T) -> Item_ }, fold_generics(generics, folder)) } - ItemStruct(ref struct_def, ref generics) => { + ast::ItemStruct(ref struct_def, ref generics) => { let struct_def = fold_struct_def(*struct_def, folder); - ItemStruct(struct_def, fold_generics(generics, folder)) + ast::ItemStruct(struct_def, fold_generics(generics, folder)) } - ItemImpl(ref generics, ref ifce, ty, ref methods) => { - ItemImpl(fold_generics(generics, folder), - ifce.as_ref().map(|p| fold_trait_ref(p, folder)), - folder.fold_ty(ty), - methods.iter().map(|x| folder.fold_method(*x)).collect() + ast::ItemImpl(ref generics, ref ifce, ty, ref methods) => { + ast::ItemImpl(fold_generics(generics, folder), + ifce.as_ref().map(|p| fold_trait_ref(p, folder)), + folder.fold_ty(ty), + methods.iter().map(|x| folder.fold_method(*x)).collect() ) } - ItemTrait(ref generics, ref sized, ref traits, ref methods) => { + ast::ItemTrait(ref generics, ref sized, ref traits, ref methods) => { let methods = methods.iter().map(|method| { match *method { - Required(ref m) => Required(folder.fold_type_method(m)), - Provided(method) => Provided(folder.fold_method(method)) + ast::Required(ref m) => ast::Required(folder.fold_type_method(m)), + ast::Provided(method) => ast::Provided(folder.fold_method(method)) } }).collect(); - ItemTrait(fold_generics(generics, folder), + ast::ItemTrait(fold_generics(generics, folder), *sized, traits.iter().map(|p| fold_trait_ref(p, folder)).collect(), methods) } - ItemMac(ref m) => ItemMac(folder.fold_mac(m)), + ast::ItemMac(ref m) => ast::ItemMac(folder.fold_mac(m)), } } -pub fn noop_fold_type_method(m: &TypeMethod, fld: &mut T) -> TypeMethod { +pub fn noop_fold_type_method(m: &ast::TypeMethod, fld: &mut T) -> ast::TypeMethod { let id = fld.new_id(m.id); // Needs to be first, for ast_map. - TypeMethod { + ast::TypeMethod { id: id, ident: fld.fold_ident(m.ident), attrs: m.attrs.iter().map(|a| fold_attribute_(*a, fld)).collect(), @@ -654,7 +655,7 @@ pub fn noop_fold_type_method(m: &TypeMethod, fld: &mut T) -> TypeMeth } } -pub fn noop_fold_mod(m: &Mod, folder: &mut T) -> Mod { +pub fn noop_fold_mod(m: &ast::Mod, folder: &mut T) -> ast::Mod { ast::Mod { inner: folder.new_span(m.inner), view_items: m.view_items @@ -664,8 +665,8 @@ pub fn noop_fold_mod(m: &Mod, folder: &mut T) -> Mod { } } -pub fn noop_fold_crate(c: Crate, folder: &mut T) -> Crate { - Crate { +pub fn noop_fold_crate(c: ast::Crate, folder: &mut T) -> ast::Crate { + ast::Crate { module: folder.fold_mod(&c.module), attrs: c.attrs.iter().map(|x| fold_attribute_(*x, folder)).collect(), config: c.config.iter().map(|x| fold_meta_item_(*x, folder)).collect(), @@ -673,18 +674,18 @@ pub fn noop_fold_crate(c: Crate, folder: &mut T) -> Crate { } } -pub fn noop_fold_item(i: &Item, folder: &mut T) -> SmallVector<@Item> { +pub fn noop_fold_item(i: &ast::Item, folder: &mut T) -> SmallVector<@ast::Item> { let id = folder.new_id(i.id); // Needs to be first, for ast_map. let node = folder.fold_item_underscore(&i.node); let ident = match node { // The node may have changed, recompute the "pretty" impl name. - ItemImpl(_, ref maybe_trait, ty, _) => { + ast::ItemImpl(_, ref maybe_trait, ty, _) => { ast_util::impl_pretty_name(maybe_trait, ty) } _ => i.ident }; - SmallVector::one(@Item { + SmallVector::one(@ast::Item { id: id, ident: folder.fold_ident(ident), attrs: i.attrs.iter().map(|e| fold_attribute_(*e, folder)).collect(), @@ -694,23 +695,24 @@ pub fn noop_fold_item(i: &Item, folder: &mut T) -> SmallVector<@Item> }) } -pub fn noop_fold_foreign_item(ni: &ForeignItem, folder: &mut T) -> @ForeignItem { +pub fn noop_fold_foreign_item(ni: &ast::ForeignItem, folder: &mut T) + -> @ast::ForeignItem { let id = folder.new_id(ni.id); // Needs to be first, for ast_map. - @ForeignItem { + @ast::ForeignItem { id: id, ident: folder.fold_ident(ni.ident), attrs: ni.attrs.iter().map(|x| fold_attribute_(*x, folder)).collect(), node: match ni.node { - ForeignItemFn(ref fdec, ref generics) => { - ForeignItemFn(P(FnDecl { + ast::ForeignItemFn(ref fdec, ref generics) => { + ast::ForeignItemFn(ast::P(ast::FnDecl { inputs: fdec.inputs.iter().map(|a| fold_arg_(a, folder)).collect(), output: folder.fold_ty(fdec.output), cf: fdec.cf, variadic: fdec.variadic }), fold_generics(generics, folder)) } - ForeignItemStatic(t, m) => { - ForeignItemStatic(folder.fold_ty(t), m) + ast::ForeignItemStatic(t, m) => { + ast::ForeignItemStatic(folder.fold_ty(t), m) } }, span: folder.new_span(ni.span), @@ -718,9 +720,9 @@ pub fn noop_fold_foreign_item(ni: &ForeignItem, folder: &mut T) -> @F } } -pub fn noop_fold_method(m: &Method, folder: &mut T) -> @Method { +pub fn noop_fold_method(m: &ast::Method, folder: &mut T) -> @ast::Method { let id = folder.new_id(m.id); // Needs to be first, for ast_map. - @Method { + @ast::Method { id: id, ident: folder.fold_ident(m.ident), attrs: m.attrs.iter().map(|a| fold_attribute_(*a, folder)).collect(), @@ -734,22 +736,23 @@ pub fn noop_fold_method(m: &Method, folder: &mut T) -> @Method { } } -pub fn noop_fold_pat(p: @Pat, folder: &mut T) -> @Pat { +pub fn noop_fold_pat(p: @ast::Pat, folder: &mut T) -> @ast::Pat { let id = folder.new_id(p.id); let node = match p.node { - PatWild => PatWild, - PatWildMulti => PatWildMulti, - PatIdent(binding_mode, ref pth, ref sub) => { - PatIdent(binding_mode, - folder.fold_path(pth), - sub.map(|x| folder.fold_pat(x))) - } - PatLit(e) => PatLit(folder.fold_expr(e)), - PatEnum(ref pth, ref pats) => { - PatEnum(folder.fold_path(pth), - pats.as_ref().map(|pats| pats.iter().map(|x| folder.fold_pat(*x)).collect())) - } - PatStruct(ref pth, ref fields, etc) => { + ast::PatWild => ast::PatWild, + ast::PatWildMulti => ast::PatWildMulti, + ast::PatIdent(binding_mode, ref pth, ref sub) => { + ast::PatIdent(binding_mode, + folder.fold_path(pth), + sub.map(|x| folder.fold_pat(x))) + } + ast::PatLit(e) => ast::PatLit(folder.fold_expr(e)), + ast::PatEnum(ref pth, ref pats) => { + ast::PatEnum(folder.fold_path(pth), + pats.as_ref().map(|pats| pats.iter() + .map(|x| folder.fold_pat(*x)).collect())) + } + ast::PatStruct(ref pth, ref fields, etc) => { let pth_ = folder.fold_path(pth); let fs = fields.iter().map(|f| { ast::FieldPat { @@ -757,121 +760,119 @@ pub fn noop_fold_pat(p: @Pat, folder: &mut T) -> @Pat { pat: folder.fold_pat(f.pat) } }).collect(); - PatStruct(pth_, fs, etc) + ast::PatStruct(pth_, fs, etc) } - PatTup(ref elts) => PatTup(elts.iter().map(|x| folder.fold_pat(*x)).collect()), - PatBox(inner) => PatBox(folder.fold_pat(inner)), - PatRegion(inner) => PatRegion(folder.fold_pat(inner)), - PatRange(e1, e2) => { - PatRange(folder.fold_expr(e1), folder.fold_expr(e2)) + ast::PatTup(ref elts) => ast::PatTup(elts.iter().map(|x| folder.fold_pat(*x)).collect()), + ast::PatBox(inner) => ast::PatBox(folder.fold_pat(inner)), + ast::PatRegion(inner) => ast::PatRegion(folder.fold_pat(inner)), + ast::PatRange(e1, e2) => { + ast::PatRange(folder.fold_expr(e1), folder.fold_expr(e2)) }, - PatVec(ref before, ref slice, ref after) => { - PatVec(before.iter().map(|x| folder.fold_pat(*x)).collect(), - slice.map(|x| folder.fold_pat(x)), - after.iter().map(|x| folder.fold_pat(*x)).collect()) + ast::PatVec(ref before, ref slice, ref after) => { + ast::PatVec(before.iter().map(|x| folder.fold_pat(*x)).collect(), + slice.map(|x| folder.fold_pat(x)), + after.iter().map(|x| folder.fold_pat(*x)).collect()) } - PatMac(ref mac) => PatMac(folder.fold_mac(mac)), + ast::PatMac(ref mac) => ast::PatMac(folder.fold_mac(mac)), }; - @Pat { + @ast::Pat { id: id, span: folder.new_span(p.span), node: node, } } -pub fn noop_fold_expr(e: @Expr, folder: &mut T) -> @Expr { +pub fn noop_fold_expr(e: @ast::Expr, folder: &mut T) -> @ast::Expr { let id = folder.new_id(e.id); let node = match e.node { - ExprVstore(e, v) => { - ExprVstore(folder.fold_expr(e), v) + ast::ExprVstore(e, v) => { + ast::ExprVstore(folder.fold_expr(e), v) } - ExprBox(p, e) => { - ExprBox(folder.fold_expr(p), folder.fold_expr(e)) + ast::ExprBox(p, e) => { + ast::ExprBox(folder.fold_expr(p), folder.fold_expr(e)) } - ExprVec(ref exprs) => { - ExprVec(exprs.iter().map(|&x| folder.fold_expr(x)).collect()) + ast::ExprVec(ref exprs) => { + ast::ExprVec(exprs.iter().map(|&x| folder.fold_expr(x)).collect()) } - ExprRepeat(expr, count) => { - ExprRepeat(folder.fold_expr(expr), folder.fold_expr(count)) + ast::ExprRepeat(expr, count) => { + ast::ExprRepeat(folder.fold_expr(expr), folder.fold_expr(count)) } - ExprTup(ref elts) => ExprTup(elts.iter().map(|x| folder.fold_expr(*x)).collect()), - ExprCall(f, ref args) => { - ExprCall(folder.fold_expr(f), - args.iter().map(|&x| folder.fold_expr(x)).collect()) + ast::ExprTup(ref elts) => ast::ExprTup(elts.iter().map(|x| folder.fold_expr(*x)).collect()), + ast::ExprCall(f, ref args) => { + ast::ExprCall(folder.fold_expr(f), + args.iter().map(|&x| folder.fold_expr(x)).collect()) } - ExprMethodCall(i, ref tps, ref args) => { - ExprMethodCall( + ast::ExprMethodCall(i, ref tps, ref args) => { + ast::ExprMethodCall( respan(i.span, folder.fold_ident(i.node)), tps.iter().map(|&x| folder.fold_ty(x)).collect(), args.iter().map(|&x| folder.fold_expr(x)).collect()) } - ExprBinary(binop, lhs, rhs) => { - ExprBinary(binop, - folder.fold_expr(lhs), - folder.fold_expr(rhs)) + ast::ExprBinary(binop, lhs, rhs) => { + ast::ExprBinary(binop, folder.fold_expr(lhs), folder.fold_expr(rhs)) } - ExprUnary(binop, ohs) => { - ExprUnary(binop, folder.fold_expr(ohs)) + ast::ExprUnary(binop, ohs) => { + ast::ExprUnary(binop, folder.fold_expr(ohs)) } - ExprLit(_) => e.node.clone(), - ExprCast(expr, ty) => { - ExprCast(folder.fold_expr(expr), folder.fold_ty(ty)) + ast::ExprLit(_) => e.node.clone(), + ast::ExprCast(expr, ty) => { + ast::ExprCast(folder.fold_expr(expr), folder.fold_ty(ty)) } - ExprAddrOf(m, ohs) => ExprAddrOf(m, folder.fold_expr(ohs)), - ExprIf(cond, tr, fl) => { - ExprIf(folder.fold_expr(cond), + ast::ExprAddrOf(m, ohs) => ast::ExprAddrOf(m, folder.fold_expr(ohs)), + ast::ExprIf(cond, tr, fl) => { + ast::ExprIf(folder.fold_expr(cond), folder.fold_block(tr), fl.map(|x| folder.fold_expr(x))) } - ExprWhile(cond, body) => { - ExprWhile(folder.fold_expr(cond), folder.fold_block(body)) + ast::ExprWhile(cond, body) => { + ast::ExprWhile(folder.fold_expr(cond), folder.fold_block(body)) } - ExprForLoop(pat, iter, body, ref maybe_ident) => { - ExprForLoop(folder.fold_pat(pat), + ast::ExprForLoop(pat, iter, body, ref maybe_ident) => { + ast::ExprForLoop(folder.fold_pat(pat), folder.fold_expr(iter), folder.fold_block(body), maybe_ident.map(|i| folder.fold_ident(i))) } - ExprLoop(body, opt_ident) => { - ExprLoop(folder.fold_block(body), + ast::ExprLoop(body, opt_ident) => { + ast::ExprLoop(folder.fold_block(body), opt_ident.map(|x| folder.fold_ident(x))) } - ExprMatch(expr, ref arms) => { - ExprMatch(folder.fold_expr(expr), + ast::ExprMatch(expr, ref arms) => { + ast::ExprMatch(folder.fold_expr(expr), arms.iter().map(|x| folder.fold_arm(x)).collect()) } - ExprFnBlock(decl, body) => { - ExprFnBlock(folder.fold_fn_decl(decl), folder.fold_block(body)) + ast::ExprFnBlock(decl, body) => { + ast::ExprFnBlock(folder.fold_fn_decl(decl), folder.fold_block(body)) } - ExprProc(decl, body) => { - ExprProc(folder.fold_fn_decl(decl), folder.fold_block(body)) + ast::ExprProc(decl, body) => { + ast::ExprProc(folder.fold_fn_decl(decl), folder.fold_block(body)) } - ExprBlock(blk) => ExprBlock(folder.fold_block(blk)), - ExprAssign(el, er) => { - ExprAssign(folder.fold_expr(el), folder.fold_expr(er)) + ast::ExprBlock(blk) => ast::ExprBlock(folder.fold_block(blk)), + ast::ExprAssign(el, er) => { + ast::ExprAssign(folder.fold_expr(el), folder.fold_expr(er)) } - ExprAssignOp(op, el, er) => { - ExprAssignOp(op, + ast::ExprAssignOp(op, el, er) => { + ast::ExprAssignOp(op, folder.fold_expr(el), folder.fold_expr(er)) } - ExprField(el, id, ref tys) => { - ExprField(folder.fold_expr(el), - folder.fold_ident(id), - tys.iter().map(|&x| folder.fold_ty(x)).collect()) + ast::ExprField(el, id, ref tys) => { + ast::ExprField(folder.fold_expr(el), + folder.fold_ident(id), + tys.iter().map(|&x| folder.fold_ty(x)).collect()) } - ExprIndex(el, er) => { - ExprIndex(folder.fold_expr(el), folder.fold_expr(er)) + ast::ExprIndex(el, er) => { + ast::ExprIndex(folder.fold_expr(el), folder.fold_expr(er)) } - ExprPath(ref pth) => ExprPath(folder.fold_path(pth)), - ExprBreak(opt_ident) => ExprBreak(opt_ident.map(|x| folder.fold_ident(x))), - ExprAgain(opt_ident) => ExprAgain(opt_ident.map(|x| folder.fold_ident(x))), - ExprRet(ref e) => { - ExprRet(e.map(|x| folder.fold_expr(x))) + ast::ExprPath(ref pth) => ast::ExprPath(folder.fold_path(pth)), + ast::ExprBreak(opt_ident) => ast::ExprBreak(opt_ident.map(|x| folder.fold_ident(x))), + ast::ExprAgain(opt_ident) => ast::ExprAgain(opt_ident.map(|x| folder.fold_ident(x))), + ast::ExprRet(ref e) => { + ast::ExprRet(e.map(|x| folder.fold_expr(x))) } - ExprInlineAsm(ref a) => { - ExprInlineAsm(InlineAsm { + ast::ExprInlineAsm(ref a) => { + ast::ExprInlineAsm(ast::InlineAsm { inputs: a.inputs.iter().map(|&(ref c, input)| { ((*c).clone(), folder.fold_expr(input)) }).collect(), @@ -881,39 +882,39 @@ pub fn noop_fold_expr(e: @Expr, folder: &mut T) -> @Expr { .. (*a).clone() }) } - ExprMac(ref mac) => ExprMac(folder.fold_mac(mac)), - ExprStruct(ref path, ref fields, maybe_expr) => { - ExprStruct(folder.fold_path(path), + ast::ExprMac(ref mac) => ast::ExprMac(folder.fold_mac(mac)), + ast::ExprStruct(ref path, ref fields, maybe_expr) => { + ast::ExprStruct(folder.fold_path(path), fields.iter().map(|x| fold_field_(*x, folder)).collect(), maybe_expr.map(|x| folder.fold_expr(x))) }, - ExprParen(ex) => ExprParen(folder.fold_expr(ex)) + ast::ExprParen(ex) => ast::ExprParen(folder.fold_expr(ex)) }; - @Expr { + @ast::Expr { id: id, node: node, span: folder.new_span(e.span), } } -pub fn noop_fold_stmt(s: &Stmt, folder: &mut T) -> SmallVector<@Stmt> { +pub fn noop_fold_stmt(s: &ast::Stmt, folder: &mut T) -> SmallVector<@ast::Stmt> { let nodes = match s.node { - StmtDecl(d, id) => { + ast::StmtDecl(d, id) => { let id = folder.new_id(id); folder.fold_decl(d).move_iter() - .map(|d| StmtDecl(d, id)) + .map(|d| ast::StmtDecl(d, id)) .collect() } - StmtExpr(e, id) => { + ast::StmtExpr(e, id) => { let id = folder.new_id(id); - SmallVector::one(StmtExpr(folder.fold_expr(e), id)) + SmallVector::one(ast::StmtExpr(folder.fold_expr(e), id)) } - StmtSemi(e, id) => { + ast::StmtSemi(e, id) => { let id = folder.new_id(id); - SmallVector::one(StmtSemi(folder.fold_expr(e), id)) + SmallVector::one(ast::StmtSemi(folder.fold_expr(e), id)) } - StmtMac(ref mac, semi) => SmallVector::one(StmtMac(folder.fold_mac(mac), semi)) + ast::StmtMac(ref mac, semi) => SmallVector::one(ast::StmtMac(folder.fold_mac(mac), semi)) }; nodes.move_iter().map(|node| @Spanned { @@ -929,7 +930,6 @@ mod test { use util::parser_testing::{string_to_crate, matches_codepattern}; use parse::token; use print::pprust; - use super::*; // this version doesn't care about getting comments or docstrings in. fn fake_print_crate(s: &mut pprust::State, diff --git a/src/libsyntax/visit.rs b/src/libsyntax/visit.rs index efa8c8e66640f..0dc49d434a631 100644 --- a/src/libsyntax/visit.rs +++ b/src/libsyntax/visit.rs @@ -9,7 +9,6 @@ // except according to those terms. use abi::Abi; -use ast::*; use ast; use codemap::Span; use parse; @@ -29,31 +28,31 @@ use owned_slice::OwnedSlice; pub enum FnKind<'a> { // fn foo() or extern "Abi" fn foo() - FkItemFn(Ident, &'a Generics, FnStyle, Abi), + FkItemFn(ast::Ident, &'a ast::Generics, ast::FnStyle, Abi), // fn foo(&self) - FkMethod(Ident, &'a Generics, &'a Method), + FkMethod(ast::Ident, &'a ast::Generics, &'a ast::Method), // |x, y| ... // proc(x, y) ... FkFnBlock, } -pub fn name_of_fn(fk: &FnKind) -> Ident { +pub fn name_of_fn(fk: &FnKind) -> ast::Ident { match *fk { FkItemFn(name, _, _, _) | FkMethod(name, _, _) => name, FkFnBlock(..) => parse::token::special_idents::invalid } } -pub fn generics_of_fn(fk: &FnKind) -> Generics { +pub fn generics_of_fn(fk: &FnKind) -> ast::Generics { match *fk { FkItemFn(_, generics, _, _) | FkMethod(_, generics, _) => { (*generics).clone() } FkFnBlock(..) => { - Generics { + ast::Generics { lifetimes: Vec::new(), ty_params: OwnedSlice::empty(), } @@ -72,36 +71,40 @@ pub fn generics_of_fn(fk: &FnKind) -> Generics { /// new default implementation gets introduced.) pub trait Visitor { - fn visit_ident(&mut self, _sp: Span, _ident: Ident, _e: E) { + fn visit_ident(&mut self, _sp: Span, _ident: ast::Ident, _e: E) { /*! Visit the idents */ } - fn visit_mod(&mut self, m: &Mod, _s: Span, _n: NodeId, e: E) { walk_mod(self, m, e) } - fn visit_view_item(&mut self, i: &ViewItem, e: E) { walk_view_item(self, i, e) } - fn visit_foreign_item(&mut self, i: &ForeignItem, e: E) { walk_foreign_item(self, i, e) } - fn visit_item(&mut self, i: &Item, e: E) { walk_item(self, i, e) } - fn visit_local(&mut self, l: &Local, e: E) { walk_local(self, l, e) } - fn visit_block(&mut self, b: &Block, e: E) { walk_block(self, b, e) } - fn visit_stmt(&mut self, s: &Stmt, e: E) { walk_stmt(self, s, e) } - fn visit_arm(&mut self, a: &Arm, e: E) { walk_arm(self, a, e) } - fn visit_pat(&mut self, p: &Pat, e: E) { walk_pat(self, p, e) } - fn visit_decl(&mut self, d: &Decl, e: E) { walk_decl(self, d, e) } - fn visit_expr(&mut self, ex: &Expr, e: E) { walk_expr(self, ex, e) } - fn visit_expr_post(&mut self, _ex: &Expr, _e: E) { } - fn visit_ty(&mut self, t: &Ty, e: E) { walk_ty(self, t, e) } - fn visit_generics(&mut self, g: &Generics, e: E) { walk_generics(self, g, e) } - fn visit_fn(&mut self, fk: &FnKind, fd: &FnDecl, b: &Block, s: Span, _: NodeId, e: E) { + fn visit_mod(&mut self, m: &ast::Mod, _s: Span, _n: ast::NodeId, e: E) { walk_mod(self, m, e) } + fn visit_view_item(&mut self, i: &ast::ViewItem, e: E) { walk_view_item(self, i, e) } + fn visit_foreign_item(&mut self, i: &ast::ForeignItem, e: E) { walk_foreign_item(self, i, e) } + fn visit_item(&mut self, i: &ast::Item, e: E) { walk_item(self, i, e) } + fn visit_local(&mut self, l: &ast::Local, e: E) { walk_local(self, l, e) } + fn visit_block(&mut self, b: &ast::Block, e: E) { walk_block(self, b, e) } + fn visit_stmt(&mut self, s: &ast::Stmt, e: E) { walk_stmt(self, s, e) } + fn visit_arm(&mut self, a: &ast::Arm, e: E) { walk_arm(self, a, e) } + fn visit_pat(&mut self, p: &ast::Pat, e: E) { walk_pat(self, p, e) } + fn visit_decl(&mut self, d: &ast::Decl, e: E) { walk_decl(self, d, e) } + fn visit_expr(&mut self, ex: &ast::Expr, e: E) { walk_expr(self, ex, e) } + fn visit_expr_post(&mut self, _ex: &ast::Expr, _e: E) { } + fn visit_ty(&mut self, t: &ast::Ty, e: E) { walk_ty(self, t, e) } + fn visit_generics(&mut self, g: &ast::Generics, e: E) { walk_generics(self, g, e) } + fn visit_fn(&mut self, fk: &FnKind, fd: &ast::FnDecl, b: &ast::Block, s: Span, + _: ast::NodeId, e: E) { walk_fn(self, fk, fd, b, s, e) } - fn visit_ty_method(&mut self, t: &TypeMethod, e: E) { walk_ty_method(self, t, e) } - fn visit_trait_method(&mut self, t: &TraitMethod, e: E) { walk_trait_method(self, t, e) } - fn visit_struct_def(&mut self, s: &StructDef, _: Ident, _: &Generics, _: NodeId, e: E) { + fn visit_ty_method(&mut self, t: &ast::TypeMethod, e: E) { walk_ty_method(self, t, e) } + fn visit_trait_method(&mut self, t: &ast::TraitMethod, e: E) { walk_trait_method(self, t, e) } + fn visit_struct_def(&mut self, s: &ast::StructDef, _: ast::Ident, _: &ast::Generics, + _: ast::NodeId, e: E) { walk_struct_def(self, s, e) } - fn visit_struct_field(&mut self, s: &StructField, e: E) { walk_struct_field(self, s, e) } - fn visit_variant(&mut self, v: &Variant, g: &Generics, e: E) { walk_variant(self, v, g, e) } + fn visit_struct_field(&mut self, s: &ast::StructField, e: E) { walk_struct_field(self, s, e) } + fn visit_variant(&mut self, v: &ast::Variant, g: &ast::Generics, e: E) { + walk_variant(self, v, g, e) + } fn visit_opt_lifetime_ref(&mut self, _span: Span, - opt_lifetime: &Option, + opt_lifetime: &Option, env: E) { /*! * Visits an optional reference to a lifetime. The `span` is @@ -113,19 +116,19 @@ pub trait Visitor { None => () } } - fn visit_lifetime_ref(&mut self, _lifetime: &Lifetime, _e: E) { + fn visit_lifetime_ref(&mut self, _lifetime: &ast::Lifetime, _e: E) { /*! Visits a reference to a lifetime */ } - fn visit_lifetime_decl(&mut self, _lifetime: &Lifetime, _e: E) { + fn visit_lifetime_decl(&mut self, _lifetime: &ast::Lifetime, _e: E) { /*! Visits a declaration of a lifetime */ } - fn visit_explicit_self(&mut self, es: &ExplicitSelf, e: E) { + fn visit_explicit_self(&mut self, es: &ast::ExplicitSelf, e: E) { walk_explicit_self(self, es, e) } - fn visit_mac(&mut self, macro: &Mac, e: E) { + fn visit_mac(&mut self, macro: &ast::Mac, e: E) { walk_mac(self, macro, e) } - fn visit_path(&mut self, path: &Path, _id: ast::NodeId, e: E) { + fn visit_path(&mut self, path: &ast::Path, _id: ast::NodeId, e: E) { walk_path(self, path, e) } } @@ -134,18 +137,18 @@ pub fn walk_inlined_item>(visitor: &mut V, item: &ast::InlinedItem, env: E) { match *item { - IIItem(i) => visitor.visit_item(i, env), - IIForeign(i) => visitor.visit_foreign_item(i, env), - IIMethod(_, _, m) => walk_method_helper(visitor, m, env), + ast::IIItem(i) => visitor.visit_item(i, env), + ast::IIForeign(i) => visitor.visit_foreign_item(i, env), + ast::IIMethod(_, _, m) => walk_method_helper(visitor, m, env), } } -pub fn walk_crate>(visitor: &mut V, krate: &Crate, env: E) { - visitor.visit_mod(&krate.module, krate.span, CRATE_NODE_ID, env) +pub fn walk_crate>(visitor: &mut V, krate: &ast::Crate, env: E) { + visitor.visit_mod(&krate.module, krate.span, ast::CRATE_NODE_ID, env) } -pub fn walk_mod>(visitor: &mut V, module: &Mod, env: E) { +pub fn walk_mod>(visitor: &mut V, module: &ast::Mod, env: E) { for view_item in module.view_items.iter() { visitor.visit_view_item(view_item, env.clone()) } @@ -155,21 +158,21 @@ pub fn walk_mod>(visitor: &mut V, module: &Mod, env: E) } } -pub fn walk_view_item>(visitor: &mut V, vi: &ViewItem, env: E) { +pub fn walk_view_item>(visitor: &mut V, vi: &ast::ViewItem, env: E) { match vi.node { - ViewItemExternCrate(name, _, _) => { + ast::ViewItemExternCrate(name, _, _) => { visitor.visit_ident(vi.span, name, env) } - ViewItemUse(ref vp) => { + ast::ViewItemUse(ref vp) => { match vp.node { - ViewPathSimple(ident, ref path, id) => { + ast::ViewPathSimple(ident, ref path, id) => { visitor.visit_ident(vp.span, ident, env.clone()); visitor.visit_path(path, id, env.clone()); } - ViewPathGlob(ref path, id) => { + ast::ViewPathGlob(ref path, id) => { visitor.visit_path(path, id, env.clone()); } - ViewPathList(ref path, ref list, _) => { + ast::ViewPathList(ref path, ref list, _) => { for id in list.iter() { visitor.visit_ident(id.span, id.node.name, env.clone()) } @@ -180,7 +183,7 @@ pub fn walk_view_item>(visitor: &mut V, vi: &ViewItem, e } } -pub fn walk_local>(visitor: &mut V, local: &Local, env: E) { +pub fn walk_local>(visitor: &mut V, local: &ast::Local, env: E) { visitor.visit_pat(local.pat, env.clone()); visitor.visit_ty(local.ty, env.clone()); match local.init { @@ -190,11 +193,11 @@ pub fn walk_local>(visitor: &mut V, local: &Local, env: } pub fn walk_explicit_self>(visitor: &mut V, - explicit_self: &ExplicitSelf, + explicit_self: &ast::ExplicitSelf, env: E) { match explicit_self.node { - SelfStatic | SelfValue | SelfUniq => {} - SelfRegion(ref lifetime, _) => { + ast::SelfStatic | ast::SelfValue | ast::SelfUniq => {} + ast::SelfRegion(ref lifetime, _) => { visitor.visit_opt_lifetime_ref(explicit_self.span, lifetime, env) } } @@ -203,19 +206,19 @@ pub fn walk_explicit_self>(visitor: &mut V, /// Like with walk_method_helper this doesn't correspond to a method /// in Visitor, and so it gets a _helper suffix. pub fn walk_trait_ref_helper>(visitor: &mut V, - trait_ref: &TraitRef, + trait_ref: &ast::TraitRef, env: E) { visitor.visit_path(&trait_ref.path, trait_ref.ref_id, env) } -pub fn walk_item>(visitor: &mut V, item: &Item, env: E) { +pub fn walk_item>(visitor: &mut V, item: &ast::Item, env: E) { visitor.visit_ident(item.span, item.ident, env.clone()); match item.node { - ItemStatic(typ, _, expr) => { + ast::ItemStatic(typ, _, expr) => { visitor.visit_ty(typ, env.clone()); visitor.visit_expr(expr, env); } - ItemFn(declaration, fn_style, abi, ref generics, body) => { + ast::ItemFn(declaration, fn_style, abi, ref generics, body) => { visitor.visit_fn(&FkItemFn(item.ident, generics, fn_style, abi), declaration, body, @@ -223,10 +226,10 @@ pub fn walk_item>(visitor: &mut V, item: &Item, env: E) item.id, env) } - ItemMod(ref module) => { + ast::ItemMod(ref module) => { visitor.visit_mod(module, item.span, item.id, env) } - ItemForeignMod(ref foreign_module) => { + ast::ItemForeignMod(ref foreign_module) => { for view_item in foreign_module.view_items.iter() { visitor.visit_view_item(view_item, env.clone()) } @@ -234,15 +237,15 @@ pub fn walk_item>(visitor: &mut V, item: &Item, env: E) visitor.visit_foreign_item(*foreign_item, env.clone()) } } - ItemTy(typ, ref type_parameters) => { + ast::ItemTy(typ, ref type_parameters) => { visitor.visit_ty(typ, env.clone()); visitor.visit_generics(type_parameters, env) } - ItemEnum(ref enum_definition, ref type_parameters) => { + ast::ItemEnum(ref enum_definition, ref type_parameters) => { visitor.visit_generics(type_parameters, env.clone()); walk_enum_def(visitor, enum_definition, type_parameters, env) } - ItemImpl(ref type_parameters, + ast::ItemImpl(ref type_parameters, ref trait_reference, typ, ref methods) => { @@ -257,7 +260,7 @@ pub fn walk_item>(visitor: &mut V, item: &Item, env: E) walk_method_helper(visitor, *method, env.clone()) } } - ItemStruct(struct_definition, ref generics) => { + ast::ItemStruct(struct_definition, ref generics) => { visitor.visit_generics(generics, env.clone()); visitor.visit_struct_def(struct_definition, item.ident, @@ -265,7 +268,7 @@ pub fn walk_item>(visitor: &mut V, item: &Item, env: E) item.id, env) } - ItemTrait(ref generics, _, ref trait_paths, ref methods) => { + ast::ItemTrait(ref generics, _, ref trait_paths, ref methods) => { visitor.visit_generics(generics, env.clone()); for trait_path in trait_paths.iter() { visitor.visit_path(&trait_path.path, @@ -276,13 +279,13 @@ pub fn walk_item>(visitor: &mut V, item: &Item, env: E) visitor.visit_trait_method(method, env.clone()) } } - ItemMac(ref macro) => visitor.visit_mac(macro, env), + ast::ItemMac(ref macro) => visitor.visit_mac(macro, env), } } pub fn walk_enum_def>(visitor: &mut V, - enum_definition: &EnumDef, - generics: &Generics, + enum_definition: &ast::EnumDef, + generics: &ast::Generics, env: E) { for &variant in enum_definition.variants.iter() { visitor.visit_variant(variant, generics, env.clone()); @@ -290,18 +293,18 @@ pub fn walk_enum_def>(visitor: &mut V, } pub fn walk_variant>(visitor: &mut V, - variant: &Variant, - generics: &Generics, + variant: &ast::Variant, + generics: &ast::Generics, env: E) { visitor.visit_ident(variant.span, variant.node.name, env.clone()); match variant.node.kind { - TupleVariantKind(ref variant_arguments) => { + ast::TupleVariantKind(ref variant_arguments) => { for variant_argument in variant_arguments.iter() { visitor.visit_ty(variant_argument.ty, env.clone()) } } - StructVariantKind(struct_definition) => { + ast::StructVariantKind(struct_definition) => { visitor.visit_struct_def(struct_definition, variant.node.name, generics, @@ -315,28 +318,28 @@ pub fn walk_variant>(visitor: &mut V, } } -pub fn skip_ty>(_: &mut V, _: &Ty, _: E) { +pub fn skip_ty>(_: &mut V, _: &ast::Ty, _: E) { // Empty! } -pub fn walk_ty>(visitor: &mut V, typ: &Ty, env: E) { +pub fn walk_ty>(visitor: &mut V, typ: &ast::Ty, env: E) { match typ.node { - TyUniq(ty) | TyVec(ty) | TyBox(ty) => { + ast::TyUniq(ty) | ast::TyVec(ty) | ast::TyBox(ty) => { visitor.visit_ty(ty, env) } - TyPtr(ref mutable_type) => { + ast::TyPtr(ref mutable_type) => { visitor.visit_ty(mutable_type.ty, env) } - TyRptr(ref lifetime, ref mutable_type) => { + ast::TyRptr(ref lifetime, ref mutable_type) => { visitor.visit_opt_lifetime_ref(typ.span, lifetime, env.clone()); visitor.visit_ty(mutable_type.ty, env) } - TyTup(ref tuple_element_types) => { + ast::TyTup(ref tuple_element_types) => { for &tuple_element_type in tuple_element_types.iter() { visitor.visit_ty(tuple_element_type, env.clone()) } } - TyClosure(ref function_declaration, ref region) => { + ast::TyClosure(ref function_declaration, ref region) => { for argument in function_declaration.decl.inputs.iter() { visitor.visit_ty(argument.ty, env.clone()) } @@ -351,7 +354,7 @@ pub fn walk_ty>(visitor: &mut V, typ: &Ty, env: E) { walk_lifetime_decls(visitor, &function_declaration.lifetimes, env.clone()); } - TyProc(ref function_declaration) => { + ast::TyProc(ref function_declaration) => { for argument in function_declaration.decl.inputs.iter() { visitor.visit_ty(argument.ty, env.clone()) } @@ -362,7 +365,7 @@ pub fn walk_ty>(visitor: &mut V, typ: &Ty, env: E) { walk_lifetime_decls(visitor, &function_declaration.lifetimes, env.clone()); } - TyBareFn(ref function_declaration) => { + ast::TyBareFn(ref function_declaration) => { for argument in function_declaration.decl.inputs.iter() { visitor.visit_ty(argument.ty, env.clone()) } @@ -370,32 +373,32 @@ pub fn walk_ty>(visitor: &mut V, typ: &Ty, env: E) { walk_lifetime_decls(visitor, &function_declaration.lifetimes, env.clone()); } - TyPath(ref path, ref bounds, id) => { + ast::TyPath(ref path, ref bounds, id) => { visitor.visit_path(path, id, env.clone()); for bounds in bounds.iter() { walk_ty_param_bounds(visitor, bounds, env.clone()) } } - TyFixedLengthVec(ty, expression) => { + ast::TyFixedLengthVec(ty, expression) => { visitor.visit_ty(ty, env.clone()); visitor.visit_expr(expression, env) } - TyTypeof(expression) => { + ast::TyTypeof(expression) => { visitor.visit_expr(expression, env) } - TyNil | TyBot | TyInfer => {} + ast::TyNil | ast::TyBot | ast::TyInfer => {} } } fn walk_lifetime_decls>(visitor: &mut V, - lifetimes: &Vec, + lifetimes: &Vec, env: E) { for l in lifetimes.iter() { visitor.visit_lifetime_decl(l, env.clone()); } } -pub fn walk_path>(visitor: &mut V, path: &Path, env: E) { +pub fn walk_path>(visitor: &mut V, path: &ast::Path, env: E) { for segment in path.segments.iter() { visitor.visit_ident(path.span, segment.identifier, env.clone()); @@ -408,9 +411,9 @@ pub fn walk_path>(visitor: &mut V, path: &Path, env: E) } } -pub fn walk_pat>(visitor: &mut V, pattern: &Pat, env: E) { +pub fn walk_pat>(visitor: &mut V, pattern: &ast::Pat, env: E) { match pattern.node { - PatEnum(ref path, ref children) => { + ast::PatEnum(ref path, ref children) => { visitor.visit_path(path, pattern.id, env.clone()); for children in children.iter() { for child in children.iter() { @@ -418,35 +421,35 @@ pub fn walk_pat>(visitor: &mut V, pattern: &Pat, env: E) } } } - PatStruct(ref path, ref fields, _) => { + ast::PatStruct(ref path, ref fields, _) => { visitor.visit_path(path, pattern.id, env.clone()); for field in fields.iter() { visitor.visit_pat(field.pat, env.clone()) } } - PatTup(ref tuple_elements) => { + ast::PatTup(ref tuple_elements) => { for tuple_element in tuple_elements.iter() { visitor.visit_pat(*tuple_element, env.clone()) } } - PatBox(subpattern) | - PatRegion(subpattern) => { + ast::PatBox(subpattern) | + ast::PatRegion(subpattern) => { visitor.visit_pat(subpattern, env) } - PatIdent(_, ref path, ref optional_subpattern) => { + ast::PatIdent(_, ref path, ref optional_subpattern) => { visitor.visit_path(path, pattern.id, env.clone()); match *optional_subpattern { None => {} Some(subpattern) => visitor.visit_pat(subpattern, env), } } - PatLit(expression) => visitor.visit_expr(expression, env), - PatRange(lower_bound, upper_bound) => { + ast::PatLit(expression) => visitor.visit_expr(expression, env), + ast::PatRange(lower_bound, upper_bound) => { visitor.visit_expr(lower_bound, env.clone()); visitor.visit_expr(upper_bound, env) } - PatWild | PatWildMulti => (), - PatVec(ref prepattern, ref slice_pattern, ref postpatterns) => { + ast::PatWild | ast::PatWildMulti => (), + ast::PatVec(ref prepattern, ref slice_pattern, ref postpatterns) => { for prepattern in prepattern.iter() { visitor.visit_pat(*prepattern, env.clone()) } @@ -457,40 +460,40 @@ pub fn walk_pat>(visitor: &mut V, pattern: &Pat, env: E) visitor.visit_pat(*postpattern, env.clone()) } } - PatMac(ref macro) => visitor.visit_mac(macro, env), + ast::PatMac(ref macro) => visitor.visit_mac(macro, env), } } pub fn walk_foreign_item>(visitor: &mut V, - foreign_item: &ForeignItem, + foreign_item: &ast::ForeignItem, env: E) { visitor.visit_ident(foreign_item.span, foreign_item.ident, env.clone()); match foreign_item.node { - ForeignItemFn(function_declaration, ref generics) => { + ast::ForeignItemFn(function_declaration, ref generics) => { walk_fn_decl(visitor, function_declaration, env.clone()); visitor.visit_generics(generics, env) } - ForeignItemStatic(typ, _) => visitor.visit_ty(typ, env), + ast::ForeignItemStatic(typ, _) => visitor.visit_ty(typ, env), } } pub fn walk_ty_param_bounds>(visitor: &mut V, - bounds: &OwnedSlice, + bounds: &OwnedSlice, env: E) { for bound in bounds.iter() { match *bound { - TraitTyParamBound(ref typ) => { + ast::TraitTyParamBound(ref typ) => { walk_trait_ref_helper(visitor, typ, env.clone()) } - StaticRegionTyParamBound => {} - OtherRegionTyParamBound(..) => {} + ast::StaticRegionTyParamBound => {} + ast::OtherRegionTyParamBound(..) => {} } } } pub fn walk_generics>(visitor: &mut V, - generics: &Generics, + generics: &ast::Generics, env: E) { for type_parameter in generics.ty_params.iter() { walk_ty_param_bounds(visitor, &type_parameter.bounds, env.clone()); @@ -503,7 +506,7 @@ pub fn walk_generics>(visitor: &mut V, } pub fn walk_fn_decl>(visitor: &mut V, - function_declaration: &FnDecl, + function_declaration: &ast::FnDecl, env: E) { for argument in function_declaration.inputs.iter() { visitor.visit_pat(argument.pat, env.clone()); @@ -517,7 +520,7 @@ pub fn walk_fn_decl>(visitor: &mut V, // because it is not a default impl of any method, though I doubt that really // clarifies anything. - Niko pub fn walk_method_helper>(visitor: &mut V, - method: &Method, + method: &ast::Method, env: E) { visitor.visit_ident(method.span, method.ident, env.clone()); visitor.visit_fn(&FkMethod(method.ident, &method.generics, method), @@ -530,8 +533,8 @@ pub fn walk_method_helper>(visitor: &mut V, pub fn walk_fn>(visitor: &mut V, function_kind: &FnKind, - function_declaration: &FnDecl, - function_body: &Block, + function_declaration: &ast::FnDecl, + function_body: &ast::Block, _span: Span, env: E) { walk_fn_decl(visitor, function_declaration, env.clone()); @@ -552,7 +555,7 @@ pub fn walk_fn>(visitor: &mut V, } pub fn walk_ty_method>(visitor: &mut V, - method_type: &TypeMethod, + method_type: &ast::TypeMethod, env: E) { visitor.visit_ident(method_type.span, method_type.ident, env.clone()); visitor.visit_explicit_self(&method_type.explicit_self, env.clone()); @@ -564,18 +567,18 @@ pub fn walk_ty_method>(visitor: &mut V, } pub fn walk_trait_method>(visitor: &mut V, - trait_method: &TraitMethod, + trait_method: &ast::TraitMethod, env: E) { match *trait_method { - Required(ref method_type) => { + ast::Required(ref method_type) => { visitor.visit_ty_method(method_type, env) } - Provided(method) => walk_method_helper(visitor, method, env), + ast::Provided(method) => walk_method_helper(visitor, method, env), } } pub fn walk_struct_def>(visitor: &mut V, - struct_definition: &StructDef, + struct_definition: &ast::StructDef, env: E) { match struct_definition.super_struct { Some(t) => visitor.visit_ty(t, env.clone()), @@ -587,10 +590,10 @@ pub fn walk_struct_def>(visitor: &mut V, } pub fn walk_struct_field>(visitor: &mut V, - struct_field: &StructField, + struct_field: &ast::StructField, env: E) { match struct_field.node.kind { - NamedField(name, _) => { + ast::NamedField(name, _) => { visitor.visit_ident(struct_field.span, name, env.clone()) } _ => {} @@ -599,7 +602,7 @@ pub fn walk_struct_field>(visitor: &mut V, visitor.visit_ty(struct_field.node.ty, env) } -pub fn walk_block>(visitor: &mut V, block: &Block, env: E) { +pub fn walk_block>(visitor: &mut V, block: &ast::Block, env: E) { for view_item in block.view_items.iter() { visitor.visit_view_item(view_item, env.clone()) } @@ -609,25 +612,25 @@ pub fn walk_block>(visitor: &mut V, block: &Block, env: walk_expr_opt(visitor, block.expr, env) } -pub fn walk_stmt>(visitor: &mut V, statement: &Stmt, env: E) { +pub fn walk_stmt>(visitor: &mut V, statement: &ast::Stmt, env: E) { match statement.node { - StmtDecl(declaration, _) => visitor.visit_decl(declaration, env), - StmtExpr(expression, _) | StmtSemi(expression, _) => { + ast::StmtDecl(declaration, _) => visitor.visit_decl(declaration, env), + ast::StmtExpr(expression, _) | ast::StmtSemi(expression, _) => { visitor.visit_expr(expression, env) } - StmtMac(ref macro, _) => visitor.visit_mac(macro, env), + ast::StmtMac(ref macro, _) => visitor.visit_mac(macro, env), } } -pub fn walk_decl>(visitor: &mut V, declaration: &Decl, env: E) { +pub fn walk_decl>(visitor: &mut V, declaration: &ast::Decl, env: E) { match declaration.node { - DeclLocal(ref local) => visitor.visit_local(*local, env), - DeclItem(item) => visitor.visit_item(item, env), + ast::DeclLocal(ref local) => visitor.visit_local(*local, env), + ast::DeclItem(item) => visitor.visit_item(item, env), } } pub fn walk_expr_opt>(visitor: &mut V, - optional_expression: Option<@Expr>, + optional_expression: Option<@ast::Expr>, env: E) { match optional_expression { None => {} @@ -636,91 +639,91 @@ pub fn walk_expr_opt>(visitor: &mut V, } pub fn walk_exprs>(visitor: &mut V, - expressions: &[@Expr], + expressions: &[@ast::Expr], env: E) { for expression in expressions.iter() { visitor.visit_expr(*expression, env.clone()) } } -pub fn walk_mac>(_: &mut V, _: &Mac, _: E) { +pub fn walk_mac>(_: &mut V, _: &ast::Mac, _: E) { // Empty! } -pub fn walk_expr>(visitor: &mut V, expression: &Expr, env: E) { +pub fn walk_expr>(visitor: &mut V, expression: &ast::Expr, env: E) { match expression.node { - ExprVstore(subexpression, _) => { + ast::ExprVstore(subexpression, _) => { visitor.visit_expr(subexpression, env.clone()) } - ExprBox(place, subexpression) => { + ast::ExprBox(place, subexpression) => { visitor.visit_expr(place, env.clone()); visitor.visit_expr(subexpression, env.clone()) } - ExprVec(ref subexpressions) => { + ast::ExprVec(ref subexpressions) => { walk_exprs(visitor, subexpressions.as_slice(), env.clone()) } - ExprRepeat(element, count) => { + ast::ExprRepeat(element, count) => { visitor.visit_expr(element, env.clone()); visitor.visit_expr(count, env.clone()) } - ExprStruct(ref path, ref fields, optional_base) => { + ast::ExprStruct(ref path, ref fields, optional_base) => { visitor.visit_path(path, expression.id, env.clone()); for field in fields.iter() { visitor.visit_expr(field.expr, env.clone()) } walk_expr_opt(visitor, optional_base, env.clone()) } - ExprTup(ref subexpressions) => { + ast::ExprTup(ref subexpressions) => { for subexpression in subexpressions.iter() { visitor.visit_expr(*subexpression, env.clone()) } } - ExprCall(callee_expression, ref arguments) => { + ast::ExprCall(callee_expression, ref arguments) => { for argument in arguments.iter() { visitor.visit_expr(*argument, env.clone()) } visitor.visit_expr(callee_expression, env.clone()) } - ExprMethodCall(_, ref types, ref arguments) => { + ast::ExprMethodCall(_, ref types, ref arguments) => { walk_exprs(visitor, arguments.as_slice(), env.clone()); for &typ in types.iter() { visitor.visit_ty(typ, env.clone()) } } - ExprBinary(_, left_expression, right_expression) => { + ast::ExprBinary(_, left_expression, right_expression) => { visitor.visit_expr(left_expression, env.clone()); visitor.visit_expr(right_expression, env.clone()) } - ExprAddrOf(_, subexpression) | ExprUnary(_, subexpression) => { + ast::ExprAddrOf(_, subexpression) | ast::ExprUnary(_, subexpression) => { visitor.visit_expr(subexpression, env.clone()) } - ExprLit(_) => {} - ExprCast(subexpression, typ) => { + ast::ExprLit(_) => {} + ast::ExprCast(subexpression, typ) => { visitor.visit_expr(subexpression, env.clone()); visitor.visit_ty(typ, env.clone()) } - ExprIf(head_expression, if_block, optional_else) => { + ast::ExprIf(head_expression, if_block, optional_else) => { visitor.visit_expr(head_expression, env.clone()); visitor.visit_block(if_block, env.clone()); walk_expr_opt(visitor, optional_else, env.clone()) } - ExprWhile(subexpression, block) => { + ast::ExprWhile(subexpression, block) => { visitor.visit_expr(subexpression, env.clone()); visitor.visit_block(block, env.clone()) } - ExprForLoop(pattern, subexpression, block, _) => { + ast::ExprForLoop(pattern, subexpression, block, _) => { visitor.visit_pat(pattern, env.clone()); visitor.visit_expr(subexpression, env.clone()); visitor.visit_block(block, env.clone()) } - ExprLoop(block, _) => visitor.visit_block(block, env.clone()), - ExprMatch(subexpression, ref arms) => { + ast::ExprLoop(block, _) => visitor.visit_block(block, env.clone()), + ast::ExprMatch(subexpression, ref arms) => { visitor.visit_expr(subexpression, env.clone()); for arm in arms.iter() { visitor.visit_arm(arm, env.clone()) } } - ExprFnBlock(function_declaration, body) => { + ast::ExprFnBlock(function_declaration, body) => { visitor.visit_fn(&FkFnBlock, function_declaration, body, @@ -728,7 +731,7 @@ pub fn walk_expr>(visitor: &mut V, expression: &Expr, en expression.id, env.clone()) } - ExprProc(function_declaration, body) => { + ast::ExprProc(function_declaration, body) => { visitor.visit_fn(&FkFnBlock, function_declaration, body, @@ -736,37 +739,37 @@ pub fn walk_expr>(visitor: &mut V, expression: &Expr, en expression.id, env.clone()) } - ExprBlock(block) => visitor.visit_block(block, env.clone()), - ExprAssign(left_hand_expression, right_hand_expression) => { + ast::ExprBlock(block) => visitor.visit_block(block, env.clone()), + ast::ExprAssign(left_hand_expression, right_hand_expression) => { visitor.visit_expr(right_hand_expression, env.clone()); visitor.visit_expr(left_hand_expression, env.clone()) } - ExprAssignOp(_, left_expression, right_expression) => { + ast::ExprAssignOp(_, left_expression, right_expression) => { visitor.visit_expr(right_expression, env.clone()); visitor.visit_expr(left_expression, env.clone()) } - ExprField(subexpression, _, ref types) => { + ast::ExprField(subexpression, _, ref types) => { visitor.visit_expr(subexpression, env.clone()); for &typ in types.iter() { visitor.visit_ty(typ, env.clone()) } } - ExprIndex(main_expression, index_expression) => { + ast::ExprIndex(main_expression, index_expression) => { visitor.visit_expr(main_expression, env.clone()); visitor.visit_expr(index_expression, env.clone()) } - ExprPath(ref path) => { + ast::ExprPath(ref path) => { visitor.visit_path(path, expression.id, env.clone()) } - ExprBreak(_) | ExprAgain(_) => {} - ExprRet(optional_expression) => { + ast::ExprBreak(_) | ast::ExprAgain(_) => {} + ast::ExprRet(optional_expression) => { walk_expr_opt(visitor, optional_expression, env.clone()) } - ExprMac(ref macro) => visitor.visit_mac(macro, env.clone()), - ExprParen(subexpression) => { + ast::ExprMac(ref macro) => visitor.visit_mac(macro, env.clone()), + ast::ExprParen(subexpression) => { visitor.visit_expr(subexpression, env.clone()) } - ExprInlineAsm(ref assembler) => { + ast::ExprInlineAsm(ref assembler) => { for &(_, input) in assembler.inputs.iter() { visitor.visit_expr(input, env.clone()) } @@ -779,7 +782,7 @@ pub fn walk_expr>(visitor: &mut V, expression: &Expr, en visitor.visit_expr_post(expression, env.clone()) } -pub fn walk_arm>(visitor: &mut V, arm: &Arm, env: E) { +pub fn walk_arm>(visitor: &mut V, arm: &ast::Arm, env: E) { for pattern in arm.pats.iter() { visitor.visit_pat(*pattern, env.clone()) }