X-Git-Url: http://git.nguyen.vg/gitweb/?a=blobdiff_plain;f=src%2Fauto%2Fata.ml;h=e07aa3f389560b45015ccd5f7a4c6f5ba1f25c3e;hb=f93c0057cfca9610e40f9214b286174a041e422a;hp=ca641b498d16aa85a42f91e7d18399ecca7dc720;hpb=902bbf3612fbad7cad16d5492b52317c83191fcd;p=tatoo.git diff --git a/src/auto/ata.ml b/src/auto/ata.ml index ca641b4..e07aa3f 100644 --- a/src/auto/ata.ml +++ b/src/auto/ata.ml @@ -14,7 +14,7 @@ (***********************************************************************) (* - Time-stamp: + Time-stamp: *) INCLUDE "utils.ml" @@ -45,11 +45,15 @@ struct let make_ctx a b c d e = { left = a; right = b; up1 = c; up2 = d; epsilon = e } - include Hcons.Make(Node) + include Hcons.Make(Node) + let _pr_buff = Buffer.create 10 + let _str_fmt = formatter_of_buffer _pr_buff + let _flush_str_fmt () = pp_print_flush _str_fmt (); + let s = Buffer.contents _pr_buff in + Buffer.clear _pr_buff; s let print ppf a = - let _ = flush_str_formatter() in - let fmt = str_formatter in + let _ = _flush_str_fmt () in let m, b, s = a.node in let dir,num = @@ -60,9 +64,9 @@ struct | `Up1 -> Pretty.up_arrow, Pretty.subscript 1 | `Up2 -> Pretty.up_arrow, Pretty.subscript 2 in - fprintf fmt "%s%s" dir num; - State.print fmt s; - let str = flush_str_formatter() in + fprintf _str_fmt "%s%s" dir num; + State.print _str_fmt s; + let str = _flush_str_fmt () in if b then fprintf ppf "%s" str else Pretty.pp_overline ppf str @@ -84,11 +88,11 @@ struct end module SFormula = Formula.Make(Move) -type 'a t = { +type t = { id : Uid.t; mutable states : StateSet.t; - mutable top_states : StateSet.t; - mutable bottom_states: StateSet.t; +(* mutable top_states : StateSet.t; + mutable bottom_states: StateSet.t; *) mutable selection_states: StateSet.t; transitions: (State.t, (QNameSet.t*SFormula.t) list) Hashtbl.t; } @@ -97,8 +101,8 @@ let next = Uid.make_maker () let create () = { id = next (); states = StateSet.empty; - top_states = StateSet.empty; - bottom_states = StateSet.empty; +(* top_states = StateSet.empty; + bottom_states = StateSet.empty; *) selection_states = StateSet.empty; transitions = Hashtbl.create 17; } @@ -132,19 +136,20 @@ let add_trans a q s f = in Hashtbl.replace a.transitions q ntrs +let _pr_buff = Buffer.create 50 +let _str_fmt = formatter_of_buffer _pr_buff +let _flush_str_fmt () = pp_print_flush _str_fmt (); + let s = Buffer.contents _pr_buff in + Buffer.clear _pr_buff; s let print fmt a = fprintf fmt - "Unique ID: %i@\n\ - States %a@\n\ - Top states: %a@\n\ - Bottom states: %a@\n\ + "\nInternal UID: %i@\n\ + States: %a@\n\ Selection states: %a@\n\ Alternating transitions:@\n" (a.id :> int) StateSet.print a.states - StateSet.print a.top_states - StateSet.print a.bottom_states StateSet.print a.selection_states; let trs = Hashtbl.fold @@ -156,21 +161,26 @@ let print fmt a = let c = State.compare q1 q2 in - (if c == 0 then QNameSet.compare s1 s2 else c)) trs in - let sfmt = str_formatter in - let _ = flush_str_formatter () in - let strs_strings, maxs = List.fold_left (fun (accl, accm) (q, s, f) -> - let s1 = State.print sfmt q; flush_str_formatter () in - let s2 = QNameSet.print sfmt s; flush_str_formatter () in - let s3 = SFormula.print sfmt f; flush_str_formatter () in - ( (s1, s2, s3) :: accl, - max - accm (2 + String.length s1 + String.length s2)) - ) ([], 0) sorted_trs + let _ = _flush_str_fmt () in + let strs_strings, max_pre, max_all = List.fold_left (fun (accl, accp, acca) (q, s, f) -> + let s1 = State.print _str_fmt q; _flush_str_fmt () in + let s2 = QNameSet.print _str_fmt s; _flush_str_fmt () in + let s3 = SFormula.print _str_fmt f; _flush_str_fmt () in + let pre = Pretty.length s1 + Pretty.length s2 in + let all = Pretty.length s3 in + ( (q, s1, s2, s3) :: accl, max accp pre, max acca all) + ) ([], 0, 0) sorted_trs in - List.iter (fun (s1, s2, s3) -> - fprintf fmt "%s, %s" s1 s2; - fprintf fmt "%s" (Pretty.padding (maxs - String.length s1 - String.length s2 - 2)); - fprintf fmt "%s %s@\n" Pretty.right_arrow s3) strs_strings + let line = Pretty.line (max_all + max_pre + 6) in + let prev_q = ref State.dummy in + List.iter (fun (q, s1, s2, s3) -> + if !prev_q != q && !prev_q != State.dummy then fprintf fmt " %s\n%!" line; + prev_q := q; + fprintf fmt " %s, %s" s1 s2; + fprintf fmt "%s" (Pretty.padding (max_pre - Pretty.length s1 - Pretty.length s2)); + fprintf fmt " %s %s@\n%!" Pretty.right_arrow s3; + ) strs_strings; + fprintf fmt " %s\n%!" line (* [complete transitions a] ensures that for each state q @@ -233,7 +243,7 @@ let normalize_negations a = end end in - StateSet.iter (fun q -> Queue.add (q, true) todo) a.top_states; + StateSet.iter (fun q -> Queue.add (q, true) todo) a.selection_states; while not (Queue.is_empty todo) do let (q, b) as key = Queue.pop todo in let q' = @@ -247,9 +257,4 @@ let normalize_negations a = let trans = Hashtbl.find a.transitions q in let trans' = List.map (fun (lab, f) -> lab, flip b f) trans in Hashtbl.replace a.transitions q' trans' - done; - Hashtbl.iter (fun (q, b) q' -> - if not (b || StateSet.mem q a.bottom_states) then - a.bottom_states <- StateSet.add q' a.bottom_states - ) memo_state - + done