Disowned the Visitor.
This commit is contained in:
parent
4e622becdc
commit
3119d18e55
57 changed files with 1039 additions and 1142 deletions
|
|
@ -11,21 +11,19 @@
|
|||
use abi::AbiSet;
|
||||
use ast::*;
|
||||
use ast;
|
||||
use ast_util::{inlined_item_utils, stmt_id};
|
||||
use ast_util;
|
||||
use codemap::Span;
|
||||
use codemap;
|
||||
use diagnostic::SpanHandler;
|
||||
use fold::ast_fold;
|
||||
use fold;
|
||||
use parse::token::get_ident_interner;
|
||||
use parse::token::ident_interner;
|
||||
use parse::token::special_idents;
|
||||
use print::pprust;
|
||||
use visit::{Visitor, fn_kind};
|
||||
use visit;
|
||||
use util::small_vector::SmallVector;
|
||||
|
||||
use std::cell::RefCell;
|
||||
use std::hashmap::HashMap;
|
||||
use std::vec;
|
||||
|
||||
#[deriving(Clone, Eq)]
|
||||
pub enum path_elt {
|
||||
|
|
@ -165,7 +163,10 @@ pub enum ast_node {
|
|||
node_expr(@Expr),
|
||||
node_stmt(@Stmt),
|
||||
node_arg(@Pat),
|
||||
node_local(Ident),
|
||||
// HACK(eddyb) should always be a pattern, but `self` is not, and thus it
|
||||
// is identified only by an ident and no span is available. In all other
|
||||
// cases, node_span will return the proper span (required by borrowck).
|
||||
node_local(Ident, Option<@Pat>),
|
||||
node_block(P<Block>),
|
||||
|
||||
/// node_struct_ctor represents a tuple struct.
|
||||
|
|
@ -195,164 +196,75 @@ impl ast_node {
|
|||
|
||||
pub type map = @RefCell<HashMap<NodeId, ast_node>>;
|
||||
|
||||
pub struct Ctx {
|
||||
pub trait FoldOps {
|
||||
fn new_id(&self, id: ast::NodeId) -> ast::NodeId {
|
||||
id
|
||||
}
|
||||
fn new_span(&self, span: Span) -> Span {
|
||||
span
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Ctx<F> {
|
||||
map: map,
|
||||
path: RefCell<path>,
|
||||
path: path,
|
||||
diag: @SpanHandler,
|
||||
fold_ops: F
|
||||
}
|
||||
|
||||
impl Ctx {
|
||||
fn extend(&self, elt: path_elt) -> @path {
|
||||
@vec::append(self.path.get(), [elt])
|
||||
}
|
||||
|
||||
fn map_method(&mut self,
|
||||
impl_did: DefId,
|
||||
impl_path: @path,
|
||||
m: @method,
|
||||
is_provided: bool) {
|
||||
let entry = if is_provided {
|
||||
node_trait_method(@provided(m), impl_did, impl_path)
|
||||
} else {
|
||||
node_method(m, impl_did, impl_path)
|
||||
};
|
||||
|
||||
impl<F> Ctx<F> {
|
||||
fn insert(&self, id: ast::NodeId, node: ast_node) {
|
||||
let mut map = self.map.borrow_mut();
|
||||
map.get().insert(m.id, entry);
|
||||
map.get().insert(m.self_id, node_local(special_idents::self_));
|
||||
map.get().insert(id, node);
|
||||
}
|
||||
|
||||
fn map_struct_def(&mut self,
|
||||
struct_def: @ast::struct_def,
|
||||
parent_node: ast_node,
|
||||
ident: ast::Ident) {
|
||||
let p = self.extend(path_name(ident));
|
||||
|
||||
// If this is a tuple-like struct, register the constructor.
|
||||
match struct_def.ctor_id {
|
||||
None => {}
|
||||
Some(ctor_id) => {
|
||||
match parent_node {
|
||||
node_item(item, _) => {
|
||||
let mut map = self.map.borrow_mut();
|
||||
map.get().insert(ctor_id,
|
||||
node_struct_ctor(struct_def,
|
||||
item,
|
||||
p));
|
||||
}
|
||||
_ => fail!("struct def parent wasn't an item")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn map_expr(&mut self, ex: @Expr) {
|
||||
{
|
||||
let mut map = self.map.borrow_mut();
|
||||
map.get().insert(ex.id, node_expr(ex));
|
||||
}
|
||||
|
||||
// Expressions which are or might be calls:
|
||||
{
|
||||
let r = ex.get_callee_id();
|
||||
for callee_id in r.iter() {
|
||||
let mut map = self.map.borrow_mut();
|
||||
map.get().insert(*callee_id, node_callee_scope(ex));
|
||||
}
|
||||
}
|
||||
|
||||
visit::walk_expr(self, ex, ());
|
||||
}
|
||||
|
||||
fn map_fn(&mut self,
|
||||
fk: &visit::fn_kind,
|
||||
decl: &fn_decl,
|
||||
body: P<Block>,
|
||||
sp: codemap::Span,
|
||||
id: NodeId) {
|
||||
for a in decl.inputs.iter() {
|
||||
let mut map = self.map.borrow_mut();
|
||||
map.get().insert(a.id, node_arg(a.pat));
|
||||
}
|
||||
match *fk {
|
||||
visit::fk_method(name, _, _) => {
|
||||
let mut path = self.path.borrow_mut();
|
||||
path.get().push(path_name(name))
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
visit::walk_fn(self, fk, decl, body, sp, id, ());
|
||||
match *fk {
|
||||
visit::fk_method(..) => {
|
||||
let mut path = self.path.borrow_mut();
|
||||
path.get().pop();
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
fn map_stmt(&mut self, stmt: @Stmt) {
|
||||
{
|
||||
let mut map = self.map.borrow_mut();
|
||||
map.get().insert(stmt_id(stmt), node_stmt(stmt));
|
||||
}
|
||||
visit::walk_stmt(self, stmt, ());
|
||||
}
|
||||
|
||||
fn map_block(&mut self, b: P<Block>) {
|
||||
{
|
||||
let mut map = self.map.borrow_mut();
|
||||
map.get().insert(b.id, node_block(b));
|
||||
}
|
||||
|
||||
visit::walk_block(self, b, ());
|
||||
}
|
||||
|
||||
fn map_pat(&mut self, pat: &Pat) {
|
||||
match pat.node {
|
||||
PatIdent(_, ref path, _) => {
|
||||
// Note: this is at least *potentially* a pattern...
|
||||
let mut map = self.map.borrow_mut();
|
||||
map.get().insert(pat.id,
|
||||
node_local(ast_util::path_to_ident(path)));
|
||||
}
|
||||
_ => ()
|
||||
}
|
||||
|
||||
visit::walk_pat(self, pat, ());
|
||||
fn map_self(&self, m: @method) {
|
||||
self.insert(m.self_id, node_local(special_idents::self_, None));
|
||||
}
|
||||
}
|
||||
|
||||
impl Visitor<()> for Ctx {
|
||||
fn visit_item(&mut self, i: @item, _: ()) {
|
||||
impl<F: FoldOps> ast_fold for Ctx<F> {
|
||||
fn new_id(&mut self, id: ast::NodeId) -> ast::NodeId {
|
||||
self.fold_ops.new_id(id)
|
||||
}
|
||||
|
||||
fn new_span(&mut self, span: Span) -> Span {
|
||||
self.fold_ops.new_span(span)
|
||||
}
|
||||
|
||||
fn fold_item(&mut self, i: @item) -> SmallVector<@item> {
|
||||
// clone is FIXME #2543
|
||||
let item_path = @self.path.get();
|
||||
{
|
||||
let mut map = self.map.borrow_mut();
|
||||
map.get().insert(i.id, node_item(i, item_path));
|
||||
}
|
||||
match i.node {
|
||||
item_impl(_, ref maybe_trait, ty, ref ms) => {
|
||||
let item_path = @self.path.clone();
|
||||
self.path.push(match i.node {
|
||||
item_impl(_, ref maybe_trait, ty, _) => {
|
||||
// Right now the ident on impls is __extensions__ which isn't
|
||||
// very pretty when debugging, so attempt to select a better
|
||||
// name to use.
|
||||
let elt = impl_pretty_name(maybe_trait, ty);
|
||||
impl_pretty_name(maybe_trait, ty)
|
||||
}
|
||||
item_mod(_) | item_foreign_mod(_) => path_mod(i.ident),
|
||||
_ => path_name(i.ident)
|
||||
});
|
||||
|
||||
let i = fold::noop_fold_item(i, self).expect_one("expected one item");
|
||||
self.insert(i.id, node_item(i, item_path));
|
||||
|
||||
match i.node {
|
||||
item_impl(_, _, _, ref ms) => {
|
||||
// clone is FIXME #2543
|
||||
let p = @self.path.clone();
|
||||
let impl_did = ast_util::local_def(i.id);
|
||||
for m in ms.iter() {
|
||||
let extended = { self.extend(elt) };
|
||||
self.map_method(impl_did, extended, *m, false)
|
||||
for &m in ms.iter() {
|
||||
self.insert(m.id, node_method(m, impl_did, p));
|
||||
self.map_self(m);
|
||||
}
|
||||
|
||||
let mut path = self.path.borrow_mut();
|
||||
path.get().push(elt);
|
||||
}
|
||||
item_enum(ref enum_definition, _) => {
|
||||
// clone is FIXME #2543
|
||||
let p = @self.path.clone();
|
||||
for &v in enum_definition.variants.iter() {
|
||||
let elt = path_name(i.ident);
|
||||
let mut map = self.map.borrow_mut();
|
||||
map.get().insert(v.node.id,
|
||||
node_variant(v, i, self.extend(elt)));
|
||||
self.insert(v.node.id, node_variant(v, i, p));
|
||||
}
|
||||
}
|
||||
item_foreign_mod(ref nm) => {
|
||||
|
|
@ -364,41 +276,38 @@ impl Visitor<()> for Ctx {
|
|||
inherited => i.vis
|
||||
};
|
||||
|
||||
let mut map = self.map.borrow_mut();
|
||||
map.get().insert(nitem.id,
|
||||
node_foreign_item(*nitem,
|
||||
nm.abis,
|
||||
visibility,
|
||||
// FIXME (#2543)
|
||||
// Anonymous extern
|
||||
// mods go in the
|
||||
// parent scope.
|
||||
@self.path.get()
|
||||
));
|
||||
self.insert(nitem.id,
|
||||
// Anonymous extern mods go in the parent scope.
|
||||
node_foreign_item(*nitem, nm.abis, visibility, item_path));
|
||||
}
|
||||
}
|
||||
item_struct(struct_def, _) => {
|
||||
self.map_struct_def(struct_def,
|
||||
node_item(i, item_path),
|
||||
i.ident)
|
||||
// If this is a tuple-like struct, register the constructor.
|
||||
match struct_def.ctor_id {
|
||||
None => {}
|
||||
Some(ctor_id) => {
|
||||
// clone is FIXME #2543
|
||||
let p = @self.path.clone();
|
||||
self.insert(ctor_id, node_struct_ctor(struct_def, i, p));
|
||||
}
|
||||
}
|
||||
}
|
||||
item_trait(_, ref traits, ref methods) => {
|
||||
for p in traits.iter() {
|
||||
let mut map = self.map.borrow_mut();
|
||||
map.get().insert(p.ref_id, node_item(i, item_path));
|
||||
for t in traits.iter() {
|
||||
self.insert(t.ref_id, node_item(i, item_path));
|
||||
}
|
||||
|
||||
// clone is FIXME #2543
|
||||
let p = @self.path.clone();
|
||||
for tm in methods.iter() {
|
||||
let ext = { self.extend(path_name(i.ident)) };
|
||||
let d_id = ast_util::local_def(i.id);
|
||||
match *tm {
|
||||
required(ref m) => {
|
||||
let entry =
|
||||
node_trait_method(@(*tm).clone(), d_id, ext);
|
||||
let mut map = self.map.borrow_mut();
|
||||
map.get().insert(m.id, entry);
|
||||
self.insert(m.id, node_trait_method(@(*tm).clone(), d_id, p));
|
||||
}
|
||||
provided(m) => {
|
||||
self.map_method(d_id, ext, m, true);
|
||||
self.insert(m.id, node_trait_method(@provided(m), d_id, p));
|
||||
self.map_self(m);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -406,100 +315,123 @@ impl Visitor<()> for Ctx {
|
|||
_ => {}
|
||||
}
|
||||
|
||||
match i.node {
|
||||
item_mod(_) | item_foreign_mod(_) => {
|
||||
let mut path = self.path.borrow_mut();
|
||||
path.get().push(path_mod(i.ident));
|
||||
self.path.pop();
|
||||
|
||||
SmallVector::one(i)
|
||||
}
|
||||
|
||||
fn fold_pat(&mut self, pat: @Pat) -> @Pat {
|
||||
let pat = fold::noop_fold_pat(pat, self);
|
||||
match pat.node {
|
||||
PatIdent(_, ref path, _) => {
|
||||
// Note: this is at least *potentially* a pattern...
|
||||
self.insert(pat.id, node_local(ast_util::path_to_ident(path), Some(pat)));
|
||||
}
|
||||
item_impl(..) => {} // this was guessed above.
|
||||
_ => {
|
||||
let mut path = self.path.borrow_mut();
|
||||
path.get().push(path_name(i.ident))
|
||||
_ => {}
|
||||
}
|
||||
|
||||
pat
|
||||
}
|
||||
|
||||
fn fold_expr(&mut self, expr: @Expr) -> @Expr {
|
||||
let expr = fold::noop_fold_expr(expr, self);
|
||||
|
||||
self.insert(expr.id, node_expr(expr));
|
||||
|
||||
// Expressions which are or might be calls:
|
||||
{
|
||||
let r = expr.get_callee_id();
|
||||
for callee_id in r.iter() {
|
||||
self.insert(*callee_id, node_callee_scope(expr));
|
||||
}
|
||||
}
|
||||
visit::walk_item(self, i, ());
|
||||
|
||||
let mut path = self.path.borrow_mut();
|
||||
path.get().pop();
|
||||
expr
|
||||
}
|
||||
|
||||
fn visit_pat(&mut self, pat: &Pat, _: ()) {
|
||||
self.map_pat(pat);
|
||||
visit::walk_pat(self, pat, ())
|
||||
fn fold_stmt(&mut self, stmt: &Stmt) -> SmallVector<@Stmt> {
|
||||
let stmt = fold::noop_fold_stmt(stmt, self).expect_one("expected one statement");
|
||||
self.insert(ast_util::stmt_id(stmt), node_stmt(stmt));
|
||||
SmallVector::one(stmt)
|
||||
}
|
||||
|
||||
fn visit_expr(&mut self, expr: @Expr, _: ()) {
|
||||
self.map_expr(expr)
|
||||
fn fold_method(&mut self, m: @method) -> @method {
|
||||
self.path.push(path_name(m.ident));
|
||||
let m = fold::noop_fold_method(m, self);
|
||||
self.path.pop();
|
||||
m
|
||||
}
|
||||
|
||||
fn visit_stmt(&mut self, stmt: @Stmt, _: ()) {
|
||||
self.map_stmt(stmt)
|
||||
fn fold_fn_decl(&mut self, decl: &fn_decl) -> P<fn_decl> {
|
||||
let decl = fold::noop_fold_fn_decl(decl, self);
|
||||
for a in decl.inputs.iter() {
|
||||
self.insert(a.id, node_arg(a.pat));
|
||||
}
|
||||
decl
|
||||
}
|
||||
|
||||
fn visit_fn(&mut self,
|
||||
function_kind: &fn_kind,
|
||||
function_declaration: &fn_decl,
|
||||
block: P<Block>,
|
||||
span: Span,
|
||||
node_id: NodeId,
|
||||
_: ()) {
|
||||
self.map_fn(function_kind, function_declaration, block, span, node_id)
|
||||
}
|
||||
|
||||
fn visit_block(&mut self, block: P<Block>, _: ()) {
|
||||
self.map_block(block)
|
||||
}
|
||||
|
||||
fn visit_ty(&mut self, typ: &Ty, _: ()) {
|
||||
visit::walk_ty(self, typ, ())
|
||||
fn fold_block(&mut self, block: P<Block>) -> P<Block> {
|
||||
let block = fold::noop_fold_block(block, self);
|
||||
self.insert(block.id, node_block(block));
|
||||
block
|
||||
}
|
||||
}
|
||||
|
||||
pub fn map_crate(diag: @SpanHandler, c: &Crate) -> map {
|
||||
pub fn map_crate<F: 'static + FoldOps>(diag: @SpanHandler, c: Crate,
|
||||
fold_ops: F) -> (Crate, map) {
|
||||
let mut cx = Ctx {
|
||||
map: @RefCell::new(HashMap::new()),
|
||||
path: RefCell::new(~[]),
|
||||
path: ~[],
|
||||
diag: diag,
|
||||
fold_ops: fold_ops
|
||||
};
|
||||
visit::walk_crate(&mut cx, c, ());
|
||||
cx.map
|
||||
(cx.fold_crate(c), cx.map)
|
||||
}
|
||||
|
||||
// Used for items loaded from external crate that are being inlined into this
|
||||
// crate. The `path` should be the path to the item but should not include
|
||||
// the item itself.
|
||||
pub fn map_decoded_item(diag: @SpanHandler,
|
||||
map: map,
|
||||
path: path,
|
||||
ii: &inlined_item) {
|
||||
pub fn map_decoded_item<F: 'static + FoldOps>(diag: @SpanHandler,
|
||||
map: map,
|
||||
path: path,
|
||||
fold_ops: F,
|
||||
fold_ii: |&mut Ctx<F>| -> inlined_item)
|
||||
-> inlined_item {
|
||||
// I believe it is ok for the local IDs of inlined items from other crates
|
||||
// to overlap with the local ids from this crate, so just generate the ids
|
||||
// starting from 0.
|
||||
let mut cx = Ctx {
|
||||
map: map,
|
||||
path: RefCell::new(path.clone()),
|
||||
path: path.clone(),
|
||||
diag: diag,
|
||||
fold_ops: fold_ops
|
||||
};
|
||||
|
||||
let ii = fold_ii(&mut cx);
|
||||
|
||||
// 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.
|
||||
match *ii {
|
||||
match ii {
|
||||
ii_item(..) => {} // fallthrough
|
||||
ii_foreign(i) => {
|
||||
let mut map = cx.map.borrow_mut();
|
||||
map.get().insert(i.id, node_foreign_item(i,
|
||||
AbiSet::Intrinsic(),
|
||||
i.vis, // Wrong but OK
|
||||
@path));
|
||||
cx.insert(i.id, node_foreign_item(i,
|
||||
AbiSet::Intrinsic(),
|
||||
i.vis, // Wrong but OK
|
||||
@path));
|
||||
}
|
||||
ii_method(impl_did, is_provided, m) => {
|
||||
cx.map_method(impl_did, @path, m, is_provided);
|
||||
let entry = if is_provided {
|
||||
node_trait_method(@provided(m), impl_did, @path)
|
||||
} else {
|
||||
node_method(m, impl_did, @path)
|
||||
};
|
||||
cx.insert(m.id, entry);
|
||||
cx.map_self(m);
|
||||
}
|
||||
}
|
||||
|
||||
// visit the item / method contents and add those to the map:
|
||||
ii.accept((), &mut cx);
|
||||
ii
|
||||
}
|
||||
|
||||
pub fn node_id_to_str(map: map, id: NodeId, itr: @ident_interner) -> ~str {
|
||||
|
|
@ -554,7 +486,7 @@ pub fn node_id_to_str(map: map, id: NodeId, itr: @ident_interner) -> ~str {
|
|||
Some(&node_arg(pat)) => {
|
||||
format!("arg {} (id={})", pprust::pat_to_str(pat, itr), id)
|
||||
}
|
||||
Some(&node_local(ident)) => {
|
||||
Some(&node_local(ident, _)) => {
|
||||
format!("local (id={}, name={})", id, itr.get(ident.name))
|
||||
}
|
||||
Some(&node_block(block)) => {
|
||||
|
|
@ -589,7 +521,10 @@ pub fn node_span(items: map,
|
|||
Some(&node_expr(expr)) => expr.span,
|
||||
Some(&node_stmt(stmt)) => stmt.span,
|
||||
Some(&node_arg(pat)) => pat.span,
|
||||
Some(&node_local(_)) => fail!("node_span: cannot get span from node_local"),
|
||||
Some(&node_local(_, pat)) => match pat {
|
||||
Some(pat) => pat.span,
|
||||
None => fail!("node_span: cannot get span from node_local (likely `self`)")
|
||||
},
|
||||
Some(&node_block(block)) => block.span,
|
||||
Some(&node_struct_ctor(_, item, _)) => item.span,
|
||||
Some(&node_callee_scope(expr)) => expr.span,
|
||||
|
|
|
|||
|
|
@ -292,38 +292,6 @@ pub fn struct_field_visibility(field: ast::struct_field) -> visibility {
|
|||
}
|
||||
}
|
||||
|
||||
pub trait inlined_item_utils {
|
||||
fn ident(&self) -> Ident;
|
||||
fn id(&self) -> ast::NodeId;
|
||||
fn accept<E: Clone, V:Visitor<E>>(&self, e: E, v: &mut V);
|
||||
}
|
||||
|
||||
impl inlined_item_utils for inlined_item {
|
||||
fn ident(&self) -> Ident {
|
||||
match *self {
|
||||
ii_item(i) => i.ident,
|
||||
ii_foreign(i) => i.ident,
|
||||
ii_method(_, _, m) => m.ident,
|
||||
}
|
||||
}
|
||||
|
||||
fn id(&self) -> ast::NodeId {
|
||||
match *self {
|
||||
ii_item(i) => i.id,
|
||||
ii_foreign(i) => i.id,
|
||||
ii_method(_, _, m) => m.id,
|
||||
}
|
||||
}
|
||||
|
||||
fn accept<E: Clone, V:Visitor<E>>(&self, e: E, v: &mut V) {
|
||||
match *self {
|
||||
ii_item(i) => v.visit_item(i, e),
|
||||
ii_foreign(i) => v.visit_foreign_item(i, e),
|
||||
ii_method(_, _, m) => visit::walk_method_helper(v, m, e),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* True if d is either a def_self, or a chain of def_upvars
|
||||
referring to a def_self */
|
||||
pub fn is_self(d: ast::Def) -> bool {
|
||||
|
|
@ -443,12 +411,12 @@ impl<'a, O: IdVisitingOperation> Visitor<()> for IdVisitor<'a, O> {
|
|||
visit::walk_view_item(self, view_item, env)
|
||||
}
|
||||
|
||||
fn visit_foreign_item(&mut self, foreign_item: @foreign_item, env: ()) {
|
||||
fn visit_foreign_item(&mut self, foreign_item: &foreign_item, 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: &item, env: ()) {
|
||||
if !self.pass_through_items {
|
||||
if self.visited_outermost {
|
||||
return
|
||||
|
|
@ -472,17 +440,17 @@ 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: &Local, env: ()) {
|
||||
self.operation.visit_id(local.id);
|
||||
visit::walk_local(self, local, env)
|
||||
}
|
||||
|
||||
fn visit_block(&mut self, block: P<Block>, env: ()) {
|
||||
fn visit_block(&mut self, block: &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: &Stmt, env: ()) {
|
||||
self.operation.visit_id(ast_util::stmt_id(statement));
|
||||
visit::walk_stmt(self, statement, env)
|
||||
}
|
||||
|
|
@ -493,7 +461,7 @@ impl<'a, O: IdVisitingOperation> Visitor<()> for IdVisitor<'a, O> {
|
|||
}
|
||||
|
||||
|
||||
fn visit_expr(&mut self, expression: @Expr, env: ()) {
|
||||
fn visit_expr(&mut self, expression: &Expr, env: ()) {
|
||||
{
|
||||
let optional_callee_id = expression.get_callee_id();
|
||||
for callee_id in optional_callee_id.iter() {
|
||||
|
|
@ -521,7 +489,7 @@ impl<'a, O: IdVisitingOperation> Visitor<()> for IdVisitor<'a, O> {
|
|||
fn visit_fn(&mut self,
|
||||
function_kind: &visit::fn_kind,
|
||||
function_declaration: &fn_decl,
|
||||
block: P<Block>,
|
||||
block: &Block,
|
||||
span: Span,
|
||||
node_id: NodeId,
|
||||
env: ()) {
|
||||
|
|
@ -572,7 +540,7 @@ impl<'a, O: IdVisitingOperation> Visitor<()> for IdVisitor<'a, O> {
|
|||
}
|
||||
|
||||
fn visit_struct_def(&mut self,
|
||||
struct_def: @struct_def,
|
||||
struct_def: &struct_def,
|
||||
ident: ast::Ident,
|
||||
generics: &ast::Generics,
|
||||
id: NodeId,
|
||||
|
|
@ -598,7 +566,12 @@ pub fn visit_ids_for_inlined_item<O: IdVisitingOperation>(item: &inlined_item,
|
|||
pass_through_items: true,
|
||||
visited_outermost: false,
|
||||
};
|
||||
item.accept((), &mut id_visitor);
|
||||
|
||||
match *item {
|
||||
ii_item(i) => id_visitor.visit_item(i, ()),
|
||||
ii_foreign(i) => id_visitor.visit_foreign_item(i, ()),
|
||||
ii_method(_, _, m) => visit::walk_method_helper(&mut id_visitor, m, ()),
|
||||
}
|
||||
}
|
||||
|
||||
struct IdRangeComputingVisitor {
|
||||
|
|
|
|||
|
|
@ -1128,7 +1128,7 @@ mod test {
|
|||
|
||||
impl Visitor<()> for NewPathExprFinderContext {
|
||||
|
||||
fn visit_expr(&mut self, expr: @ast::Expr, _: ()) {
|
||||
fn visit_expr(&mut self, expr: &ast::Expr, _: ()) {
|
||||
match *expr {
|
||||
ast::Expr{id:_,span:_,node:ast::ExprPath(ref p)} => {
|
||||
self.path_accumulator.push(p.clone());
|
||||
|
|
|
|||
|
|
@ -84,32 +84,7 @@ pub trait ast_fold {
|
|||
}
|
||||
|
||||
fn fold_foreign_item(&mut self, ni: @foreign_item) -> @foreign_item {
|
||||
let fold_attribute = |x| fold_attribute_(x, self);
|
||||
|
||||
@ast::foreign_item {
|
||||
ident: self.fold_ident(ni.ident),
|
||||
attrs: ni.attrs.map(|x| fold_attribute(*x)),
|
||||
node:
|
||||
match ni.node {
|
||||
foreign_item_fn(ref fdec, ref generics) => {
|
||||
foreign_item_fn(
|
||||
P(fn_decl {
|
||||
inputs: fdec.inputs.map(|a| fold_arg_(a,
|
||||
self)),
|
||||
output: self.fold_ty(fdec.output),
|
||||
cf: fdec.cf,
|
||||
variadic: fdec.variadic
|
||||
}),
|
||||
fold_generics(generics, self))
|
||||
}
|
||||
foreign_item_static(t, m) => {
|
||||
foreign_item_static(self.fold_ty(t), m)
|
||||
}
|
||||
},
|
||||
id: self.new_id(ni.id),
|
||||
span: self.new_span(ni.span),
|
||||
vis: ni.vis,
|
||||
}
|
||||
noop_fold_foreign_item(ni, self)
|
||||
}
|
||||
|
||||
fn fold_item(&mut self, i: @item) -> SmallVector<@item> {
|
||||
|
|
@ -134,24 +109,16 @@ pub trait ast_fold {
|
|||
noop_fold_item_underscore(i, self)
|
||||
}
|
||||
|
||||
fn fold_fn_decl(&mut self, d: &fn_decl) -> P<fn_decl> {
|
||||
noop_fold_fn_decl(d, self)
|
||||
}
|
||||
|
||||
fn fold_type_method(&mut self, m: &TypeMethod) -> TypeMethod {
|
||||
noop_fold_type_method(m, self)
|
||||
}
|
||||
|
||||
fn fold_method(&mut self, m: @method) -> @method {
|
||||
@ast::method {
|
||||
ident: self.fold_ident(m.ident),
|
||||
attrs: m.attrs.map(|a| fold_attribute_(*a, self)),
|
||||
generics: fold_generics(&m.generics, self),
|
||||
explicit_self: self.fold_explicit_self(&m.explicit_self),
|
||||
purity: m.purity,
|
||||
decl: fold_fn_decl(m.decl, self),
|
||||
body: self.fold_block(m.body),
|
||||
id: self.new_id(m.id),
|
||||
span: self.new_span(m.span),
|
||||
self_id: self.new_id(m.self_id),
|
||||
vis: m.vis,
|
||||
}
|
||||
noop_fold_method(m, self)
|
||||
}
|
||||
|
||||
fn fold_block(&mut self, b: P<Block>) -> P<Block> {
|
||||
|
|
@ -171,48 +138,7 @@ pub trait ast_fold {
|
|||
}
|
||||
|
||||
fn fold_pat(&mut self, p: @Pat) -> @Pat {
|
||||
let node = match p.node {
|
||||
PatWild => PatWild,
|
||||
PatWildMulti => PatWildMulti,
|
||||
PatIdent(binding_mode, ref pth, ref sub) => {
|
||||
PatIdent(binding_mode,
|
||||
self.fold_path(pth),
|
||||
sub.map(|x| self.fold_pat(x)))
|
||||
}
|
||||
PatLit(e) => PatLit(self.fold_expr(e)),
|
||||
PatEnum(ref pth, ref pats) => {
|
||||
PatEnum(self.fold_path(pth),
|
||||
pats.as_ref().map(|pats| pats.map(|x| self.fold_pat(*x))))
|
||||
}
|
||||
PatStruct(ref pth, ref fields, etc) => {
|
||||
let pth_ = self.fold_path(pth);
|
||||
let fs = fields.map(|f| {
|
||||
ast::FieldPat {
|
||||
ident: f.ident,
|
||||
pat: self.fold_pat(f.pat)
|
||||
}
|
||||
});
|
||||
PatStruct(pth_, fs, etc)
|
||||
}
|
||||
PatTup(ref elts) => PatTup(elts.map(|x| self.fold_pat(*x))),
|
||||
PatBox(inner) => PatBox(self.fold_pat(inner)),
|
||||
PatUniq(inner) => PatUniq(self.fold_pat(inner)),
|
||||
PatRegion(inner) => PatRegion(self.fold_pat(inner)),
|
||||
PatRange(e1, e2) => {
|
||||
PatRange(self.fold_expr(e1), self.fold_expr(e2))
|
||||
},
|
||||
PatVec(ref before, ref slice, ref after) => {
|
||||
PatVec(before.map(|x| self.fold_pat(*x)),
|
||||
slice.map(|x| self.fold_pat(x)),
|
||||
after.map(|x| self.fold_pat(*x)))
|
||||
}
|
||||
};
|
||||
|
||||
@Pat {
|
||||
id: self.new_id(p.id),
|
||||
span: self.new_span(p.span),
|
||||
node: node,
|
||||
}
|
||||
noop_fold_pat(p, self)
|
||||
}
|
||||
|
||||
fn fold_decl(&mut self, d: @Decl) -> SmallVector<@Decl> {
|
||||
|
|
@ -252,7 +178,7 @@ pub trait ast_fold {
|
|||
region: fold_opt_lifetime(&f.region, self),
|
||||
onceness: f.onceness,
|
||||
bounds: fold_opt_bounds(&f.bounds, self),
|
||||
decl: fold_fn_decl(f.decl, self),
|
||||
decl: self.fold_fn_decl(f.decl),
|
||||
lifetimes: f.lifetimes.map(|l| fold_lifetime(l, self)),
|
||||
})
|
||||
}
|
||||
|
|
@ -261,7 +187,7 @@ pub trait ast_fold {
|
|||
lifetimes: f.lifetimes.map(|l| fold_lifetime(l, self)),
|
||||
purity: f.purity,
|
||||
abis: f.abis,
|
||||
decl: fold_fn_decl(f.decl, self)
|
||||
decl: self.fold_fn_decl(f.decl)
|
||||
})
|
||||
}
|
||||
ty_tup(ref tys) => ty_tup(tys.map(|&ty| self.fold_ty(ty))),
|
||||
|
|
@ -410,7 +336,7 @@ pub trait ast_fold {
|
|||
/* some little folds that probably aren't useful to have in ast_fold itself*/
|
||||
|
||||
//used in noop_fold_item and noop_fold_crate and noop_fold_crate_directive
|
||||
fn fold_meta_item_<T:ast_fold>(mi: @MetaItem, fld: &mut T) -> @MetaItem {
|
||||
fn fold_meta_item_<T: ast_fold>(mi: @MetaItem, fld: &mut T) -> @MetaItem {
|
||||
@Spanned {
|
||||
node:
|
||||
match mi.node {
|
||||
|
|
@ -428,7 +354,7 @@ fn fold_meta_item_<T:ast_fold>(mi: @MetaItem, fld: &mut T) -> @MetaItem {
|
|||
}
|
||||
|
||||
//used in noop_fold_item and noop_fold_crate
|
||||
fn fold_attribute_<T:ast_fold>(at: Attribute, fld: &mut T) -> Attribute {
|
||||
fn fold_attribute_<T: ast_fold>(at: Attribute, fld: &mut T) -> Attribute {
|
||||
Spanned {
|
||||
span: fld.new_span(at.span),
|
||||
node: ast::Attribute_ {
|
||||
|
|
@ -440,7 +366,7 @@ fn fold_attribute_<T:ast_fold>(at: Attribute, fld: &mut T) -> Attribute {
|
|||
}
|
||||
|
||||
//used in noop_fold_foreign_item and noop_fold_fn_decl
|
||||
fn fold_arg_<T:ast_fold>(a: &arg, fld: &mut T) -> arg {
|
||||
fn fold_arg_<T: ast_fold>(a: &arg, fld: &mut T) -> arg {
|
||||
ast::arg {
|
||||
ty: fld.fold_ty(a.ty),
|
||||
pat: fld.fold_pat(a.pat),
|
||||
|
|
@ -450,7 +376,7 @@ fn fold_arg_<T:ast_fold>(a: &arg, fld: &mut T) -> arg {
|
|||
|
||||
// build a new vector of tts by appling the ast_fold's fold_ident to
|
||||
// all of the identifiers in the token trees.
|
||||
pub fn fold_tts<T:ast_fold>(tts: &[token_tree], fld: &mut T) -> ~[token_tree] {
|
||||
pub fn fold_tts<T: ast_fold>(tts: &[token_tree], fld: &mut T) -> ~[token_tree] {
|
||||
tts.map(|tt| {
|
||||
match *tt {
|
||||
tt_tok(span, ref tok) =>
|
||||
|
|
@ -468,7 +394,7 @@ pub fn fold_tts<T:ast_fold>(tts: &[token_tree], fld: &mut T) -> ~[token_tree] {
|
|||
}
|
||||
|
||||
// apply ident folder if it's an ident, otherwise leave it alone
|
||||
fn maybe_fold_ident<T:ast_fold>(t: &token::Token, fld: &mut T) -> token::Token {
|
||||
fn maybe_fold_ident<T: ast_fold>(t: &token::Token, fld: &mut T) -> token::Token {
|
||||
match *t {
|
||||
token::IDENT(id, followed_by_colons) => {
|
||||
token::IDENT(fld.fold_ident(id), followed_by_colons)
|
||||
|
|
@ -477,8 +403,8 @@ fn maybe_fold_ident<T:ast_fold>(t: &token::Token, fld: &mut T) -> token::Token {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn fold_fn_decl<T:ast_fold>(decl: &ast::fn_decl, fld: &mut T)
|
||||
-> P<fn_decl> {
|
||||
pub fn noop_fold_fn_decl<T: ast_fold>(decl: &fn_decl, fld: &mut T)
|
||||
-> P<fn_decl> {
|
||||
P(fn_decl {
|
||||
inputs: decl.inputs.map(|x| fold_arg_(x, fld)), // bad copy
|
||||
output: fld.fold_ty(decl.output),
|
||||
|
|
@ -487,15 +413,15 @@ pub fn fold_fn_decl<T:ast_fold>(decl: &ast::fn_decl, fld: &mut T)
|
|||
})
|
||||
}
|
||||
|
||||
fn fold_ty_param_bound<T:ast_fold>(tpb: &TyParamBound, fld: &mut T)
|
||||
-> TyParamBound {
|
||||
fn fold_ty_param_bound<T: ast_fold>(tpb: &TyParamBound, fld: &mut T)
|
||||
-> TyParamBound {
|
||||
match *tpb {
|
||||
TraitTyParamBound(ref ty) => TraitTyParamBound(fold_trait_ref(ty, fld)),
|
||||
RegionTyParamBound => RegionTyParamBound
|
||||
}
|
||||
}
|
||||
|
||||
pub fn fold_ty_param<T:ast_fold>(tp: &TyParam, fld: &mut T) -> TyParam {
|
||||
pub fn fold_ty_param<T: ast_fold>(tp: &TyParam, fld: &mut T) -> TyParam {
|
||||
TyParam {
|
||||
ident: tp.ident,
|
||||
id: fld.new_id(tp.id),
|
||||
|
|
@ -503,12 +429,12 @@ pub fn fold_ty_param<T:ast_fold>(tp: &TyParam, fld: &mut T) -> TyParam {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn fold_ty_params<T:ast_fold>(tps: &OptVec<TyParam>, fld: &mut T)
|
||||
-> OptVec<TyParam> {
|
||||
pub fn fold_ty_params<T: ast_fold>(tps: &OptVec<TyParam>, fld: &mut T)
|
||||
-> OptVec<TyParam> {
|
||||
tps.map(|tp| fold_ty_param(tp, fld))
|
||||
}
|
||||
|
||||
pub fn fold_lifetime<T:ast_fold>(l: &Lifetime, fld: &mut T) -> Lifetime {
|
||||
pub fn fold_lifetime<T: ast_fold>(l: &Lifetime, fld: &mut T) -> Lifetime {
|
||||
Lifetime {
|
||||
id: fld.new_id(l.id),
|
||||
span: fld.new_span(l.span),
|
||||
|
|
@ -516,37 +442,36 @@ pub fn fold_lifetime<T:ast_fold>(l: &Lifetime, fld: &mut T) -> Lifetime {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn fold_lifetimes<T:ast_fold>(lts: &OptVec<Lifetime>, fld: &mut T)
|
||||
-> OptVec<Lifetime> {
|
||||
pub fn fold_lifetimes<T: ast_fold>(lts: &OptVec<Lifetime>, fld: &mut T)
|
||||
-> OptVec<Lifetime> {
|
||||
lts.map(|l| fold_lifetime(l, fld))
|
||||
}
|
||||
|
||||
pub fn fold_opt_lifetime<T:ast_fold>(o_lt: &Option<Lifetime>, fld: &mut T)
|
||||
-> Option<Lifetime> {
|
||||
pub fn fold_opt_lifetime<T: ast_fold>(o_lt: &Option<Lifetime>, fld: &mut T)
|
||||
-> Option<Lifetime> {
|
||||
o_lt.as_ref().map(|lt| fold_lifetime(lt, fld))
|
||||
}
|
||||
|
||||
pub fn fold_generics<T:ast_fold>(generics: &Generics, fld: &mut T) -> Generics {
|
||||
pub fn fold_generics<T: ast_fold>(generics: &Generics, fld: &mut T) -> Generics {
|
||||
Generics {ty_params: fold_ty_params(&generics.ty_params, fld),
|
||||
lifetimes: fold_lifetimes(&generics.lifetimes, fld)}
|
||||
}
|
||||
|
||||
fn fold_struct_def<T:ast_fold>(struct_def: @ast::struct_def, fld: &mut T)
|
||||
-> @ast::struct_def {
|
||||
fn fold_struct_def<T: ast_fold>(struct_def: @struct_def, fld: &mut T) -> @struct_def {
|
||||
@ast::struct_def {
|
||||
fields: struct_def.fields.map(|f| fold_struct_field(f, fld)),
|
||||
ctor_id: struct_def.ctor_id.map(|cid| fld.new_id(cid)),
|
||||
}
|
||||
}
|
||||
|
||||
fn fold_trait_ref<T:ast_fold>(p: &trait_ref, fld: &mut T) -> trait_ref {
|
||||
fn fold_trait_ref<T: ast_fold>(p: &trait_ref, fld: &mut T) -> trait_ref {
|
||||
ast::trait_ref {
|
||||
path: fld.fold_path(&p.path),
|
||||
ref_id: fld.new_id(p.ref_id),
|
||||
}
|
||||
}
|
||||
|
||||
fn fold_struct_field<T:ast_fold>(f: &struct_field, fld: &mut T) -> struct_field {
|
||||
fn fold_struct_field<T: ast_fold>(f: &struct_field, fld: &mut T) -> struct_field {
|
||||
Spanned {
|
||||
node: ast::struct_field_ {
|
||||
kind: f.node.kind,
|
||||
|
|
@ -558,7 +483,7 @@ fn fold_struct_field<T:ast_fold>(f: &struct_field, fld: &mut T) -> struct_field
|
|||
}
|
||||
}
|
||||
|
||||
fn fold_field_<T:ast_fold>(field: Field, folder: &mut T) -> Field {
|
||||
fn fold_field_<T: ast_fold>(field: Field, folder: &mut T) -> Field {
|
||||
ast::Field {
|
||||
ident: respan(field.ident.span, folder.fold_ident(field.ident.node)),
|
||||
expr: folder.fold_expr(field.expr),
|
||||
|
|
@ -566,15 +491,15 @@ fn fold_field_<T:ast_fold>(field: Field, folder: &mut T) -> Field {
|
|||
}
|
||||
}
|
||||
|
||||
fn fold_mt<T:ast_fold>(mt: &mt, folder: &mut T) -> mt {
|
||||
fn fold_mt<T: ast_fold>(mt: &mt, folder: &mut T) -> mt {
|
||||
mt {
|
||||
ty: folder.fold_ty(mt.ty),
|
||||
mutbl: mt.mutbl,
|
||||
}
|
||||
}
|
||||
|
||||
fn fold_opt_bounds<T:ast_fold>(b: &Option<OptVec<TyParamBound>>, folder: &mut T)
|
||||
-> Option<OptVec<TyParamBound>> {
|
||||
fn fold_opt_bounds<T: ast_fold>(b: &Option<OptVec<TyParamBound>>, folder: &mut T)
|
||||
-> Option<OptVec<TyParamBound>> {
|
||||
b.as_ref().map(|bounds| {
|
||||
bounds.map(|bound| {
|
||||
fold_ty_param_bound(bound, folder)
|
||||
|
|
@ -582,15 +507,14 @@ fn fold_opt_bounds<T:ast_fold>(b: &Option<OptVec<TyParamBound>>, folder: &mut T)
|
|||
})
|
||||
}
|
||||
|
||||
fn fold_variant_arg_<T:ast_fold>(va: &variant_arg, folder: &mut T)
|
||||
-> variant_arg {
|
||||
fn fold_variant_arg_<T: ast_fold>(va: &variant_arg, folder: &mut T) -> variant_arg {
|
||||
ast::variant_arg {
|
||||
ty: folder.fold_ty(va.ty),
|
||||
id: folder.new_id(va.id)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn noop_fold_block<T:ast_fold>(b: P<Block>, folder: &mut T) -> P<Block> {
|
||||
pub fn noop_fold_block<T: ast_fold>(b: P<Block>, folder: &mut T) -> P<Block> {
|
||||
let view_items = b.view_items.map(|x| folder.fold_view_item(x));
|
||||
let stmts = b.stmts.iter().flat_map(|s| folder.fold_stmt(*s).move_iter()).collect();
|
||||
P(Block {
|
||||
|
|
@ -603,14 +527,14 @@ pub fn noop_fold_block<T:ast_fold>(b: P<Block>, folder: &mut T) -> P<Block> {
|
|||
})
|
||||
}
|
||||
|
||||
pub fn noop_fold_item_underscore<T:ast_fold>(i: &item_, folder: &mut T) -> item_ {
|
||||
pub fn noop_fold_item_underscore<T: ast_fold>(i: &item_, folder: &mut T) -> item_ {
|
||||
match *i {
|
||||
item_static(t, m, e) => {
|
||||
item_static(folder.fold_ty(t), m, folder.fold_expr(e))
|
||||
}
|
||||
item_fn(decl, purity, abi, ref generics, body) => {
|
||||
item_fn(
|
||||
fold_fn_decl(decl, folder),
|
||||
folder.fold_fn_decl(decl),
|
||||
purity,
|
||||
abi,
|
||||
fold_generics(generics, folder),
|
||||
|
|
@ -660,13 +584,12 @@ pub fn noop_fold_item_underscore<T:ast_fold>(i: &item_, folder: &mut T) -> item_
|
|||
}
|
||||
}
|
||||
|
||||
pub fn noop_fold_type_method<T:ast_fold>(m: &TypeMethod, fld: &mut T)
|
||||
-> TypeMethod {
|
||||
pub fn noop_fold_type_method<T: ast_fold>(m: &TypeMethod, fld: &mut T) -> TypeMethod {
|
||||
TypeMethod {
|
||||
ident: fld.fold_ident(m.ident),
|
||||
attrs: m.attrs.map(|a| fold_attribute_(*a, fld)),
|
||||
purity: m.purity,
|
||||
decl: fold_fn_decl(m.decl, fld),
|
||||
decl: fld.fold_fn_decl(m.decl),
|
||||
generics: fold_generics(&m.generics, fld),
|
||||
explicit_self: fld.fold_explicit_self(&m.explicit_self),
|
||||
id: fld.new_id(m.id),
|
||||
|
|
@ -674,7 +597,7 @@ pub fn noop_fold_type_method<T:ast_fold>(m: &TypeMethod, fld: &mut T)
|
|||
}
|
||||
}
|
||||
|
||||
pub fn noop_fold_mod<T:ast_fold>(m: &_mod, folder: &mut T) -> _mod {
|
||||
pub fn noop_fold_mod<T: ast_fold>(m: &_mod, folder: &mut T) -> _mod {
|
||||
ast::_mod {
|
||||
view_items: m.view_items
|
||||
.iter()
|
||||
|
|
@ -683,7 +606,7 @@ pub fn noop_fold_mod<T:ast_fold>(m: &_mod, folder: &mut T) -> _mod {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn noop_fold_crate<T:ast_fold>(c: Crate, folder: &mut T) -> Crate {
|
||||
pub fn noop_fold_crate<T: ast_fold>(c: Crate, folder: &mut T) -> Crate {
|
||||
let fold_meta_item = |x| fold_meta_item_(x, folder);
|
||||
let fold_attribute = |x| fold_attribute_(x, folder);
|
||||
|
||||
|
|
@ -695,11 +618,11 @@ pub fn noop_fold_crate<T:ast_fold>(c: Crate, folder: &mut T) -> Crate {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn noop_fold_item<T:ast_fold>(i: @ast::item, folder: &mut T)
|
||||
-> SmallVector<@ast::item> {
|
||||
pub fn noop_fold_item<T: ast_fold>(i: &item, folder: &mut T)
|
||||
-> SmallVector<@item> {
|
||||
let fold_attribute = |x| fold_attribute_(x, folder);
|
||||
|
||||
SmallVector::one(@ast::item {
|
||||
SmallVector::one(@item {
|
||||
ident: folder.fold_ident(i.ident),
|
||||
attrs: i.attrs.map(|e| fold_attribute(*e)),
|
||||
id: folder.new_id(i.id),
|
||||
|
|
@ -709,7 +632,92 @@ pub fn noop_fold_item<T:ast_fold>(i: @ast::item, folder: &mut T)
|
|||
})
|
||||
}
|
||||
|
||||
pub fn noop_fold_expr<T:ast_fold>(e: @ast::Expr, folder: &mut T) -> @ast::Expr {
|
||||
pub fn noop_fold_foreign_item<T: ast_fold>(ni: &foreign_item, folder: &mut T)
|
||||
-> @foreign_item {
|
||||
@foreign_item {
|
||||
ident: folder.fold_ident(ni.ident),
|
||||
attrs: ni.attrs.map(|x| fold_attribute_(*x, folder)),
|
||||
node: match ni.node {
|
||||
foreign_item_fn(ref fdec, ref generics) => {
|
||||
foreign_item_fn(P(fn_decl {
|
||||
inputs: fdec.inputs.map(|a| fold_arg_(a, folder)),
|
||||
output: folder.fold_ty(fdec.output),
|
||||
cf: fdec.cf,
|
||||
variadic: fdec.variadic
|
||||
}), fold_generics(generics, folder))
|
||||
}
|
||||
foreign_item_static(t, m) => {
|
||||
foreign_item_static(folder.fold_ty(t), m)
|
||||
}
|
||||
},
|
||||
id: folder.new_id(ni.id),
|
||||
span: folder.new_span(ni.span),
|
||||
vis: ni.vis,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn noop_fold_method<T: ast_fold>(m: &method, folder: &mut T) -> @method {
|
||||
@method {
|
||||
ident: folder.fold_ident(m.ident),
|
||||
attrs: m.attrs.map(|a| fold_attribute_(*a, folder)),
|
||||
generics: fold_generics(&m.generics, folder),
|
||||
explicit_self: folder.fold_explicit_self(&m.explicit_self),
|
||||
purity: m.purity,
|
||||
decl: folder.fold_fn_decl(m.decl),
|
||||
body: folder.fold_block(m.body),
|
||||
id: folder.new_id(m.id),
|
||||
span: folder.new_span(m.span),
|
||||
self_id: folder.new_id(m.self_id),
|
||||
vis: m.vis
|
||||
}
|
||||
}
|
||||
|
||||
pub fn noop_fold_pat<T: ast_fold>(p: @Pat, folder: &mut T) -> @Pat {
|
||||
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.map(|x| folder.fold_pat(*x))))
|
||||
}
|
||||
PatStruct(ref pth, ref fields, etc) => {
|
||||
let pth_ = folder.fold_path(pth);
|
||||
let fs = fields.map(|f| {
|
||||
ast::FieldPat {
|
||||
ident: f.ident,
|
||||
pat: folder.fold_pat(f.pat)
|
||||
}
|
||||
});
|
||||
PatStruct(pth_, fs, etc)
|
||||
}
|
||||
PatTup(ref elts) => PatTup(elts.map(|x| folder.fold_pat(*x))),
|
||||
PatBox(inner) => PatBox(folder.fold_pat(inner)),
|
||||
PatUniq(inner) => PatUniq(folder.fold_pat(inner)),
|
||||
PatRegion(inner) => PatRegion(folder.fold_pat(inner)),
|
||||
PatRange(e1, e2) => {
|
||||
PatRange(folder.fold_expr(e1), folder.fold_expr(e2))
|
||||
},
|
||||
PatVec(ref before, ref slice, ref after) => {
|
||||
PatVec(before.map(|x| folder.fold_pat(*x)),
|
||||
slice.map(|x| folder.fold_pat(x)),
|
||||
after.map(|x| folder.fold_pat(*x)))
|
||||
}
|
||||
};
|
||||
|
||||
@Pat {
|
||||
id: folder.new_id(p.id),
|
||||
span: folder.new_span(p.span),
|
||||
node: node,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn noop_fold_expr<T: ast_fold>(e: @Expr, folder: &mut T) -> @Expr {
|
||||
let fold_field = |x| fold_field_(x, folder);
|
||||
|
||||
let node = match e.node {
|
||||
|
|
@ -776,13 +784,10 @@ pub fn noop_fold_expr<T:ast_fold>(e: @ast::Expr, folder: &mut T) -> @ast::Expr {
|
|||
arms.map(|x| folder.fold_arm(x)))
|
||||
}
|
||||
ExprFnBlock(decl, body) => {
|
||||
ExprFnBlock(
|
||||
fold_fn_decl(decl, folder),
|
||||
folder.fold_block(body)
|
||||
)
|
||||
ExprFnBlock(folder.fold_fn_decl(decl), folder.fold_block(body))
|
||||
}
|
||||
ExprProc(decl, body) => {
|
||||
ExprProc(fold_fn_decl(decl, folder), folder.fold_block(body))
|
||||
ExprProc(folder.fold_fn_decl(decl), folder.fold_block(body))
|
||||
}
|
||||
ExprBlock(blk) => ExprBlock(folder.fold_block(blk)),
|
||||
ExprAssign(el, er) => {
|
||||
|
|
@ -835,7 +840,7 @@ pub fn noop_fold_expr<T:ast_fold>(e: @ast::Expr, folder: &mut T) -> @ast::Expr {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn noop_fold_stmt<T:ast_fold>(s: &Stmt, folder: &mut T) -> SmallVector<@Stmt> {
|
||||
pub fn noop_fold_stmt<T: ast_fold>(s: &Stmt, folder: &mut T) -> SmallVector<@Stmt> {
|
||||
let nodes = match s.node {
|
||||
StmtDecl(d, nid) => {
|
||||
folder.fold_decl(d).move_iter()
|
||||
|
|
|
|||
|
|
@ -64,34 +64,34 @@ pub fn generics_of_fn(fk: &fn_kind) -> Generics {
|
|||
}
|
||||
}
|
||||
|
||||
pub trait Visitor<E:Clone> {
|
||||
pub trait Visitor<E: Clone> {
|
||||
fn visit_ident(&mut self, _sp: Span, _ident: 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:&view_item, e:E) { walk_view_item(self, i, e) }
|
||||
fn visit_foreign_item(&mut self, i:@foreign_item, 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:P<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:&fn_kind, fd:&fn_decl, b:P<Block>, s:Span, n:NodeId, e:E) {
|
||||
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: &view_item, e: E) { walk_view_item(self, i, e) }
|
||||
fn visit_foreign_item(&mut self, i: &foreign_item, 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: &fn_kind, fd: &fn_decl, b: &Block, s: Span, n: NodeId, e: E) {
|
||||
walk_fn(self, fk, fd, b, s, n , e)
|
||||
}
|
||||
fn visit_ty_method(&mut self, t:&TypeMethod, e:E) { walk_ty_method(self, t, e) }
|
||||
fn visit_trait_method(&mut self, t:&trait_method, e:E) { walk_trait_method(self, t, e) }
|
||||
fn visit_struct_def(&mut self, s:@struct_def, i:Ident, g:&Generics, n:NodeId, e:E) {
|
||||
fn visit_ty_method(&mut self, t: &TypeMethod, e: E) { walk_ty_method(self, t, e) }
|
||||
fn visit_trait_method(&mut self, t: &trait_method, e: E) { walk_trait_method(self, t, e) }
|
||||
fn visit_struct_def(&mut self, s: &struct_def, i: Ident, g: &Generics, n: NodeId, e: E) {
|
||||
walk_struct_def(self, s, i, g, n, e)
|
||||
}
|
||||
fn visit_struct_field(&mut self, s:&struct_field, 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: &struct_field, 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_opt_lifetime_ref(&mut self,
|
||||
_span: Span,
|
||||
opt_lifetime: &Option<Lifetime>,
|
||||
|
|
@ -115,7 +115,7 @@ pub trait Visitor<E:Clone> {
|
|||
fn visit_explicit_self(&mut self, es: &explicit_self, e: E) {
|
||||
walk_explicit_self(self, es, e)
|
||||
}
|
||||
fn visit_mac(&mut self, macro:&mac, e:E) {
|
||||
fn visit_mac(&mut self, macro: &mac, e: E) {
|
||||
walk_mac(self, macro, e)
|
||||
}
|
||||
fn visit_path(&mut self, path: &Path, _id: ast::NodeId, e: E) {
|
||||
|
|
@ -123,11 +123,11 @@ pub trait Visitor<E:Clone> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn walk_crate<E:Clone, V:Visitor<E>>(visitor: &mut V, crate: &Crate, env: E) {
|
||||
pub fn walk_crate<E: Clone, V: Visitor<E>>(visitor: &mut V, crate: &Crate, env: E) {
|
||||
visitor.visit_mod(&crate.module, crate.span, CRATE_NODE_ID, env)
|
||||
}
|
||||
|
||||
pub fn walk_mod<E:Clone, V:Visitor<E>>(visitor: &mut V, module: &_mod, env: E) {
|
||||
pub fn walk_mod<E: Clone, V: Visitor<E>>(visitor: &mut V, module: &_mod, env: E) {
|
||||
for view_item in module.view_items.iter() {
|
||||
visitor.visit_view_item(view_item, env.clone())
|
||||
}
|
||||
|
|
@ -137,7 +137,7 @@ pub fn walk_mod<E:Clone, V:Visitor<E>>(visitor: &mut V, module: &_mod, env: E) {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn walk_view_item<E:Clone, V:Visitor<E>>(visitor: &mut V, vi: &view_item, env: E) {
|
||||
pub fn walk_view_item<E: Clone, V: Visitor<E>>(visitor: &mut V, vi: &view_item, env: E) {
|
||||
match vi.node {
|
||||
view_item_extern_mod(name, _, _) => {
|
||||
visitor.visit_ident(vi.span, name, env)
|
||||
|
|
@ -164,7 +164,7 @@ pub fn walk_view_item<E:Clone, V:Visitor<E>>(visitor: &mut V, vi: &view_item, en
|
|||
}
|
||||
}
|
||||
|
||||
pub fn walk_local<E:Clone, V:Visitor<E>>(visitor: &mut V, local: &Local, env: E) {
|
||||
pub fn walk_local<E: Clone, V: Visitor<E>>(visitor: &mut V, local: &Local, env: E) {
|
||||
visitor.visit_pat(local.pat, env.clone());
|
||||
visitor.visit_ty(local.ty, env.clone());
|
||||
match local.init {
|
||||
|
|
@ -173,9 +173,9 @@ pub fn walk_local<E:Clone, V:Visitor<E>>(visitor: &mut V, local: &Local, env: E)
|
|||
}
|
||||
}
|
||||
|
||||
fn walk_explicit_self<E:Clone, V:Visitor<E>>(visitor: &mut V,
|
||||
explicit_self: &explicit_self,
|
||||
env: E) {
|
||||
fn walk_explicit_self<E: Clone, V: Visitor<E>>(visitor: &mut V,
|
||||
explicit_self: &explicit_self,
|
||||
env: E) {
|
||||
match explicit_self.node {
|
||||
sty_static | sty_value(_) | sty_box(_) | sty_uniq(_) => {
|
||||
}
|
||||
|
|
@ -185,13 +185,13 @@ fn walk_explicit_self<E:Clone, V:Visitor<E>>(visitor: &mut V,
|
|||
}
|
||||
}
|
||||
|
||||
fn walk_trait_ref<E:Clone, V:Visitor<E>>(visitor: &mut V,
|
||||
trait_ref: &ast::trait_ref,
|
||||
env: E) {
|
||||
fn walk_trait_ref<E: Clone, V: Visitor<E>>(visitor: &mut V,
|
||||
trait_ref: &trait_ref,
|
||||
env: E) {
|
||||
visitor.visit_path(&trait_ref.path, trait_ref.ref_id, env)
|
||||
}
|
||||
|
||||
pub fn walk_item<E:Clone, V:Visitor<E>>(visitor: &mut V, item: &item, env: E) {
|
||||
pub fn walk_item<E: Clone, V: Visitor<E>>(visitor: &mut V, item: &item, env: E) {
|
||||
visitor.visit_ident(item.span, item.ident, env.clone());
|
||||
match item.node {
|
||||
item_static(typ, _, expr) => {
|
||||
|
|
@ -261,19 +261,19 @@ pub fn walk_item<E:Clone, V:Visitor<E>>(visitor: &mut V, item: &item, env: E) {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn walk_enum_def<E:Clone, V:Visitor<E>>(visitor: &mut V,
|
||||
enum_definition: &ast::enum_def,
|
||||
generics: &Generics,
|
||||
env: E) {
|
||||
pub fn walk_enum_def<E: Clone, V:Visitor<E>>(visitor: &mut V,
|
||||
enum_definition: &enum_def,
|
||||
generics: &Generics,
|
||||
env: E) {
|
||||
for &variant in enum_definition.variants.iter() {
|
||||
visitor.visit_variant(variant, generics, env.clone());
|
||||
}
|
||||
}
|
||||
|
||||
pub fn walk_variant<E:Clone, V:Visitor<E>>(visitor:&mut V,
|
||||
variant: &variant,
|
||||
generics: &Generics,
|
||||
env: E) {
|
||||
pub fn walk_variant<E: Clone, V: Visitor<E>>(visitor: &mut V,
|
||||
variant: &variant,
|
||||
generics: &Generics,
|
||||
env: E) {
|
||||
visitor.visit_ident(variant.span, variant.node.name, env.clone());
|
||||
|
||||
match variant.node.kind {
|
||||
|
|
@ -296,11 +296,11 @@ pub fn walk_variant<E:Clone, V:Visitor<E>>(visitor:&mut V,
|
|||
}
|
||||
}
|
||||
|
||||
pub fn skip_ty<E, V:Visitor<E>>(_: &mut V, _: &Ty, _: E) {
|
||||
pub fn skip_ty<E, V: Visitor<E>>(_: &mut V, _: &Ty, _: E) {
|
||||
// Empty!
|
||||
}
|
||||
|
||||
pub fn walk_ty<E:Clone, V:Visitor<E>>(visitor: &mut V, typ: &Ty, env: E) {
|
||||
pub fn walk_ty<E: Clone, V: Visitor<E>>(visitor: &mut V, typ: &Ty, env: E) {
|
||||
match typ.node {
|
||||
ty_uniq(ty) | ty_vec(ty) | ty_box(ty) => {
|
||||
visitor.visit_ty(ty, env)
|
||||
|
|
@ -357,15 +357,15 @@ pub fn walk_ty<E:Clone, V:Visitor<E>>(visitor: &mut V, typ: &Ty, env: E) {
|
|||
}
|
||||
}
|
||||
|
||||
fn walk_lifetime_decls<E:Clone, V:Visitor<E>>(visitor: &mut V,
|
||||
lifetimes: &OptVec<Lifetime>,
|
||||
env: E) {
|
||||
fn walk_lifetime_decls<E: Clone, V: Visitor<E>>(visitor: &mut V,
|
||||
lifetimes: &OptVec<Lifetime>,
|
||||
env: E) {
|
||||
for l in lifetimes.iter() {
|
||||
visitor.visit_lifetime_decl(l, env.clone());
|
||||
}
|
||||
}
|
||||
|
||||
pub fn walk_path<E:Clone, V:Visitor<E>>(visitor: &mut V, path: &Path, env: E) {
|
||||
pub fn walk_path<E: Clone, V: Visitor<E>>(visitor: &mut V, path: &Path, env: E) {
|
||||
for segment in path.segments.iter() {
|
||||
visitor.visit_ident(path.span, segment.identifier, env.clone());
|
||||
|
||||
|
|
@ -378,7 +378,7 @@ pub fn walk_path<E:Clone, V:Visitor<E>>(visitor: &mut V, path: &Path, env: E) {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn walk_pat<E:Clone, V:Visitor<E>>(visitor: &mut V, pattern: &Pat, env: E) {
|
||||
pub fn walk_pat<E: Clone, V: Visitor<E>>(visitor: &mut V, pattern: &Pat, env: E) {
|
||||
match pattern.node {
|
||||
PatEnum(ref path, ref children) => {
|
||||
visitor.visit_path(path, pattern.id, env.clone());
|
||||
|
|
@ -431,9 +431,9 @@ pub fn walk_pat<E:Clone, V:Visitor<E>>(visitor: &mut V, pattern: &Pat, env: E) {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn walk_foreign_item<E:Clone, V:Visitor<E>>(visitor: &mut V,
|
||||
foreign_item: &foreign_item,
|
||||
env: E) {
|
||||
pub fn walk_foreign_item<E: Clone, V: Visitor<E>>(visitor: &mut V,
|
||||
foreign_item: &foreign_item,
|
||||
env: E) {
|
||||
visitor.visit_ident(foreign_item.span, foreign_item.ident, env.clone());
|
||||
|
||||
match foreign_item.node {
|
||||
|
|
@ -445,9 +445,9 @@ pub fn walk_foreign_item<E:Clone, V:Visitor<E>>(visitor: &mut V,
|
|||
}
|
||||
}
|
||||
|
||||
pub fn walk_ty_param_bounds<E:Clone, V:Visitor<E>>(visitor: &mut V,
|
||||
bounds: &OptVec<TyParamBound>,
|
||||
env: E) {
|
||||
pub fn walk_ty_param_bounds<E: Clone, V: Visitor<E>>(visitor: &mut V,
|
||||
bounds: &OptVec<TyParamBound>,
|
||||
env: E) {
|
||||
for bound in bounds.iter() {
|
||||
match *bound {
|
||||
TraitTyParamBound(ref typ) => {
|
||||
|
|
@ -458,18 +458,18 @@ pub fn walk_ty_param_bounds<E:Clone, V:Visitor<E>>(visitor: &mut V,
|
|||
}
|
||||
}
|
||||
|
||||
pub fn walk_generics<E:Clone, V:Visitor<E>>(visitor: &mut V,
|
||||
generics: &Generics,
|
||||
env: E) {
|
||||
pub fn walk_generics<E: Clone, V: Visitor<E>>(visitor: &mut V,
|
||||
generics: &Generics,
|
||||
env: E) {
|
||||
for type_parameter in generics.ty_params.iter() {
|
||||
walk_ty_param_bounds(visitor, &type_parameter.bounds, env.clone())
|
||||
}
|
||||
walk_lifetime_decls(visitor, &generics.lifetimes, env);
|
||||
}
|
||||
|
||||
pub fn walk_fn_decl<E:Clone, V:Visitor<E>>(visitor: &mut V,
|
||||
function_declaration: &fn_decl,
|
||||
env: E) {
|
||||
pub fn walk_fn_decl<E: Clone, V: Visitor<E>>(visitor: &mut V,
|
||||
function_declaration: &fn_decl,
|
||||
env: E) {
|
||||
for argument in function_declaration.inputs.iter() {
|
||||
visitor.visit_pat(argument.pat, env.clone());
|
||||
visitor.visit_ty(argument.ty, env.clone())
|
||||
|
|
@ -481,9 +481,9 @@ pub fn walk_fn_decl<E:Clone, V:Visitor<E>>(visitor: &mut V,
|
|||
// visit_fn() and check for fk_method(). I named this visit_method_helper()
|
||||
// because it is not a default impl of any method, though I doubt that really
|
||||
// clarifies anything. - Niko
|
||||
pub fn walk_method_helper<E:Clone, V:Visitor<E>>(visitor: &mut V,
|
||||
method: &method,
|
||||
env: E) {
|
||||
pub fn walk_method_helper<E: Clone, V: Visitor<E>>(visitor: &mut V,
|
||||
method: &method,
|
||||
env: E) {
|
||||
visitor.visit_ident(method.span, method.ident, env.clone());
|
||||
visitor.visit_fn(&fk_method(method.ident, &method.generics, method),
|
||||
method.decl,
|
||||
|
|
@ -493,13 +493,13 @@ pub fn walk_method_helper<E:Clone, V:Visitor<E>>(visitor: &mut V,
|
|||
env)
|
||||
}
|
||||
|
||||
pub fn walk_fn<E:Clone, V:Visitor<E>>(visitor: &mut V,
|
||||
function_kind: &fn_kind,
|
||||
function_declaration: &fn_decl,
|
||||
function_body: P<Block>,
|
||||
_span: Span,
|
||||
_: NodeId,
|
||||
env: E) {
|
||||
pub fn walk_fn<E: Clone, V: Visitor<E>>(visitor: &mut V,
|
||||
function_kind: &fn_kind,
|
||||
function_declaration: &fn_decl,
|
||||
function_body: &Block,
|
||||
_span: Span,
|
||||
_: NodeId,
|
||||
env: E) {
|
||||
walk_fn_decl(visitor, function_declaration, env.clone());
|
||||
|
||||
match *function_kind {
|
||||
|
|
@ -518,9 +518,9 @@ pub fn walk_fn<E:Clone, V:Visitor<E>>(visitor: &mut V,
|
|||
visitor.visit_block(function_body, env)
|
||||
}
|
||||
|
||||
pub fn walk_ty_method<E:Clone, V:Visitor<E>>(visitor: &mut V,
|
||||
method_type: &TypeMethod,
|
||||
env: E) {
|
||||
pub fn walk_ty_method<E: Clone, V: Visitor<E>>(visitor: &mut V,
|
||||
method_type: &TypeMethod,
|
||||
env: E) {
|
||||
visitor.visit_ident(method_type.span, method_type.ident, env.clone());
|
||||
visitor.visit_explicit_self(&method_type.explicit_self, env.clone());
|
||||
for argument_type in method_type.decl.inputs.iter() {
|
||||
|
|
@ -530,9 +530,9 @@ pub fn walk_ty_method<E:Clone, V:Visitor<E>>(visitor: &mut V,
|
|||
visitor.visit_ty(method_type.decl.output, env);
|
||||
}
|
||||
|
||||
pub fn walk_trait_method<E:Clone, V:Visitor<E>>(visitor: &mut V,
|
||||
trait_method: &trait_method,
|
||||
env: E) {
|
||||
pub fn walk_trait_method<E: Clone, V: Visitor<E>>(visitor: &mut V,
|
||||
trait_method: &trait_method,
|
||||
env: E) {
|
||||
match *trait_method {
|
||||
required(ref method_type) => {
|
||||
visitor.visit_ty_method(method_type, env)
|
||||
|
|
@ -541,20 +541,20 @@ pub fn walk_trait_method<E:Clone, V:Visitor<E>>(visitor: &mut V,
|
|||
}
|
||||
}
|
||||
|
||||
pub fn walk_struct_def<E:Clone, V:Visitor<E>>(visitor: &mut V,
|
||||
struct_definition: @struct_def,
|
||||
_: ast::Ident,
|
||||
_: &Generics,
|
||||
_: NodeId,
|
||||
env: E) {
|
||||
pub fn walk_struct_def<E: Clone, V: Visitor<E>>(visitor: &mut V,
|
||||
struct_definition: &struct_def,
|
||||
_: Ident,
|
||||
_: &Generics,
|
||||
_: NodeId,
|
||||
env: E) {
|
||||
for field in struct_definition.fields.iter() {
|
||||
visitor.visit_struct_field(field, env.clone())
|
||||
}
|
||||
}
|
||||
|
||||
pub fn walk_struct_field<E:Clone, V:Visitor<E>>(visitor: &mut V,
|
||||
struct_field: &struct_field,
|
||||
env: E) {
|
||||
pub fn walk_struct_field<E: Clone, V: Visitor<E>>(visitor: &mut V,
|
||||
struct_field: &struct_field,
|
||||
env: E) {
|
||||
match struct_field.node.kind {
|
||||
named_field(name, _) => {
|
||||
visitor.visit_ident(struct_field.span, name, env.clone())
|
||||
|
|
@ -565,7 +565,7 @@ pub fn walk_struct_field<E:Clone, V:Visitor<E>>(visitor: &mut V,
|
|||
visitor.visit_ty(struct_field.node.ty, env)
|
||||
}
|
||||
|
||||
pub fn walk_block<E:Clone, V:Visitor<E>>(visitor: &mut V, block: P<Block>, env: E) {
|
||||
pub fn walk_block<E: Clone, V: Visitor<E>>(visitor: &mut V, block: &Block, env: E) {
|
||||
for view_item in block.view_items.iter() {
|
||||
visitor.visit_view_item(view_item, env.clone())
|
||||
}
|
||||
|
|
@ -575,7 +575,7 @@ pub fn walk_block<E:Clone, V:Visitor<E>>(visitor: &mut V, block: P<Block>, env:
|
|||
walk_expr_opt(visitor, block.expr, env)
|
||||
}
|
||||
|
||||
pub fn walk_stmt<E:Clone, V:Visitor<E>>(visitor: &mut V, statement: &Stmt, env: E) {
|
||||
pub fn walk_stmt<E: Clone, V: Visitor<E>>(visitor: &mut V, statement: &Stmt, env: E) {
|
||||
match statement.node {
|
||||
StmtDecl(declaration, _) => visitor.visit_decl(declaration, env),
|
||||
StmtExpr(expression, _) | StmtSemi(expression, _) => {
|
||||
|
|
@ -585,35 +585,35 @@ pub fn walk_stmt<E:Clone, V:Visitor<E>>(visitor: &mut V, statement: &Stmt, env:
|
|||
}
|
||||
}
|
||||
|
||||
pub fn walk_decl<E:Clone, V:Visitor<E>>(visitor: &mut V, declaration: &Decl, env: E) {
|
||||
pub fn walk_decl<E: Clone, V: Visitor<E>>(visitor: &mut V, declaration: &Decl, env: E) {
|
||||
match declaration.node {
|
||||
DeclLocal(ref local) => visitor.visit_local(*local, env),
|
||||
DeclItem(item) => visitor.visit_item(item, env),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn walk_expr_opt<E:Clone, V:Visitor<E>>(visitor: &mut V,
|
||||
optional_expression: Option<@Expr>,
|
||||
env: E) {
|
||||
pub fn walk_expr_opt<E: Clone, V: Visitor<E>>(visitor: &mut V,
|
||||
optional_expression: Option<@Expr>,
|
||||
env: E) {
|
||||
match optional_expression {
|
||||
None => {}
|
||||
Some(expression) => visitor.visit_expr(expression, env),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn walk_exprs<E:Clone, V:Visitor<E>>(visitor: &mut V,
|
||||
expressions: &[@Expr],
|
||||
env: E) {
|
||||
pub fn walk_exprs<E: Clone, V: Visitor<E>>(visitor: &mut V,
|
||||
expressions: &[@Expr],
|
||||
env: E) {
|
||||
for expression in expressions.iter() {
|
||||
visitor.visit_expr(*expression, env.clone())
|
||||
}
|
||||
}
|
||||
|
||||
pub fn walk_mac<E, V:Visitor<E>>(_: &mut V, _: &mac, _: E) {
|
||||
pub fn walk_mac<E, V: Visitor<E>>(_: &mut V, _: &mac, _: E) {
|
||||
// Empty!
|
||||
}
|
||||
|
||||
pub fn walk_expr<E:Clone, V:Visitor<E>>(visitor: &mut V, expression: @Expr, env: E) {
|
||||
pub fn walk_expr<E: Clone, V: Visitor<E>>(visitor: &mut V, expression: &Expr, env: E) {
|
||||
match expression.node {
|
||||
ExprVstore(subexpression, _) => {
|
||||
visitor.visit_expr(subexpression, env.clone())
|
||||
|
|
@ -745,7 +745,7 @@ pub fn walk_expr<E:Clone, V:Visitor<E>>(visitor: &mut V, expression: @Expr, env:
|
|||
visitor.visit_expr_post(expression, env.clone())
|
||||
}
|
||||
|
||||
pub fn walk_arm<E:Clone, V:Visitor<E>>(visitor: &mut V, arm: &Arm, env: E) {
|
||||
pub fn walk_arm<E: Clone, V: Visitor<E>>(visitor: &mut V, arm: &Arm, env: E) {
|
||||
for pattern in arm.pats.iter() {
|
||||
visitor.visit_pat(*pattern, env.clone())
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue