Project

General

Profile

« Previous | Next » 

Revision 7075d9fc

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

kind2 option for printing expressions

View differences:

src/printers.ml
13 13
open Format
14 14
open Utils
15 15

  
16
let kind2_language_cst =
17
  [ "initial" ]
18
  
19
let kind2_protect id =
20
  if List.mem id kind2_language_cst then
21
    "_KIND2_PROTECT_" ^ id
22
  else
23
    id
24
  
25
   
16 26
(* Prints [v] as [pp_fun] would do, but adds a backslash at each end of line,
17 27
   following the C convention for multiple lines macro *)
18 28
let pp_as_c_macro pp_fun fmt v =
......
46 56
let pp_var_type_dec fmt ty =
47 57
  pp_var_type_dec_desc fmt ty.ty_dec_desc
48 58

  
49
let pp_var_name fmt id = fprintf fmt "%s" id.var_id
59
let pp_var_name fmt id =
60
  fprintf fmt "%s" (if !Options.kind2_print then kind2_protect id.var_id else id.var_id) 
61

  
50 62
let pp_var_type fmt id =
51 63
  if !Options.print_dec_types then
52 64
    pp_var_type_dec fmt id.var_dec_type
......
59 71
let pp_var fmt id =
60 72
  fprintf fmt "%s%s: %a"
61 73
    (if id.var_dec_const then "const " else "")
62
    id.var_id
74
    (if !Options.kind2_print then kind2_protect id.var_id else id.var_id)
63 75
    pp_var_type id
64 76

  
65 77
let pp_vars fmt vars =
......
75 87
and pp_const fmt c = 
76 88
  match c with
77 89
    | Const_int i -> pp_print_int fmt i
78
    | Const_real (c, e, s) -> fprintf fmt "%s%s"
79
                                s
80
                                (if String.get s (-1 + String.length s) = '.' then "0" else "")
90
    | Const_real r -> Real.pp fmt r
81 91
    (*if e = 0 then pp_print_int fmt c else if e < 0 then Format.fprintf fmt "%ie%i" c (-e) else Format.fprintf fmt "%ie-%i" c e *)
82 92
    (* | Const_float r -> pp_print_float fmt r *)
83 93
    | Const_tag  t -> pp_print_string fmt t
......
111 121
    (fun fmt -> 
112 122
      match expr.expr_desc with
113 123
      | Expr_const c -> pp_const fmt c
114
      | Expr_ident id -> fprintf fmt "%s" id
124
      | Expr_ident id ->
125
         fprintf fmt "%s"
126
           (if !Options.kind2_print then kind2_protect id else id)
127

  
115 128
      | Expr_array a -> fprintf fmt "[%a]" pp_tuple a
116 129
      | Expr_access (a, d) -> fprintf fmt "%a[%a]" pp_expr a Dimension.pp_dimension d
117 130
      | Expr_power (a, d) -> fprintf fmt "(%a^%a)" pp_expr a Dimension.pp_dimension d
......
276 289
  begin
277 290
    fprintf fmt "%s%s: %a%a"
278 291
      (if id.var_dec_const then "const " else "")
279
      id.var_id
292
      (if !Options.kind2_print then kind2_protect id.var_id else id.var_id)
280 293
      pp_var_type id
281 294
      pp_var_clock id;
282 295
    match id.var_dec_value with

Also available in: Unified diff