Project

General

Profile

« Previous | Next » 

Revision 42f91c0b

Added by Pierre-Loïc Garoche about 5 years ago

Better EMF output, solved some invalid JSON produced

View differences:

src/backends/EMF/EMF_common.ml
102 102
  match dec_t with
103 103
  | Tydec_any -> (* Dynamical built variable. No declared type. Shall
104 104
                    use the infered one. *)
105
     pp_infered_type fmt infered_t
105
     fprintf fmt "{ \"kind\": \"%a\" }" pp_infered_type infered_t
106 106
  | Tydec_int -> fprintf fmt "{ \"kind\": \"int\" }" (* !Options.int_type *)
107 107
  | Tydec_real -> fprintf fmt "{ \"kind\": \"real\" }" (* !Options.real_type *)
108 108
  (* TODO we could add more concrete types here if they were available in
......
215 215
  
216 216
(* Print the variable declaration *)
217 217
let pp_emf_var_decl fmt v =
218
  fprintf fmt "@[{\"name\": \"%a\", \"datatype\":\"%a\", \"original_name\": \"%a\"}@]"
218
  fprintf fmt "@[{\"name\": \"%a\", \"datatype\": %a, \"original_name\": \"%a\"}@]"
219 219
    pp_var_name v
220 220
    pp_var_type v
221 221
    Printers.pp_var_name v
......
251 251
    
252 252
let pp_emf_cst c inf fmt =
253 253
  let pp_typ fmt =
254
    fprintf fmt "\"datatype\": \"";
255
    pp_cst_type c inf fmt;
256
    fprintf fmt "\"@ "
254
    fprintf fmt "\"datatype\": { \"kind\": \"%t\" } @ "
255
      (pp_cst_type c inf)   
257 256
  in
258 257
  match c with
259 258
  | Const_tag t->
......
293 292
    fprintf fmt "{@[\"type\": \"variable\",@ \"value\": \"%a\",@ "
294 293
      pp_var_name v;
295 294
    (*    fprintf fmt "\"original_name\": \"%a\",@ " Printers.pp_var_name v; *)
296
    fprintf fmt "\"datatype\": \"%a\"@ " pp_var_type v;
295
    fprintf fmt "\"datatype\": %a@ " pp_var_type v;
297 296
    fprintf fmt "@]}"
298 297
  )
299 298
  | _ -> eprintf "Not of cst or var: %a@." (pp_val m) v ; assert false (* Invalid argument *)
......
310 309
  | Expr_ident id ->
311 310
     fprintf fmt "{@[\"type\": \"variable\",@ \"value\": \"%a\",@ "
312 311
       print_protect (fun fmt -> pp_print_string fmt id);
313
    fprintf fmt "\"datatype\": \"%t\"@ "
312
    fprintf fmt "\"datatype\": %t@ "
314 313
      (pp_concrete_type
315 314
	 Tydec_any (* don't know much about that time since it was not
316 315
		      declared. That may not work with clock constants *)
......
338 337
      (fun fmt ->
339 338
	fprintf fmt "Warning: unhandled expression %a in annotation.@ "
340 339
	  Printers.pp_expr e;
341
	fprintf fmt "Will not be produced in the experted JSON EMF"
340
 	fprintf fmt "Will not be produced in the experted JSON EMF@."
342 341
      );    
343 342
    fprintf fmt "\"unhandled construct, complain to Ploc\""
344 343
  )
......
357 356
let pp_emf_exprs = pp_emf_list pp_emf_expr
358 357
       
359 358
let pp_emf_const fmt v =
360
  fprintf fmt "@[{\"name\": \"%a\", \"datatype\":\"%a\", \"original_name\": \"%a\", \"value\": \"%a\"}@]"
359
  fprintf fmt "@[<hov 0>{\"name\": \"%a\",@ \"datatype\":%a,@ \"original_name\": \"%a\",@ \"value\": %a}@]"
361 360
    pp_var_name v
362 361
    pp_var_type v
363 362
    Printers.pp_var_name v
......
386 385
  | Eq eq -> (
387 386
    fprintf fmt "@[ @[<v 2>\"%a\": {@ " (Utils.fprintf_list ~sep:"_" pp_print_string) eq.eq_lhs;
388 387
    fprintf fmt "\"lhs\": [%a],@ " (Utils.fprintf_list ~sep:", " (fun fmt vid -> fprintf fmt "\"%s\"" vid)) eq.eq_lhs;
389
    fprintf fmt "\"rhs\": \"%a\",@ " pp_emf_expr eq.eq_rhs;
388
    fprintf fmt "\"rhs\": %a,@ " pp_emf_expr eq.eq_rhs;
390 389
    fprintf fmt "@]@]@ }"
391 390
  )
392 391

  
......
419 418
  
420 419
let pp_emf_top_const fmt const_top = 
421 420
  let const = Corelang.const_of_top const_top in
422
  fprintf fmt "\"%s\": " const.const_id;
423
  pp_emf_cst const.const_value const.const_type fmt
421
  fprintf fmt "{ \"%s\": %t }"
422
    const.const_id
423
    (pp_emf_cst const.const_value const.const_type)
424 424

  
425 425
(* Local Variables: *)
426 426
(* compile-command: "make -C ../.." *)

Also available in: Unified diff