Project

General

Profile

Revision 66359a5e src/backends/EMF/EMF_common.ml

View differences:

src/backends/EMF/EMF_common.ml
86 86
      
87 87
   
88 88
     
89
let pp_cst_type c infered_typ fmt =
89
let pp_cst_type fmt c (*infered_typ*) =
90 90
  match c with
91 91
  | Const_tag t ->
92 92
     let typ = (Corelang.typedef_of_top (Hashtbl.find Corelang.tag_table t)) in
......
94 94
       fprintf fmt "bool"
95 95
     else
96 96
       pp_tag_type fmt typ
97
  | Const_int _ -> fprintf fmt "%s" !Options.int_type
98
  | Const_real _ -> fprintf fmt "%s" !Options.real_type
99
  | _ -> Format.eprintf "cst: %a@." Printers.pp_const c; assert false
97
  | Const_int _ -> fprintf fmt "int" (*!Options.int_type*)
98
  | Const_real _ -> fprintf fmt "real" (*!Options.real_type*)
99
  | Const_string _ -> fprintf fmt "string" 
100
  | _ -> eprintf "cst: %a@." Printers.pp_const c; assert false
100 101

  
101 102
let rec pp_infered_type fmt t =
102 103
  let open Types in
104
  if is_bool_type t  then fprintf fmt "bool" else
105
  if is_int_type t then fprintf fmt "int" else (* !Options.int_type *)
106
  if is_real_type t then fprintf fmt "real" else (* !Options.real_type *)
103 107
  match t.tdesc with
104
  | Tint ->
105
     fprintf fmt "%s" !Options.int_type
106
  | Treal ->
107
     fprintf fmt "%s" !Options.real_type
108
  | Tbool ->
109
     fprintf fmt "bool"
110 108
  | Tclock t ->
111 109
     pp_infered_type fmt t
112 110
  | Tstatic (_, t) ->
......
119 117
     pp_tag_type fmt typ
120 118
   | Tlink ty -> 
121 119
       pp_infered_type fmt ty 
122
  | _ -> Format.eprintf "unhandled type: %a@." Types.print_node_ty t; assert false
120
   | _ -> eprintf "unhandled type: %a@." Types.print_node_ty t; assert false
121
     
123 122
let rec pp_concrete_type dec_t infered_t fmt =
124 123
  match dec_t with
125
  | Tydec_int -> fprintf fmt "%s" !Options.int_type
126
  | Tydec_real -> fprintf fmt "%s" !Options.real_type
124
  | Tydec_int -> fprintf fmt "int" (* !Options.int_type *)
125
  | Tydec_real -> fprintf fmt "real" (* !Options.real_type *)
127 126
  (* TODO we could add more concrete types here if they were available in
128 127
     dec_t *)
129 128
  | Tydec_bool -> fprintf fmt "bool"
......
134 133
    pp_tag_type fmt typ
135 134
  )
136 135
  | Tydec_any -> pp_infered_type fmt infered_t 
137
  | _ -> Format.eprintf
136
  | _ -> eprintf
138 137
     "unhandled construct in type printing for EMF backend: %a@."
139 138
     Printers.pp_var_type_dec_desc dec_t; raise (Failure "var")
140 139
       
141 140

  
142
let pp_cst_type fmt v =
141
(*let pp_cst_type fmt v =
143 142
  match v.value_desc with
144 143
  | Cst c-> pp_cst_type c v.value_type fmt (* constants do not have declared type (yet) *)
145 144
  | _ -> assert false
146
     
145
*)
146
       
147 147
let pp_var_type fmt v =
148 148
  try
149
  pp_concrete_type v.var_dec_type.ty_dec_desc v.var_type fmt
150
  with Failure _ -> Format.eprintf "failed var: %a@." Printers.pp_var v; assert false
149
    if Machine_types.is_specified v then
150
      Machine_types.pp_var_type fmt v
151
    else
152
      pp_concrete_type v.var_dec_type.ty_dec_desc v.var_type fmt
153
  with Failure _ -> eprintf "failed var: %a@." Printers.pp_var v; assert false
154
    
151 155
(******** Other print functions *)
152 156
    
153 157
let pp_emf_var_decl fmt v =
......
171 175
  else
172 176
    let const_list = match typ.tydef_desc with Tydec_enum tl -> tl | _ -> assert false in
173 177
    fprintf fmt "%i" (get_idx t const_list)
174
     
175
let pp_emf_cst_or_var fmt v =
176
  match v.value_desc with
177
  | Cst ((Const_tag t) as c)->
178

  
179
let pp_emf_cst fmt c =
180
  match c with
181
  | Const_tag t->
178 182
     let typ = (Corelang.typedef_of_top (Hashtbl.find Corelang.tag_table t)) in
179 183
     if typ.tydef_id = "bool" then (
180 184
       fprintf fmt "{@[\"type\": \"constant\",@ ";
181 185
       fprintf fmt"\"value\": \"%a\",@ "
182 186
	 Printers.pp_const c;
183
       fprintf fmt "\"datatype\": \"%a\"@ " pp_cst_type v;
187
       fprintf fmt "\"datatype\": \"%a\"@ " pp_cst_type c;
184 188
       fprintf fmt "@]}"
185 189
     )
186 190
     else (
......
188 192
	 pp_tag_id t;
189 193
       fprintf fmt "\"origin_type\": \"%s\",@ \"origin_value\": \"%s\",@ "
190 194
	 typ.tydef_id t;
191
       fprintf fmt "\"datatype\": \"%a\"@ " pp_cst_type v;
195
       fprintf fmt "\"datatype\": \"%a\"@ " pp_cst_type c;
192 196
       fprintf fmt "@]}"
193 197
     )
194
  | Cst c -> (
198
  | Const_string s ->
199
    fprintf fmt "{@[\"type\": \"constant\",@ \"value\": \"%s\",@ " s;
200
    fprintf fmt "\"datatype\": \"%a\"@ " pp_cst_type c;
201
    fprintf fmt "@]}"
202
     
203
  | _ -> (
195 204
    fprintf fmt "{@[\"type\": \"constant\",@ \"value\": \"%a\",@ "
196 205
      Printers.pp_const c;
197
    fprintf fmt "\"datatype\": \"%a\"@ " pp_cst_type v;
206
    fprintf fmt "\"datatype\": \"%a\"@ " pp_cst_type c;
198 207
    fprintf fmt "@]}"
199 208
  )
209
  
210
  
211
let pp_emf_cst_or_var fmt v =
212
  match v.value_desc with
213
  | Cst c -> pp_emf_cst fmt c
200 214
  | LocalVar v
201 215
  | StateVar v -> (
202 216
    fprintf fmt "{@[\"type\": \"variable\",@ \"value\": \"%a\",@ "
......
205 219
    fprintf fmt "\"datatype\": \"%a\"@ " pp_var_type v;
206 220
    fprintf fmt "@]}"
207 221
  )
208
  | _ -> Format.eprintf "Not of cst or var: %a@." Machine_code.pp_val v ; assert false (* Invalid argument *)
222
  | _ -> eprintf "Not of cst or var: %a@." Machine_code.pp_val v ; assert false (* Invalid argument *)
209 223

  
210 224

  
211 225
let pp_emf_cst_or_var_list =
212 226
  Utils.fprintf_list ~sep:",@ " pp_emf_cst_or_var
213 227

  
228
(* Printer lustre expr and eexpr *)
229
    
230
let rec pp_emf_expr fmt e =
231
  match e.expr_desc with
232
  | Expr_const c -> pp_emf_cst fmt c
233
  | Expr_ident id ->
234
     fprintf fmt "{@[\"type\": \"variable\",@ \"value\": \"%a\",@ "
235
       print_protect (fun fmt -> pp_print_string fmt id);
236
    fprintf fmt "\"datatype\": \"%t\"@ "
237
      (pp_concrete_type
238
	 Tydec_any (* don't know much about that time since it was not
239
		      declared. That may not work with clock constants *)
240
	 e.expr_type
241
      );
242
    fprintf fmt "@]}"
243

  
244
  | Expr_tuple el ->
245
     fprintf fmt "[@[<hov 0>%a@ @]]"
246
       (Utils.fprintf_list ~sep:",@ " pp_emf_expr) el
247
  | _ -> (
248
    Log.report ~level:2
249
      (fun fmt ->
250
	fprintf fmt "Warning: unhandled expression %a in annotation.@ "
251
	  Printers.pp_expr e;
252
	fprintf fmt "Will not be produced in the experted JSON EMF"
253
      );    
254
    fprintf fmt "\"unhandled construct, complain to Ploc\""
255
  )
256
(* Remaining constructs *)  
257
(* | Expr_ite   of expr * expr * expr *)
258
(* | Expr_arrow of expr * expr *)
259
(* | Expr_fby of expr * expr *)
260
(* | Expr_array of expr list *)
261
(* | Expr_access of expr * Dimension.dim_expr *)
262
(* | Expr_power of expr * Dimension.dim_expr *)
263
(* | Expr_pre of expr *)
264
(* | Expr_when of expr * ident * label *)
265
(* | Expr_merge of ident * (label * expr) list *)
266
(* | Expr_appl of call_t *)
267
     
214 268

  
269
let pp_emf_eexpr fmt ee =
270
  fprintf fmt "{@[<hov 0>\"quantifiers\": \"%a\",@ \"qfexpr\": @[%a@]@] }"
271
    (Utils.fprintf_list ~sep:"; " Printers.pp_quantifiers) ee.eexpr_quantifiers
272
    pp_emf_expr ee.eexpr_qfexpr
273
    
274
    
215 275
(* Local Variables: *)
216 276
(* compile-command: "make -C ../.." *)
217 277
(* End: *)

Also available in: Unified diff