-
Notifications
You must be signed in to change notification settings - Fork 14k
Closed
Description
Currently libsyntax/visit.rs provides a record that holds a collection of @fn's, using a mix of lambda-lifting and an explicit virtual method table to define traversals over the AST.
pub struct Visitor<E> {
visit_mod: @fn(&_mod, span, node_id, E, vt<E>),
visit_view_item: @fn(@view_item, E, vt<E>),
...
}where
pub enum vt<E> { mk_vt(visitor<E>), }So then a use of the visitor looks like this (taken from freevars.rs):
let v = visit::mk_vt(@visit::Visitor {visit_item: ignore_item,
visit_expr: walk_expr,
.. *visit::default_visitor()});
(v.visit_block)(blk, 1, v);where ignore_item and walk_expr are defined accordingly.
The above is awkward. A more natural way to encode this would be via a Visitor trait that defined the visit methods; then instances of the trait would correspond to the accumulated state denoted above by E in the struct definition and 1 in the freevars example.
(I originally had written a @Visitor object, but there is no need to commit to using objects in the Visitor interface.)
Metadata
Metadata
Assignees
Labels
No labels