Commit c5f91537 authored by POTTIER Francois's avatar POTTIER Francois

Implement [ba] on top of [iter] instead of [reduce].

parent 2fc8078a
......@@ -69,6 +69,8 @@
(* -------------------------------------------------------------------------- *)
(* [ba] could be defined in terms of [reduce], as follows. *)
#define BA_CLASS __ba
#define BA_FUN(term) CONCAT(ba_, term)
......@@ -82,6 +84,26 @@
let BA_FUN(term) t = \
new BA_CLASS # VISIT(term) () t \
#undef __BA
#undef BA
(* -------------------------------------------------------------------------- *)
(* We prefer to define [ba] in terms of [iter] because we wish to eliminate
our dependency on [reduce] visitors. *)
#define __BA \
class ['self] BA_CLASS = object (_ : 'self) \
inherit [_] iter \
inherit [_] KitBa.iter \
end \
#define BA(term) \
let BA_FUN(term) t = \
let o = new BA_CLASS in \
o # VISIT(term) () t; \
o # accu \
(* -------------------------------------------------------------------------- *)
#define AVOIDS_CLASS __avoids
......
(* This kit serves to compute the set of ``bound atoms'' of a term, that is,
the set of all binding name occurrences. *)
(* This computation can be performed either on top of an [iter] visitor, or
on top of a [reduce] visitor. *)
class ['self] iter = object (_ : 'self)
val mutable accu = Atom.Set.empty
method accu = accu (* must be public *)
(* A bound atom is added to the accumulator when its scope is entered. *)
method private extend x () =
accu <- Atom.Set.add x accu
method private visit_'fn () _x =
()
end
class ['self] reduce = object (_ : 'self)
method private extend _x () =
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment