diff options
| author | Brian Anderson <banderson@mozilla.com> | 2012-03-22 16:07:30 -0700 |
|---|---|---|
| committer | Brian Anderson <banderson@mozilla.com> | 2012-03-29 14:42:30 -0700 |
| commit | 9e299f53f4d180c6bb3ee91355c934c475ad3393 (patch) | |
| tree | 149ebd1c3322f71bc05e72df218154156c803d2f /src/rustc | |
| parent | 140151f3f99fb7d8a4422af13e4368e3f3ede792 (diff) | |
| download | rust-9e299f53f4d180c6bb3ee91355c934c475ad3393.tar.gz rust-9e299f53f4d180c6bb3ee91355c934c475ad3393.zip | |
rustc: Move ast, ast_util, visit to rustsyntax
Diffstat (limited to 'src/rustc')
| -rw-r--r-- | src/rustc/rustc.rc | 4 | ||||
| -rw-r--r-- | src/rustc/syntax.rs | 9 | ||||
| -rw-r--r-- | src/rustc/syntax/ast.rs | 716 | ||||
| -rw-r--r-- | src/rustc/syntax/ast_util.rs | 330 | ||||
| -rw-r--r-- | src/rustc/syntax/visit.rs | 558 |
5 files changed, 9 insertions, 1608 deletions
diff --git a/src/rustc/rustc.rc b/src/rustc/rustc.rc index e70043681be..8b63dc1f140 100644 --- a/src/rustc/rustc.rc +++ b/src/rustc/rustc.rc @@ -70,11 +70,7 @@ mod middle { mod syntax { - mod ast; - mod ast_util; - mod fold; - mod visit; mod parse { mod lexer; mod parser; diff --git a/src/rustc/syntax.rs b/src/rustc/syntax.rs index eaa5c783777..93f807bdf9f 100644 --- a/src/rustc/syntax.rs +++ b/src/rustc/syntax.rs @@ -2,6 +2,15 @@ import rustsyntax::codemap; export codemap; +import rustsyntax::ast; +export ast; + +import rustsyntax::ast_util; +export ast_util; + +import rustsyntax::visit; +export visit; + export ast; export ast_util; export visit; diff --git a/src/rustc/syntax/ast.rs b/src/rustc/syntax/ast.rs deleted file mode 100644 index c6fe959e290..00000000000 --- a/src/rustc/syntax/ast.rs +++ /dev/null @@ -1,716 +0,0 @@ -// The Rust abstract syntax tree. - -import codemap::{span, filename}; -import std::serialization::{serializer, - deserializer, - serialize_option, - deserialize_option, - serialize_uint, - deserialize_uint, - serialize_int, - deserialize_int, - serialize_i64, - deserialize_i64, - serialize_u64, - deserialize_u64, - serialize_str, - deserialize_str, - serialize_bool, - deserialize_bool}; - -fn serialize_span<S>(_s: S, _v: span) { - // FIXME-- serialize some span info -} - -fn deserialize_span<D>(_d: D) -> span { - ast_util::dummy_sp() -} - -#[auto_serialize] -type spanned<T> = {node: T, span: span}; - -#[auto_serialize] -type ident = str; - -// Functions may or may not have names. -#[auto_serialize] -type fn_ident = option<ident>; - -#[auto_serialize] -type path_ = {global: bool, idents: [ident], types: [@ty]}; - -#[auto_serialize] -type path = spanned<path_>; - -#[auto_serialize] -type crate_num = int; - -#[auto_serialize] -type node_id = int; - -#[auto_serialize] -type def_id = {crate: crate_num, node: node_id}; - -const local_crate: crate_num = 0; -const crate_node_id: node_id = 0; - -#[auto_serialize] -enum ty_param_bound { - bound_copy, - bound_send, - bound_iface(@ty), -} - -#[auto_serialize] -type ty_param = {ident: ident, id: node_id, bounds: @[ty_param_bound]}; - -#[auto_serialize] -enum def { - def_fn(def_id, purity), - def_self(node_id), - def_mod(def_id), - def_native_mod(def_id), - def_const(def_id), - def_arg(node_id, mode), - def_local(node_id, bool /* is_mutbl */), - def_variant(def_id /* enum */, def_id /* variant */), - def_ty(def_id), - def_prim_ty(prim_ty), - def_ty_param(def_id, uint), - def_binding(node_id), - def_use(def_id), - def_upvar(node_id /* local id of closed over var */, - @def /* closed over def */, - node_id /* expr node that creates the closure */), - def_class(def_id), - def_region(node_id) -} - -// The set of meta_items that define the compilation environment of the crate, -// used to drive conditional compilation -type crate_cfg = [@meta_item]; - -type crate = spanned<crate_>; - -type crate_ = - {directives: [@crate_directive], - module: _mod, - attrs: [attribute], - config: crate_cfg}; - -enum crate_directive_ { - cdir_src_mod(ident, [attribute]), - cdir_dir_mod(ident, [@crate_directive], [attribute]), - - // NB: cdir_view_item is *not* processed by the rest of the compiler, the - // attached view_items are sunk into the crate's module during parsing, - // and processed (resolved, imported, etc.) there. This enum-variant - // exists only to preserve the view items in order in case we decide to - // pretty-print crates in the future. - cdir_view_item(@view_item), - - cdir_syntax(@path), -} - -type crate_directive = spanned<crate_directive_>; - -#[auto_serialize] -type meta_item = spanned<meta_item_>; - -#[auto_serialize] -enum meta_item_ { - meta_word(ident), - meta_list(ident, [@meta_item]), - meta_name_value(ident, lit), -} - -#[auto_serialize] -type blk = spanned<blk_>; - -#[auto_serialize] -type blk_ = {view_items: [@view_item], stmts: [@stmt], expr: option<@expr>, - id: node_id, rules: blk_check_mode}; - -#[auto_serialize] -type pat = {id: node_id, node: pat_, span: span}; - -#[auto_serialize] -type field_pat = {ident: ident, pat: @pat}; - -#[auto_serialize] -enum pat_ { - pat_wild, - // A pat_ident may either be a new bound variable, - // or a nullary enum (in which case the second field - // is none). - // In the nullary enum case, the parser can't determine - // which it is. The resolver determines this, and - // records this pattern's node_id in an auxiliary - // set (of "pat_idents that refer to nullary enums") - pat_ident(@path, option<@pat>), - pat_enum(@path, [@pat]), - pat_rec([field_pat], bool), - pat_tup([@pat]), - pat_box(@pat), - pat_uniq(@pat), - pat_lit(@expr), - pat_range(@expr, @expr), -} - -#[auto_serialize] -enum mutability { m_mutbl, m_imm, m_const, } - -#[auto_serialize] -enum proto { - proto_bare, // native fn - proto_any, // fn - proto_uniq, // fn~ - proto_box, // fn@ - proto_block, // fn& -} - -pure fn is_blockish(p: ast::proto) -> bool { - alt p { - proto_any | proto_block { true } - proto_bare | proto_uniq | proto_box { false } - } -} - -#[auto_serialize] -enum binop { - add, - subtract, - mul, - div, - rem, - and, - or, - bitxor, - bitand, - bitor, - lsl, - lsr, - asr, - eq, - lt, - le, - ne, - ge, - gt, -} - -#[auto_serialize] -enum unop { - box(mutability), - uniq(mutability), - deref, not, neg -} - -// Generally, after typeck you can get the inferred value -// using ty::resolved_T(...). -#[auto_serialize] -enum inferable<T> { - expl(T), infer(node_id) -} - -// "resolved" mode: the real modes. -#[auto_serialize] -enum rmode { by_ref, by_val, by_mutbl_ref, by_move, by_copy } - -// inferable mode. -#[auto_serialize] -type mode = inferable<rmode>; - -#[auto_serialize] -type stmt = spanned<stmt_>; - -#[auto_serialize] -enum stmt_ { - stmt_decl(@decl, node_id), - - // expr without trailing semi-colon (must have unit type): - stmt_expr(@expr, node_id), - - // expr with trailing semi-colon (may have any type): - stmt_semi(@expr, node_id), -} - -#[auto_serialize] -enum init_op { init_assign, init_move, } - -#[auto_serialize] -type initializer = {op: init_op, expr: @expr}; - -#[auto_serialize] -type local_ = // FIXME: should really be a refinement on pat - {is_mutbl: bool, ty: @ty, pat: @pat, - init: option<initializer>, id: node_id}; - -#[auto_serialize] -type local = spanned<local_>; - -#[auto_serialize] -type decl = spanned<decl_>; - -#[auto_serialize] -enum decl_ { decl_local([@local]), decl_item(@item), } - -#[auto_serialize] -type arm = {pats: [@pat], guard: option<@expr>, body: blk}; - -#[auto_serialize] -type field_ = {mutbl: mutability, ident: ident, expr: @expr}; - -#[auto_serialize] -type field = spanned<field_>; - -#[auto_serialize] -enum blk_check_mode { default_blk, unchecked_blk, unsafe_blk, } - -#[auto_serialize] -enum expr_check_mode { claimed_expr, checked_expr, } - -#[auto_serialize] -type expr = {id: node_id, node: expr_, span: span}; - -#[auto_serialize] -enum alt_mode { alt_check, alt_exhaustive, } - -#[auto_serialize] -enum expr_ { - expr_vec([@expr], mutability), - expr_rec([field], option<@expr>), - expr_call(@expr, [@expr], bool), - expr_tup([@expr]), - expr_bind(@expr, [option<@expr>]), - expr_binary(binop, @expr, @expr), - expr_unary(unop, @expr), - expr_lit(@lit), - expr_cast(@expr, @ty), - expr_if(@expr, blk, option<@expr>), - expr_while(@expr, blk), - expr_for(@local, @expr, blk), - expr_do_while(blk, @expr), - /* Conditionless loop (can be exited with break, cont, ret, or fail) - Same semantics as while(true) { body }, but typestate knows that the - (implicit) condition is always true. */ - expr_loop(blk), - expr_alt(@expr, [arm], alt_mode), - expr_fn(proto, fn_decl, blk, @capture_clause), - expr_fn_block(fn_decl, blk), - // Inner expr is always an expr_fn_block. We need the wrapping node to - // sanely type this (a function returning nil on the inside but bool on - // the outside). - expr_loop_body(@expr), - expr_block(blk), - - /* - * FIXME: many of these @exprs should be constrained with - * is_lval once we have constrained types working. - */ - expr_copy(@expr), - expr_move(@expr, @expr), - expr_assign(@expr, @expr), - expr_swap(@expr, @expr), - expr_assign_op(binop, @expr, @expr), - expr_field(@expr, ident, [@ty]), - expr_index(@expr, @expr), - expr_path(@path), - expr_addr_of(mutability, @expr), - expr_fail(option<@expr>), - expr_break, - expr_cont, - expr_ret(option<@expr>), - expr_be(@expr), - expr_log(int, @expr, @expr), - - expr_new(/* arena */ @expr, - /* id for the alloc() call */ node_id, - /* value */ @expr), - - /* just an assert, no significance to typestate */ - expr_assert(@expr), - - /* preds that typestate is aware of */ - expr_check(expr_check_mode, @expr), - - /* FIXME Would be nice if expr_check desugared - to expr_if_check. */ - expr_if_check(@expr, blk, option<@expr>), - expr_mac(mac), -} - -#[auto_serialize] -type capture_item = { - id: int, - name: ident, // Currently, can only capture a local var. - span: span -}; - -#[auto_serialize] -type capture_clause = { - copies: [@capture_item], - moves: [@capture_item] -}; - -/* -// Says whether this is a block the user marked as -// "unchecked" -enum blk_sort { - blk_unchecked, // declared as "exception to effect-checking rules" - blk_checked, // all typing rules apply -} -*/ - -#[auto_serialize] -type mac = spanned<mac_>; - -#[auto_serialize] -type mac_arg = option<@expr>; - -#[auto_serialize] -type mac_body_ = {span: span}; - -#[auto_serialize] -type mac_body = option<mac_body_>; - -#[auto_serialize] -enum mac_ { - mac_invoc(@path, mac_arg, mac_body), - mac_embed_type(@ty), - mac_embed_block(blk), - mac_ellipsis, - // the span is used by the quoter/anti-quoter ... - mac_aq(span /* span of quote */, @expr), // anti-quote - mac_var(uint) -} - -#[auto_serialize] -type lit = spanned<lit_>; - -#[auto_serialize] -enum lit_ { - lit_str(str), - lit_int(i64, int_ty), - lit_uint(u64, uint_ty), - lit_float(str, float_ty), - lit_nil, - lit_bool(bool), -} - -// NB: If you change this, you'll probably want to change the corresponding -// type structure in middle/ty.rs as well. -#[auto_serialize] -type mt = {ty: @ty, mutbl: mutability}; - -#[auto_serialize] -type ty_field_ = {ident: ident, mt: mt}; - -#[auto_serialize] -type ty_field = spanned<ty_field_>; - -#[auto_serialize] -type ty_method = {ident: ident, attrs: [attribute], - decl: fn_decl, tps: [ty_param], span: span}; - -#[auto_serialize] -enum int_ty { ty_i, ty_char, ty_i8, ty_i16, ty_i32, ty_i64, } - -#[auto_serialize] -enum uint_ty { ty_u, ty_u8, ty_u16, ty_u32, ty_u64, } - -#[auto_serialize] -enum float_ty { ty_f, ty_f32, ty_f64, } - -#[auto_serialize] -type ty = {id: node_id, node: ty_, span: span}; - -// Not represented directly in the AST, referred to by name through a ty_path. -#[auto_serialize] -enum prim_ty { - ty_int(int_ty), - ty_uint(uint_ty), - ty_float(float_ty), - ty_str, - ty_bool, -} - -#[auto_serialize] -type region = {id: node_id, node: region_}; - -#[auto_serialize] -enum region_ { - re_inferred, - re_named(ident), - re_self -} - -#[auto_serialize] -enum ty_ { - ty_nil, - ty_bot, /* bottom type */ - ty_box(mt), - ty_uniq(mt), - ty_vec(mt), - ty_ptr(mt), - ty_rptr(region, mt), - ty_rec([ty_field]), - ty_fn(proto, fn_decl), - ty_tup([@ty]), - ty_path(@path, node_id), - ty_constr(@ty, [@ty_constr]), - ty_mac(mac), - // ty_infer means the type should be inferred instead of it having been - // specified. This should only appear at the "top level" of a type and not - // nested in one. - ty_infer, -} - - -/* -A constraint arg that's a function argument is referred to by its position -rather than name. This is so we could have higher-order functions that have -constraints (potentially -- right now there's no way to write that), and also -so that the typestate pass doesn't have to map a function name onto its decl. -So, the constr_arg type is parameterized: it's instantiated with uint for -declarations, and ident for uses. -*/ -#[auto_serialize] -enum constr_arg_general_<T> { carg_base, carg_ident(T), carg_lit(@lit), } - -#[auto_serialize] -type fn_constr_arg = constr_arg_general_<uint>; - -#[auto_serialize] -type sp_constr_arg<T> = spanned<constr_arg_general_<T>>; - -#[auto_serialize] -type ty_constr_arg = sp_constr_arg<@path>; - -#[auto_serialize] -type constr_arg = spanned<fn_constr_arg>; - -// Constrained types' args are parameterized by paths, since -// we refer to paths directly and not by indices. -// The implicit root of such path, in the constraint-list for a -// constrained type, is * (referring to the base record) - -#[auto_serialize] -type constr_general_<ARG, ID> = - {path: @path, args: [@spanned<constr_arg_general_<ARG>>], id: ID}; - -// In the front end, constraints have a node ID attached. -// Typeck turns this to a def_id, using the output of resolve. -#[auto_serialize] -type constr_general<ARG> = spanned<constr_general_<ARG, node_id>>; - -#[auto_serialize] -type constr_ = constr_general_<uint, node_id>; - -#[auto_serialize] -type constr = spanned<constr_general_<uint, node_id>>; - -#[auto_serialize] -type ty_constr_ = constr_general_<@path, node_id>; - -#[auto_serialize] -type ty_constr = spanned<ty_constr_>; - -/* The parser generates ast::constrs; resolve generates - a mapping from each function to a list of ty::constr_defs, - corresponding to these. */ -#[auto_serialize] -type arg = {mode: mode, ty: @ty, ident: ident, id: node_id}; - -#[auto_serialize] -type fn_decl = - {inputs: [arg], - output: @ty, - purity: purity, - cf: ret_style, - constraints: [@constr]}; - -#[auto_serialize] -enum purity { - pure_fn, // declared with "pure fn" - unsafe_fn, // declared with "unsafe fn" - impure_fn, // declared with "fn" - crust_fn, // declared with "crust fn" -} - -#[auto_serialize] -enum ret_style { - noreturn, // functions with return type _|_ that always - // raise an error or exit (i.e. never return to the caller) - return_val, // everything else -} - -#[auto_serialize] -type method = {ident: ident, attrs: [attribute], - tps: [ty_param], decl: fn_decl, body: blk, - id: node_id, span: span, self_id: node_id, - privacy: privacy}; // privacy is always public, unless it's a - // class method - -#[auto_serialize] -type _mod = {view_items: [@view_item], items: [@item]}; - -#[auto_serialize] -enum native_abi { - native_abi_rust_intrinsic, - native_abi_cdecl, - native_abi_stdcall, -} - -#[auto_serialize] -type native_mod = - {view_items: [@view_item], - items: [@native_item]}; - -#[auto_serialize] -type variant_arg = {ty: @ty, id: node_id}; - -#[auto_serialize] -type variant_ = {name: ident, attrs: [attribute], args: [variant_arg], - id: node_id, disr_expr: option<@expr>}; - -#[auto_serialize] -type variant = spanned<variant_>; - -// FIXME: May want to just use path here, which would allow things like -// 'import ::foo' -#[auto_serialize] -type simple_path = [ident]; - -#[auto_serialize] -type path_list_ident_ = {name: ident, id: node_id}; - -#[auto_serialize] -type path_list_ident = spanned<path_list_ident_>; - -#[auto_serialize] -type view_path = spanned<view_path_>; - -#[auto_serialize] -enum view_path_ { - - // quux = foo::bar::baz - // - // or just - // - // foo::bar::baz (with 'baz =' implicitly on the left) - view_path_simple(ident, @simple_path, node_id), - - // foo::bar::* - view_path_glob(@simple_path, node_id), - - // foo::bar::{a,b,c} - view_path_list(@simple_path, [path_list_ident], node_id) -} - -#[auto_serialize] -type view_item = spanned<view_item_>; - -#[auto_serialize] -enum view_item_ { - view_item_use(ident, [@meta_item], node_id), - view_item_import([@view_path]), - view_item_export([@view_path]) -} - -// Meta-data associated with an item -#[auto_serialize] -type attribute = spanned<attribute_>; - -// Distinguishes between attributes that decorate items and attributes that -// are contained as statements within items. These two cases need to be -// distinguished for pretty-printing. -#[auto_serialize] -enum attr_style { attr_outer, attr_inner, } - -#[auto_serialize] -type attribute_ = {style: attr_style, value: meta_item}; - -#[auto_serialize] -type item = {ident: ident, attrs: [attribute], - id: node_id, node: item_, span: span}; - -#[auto_serialize] -enum item_ { - item_const(@ty, @expr), - item_fn(fn_decl, [ty_param], blk), - item_mod(_mod), - item_native_mod(native_mod), - item_ty(@ty, [ty_param]), - item_enum([variant], [ty_param]), - item_res(fn_decl /* dtor */, [ty_param], blk, - node_id /* dtor id */, node_id /* ctor id */), - item_class([ty_param], /* ty params for class */ - [@class_member], /* methods, etc. */ - /* (not including ctor) */ - class_ctor - ), - item_iface([ty_param], [ty_method]), - item_impl([ty_param], option<@ty> /* iface */, - @ty /* self */, [@method]), -} - -#[auto_serialize] -type class_member = spanned<class_member_>; - -#[auto_serialize] -enum class_member_ { - instance_var(ident, @ty, class_mutability, node_id, privacy), - class_method(@method) - // without constrained types, have to duplicate some stuff. or factor out - // item to separate out things with type params? - // (FIXME) where do we enforce that type params is empty? -} - -#[auto_serialize] -enum class_mutability { class_mutable, class_immutable } - -#[auto_serialize] -enum privacy { priv, pub } - -#[auto_serialize] -type class_ctor = spanned<class_ctor_>; - -#[auto_serialize] -type class_ctor_ = {id: node_id, - self_id: node_id, - dec: fn_decl, - body: blk}; - -#[auto_serialize] -type native_item = - {ident: ident, - attrs: [attribute], - node: native_item_, - id: node_id, - span: span}; - -#[auto_serialize] -enum native_item_ { - native_item_fn(fn_decl, [ty_param]), -} - -// The data we save and restore about an inlined item or method. This is not -// part of the AST that we parse from a file, but it becomes part of the tree -// that we trans. -#[auto_serialize] -enum inlined_item { - ii_item(@item), - ii_method(def_id /* impl id */, @method), - ii_native(@native_item), -} - -// -// Local Variables: -// mode: rust -// fill-column: 78; -// indent-tabs-mode: nil -// c-basic-offset: 4 -// buffer-file-coding-system: utf-8-unix -// End: -// diff --git a/src/rustc/syntax/ast_util.rs b/src/rustc/syntax/ast_util.rs deleted file mode 100644 index 5e0f1c89817..00000000000 --- a/src/rustc/syntax/ast_util.rs +++ /dev/null @@ -1,330 +0,0 @@ -import codemap::span; -import ast::*; - -fn respan<T: copy>(sp: span, t: T) -> spanned<T> { - ret {node: t, span: sp}; -} - -/* assuming that we're not in macro expansion */ -fn mk_sp(lo: uint, hi: uint) -> span { - ret {lo: lo, hi: hi, expn_info: none}; -} - -// make this a const, once the compiler supports it -fn dummy_sp() -> span { ret mk_sp(0u, 0u); } - -fn path_name(p: @path) -> str { path_name_i(p.node.idents) } - -fn path_name_i(idents: [ident]) -> str { str::connect(idents, "::") } - -fn local_def(id: node_id) -> def_id { {crate: local_crate, node: id} } - -pure fn is_local(did: ast::def_id) -> bool { did.crate == local_crate } - -fn stmt_id(s: stmt) -> node_id { - alt s.node { - stmt_decl(_, id) { id } - stmt_expr(_, id) { id } - stmt_semi(_, id) { id } - } -} - -fn variant_def_ids(d: def) -> {enm: def_id, var: def_id} { - alt d { def_variant(enum_id, var_id) { - ret {enm: enum_id, var: var_id}; } - _ { fail "non-variant in variant_def_ids"; } } -} - -fn def_id_of_def(d: def) -> def_id { - alt d { - def_fn(id, _) | def_mod(id) | - def_native_mod(id) | def_const(id) | - def_variant(_, id) | def_ty(id) | def_ty_param(id, _) | - def_use(id) | def_class(id) { id } - def_arg(id, _) | def_local(id, _) | def_self(id) | - def_upvar(id, _, _) | def_binding(id) | def_region(id) { - local_def(id) - } - - def_prim_ty(_) { fail; } - } -} - -fn binop_to_str(op: binop) -> str { - alt op { - add { ret "+"; } - subtract { ret "-"; } - mul { ret "*"; } - div { ret "/"; } - rem { ret "%"; } - and { ret "&&"; } - or { ret "||"; } - bitxor { ret "^"; } - bitand { ret "&"; } - bitor { ret "|"; } - lsl { ret "<<"; } - lsr { ret ">>"; } - asr { ret ">>>"; } - eq { ret "=="; } - lt { ret "<"; } - le { ret "<="; } - ne { ret "!="; } - ge { ret ">="; } - gt { ret ">"; } - } -} - -pure fn lazy_binop(b: binop) -> bool { - alt b { and { true } or { true } _ { false } } -} - -pure fn is_shift_binop(b: binop) -> bool { - alt b { - lsl { true } - lsr { true } - asr { true } - _ { false } - } -} - -fn unop_to_str(op: unop) -> str { - alt op { - box(mt) { if mt == m_mutbl { ret "@mut "; } ret "@"; } - uniq(mt) { if mt == m_mutbl { ret "~mut "; } ret "~"; } - deref { ret "*"; } - not { ret "!"; } - neg { ret "-"; } - addr_of { ret "&"; } - } -} - -fn is_path(e: @expr) -> bool { - ret alt e.node { expr_path(_) { true } _ { false } }; -} - -fn int_ty_to_str(t: int_ty) -> str { - alt t { - ty_char { "u8" } // ??? - ty_i { "" } ty_i8 { "i8" } ty_i16 { "i16" } - ty_i32 { "i32" } ty_i64 { "i64" } - } -} - -fn int_ty_max(t: int_ty) -> u64 { - alt t { - ty_i8 { 0x80u64 } - ty_i16 { 0x800u64 } - ty_i | ty_char | ty_i32 { 0x80000000u64 } // actually ni about ty_i - ty_i64 { 0x8000000000000000u64 } - } -} - -fn uint_ty_to_str(t: uint_ty) -> str { - alt t { - ty_u { "u" } ty_u8 { "u8" } ty_u16 { "u16" } - ty_u32 { "u32" } ty_u64 { "u64" } - } -} - -fn uint_ty_max(t: uint_ty) -> u64 { - alt t { - ty_u8 { 0xffu64 } - ty_u16 { 0xffffu64 } - ty_u | ty_u32 { 0xffffffffu64 } // actually ni about ty_u - ty_u64 { 0xffffffffffffffffu64 } - } -} - -fn float_ty_to_str(t: float_ty) -> str { - alt t { ty_f { "" } ty_f32 { "f32" } ty_f64 { "f64" } } -} - -fn is_exported(i: ident, m: _mod) -> bool { - let mut local = false; - let mut parent_enum : option<ident> = none; - for it: @item in m.items { - if it.ident == i { local = true; } - alt it.node { - item_enum(variants, _) { - for v: variant in variants { - if v.node.name == i { - local = true; - parent_enum = some(it.ident); - } - } - } - _ { } - } - if local { break; } - } - let mut has_explicit_exports = false; - for vi: @view_item in m.view_items { - alt vi.node { - view_item_export(vps) { - has_explicit_exports = true; - for vp in vps { - alt vp.node { - ast::view_path_simple(id, _, _) { - if id == i { ret true; } - alt parent_enum { - some(parent_enum_id) { - if id == parent_enum_id { ret true; } - } - _ {} - } - } - - ast::view_path_list(path, ids, _) { - if vec::len(*path) == 1u { - if i == path[0] { ret true; } - for id in ids { - if id.node.name == i { ret true; } - } - } else { - fail "export of path-qualified list"; - } - } - - // FIXME: glob-exports aren't supported yet. - _ {} - } - } - } - _ {} - } - } - // If there are no declared exports then - // everything not imported is exported - // even if it's local (since it's explicit) - ret !has_explicit_exports && local; -} - -pure fn is_call_expr(e: @expr) -> bool { - alt e.node { expr_call(_, _, _) { true } _ { false } } -} - -fn is_constraint_arg(e: @expr) -> bool { - alt e.node { - expr_lit(_) { ret true; } - expr_path(_) { ret true; } - _ { ret false; } - } -} - -fn eq_ty(&&a: @ty, &&b: @ty) -> bool { ret box::ptr_eq(a, b); } - -fn hash_ty(&&t: @ty) -> uint { - let res = (t.span.lo << 16u) + t.span.hi; - ret res; -} - -fn hash_def_id(&&id: def_id) -> uint { - (id.crate as uint << 16u) + (id.node as uint) -} - -fn eq_def_id(&&a: def_id, &&b: def_id) -> bool { - a == b -} - -fn new_def_id_hash<T: copy>() -> std::map::hashmap<def_id, T> { - std::map::hashmap(hash_def_id, eq_def_id) -} - -fn block_from_expr(e: @expr) -> blk { - let blk_ = default_block([], option::some::<@expr>(e), e.id); - ret {node: blk_, span: e.span}; -} - -fn default_block(stmts1: [@stmt], expr1: option<@expr>, id1: node_id) -> - blk_ { - {view_items: [], stmts: stmts1, expr: expr1, id: id1, rules: default_blk} -} - -fn ident_to_path(s: span, i: ident) -> @path { - @respan(s, {global: false, idents: [i], types: []}) -} - -pure fn is_unguarded(&&a: arm) -> bool { - alt a.guard { - none { true } - _ { false } - } -} - -pure fn unguarded_pat(a: arm) -> option<[@pat]> { - if is_unguarded(a) { some(a.pats) } else { none } -} - -// Provides an extra node_id to hang callee information on, in case the -// operator is deferred to a user-supplied method. The parser is responsible -// for reserving this id. -fn op_expr_callee_id(e: @expr) -> node_id { e.id - 1 } - -pure fn class_item_ident(ci: @class_member) -> ident { - alt ci.node { - instance_var(i,_,_,_,_) { i } - class_method(it) { it.ident } - } -} - -type ivar = {ident: ident, ty: @ty, cm: class_mutability, - id: node_id, privacy: privacy}; - -fn public_methods(ms: [@method]) -> [@method] { - vec::filter(ms, {|m| alt m.privacy { - pub { true } - _ { false }}}) -} - -fn split_class_items(cs: [@class_member]) -> ([ivar], [@method]) { - let mut vs = [], ms = []; - for c in cs { - alt c.node { - instance_var(i, t, cm, id, privacy) { - vs += [{ident: i, ty: t, cm: cm, id: id, privacy: privacy}]; - } - class_method(m) { ms += [m]; } - } - } - (vs, ms) -} - -pure fn class_member_privacy(ci: @class_member) -> privacy { - alt ci.node { - instance_var(_, _, _, _, p) { p } - class_method(m) { m.privacy } - } -} - -impl inlined_item_methods for inlined_item { - fn ident() -> ident { - alt self { - ii_item(i) { i.ident } - ii_native(i) { i.ident } - ii_method(_, m) { m.ident } - } - } - - fn id() -> ast::node_id { - alt self { - ii_item(i) { i.id } - ii_native(i) { i.id } - ii_method(_, m) { m.id } - } - } - - fn accept<E>(e: E, v: visit::vt<E>) { - alt self { - ii_item(i) { v.visit_item(i, e, v) } - ii_native(i) { v.visit_native_item(i, e, v) } - ii_method(_, m) { visit::visit_method_helper(m, e, v) } - } - } -} -// Local Variables: -// mode: rust -// fill-column: 78; -// indent-tabs-mode: nil -// c-basic-offset: 4 -// buffer-file-coding-system: utf-8-unix -// End: diff --git a/src/rustc/syntax/visit.rs b/src/rustc/syntax/visit.rs deleted file mode 100644 index b4bcb3aaa31..00000000000 --- a/src/rustc/syntax/visit.rs +++ /dev/null @@ -1,558 +0,0 @@ - -import ast::*; -import codemap::span; - -// Context-passing AST walker. Each overridden visit method has full control -// over what happens with its node, it can do its own traversal of the node's -// children (potentially passing in different contexts to each), call -// visit::visit_* to apply the default traversal algorithm (again, it can -// override the context), or prevent deeper traversal by doing nothing. - -// Our typesystem doesn't do circular types, so the visitor record can not -// hold functions that take visitors. A vt enum is used to break the cycle. -enum vt<E> { mk_vt(visitor<E>), } - -enum fn_kind { - fk_item_fn(ident, [ty_param]), //< an item declared with fn() - fk_method(ident, [ty_param], @method), - fk_res(ident, [ty_param]), - fk_anon(proto), //< an anonymous function like fn@(...) - fk_fn_block, //< a block {||...} - fk_ctor(ident, [ty_param]) // class constructor -} - -fn name_of_fn(fk: fn_kind) -> ident { - alt fk { - fk_item_fn(name, _) | fk_method(name, _, _) | fk_res(name, _) - | fk_ctor(name, _) { name } - fk_anon(_) | fk_fn_block { "anon" } - } -} - -fn tps_of_fn(fk: fn_kind) -> [ty_param] { - alt fk { - fk_item_fn(_, tps) | fk_method(_, tps, _) | fk_res(_, tps) - | fk_ctor(_, tps) { tps } - fk_anon(_) | fk_fn_block { [] } - } -} - -type visitor<E> = - // takes the components so that one function can be - // generic over constr and ty_constr - @{visit_mod: fn@(_mod, span, node_id, E, vt<E>), - visit_view_item: fn@(@view_item, E, vt<E>), - visit_native_item: fn@(@native_item, E, vt<E>), - visit_item: fn@(@item, E, vt<E>), - visit_local: fn@(@local, E, vt<E>), - visit_block: fn@(ast::blk, E, vt<E>), - visit_stmt: fn@(@stmt, E, vt<E>), - visit_arm: fn@(arm, E, vt<E>), - visit_pat: fn@(@pat, E, vt<E>), - visit_decl: fn@(@decl, E, vt<E>), - visit_expr: fn@(@expr, E, vt<E>), - visit_ty: fn@(@ty, E, vt<E>), - visit_ty_params: fn@([ty_param], E, vt<E>), - visit_constr: fn@(@path, span, node_id, E, vt<E>), - visit_fn: fn@(fn_kind, fn_decl, blk, span, node_id, E, vt<E>), - visit_class_item: fn@(@class_member, E, vt<E>)}; - -fn default_visitor<E>() -> visitor<E> { - ret @{visit_mod: bind visit_mod::<E>(_, _, _, _, _), - visit_view_item: bind visit_view_item::<E>(_, _, _), - visit_native_item: bind visit_native_item::<E>(_, _, _), - visit_item: bind visit_item::<E>(_, _, _), - visit_local: bind visit_local::<E>(_, _, _), - visit_block: bind visit_block::<E>(_, _, _), - visit_stmt: bind visit_stmt::<E>(_, _, _), - visit_arm: bind visit_arm::<E>(_, _, _), - visit_pat: bind visit_pat::<E>(_, _, _), - visit_decl: bind visit_decl::<E>(_, _, _), - visit_expr: bind visit_expr::<E>(_, _, _), - visit_ty: bind skip_ty::<E>(_, _, _), - visit_ty_params: bind visit_ty_params::<E>(_, _, _), - visit_constr: bind visit_constr::<E>(_, _, _, _, _), - visit_fn: bind visit_fn::<E>(_, _, _, _, _, _, _), - visit_class_item: bind visit_class_item::<E>(_,_,_)}; -} - -fn visit_crate<E>(c: crate, e: E, v: vt<E>) { - v.visit_mod(c.node.module, c.span, crate_node_id, e, v); -} - -fn visit_crate_directive<E>(cd: @crate_directive, e: E, v: vt<E>) { - alt cd.node { - cdir_src_mod(_, _) { } - cdir_dir_mod(_, cdirs, _) { - for cdir: @crate_directive in cdirs { - visit_crate_directive(cdir, e, v); - } - } - cdir_view_item(vi) { v.visit_view_item(vi, e, v); } - cdir_syntax(_) { } - } -} - -fn visit_mod<E>(m: _mod, _sp: span, _id: node_id, e: E, v: vt<E>) { - for vi: @view_item in m.view_items { v.visit_view_item(vi, e, v); } - for i: @item in m.items { v.visit_item(i, e, v); } -} - -fn visit_view_item<E>(_vi: @view_item, _e: E, _v: vt<E>) { } - -fn visit_local<E>(loc: @local, e: E, v: vt<E>) { - v.visit_pat(loc.node.pat, e, v); - v.visit_ty(loc.node.ty, e, v); - alt loc.node.init { none { } some(i) { v.visit_expr(i.expr, e, v); } } -} - -fn visit_item<E>(i: @item, e: E, v: vt<E>) { - alt i.node { - item_const(t, ex) { v.visit_ty(t, e, v); v.visit_expr(ex, e, v); } - item_fn(decl, tp, body) { - v.visit_fn(fk_item_fn(i.ident, tp), decl, body, i.span, i.id, e, v); - } - item_mod(m) { v.visit_mod(m, i.span, i.id, e, v); } - item_native_mod(nm) { - for vi: @view_item in nm.view_items { v.visit_view_item(vi, e, v); } - for ni: @native_item in nm.items { v.visit_native_item(ni, e, v); } - } - item_ty(t, tps) { v.visit_ty(t, e, v); v.visit_ty_params(tps, e, v); } - item_res(decl, tps, body, dtor_id, _) { - v.visit_fn(fk_res(i.ident, tps), decl, body, i.span, - dtor_id, e, v); - } - item_enum(variants, tps) { - v.visit_ty_params(tps, e, v); - for vr: variant in variants { - for va: variant_arg in vr.node.args { v.visit_ty(va.ty, e, v); } - } - } - item_impl(tps, ifce, ty, methods) { - v.visit_ty_params(tps, e, v); - alt ifce { some(ty) { v.visit_ty(ty, e, v); } _ {} } - v.visit_ty(ty, e, v); - for m in methods { - visit_method_helper(m, e, v) - } - } - item_class(tps, members, ctor) { - v.visit_ty_params(tps, e, v); - for m in members { - v.visit_class_item(m, e, v); - } - // make up a fake fn so as to call visit_fn on the ctor - v.visit_fn(fk_ctor(i.ident, tps), ctor.node.dec, - ctor.node.body, ctor.span, ctor.node.id, e, v); - } - item_iface(tps, methods) { - v.visit_ty_params(tps, e, v); - for m in methods { - for a in m.decl.inputs { v.visit_ty(a.ty, e, v); } - v.visit_ty(m.decl.output, e, v); - } - } - } -} - -fn visit_class_item<E>(cm: @class_member, e:E, v:vt<E>) { - alt cm.node { - instance_var(_, t, _, _, _) { - v.visit_ty(t, e, v); - } - class_method(m) { - visit_method_helper(m, e, v); - } - } -} - -fn skip_ty<E>(_t: @ty, _e: E, _v: vt<E>) {} - -fn visit_ty<E>(t: @ty, e: E, v: vt<E>) { - alt t.node { - ty_box(mt) { v.visit_ty(mt.ty, e, v); } - ty_uniq(mt) { v.visit_ty(mt.ty, e, v); } - ty_vec(mt) { v.visit_ty(mt.ty, e, v); } - ty_ptr(mt) { v.visit_ty(mt.ty, e, v); } - ty_rptr(_, mt) { v.visit_ty(mt.ty, e, v); } - ty_rec(flds) { - for f: ty_field in flds { v.visit_ty(f.node.mt.ty, e, v); } - } - ty_tup(ts) { for tt in ts { v.visit_ty(tt, e, v); } } - ty_fn(_, decl) { - for a in decl.inputs { v.visit_ty(a.ty, e, v); } - for c: @constr in decl.constraints { - v.visit_constr(c.node.path, c.span, c.node.id, e, v); - } - v.visit_ty(decl.output, e, v); - } - ty_path(p, _) { visit_path(p, e, v); } - ty_constr(t, cs) { - v.visit_ty(t, e, v); - for tc: @spanned<constr_general_<@path, node_id>> in cs { - v.visit_constr(tc.node.path, tc.span, tc.node.id, e, v); - } - } - _ {} - } -} - -fn visit_constr<E>(_operator: @path, _sp: span, _id: node_id, _e: E, - _v: vt<E>) { - // default -} - -fn visit_path<E>(p: @path, e: E, v: vt<E>) { - for tp: @ty in p.node.types { v.visit_ty(tp, e, v); } -} - -fn visit_pat<E>(p: @pat, e: E, v: vt<E>) { - alt p.node { - pat_enum(path, children) { - visit_path(path, e, v); - for child: @pat in children { v.visit_pat(child, e, v); } - } - pat_rec(fields, _) { - for f: field_pat in fields { v.visit_pat(f.pat, e, v); } - } - pat_tup(elts) { for elt in elts { v.visit_pat(elt, e, v); } } - pat_box(inner) | pat_uniq(inner) { - v.visit_pat(inner, e, v); - } - pat_ident(path, inner) { - visit_path(path, e, v); - option::may(inner, {|subpat| v.visit_pat(subpat, e, v)}); - } - pat_lit(ex) { v.visit_expr(ex, e, v); } - pat_range(e1, e2) { v.visit_expr(e1, e, v); v.visit_expr(e2, e, v); } - pat_wild {} - } -} - -fn visit_native_item<E>(ni: @native_item, e: E, v: vt<E>) { - alt ni.node { - native_item_fn(fd, tps) { - v.visit_ty_params(tps, e, v); - visit_fn_decl(fd, e, v); - } - } -} - -fn visit_ty_params<E>(tps: [ty_param], e: E, v: vt<E>) { - for tp in tps { - for bound in *tp.bounds { - alt bound { - bound_iface(t) { v.visit_ty(t, e, v); } - _ {} - } - } - } -} - -fn visit_fn_decl<E>(fd: fn_decl, e: E, v: vt<E>) { - for a: arg in fd.inputs { v.visit_ty(a.ty, e, v); } - for c: @constr in fd.constraints { - v.visit_constr(c.node.path, c.span, c.node.id, e, v); - } - v.visit_ty(fd.output, e, v); -} - -// Note: there is no visit_method() method in the visitor, instead override -// 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 -fn visit_method_helper<E>(m: @method, e: E, v: vt<E>) { - v.visit_fn(fk_method(m.ident, m.tps, m), m.decl, m.body, m.span, - m.id, e, v); -} - -fn visit_fn<E>(fk: fn_kind, decl: fn_decl, body: blk, _sp: span, - _id: node_id, e: E, v: vt<E>) { - visit_fn_decl(decl, e, v); - v.visit_ty_params(tps_of_fn(fk), e, v); - v.visit_block(body, e, v); -} - -fn visit_block<E>(b: ast::blk, e: E, v: vt<E>) { - for vi in b.node.view_items { v.visit_view_item(vi, e, v); } - for s in b.node.stmts { v.visit_stmt(s, e, v); } - visit_expr_opt(b.node.expr, e, v); -} - -fn visit_stmt<E>(s: @stmt, e: E, v: vt<E>) { - alt s.node { - stmt_decl(d, _) { v.visit_decl(d, e, v); } - stmt_expr(ex, _) { v.visit_expr(ex, e, v); } - stmt_semi(ex, _) { v.visit_expr(ex, e, v); } - } -} - -fn visit_decl<E>(d: @decl, e: E, v: vt<E>) { - alt d.node { - decl_local(locs) { - for loc in locs { v.visit_local(loc, e, v); } - } - decl_item(it) { v.visit_item(it, e, v); } - } -} - -fn visit_expr_opt<E>(eo: option<@expr>, e: E, v: vt<E>) { - alt eo { none { } some(ex) { v.visit_expr(ex, e, v); } } -} - -fn visit_exprs<E>(exprs: [@expr], e: E, v: vt<E>) { - for ex: @expr in exprs { v.visit_expr(ex, e, v); } -} - -fn visit_mac<E>(m: mac, e: E, v: vt<E>) { - alt m.node { - ast::mac_invoc(pth, arg, body) { - option::map(arg) {|arg| v.visit_expr(arg, e, v)}; } - ast::mac_embed_type(ty) { v.visit_ty(ty, e, v); } - ast::mac_embed_block(blk) { v.visit_block(blk, e, v); } - ast::mac_ellipsis { } - ast::mac_aq(_, e) { /* FIXME: maybe visit */ } - ast::mac_var(_) { } - } -} - -fn visit_expr<E>(ex: @expr, e: E, v: vt<E>) { - alt ex.node { - expr_new(pool, _, val) { - v.visit_expr(pool, e, v); - v.visit_expr(val, e, v); - } - expr_vec(es, _) { visit_exprs(es, e, v); } - expr_rec(flds, base) { - for f: field in flds { v.visit_expr(f.node.expr, e, v); } - visit_expr_opt(base, e, v); - } - expr_tup(elts) { for el in elts { v.visit_expr(el, e, v); } } - expr_call(callee, args, _) { - visit_exprs(args, e, v); - v.visit_expr(callee, e, v); - } - expr_bind(callee, args) { - v.visit_expr(callee, e, v); - for eo: option<@expr> in args { visit_expr_opt(eo, e, v); } - } - expr_binary(_, a, b) { v.visit_expr(a, e, v); v.visit_expr(b, e, v); } - expr_addr_of(_, x) | expr_unary(_, x) | expr_loop_body(x) | - expr_check(_, x) | expr_assert(x) { - v.visit_expr(x, e, v); - } - expr_lit(_) { } - expr_cast(x, t) { v.visit_expr(x, e, v); v.visit_ty(t, e, v); } - expr_if(x, b, eo) { - v.visit_expr(x, e, v); - v.visit_block(b, e, v); - visit_expr_opt(eo, e, v); - } - expr_if_check(x, b, eo) { - v.visit_expr(x, e, v); - v.visit_block(b, e, v); - visit_expr_opt(eo, e, v); - } - expr_while(x, b) { v.visit_expr(x, e, v); v.visit_block(b, e, v); } - expr_loop(b) { v.visit_block(b, e, v); } - expr_for(dcl, x, b) { - v.visit_local(dcl, e, v); - v.visit_expr(x, e, v); - v.visit_block(b, e, v); - } - expr_do_while(b, x) { v.visit_block(b, e, v); v.visit_expr(x, e, v); } - expr_alt(x, arms, _) { - v.visit_expr(x, e, v); - for a: arm in arms { v.visit_arm(a, e, v); } - } - expr_fn(proto, decl, body, _) { - v.visit_fn(fk_anon(proto), decl, body, ex.span, ex.id, e, v); - } - expr_fn_block(decl, body) { - v.visit_fn(fk_fn_block, decl, body, ex.span, ex.id, e, v); - } - expr_block(b) { v.visit_block(b, e, v); } - expr_assign(a, b) { v.visit_expr(b, e, v); v.visit_expr(a, e, v); } - expr_copy(a) { v.visit_expr(a, e, v); } - expr_move(a, b) { v.visit_expr(b, e, v); v.visit_expr(a, e, v); } - expr_swap(a, b) { v.visit_expr(a, e, v); v.visit_expr(b, e, v); } - expr_assign_op(_, a, b) { - v.visit_expr(b, e, v); - v.visit_expr(a, e, v); - } - expr_field(x, _, tys) { - v.visit_expr(x, e, v); - for tp in tys { v.visit_ty(tp, e, v); } - } - expr_index(a, b) { v.visit_expr(a, e, v); v.visit_expr(b, e, v); } - expr_path(p) { visit_path(p, e, v); } - expr_fail(eo) { visit_expr_opt(eo, e, v); } - expr_break { } - expr_cont { } - expr_ret(eo) { visit_expr_opt(eo, e, v); } - expr_be(x) { v.visit_expr(x, e, v); } - expr_log(_, lv, x) { - v.visit_expr(lv, e, v); - v.visit_expr(x, e, v); - } - expr_mac(mac) { visit_mac(mac, e, v); } - } -} - -fn visit_arm<E>(a: arm, e: E, v: vt<E>) { - for p: @pat in a.pats { v.visit_pat(p, e, v); } - visit_expr_opt(a.guard, e, v); - v.visit_block(a.body, e, v); -} - -// Simpler, non-context passing interface. Always walks the whole tree, simply -// calls the given functions on the nodes. - -type simple_visitor = - // takes the components so that one function can be - // generic over constr and ty_constr - @{visit_mod: fn@(_mod, span, node_id), - visit_view_item: fn@(@view_item), - visit_native_item: fn@(@native_item), - visit_item: fn@(@item), - visit_local: fn@(@local), - visit_block: fn@(ast::blk), - visit_stmt: fn@(@stmt), - visit_arm: fn@(arm), - visit_pat: fn@(@pat), - visit_decl: fn@(@decl), - visit_expr: fn@(@expr), - visit_ty: fn@(@ty), - visit_ty_params: fn@([ty_param]), - visit_constr: fn@(@path, span, node_id), - visit_fn: fn@(fn_kind, fn_decl, blk, span, node_id), - visit_class_item: fn@(@class_member)}; - -fn simple_ignore_ty(_t: @ty) {} - -fn default_simple_visitor() -> simple_visitor { - ret @{visit_mod: fn@(_m: _mod, _sp: span, _id: node_id) { }, - visit_view_item: fn@(_vi: @view_item) { }, - visit_native_item: fn@(_ni: @native_item) { }, - visit_item: fn@(_i: @item) { }, - visit_local: fn@(_l: @local) { }, - visit_block: fn@(_b: ast::blk) { }, - visit_stmt: fn@(_s: @stmt) { }, - visit_arm: fn@(_a: arm) { }, - visit_pat: fn@(_p: @pat) { }, - visit_decl: fn@(_d: @decl) { }, - visit_expr: fn@(_e: @expr) { }, - visit_ty: simple_ignore_ty, - visit_ty_params: fn@(_ps: [ty_param]) {}, - visit_constr: fn@(_p: @path, _sp: span, _id: node_id) { }, - visit_fn: fn@(_fk: fn_kind, _d: fn_decl, _b: blk, _sp: span, - _id: node_id) { }, - visit_class_item: fn@(_c: @class_member) {} - }; -} - -fn mk_simple_visitor(v: simple_visitor) -> vt<()> { - fn v_mod(f: fn@(_mod, span, node_id), m: _mod, sp: span, id: node_id, - &&e: (), v: vt<()>) { - f(m, sp, id); - visit_mod(m, sp, id, e, v); - } - fn v_view_item(f: fn@(@view_item), vi: @view_item, &&e: (), v: vt<()>) { - f(vi); - visit_view_item(vi, e, v); - } - fn v_native_item(f: fn@(@native_item), ni: @native_item, &&e: (), - v: vt<()>) { - f(ni); - visit_native_item(ni, e, v); - } - fn v_item(f: fn@(@item), i: @item, &&e: (), v: vt<()>) { - f(i); - visit_item(i, e, v); - } - fn v_local(f: fn@(@local), l: @local, &&e: (), v: vt<()>) { - f(l); - visit_local(l, e, v); - } - fn v_block(f: fn@(ast::blk), bl: ast::blk, &&e: (), v: vt<()>) { - f(bl); - visit_block(bl, e, v); - } - fn v_stmt(f: fn@(@stmt), st: @stmt, &&e: (), v: vt<()>) { - f(st); - visit_stmt(st, e, v); - } - fn v_arm(f: fn@(arm), a: arm, &&e: (), v: vt<()>) { - f(a); - visit_arm(a, e, v); - } - fn v_pat(f: fn@(@pat), p: @pat, &&e: (), v: vt<()>) { - f(p); - visit_pat(p, e, v); - } - fn v_decl(f: fn@(@decl), d: @decl, &&e: (), v: vt<()>) { - f(d); - visit_decl(d, e, v); - } - fn v_expr(f: fn@(@expr), ex: @expr, &&e: (), v: vt<()>) { - f(ex); - visit_expr(ex, e, v); - } - fn v_ty(f: fn@(@ty), ty: @ty, &&e: (), v: vt<()>) { - f(ty); - visit_ty(ty, e, v); - } - fn v_ty_params(f: fn@([ty_param]), ps: [ty_param], &&e: (), v: vt<()>) { - f(ps); - visit_ty_params(ps, e, v); - } - fn v_constr(f: fn@(@path, span, node_id), pt: @path, sp: span, - id: node_id, &&e: (), v: vt<()>) { - f(pt, sp, id); - visit_constr(pt, sp, id, e, v); - } - fn v_fn(f: fn@(fn_kind, fn_decl, blk, span, node_id), - fk: fn_kind, decl: fn_decl, body: blk, sp: span, - id: node_id, &&e: (), v: vt<()>) { - f(fk, decl, body, sp, id); - visit_fn(fk, decl, body, sp, id, e, v); - } - let visit_ty = if v.visit_ty == simple_ignore_ty { - bind skip_ty(_, _, _) - } else { - bind v_ty(v.visit_ty, _, _, _) - }; - fn v_class_item(f: fn@(@class_member), - cm: @class_member, &&e: (), - v: vt<()>) { - f(cm); - visit_class_item(cm, e, v); - } - ret mk_vt(@{visit_mod: bind v_mod(v.visit_mod, _, _, _, _, _), - visit_view_item: bind v_view_item(v.visit_view_item, _, _, _), - visit_native_item: - bind v_native_item(v.visit_native_item, _, _, _), - visit_item: bind v_item(v.visit_item, _, _, _), - visit_local: bind v_local(v.visit_local, _, _, _), - visit_block: bind v_block(v.visit_block, _, _, _), - visit_stmt: bind v_stmt(v.visit_stmt, _, _, _), - visit_arm: bind v_arm(v.visit_arm, _, _, _), - visit_pat: bind v_pat(v.visit_pat, _, _, _), - visit_decl: bind v_decl(v.visit_decl, _, _, _), - visit_expr: bind v_expr(v.visit_expr, _, _, _), - visit_ty: visit_ty, - visit_ty_params: bind v_ty_params(v.visit_ty_params, _, _, _), - visit_constr: bind v_constr(v.visit_constr, _, _, _, _, _), - visit_fn: bind v_fn(v.visit_fn, _, _, _, _, _, _, _), - visit_class_item: bind v_class_item(v.visit_class_item, _, _, - _) - }); -} - -// Local Variables: -// mode: rust -// fill-column: 78; -// indent-tabs-mode: nil -// c-basic-offset: 4 -// buffer-file-coding-system: utf-8-unix -// End: |
