1 (***********************************************************************)
5 (* Kim Nguyen, LRI UMR8623 *)
6 (* Université Paris-Sud & CNRS *)
8 (* Copyright 2010-2013 Université Paris-Sud and Centre National de la *)
9 (* Recherche Scientifique. All rights reserved. This file is *)
10 (* distributed under the terms of the GNU Lesser General Public *)
11 (* License, with the special exception on linking described in file *)
14 (***********************************************************************)
17 Time-stamp: <Last modified on 2013-03-16 09:39:39 CET by Kim Nguyen>
24 module Make (T : Tree.Sig.S) :
26 val eval : Ata.t -> T.t -> T.node -> T.node list
40 type cache = StateSet.t Cache.N1.t
41 let get c t n = Cache.N1.find c (T.preorder t n)
43 let set c t n v = Cache.N1.add c (T.preorder t n) v
46 let top_down_run auto tree node cache _i =
47 let redo = ref false in
49 if node != T.nil then begin
50 let parent = T.parent tree node in
51 let fc = T.first_child tree node in
52 let ns = T.next_sibling tree node in
53 let tag = T.tag tree node in
54 let states0 = get cache tree node in
55 let trans0 = Ata.get_trans auto tag auto.Ata.states in
57 TRACE(Html.trace (T.preorder tree node) _i "Pre States: %a<br/>Pre Trans: %a<br/>"
58 StateSet.print states0 (Ata.TransList.print ~sep:"<br/>") trans0)
60 let ps = get cache tree parent in
61 let fcs = get cache tree fc in
62 let nss = get cache tree ns in
63 let is_left = node == T.first_child tree parent
64 and is_right = node == T.next_sibling tree parent
65 and has_left = fc != T.nil
66 and has_right = ns != T.nil
67 and kind = T.kind tree node
70 Ata.eval_trans auto trans0
72 is_left is_right has_left has_right kind
75 TRACE(Html.trace (T.preorder tree node) _i "TD States: %a<br/>TD Trans: %a<br/>" StateSet.print states1 (Ata.TransList.print ~sep:"<br/>") trans1)
77 if states1 != states0 then set cache tree node states1;
79 let fcs1 = get cache tree fc in
81 Ata.eval_trans auto trans1
83 is_left is_right has_left has_right kind
86 TRACE(Html.trace (T.preorder tree node) _i "Left BU States: %a<br/>Left BU Trans: %a<br/>" StateSet.print states2 (Ata.TransList.print ~sep:"<br/>") trans2)
88 if states2 != states1 then set cache tree node states2;
90 let _trans3, states3 =
91 Ata.eval_trans auto trans2
92 fcs1 (get cache tree ns) ps states2
93 is_left is_right has_left has_right kind
96 TRACE(Html.trace (T.preorder tree node) _i "Right BU States: %a<br/>Right BU Trans: %a<br/>" StateSet.print states3 (Ata.TransList.print ~sep:"<br/>") _trans3)
98 if states3 != states2 then set cache tree node states3;
99 (*if states0 != states3 && (not !redo) then redo := true *)
101 && not (Ata.TransList.nil == _trans3)
102 && (states1 != states3)
103 && not (StateSet.intersect states3 auto.Ata.selection_states)
110 let get_results auto tree node cache =
111 let rec loop node acc =
112 if node == T.nil then acc
114 let acc0 = loop (T.next_sibling tree node) acc in
115 let acc1 = loop (T.first_child tree node) acc0 in
117 if StateSet.intersect (get cache tree node) auto.Ata.selection_states then
124 let eval auto tree node =
125 let cache = Cache.N1.create StateSet.empty in
126 let redo = ref true in
131 redo := top_down_run auto tree node cache !iter;
134 at_exit (fun () -> eprintf "INFO: %i iterations\n" !iter);
135 let r = get_results auto tree node cache in
136 TRACE(Html.gen_trace (module T : Tree.Sig.S with type t = T.t) (tree));