Project

General

Profile

Statistics
| Branch: | Tag: | Revision:

lustrec / src / tools / stateflow / common / basetypes.ml @ 93119c3f

History | View | Annotate | Download (4.22 KB)

1

    
2
let sf_level = 2
3
  
4
(* Basic datatype for model elements: state and junction name, events ... *)
5
type state_name_t    = string
6
type junction_name_t = string
7
type path_t = state_name_t list
8
type event_base_t = string
9
type event_t      = event_base_t option
10

    
11
(* Connected to lustrec types *)
12
type base_action_t = { defs : LustreSpec.eq list; ident : string }
13
type base_condition_t = LustreSpec.expr
14
  
15
(* P(r)etty printers *)
16
let pp_state_name = Format.pp_print_string
17
let pp_junction_name = Format.pp_print_string
18
let pp_path fmt p = Utils.fprintf_list ~sep:"." pp_state_name fmt p
19
let pp_event fmt e = match e with None -> Format.fprintf fmt "none" | Some s -> Format.fprintf fmt "%s" s
20
let pp_base_act fmt a = Utils.fprintf_list ~sep:",@ " Printers.pp_node_eq fmt a.defs
21
let pp_base_cond = Printers.pp_expr
22
  
23
(* Action and Condition types and functions. *)
24

    
25
(* Actions are defined by string + the opening and closing of states *)
26

    
27
(* This version is slightly more complex than the one of EMSOFT'05 to enable the
28
   use of function calls in action.
29

    
30
   TODO: these rich call type could be externalized and a functor introduced. *)
31

    
32
type frontier_t =
33
  | Loose
34
  | Strict
35

    
36
let pp_frontier fmt frontier =
37
  match frontier with
38
  | Loose  -> Format.fprintf fmt "Loose"
39
  | Strict -> Format.fprintf fmt "Strict"
40

    
41
type _ call_t =
42
  | Ecall : (path_t * path_t * frontier_t) call_t
43
  | Dcall : path_t call_t
44
  | Xcall : (path_t * frontier_t) call_t
45

    
46
let pp_call :
47
type a. Format.formatter -> a call_t -> unit = 
48
  fun fmt call ->
49
    match call with
50
    | Ecall -> Format.fprintf fmt "CallE"
51
    | Dcall -> Format.fprintf fmt "CallD"
52
    | Xcall -> Format.fprintf fmt "CallX"
53
  
54
module type ActionType =
55
sig
56
  type t
57
  val nil : t
58
  val aquote : base_action_t -> t
59
  val open_path : path_t -> t
60
  val close_path : path_t -> t
61
  val call : 'c call_t -> 'c -> t
62
    
63
  val pp_act : Format.formatter -> t -> unit
64
end
65

    
66

    
67
module Action =
68
struct
69
  type t =
70
    | Quote : base_action_t -> t
71
    | Close : path_t -> t
72
    | Open  : path_t -> t
73
    | Call  : 'c call_t * 'c -> t
74
    | Nil   : t
75

    
76
    
77
  let nil = Nil
78
  let aquote act = Quote act
79
  let open_path p = Open p
80
  let close_path p = Close p
81
  let call c a = Call (c, a)
82

    
83
  let pp_call : type c. Format.formatter -> c call_t -> c -> unit =
84
    fun fmt call ->
85
    match call with
86
    | Ecall -> (fun (p, p', f) -> Format.fprintf fmt "%a(%a, %a, %a)" pp_call call pp_path p pp_path p' pp_frontier f)
87
    | Dcall -> (fun p          -> Format.fprintf fmt "%a(%a)" pp_call call pp_path p)
88
    | Xcall -> (fun (p, f)     -> Format.fprintf fmt "%a(%a, %a)" pp_call call pp_path p pp_frontier f)
89

    
90
  let pp_act fmt act =
91
    match act with
92
    | Call (c, a)      -> pp_call fmt c a
93
    | Quote a          -> Format.fprintf fmt "%a" pp_base_act a
94
    | Close p          -> Format.fprintf fmt "Close(%a)" pp_path p
95
    | Open p           -> Format.fprintf fmt "Open(%a)" pp_path p
96
    | Nil              -> Format.fprintf fmt "Nil"
97
end
98

    
99
let _ = (module Action : ActionType) 
100

    
101

    
102
(* Conditions are either (1) simple strings, (2) the active status of a state or
103
   (3) occurence of an event. They can be combined (conjunction, negation) *)
104
module type ConditionType =
105
sig
106
  type t
107
  val cquote : base_condition_t -> t
108
  val tru : t
109
  val active : path_t -> t
110
  val event : event_t -> t
111
  val ( && ) : t -> t -> t
112
  val neg : t -> t
113

    
114
  val pp_cond : Format.formatter -> t -> unit
115
end
116

    
117
  module Condition =
118
struct
119
  type t =
120
    | Quote of base_condition_t
121
    | Active of path_t
122
    | Event of event_base_t
123
    | And of t * t
124
    | Neg of t
125
    | True
126

    
127
  let cquote cond = Quote cond
128
  let tru = True
129
  let neg cond = Neg cond
130
  let ( && ) cond1 cond2 = And (cond1, cond2)
131
  let active path = Active path
132
  let event evt =
133
    match evt with
134
    | None   -> True
135
    | Some e -> Event e
136

    
137
  let rec pp_cond fmt cond =
138
    match cond with
139
    | True               -> Format.fprintf fmt "true"
140
    | Active p           -> Format.fprintf fmt "Active(%a)" pp_path p
141
    | Event e            -> Format.fprintf fmt "Event(%s)" e
142
    | Neg cond           -> Format.fprintf fmt "(neg %a)" pp_cond cond
143
    | And (cond1, cond2) -> Format.fprintf fmt "%a /\\ %a" pp_cond cond1 pp_cond cond2
144
    | Quote c            -> Format.fprintf fmt "%a" pp_base_cond c
145

    
146
end
147

    
148
let _ = (module Condition : ConditionType)