(***********************************************************************) (* *) (* TAToo *) (* *) (* Lucca Hirschi, ? *) (* ? *) (* *) (* Copyright 2010-2012 Université Paris-Sud and Centre National de la *) (* Recherche Scientifique. All rights reserved. This file is *) (* distributed under the terms of the GNU Lesser General Public *) (* License, with the special exception on linking described in file *) (* ../LICENSE. *) (* *) (***********************************************************************) type state = State.t type label = QNameSet.t type formula = Formula.t module Transition = struct type t = state * label * formula let compare (st,la,f) (st',la',f') = let x_1 = State.compare st st' in if x_1 != 0 then x_1 else let x_2 = QNameSet.compare la la' in if x_2 != 0 then x_2 else Formula.compare f f' let st (st,la,f) = st let la (st,la,f) = la let fo (st,la,f) = f let print fmt (st,la,f) = Format.fprintf fmt "%a ----%s---> %a" State.print st (QNameSet.to_string la) Formula.print f end module SetT = struct include Set.Make(Transition) end type transition = Transition.t type t = { mutable quer : StateSet.t; mutable reco : StateSet.t; mutable selec : StateSet.t; mutable bottom : StateSet.t; mutable top : StateSet.t; mutable trans : SetT.t; } exception Not_found_transition exception Transition_not_injective let transition asta st lab = let filter (s,l,f) = (State.compare s st = 0) && (QNameSet.compare l lab = 0) in let tr_set = SetT.elements (SetT.filter filter asta.trans) in match tr_set with | [] -> raise Not_found_transition | x::y::z -> raise Transition_not_injective | [l] -> Transition.fo l let transitions asta st = let filter (s,l,f) = State.compare s st = 0 in let rec remove_states l = match l with | [] -> [] | (a,s,l) :: tl -> (s,l) :: (remove_states tl) in remove_states (SetT.elements (SetT.filter filter asta.trans)) let empty = { quer = StateSet.empty; reco = StateSet.empty; selec = StateSet.empty; bottom = StateSet.empty; top = StateSet.empty; trans = SetT.empty; } let any_label = QNameSet.complement (QNameSet.empty) let new_state () = State.make() let add_tr ast tr = ast.trans <- (SetT.add tr (ast.trans)) let add_quer ast st = ast.quer <- (StateSet.add st (ast.quer)) let add_reco ast st = ast.reco <- (StateSet.add st (ast.reco)) let add_selec ast st = ast.selec <- (StateSet.add st (ast.selec)) let add_bot ast st = ast.bottom <- (StateSet.add st (ast.bottom)) let add_top ast st = ast.top <- (StateSet.add st (ast.top)) let init_top ast = ast.top <- (StateSet.empty) let top_states ast = StateSet.elements ast.top let print fmt asta = let pp = Format.fprintf fmt in pp "Query states: "; StateSet.print fmt asta.quer; pp "\nRecognizing states: "; StateSet.print fmt asta.reco; pp "\nSelecting states: "; StateSet.print fmt asta.selec; pp "\nBottom states: "; StateSet.print fmt asta.bottom; pp "\nTop states: "; StateSet.print fmt asta.top; pp "\nTransitions: \n"; Format.fprintf fmt "{"; Format.open_vbox 20; SetT.iter (fun x -> Format.fprintf fmt "%a @." Transition.print x) (asta.trans); Format.print_flush (); Format.fprintf fmt "}" let to_file out asta = ()