Project

General

Profile

« Previous | Next » 

Revision ca7ff3f7

Added by LĂ©lio Brun 7 months ago

reformatting

View differences:

src/tools/stateflow/common/datatype.ml
3 3

  
4 4
(* Type definitions of a model *)
5 5

  
6
type destination_t =
7
  | DPath of path_t
8
  | DJunction of junction_name_t
6
type destination_t = DPath of path_t | DJunction of junction_name_t
9 7

  
10 8
type trans_t = {
11
  event: event_t;
12
  condition: Condition.t;
13
  condition_act: Action.t;
14
  transition_act: Action.t;
15
  dest: destination_t;
9
  event : event_t;
10
  condition : Condition.t;
11
  condition_act : Action.t;
12
  transition_act : Action.t;
13
  dest : destination_t;
16 14
}
17 15

  
18 16
type transitions_t = trans_t list
......
22 20
  | And of state_name_t list
23 21

  
24 22
type state_actions_t = {
25
  entry_act: Action.t;
26
  during_act: Action.t;
27
  exit_act: Action.t;
23
  entry_act : Action.t;
24
  during_act : Action.t;
25
  exit_act : Action.t;
28 26
}
29 27

  
30 28
type state_def_t = {
......
39 37
  | Junction of junction_name_t * transitions_t
40 38
  | SFFunction of 'prog_t
41 39

  
42
type prog_t = Program of state_name_t * prog_t src_components_t list * (Lustre_types.var_decl * Lustre_types.expr) list
40
type prog_t =
41
  | Program of
42
      state_name_t
43
      * prog_t src_components_t list
44
      * (Lustre_types.var_decl * Lustre_types.expr) list
43 45

  
44 46
type scope_t = Constant | Input | Local | Output | Parameter
45 47

  
......
51 53

  
52 54
module type MODEL_T = sig
53 55
  val name : string
56

  
54 57
  val model : prog_t
55
  val traces: trace_t list
58

  
59
  val traces : trace_t list
56 60
end
57 61

  
58 62
(* Module (S)tate(F)low provides basic constructors for action, condition,
59 63
   events, as well as printer functions *)
60
module SF =
61
struct
62

  
64
module SF = struct
63 65
  (* Basic constructors *)
64 66

  
65
  let no_action    = Action.nil
67
  let no_action = Action.nil
68

  
66 69
  let no_condition = Condition.tru
67
  let no_event     = None
68
  let event s      = Some s
69
  let action s     = Action.aquote s
70
  let condition s  = Condition.cquote s
71
  let no_state_action    = {entry_act = no_action; during_act = no_action; exit_act = no_action; }
72
  let state_action a b c = {entry_act = a; during_act = b; exit_act = c; }
70

  
71
  let no_event = None
72

  
73
  let event s = Some s
74

  
75
  let action s = Action.aquote s
76

  
77
  let condition s = Condition.cquote s
78

  
79
  let no_state_action =
80
    { entry_act = no_action; during_act = no_action; exit_act = no_action }
81

  
82
  let state_action a b c = { entry_act = a; during_act = b; exit_act = c }
73 83

  
74 84
  let states (Program (_, defs, _)) =
75 85
    List.fold_left
76 86
      (fun res c ->
77
	match c with
78
	| State (p, _) -> ActiveStates.Vars.add p res
79
	| Junction _  -> res
80
        | SFFunction _ -> res
81
      )
87
        match c with
88
        | State (p, _) ->
89
          ActiveStates.Vars.add p res
90
        | Junction _ ->
91
          res
92
        | SFFunction _ ->
93
          res)
82 94
      ActiveStates.Vars.empty defs
83 95

  
84 96
  let init_env model = ActiveStates.Env.from_set (states model) false
......
89 101

  
90 102
  let pp_event fmt e =
91 103
    match e with
92
    | Some e -> Format.fprintf fmt "%s" e
93
    | None -> Format.fprintf fmt "noevent"
94

  
95
  let pp_dest fmt d = match d with
96
    | DPath p -> Format.fprintf fmt "Path %a" pp_path p
97
    | DJunction j -> Format.fprintf fmt "Junction %a" pp_junction_name j
104
    | Some e ->
105
      Format.fprintf fmt "%s" e
106
    | None ->
107
      Format.fprintf fmt "noevent"
108

  
109
  let pp_dest fmt d =
110
    match d with
111
    | DPath p ->
112
      Format.fprintf fmt "Path %a" pp_path p
113
    | DJunction j ->
114
      Format.fprintf fmt "Junction %a" pp_junction_name j
98 115

  
99 116
  let pp_trans fmt t =
100
    Format.fprintf fmt
101
      "@[<hov 0>(@[<hov 0>%a,@ %a,@ %a,@ %a,@ %a@]@ )@]"
102
      pp_event t.event
103
      Condition.pp_cond t.condition
104
      Action.pp_act t.condition_act
105
      Action.pp_act t.transition_act
106
      pp_dest t.dest
117
    Format.fprintf fmt "@[<hov 0>(@[<hov 0>%a,@ %a,@ %a,@ %a,@ %a@]@ )@]"
118
      pp_event t.event Condition.pp_cond t.condition Action.pp_act
119
      t.condition_act Action.pp_act t.transition_act pp_dest t.dest
107 120

  
108 121
  let pp_transitions fmt l =
109
    Format.fprintf fmt
110
      "@[<hov 0>[@[<hov 0>%a@]@ ]@]"
111
      (Utils.fprintf_list ~sep:";@ " pp_trans) l
122
    Format.fprintf fmt "@[<hov 0>[@[<hov 0>%a@]@ ]@]"
123
      (Utils.fprintf_list ~sep:";@ " pp_trans)
124
      l
112 125

  
113
  let pp_comp fmt c = match c with
126
  let pp_comp fmt c =
127
    match c with
114 128
    | Or (_T, _S) ->
115
       Format.fprintf fmt "Or(%a, {%a})"
116
	 pp_transitions _T
117
	 (Utils.fprintf_list ~sep:"; " pp_state_name) _S
118
    | And (_S) ->
119
       Format.fprintf fmt "And({%a})"
120
	 (Utils.fprintf_list ~sep:"; " pp_state_name) _S
129
      Format.fprintf fmt "Or(%a, {%a})" pp_transitions _T
130
        (Utils.fprintf_list ~sep:"; " pp_state_name)
131
        _S
132
    | And _S ->
133
      Format.fprintf fmt "And({%a})"
134
        (Utils.fprintf_list ~sep:"; " pp_state_name)
135
        _S
121 136

  
122 137
  let pp_state_actions fmt sa =
123
    Format.fprintf fmt "@[<hov 0>(%a,@ %a,@ %a)@]"
124
      Action.pp_act sa.entry_act
125
      Action.pp_act sa.during_act
126
      Action.pp_act sa.exit_act
138
    Format.fprintf fmt "@[<hov 0>(%a,@ %a,@ %a)@]" Action.pp_act sa.entry_act
139
      Action.pp_act sa.during_act Action.pp_act sa.exit_act
127 140

  
128 141
  let pp_state fmt s =
129 142
    Format.fprintf fmt "@[<v 0>(@[<v 0>%a,@ %a,@ %a,@ %a@]@ @])"
130
      pp_state_actions s.state_actions
131
      pp_transitions s.outer_trans
132
      pp_transitions s.inner_trans
133
      pp_comp s.internal_composition
143
      pp_state_actions s.state_actions pp_transitions s.outer_trans
144
      pp_transitions s.inner_trans pp_comp s.internal_composition
134 145

  
135 146
  let pp_src pp_sffunction fmt src =
136 147
    Format.fprintf fmt "@[<v>%a@ @]"
137
      (Utils.fprintf_list ~sep:"@ @ "
138
         (fun fmt src -> match src with
139
	    | State (p, def)   -> Format.fprintf fmt "%a: %a"
140
                                  pp_path p pp_state def
141
            | Junction (s, tl) -> Format.fprintf fmt "%a: %a"
142
	                            pp_state_name s
143
	                            pp_transitions tl
144
            | SFFunction p     -> pp_sffunction fmt p
145
         ))
148
      (Utils.fprintf_list ~sep:"@ @ " (fun fmt src ->
149
           match src with
150
           | State (p, def) ->
151
             Format.fprintf fmt "%a: %a" pp_path p pp_state def
152
           | Junction (s, tl) ->
153
             Format.fprintf fmt "%a: %a" pp_state_name s pp_transitions tl
154
           | SFFunction p ->
155
             pp_sffunction fmt p))
146 156
      src
147 157

  
148 158
  let rec pp_sffunction fmt (Program (name, component_list, _)) =
149
    Format.fprintf fmt "SFFunction name: %s@ %a@ "
150
      name
151
      (pp_src pp_sffunction) component_list
159
    Format.fprintf fmt "SFFunction name: %s@ %a@ " name (pp_src pp_sffunction)
160
      component_list
152 161

  
153 162
  let pp_vars fmt src =
154 163
    Format.fprintf fmt "@[<v>%a@ @]"
155 164
      (Utils.fprintf_list ~sep:"@ " Printers.pp_var)
156
    src
165
      src
157 166

  
158 167
  let pp_prog fmt (Program (name, component_list, vars)) =
159
    Format.fprintf fmt "Main node name: %s@ %a@ %a@"
160
      name
161
      (pp_src pp_sffunction) component_list
162
      pp_vars (List.map fst vars)
168
    Format.fprintf fmt "Main node name: %s@ %a@ %a@" name (pp_src pp_sffunction)
169
      component_list pp_vars (List.map fst vars)
163 170

  
164 171
  let pp_scope fmt src =
165
    Format.fprintf fmt (match src with
166
        | Constant  -> "Constant"
167
        | Input     -> "Input"
168
        | Local     -> "Local"
169
        | Output    -> "Output"
170
        | Parameter -> "Parameter")
172
    Format.fprintf fmt
173
      (match src with
174
      | Constant ->
175
        "Constant"
176
      | Input ->
177
        "Input"
178
      | Local ->
179
        "Local"
180
      | Output ->
181
        "Output"
182
      | Parameter ->
183
        "Parameter")
171 184
end

Also available in: Unified diff