ocaml_printer.ml 16.3 KB
Newer Older
Mário Pereira's avatar
Mário Pereira committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
(********************************************************************)
(*                                                                  *)
(*  The Why3 Verification Platform   /   The Why3 Development Team  *)
(*  Copyright 2010-2016   --   INRIA - CNRS - Paris-Sud University  *)
(*                                                                  *)
(*  This software is distributed under the terms of the GNU Lesser  *)
(*  General Public License version 2.1, with the special exception  *)
(*  on linking described in file LICENSE.                           *)
(*                                                                  *)
(********************************************************************)

(** Printer for extracted OCaml code *)

open Compile
open Format
open Ident
open Pp
18
19
open Ity
open Term
20
21
open Expr
open Ty
22
23
24
open Theory
open Pmodule
open Stdlib
Mário Pereira's avatar
Mário Pereira committed
25
open Pdecl
Mario Pereira's avatar
Mario Pereira committed
26
open Printer
Mário Pereira's avatar
Mário Pereira committed
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42

module Print = struct

  open ML

  let ocaml_keywords =
    ["and"; "as"; "assert"; "asr"; "begin";
     "class"; "constraint"; "do"; "done"; "downto"; "else"; "end";
     "exception"; "external"; "false"; "for"; "fun"; "function";
     "functor"; "if"; "in"; "include"; "inherit"; "initializer";
     "land"; "lazy"; "let"; "lor"; "lsl"; "lsr"; "lxor"; "match";
     "method"; "mod"; "module"; "mutable"; "new"; "object"; "of";
     "open"; "or"; "private"; "rec"; "sig"; "struct"; "then"; "to";
     "true"; "try"; "type"; "val"; "virtual"; "when"; "while"; "with";
     "raise";]

43
44
45
46
47
  let is_ocaml_keyword =
    let h = Hstr.create 16 in
    List.iter (fun s -> Hstr.add h s ()) ocaml_keywords;
    Hstr.mem h

Mário Pereira's avatar
Mário Pereira committed
48
  let iprinter, aprinter =
Mário Pereira's avatar
Mário Pereira committed
49
    let isanitize = sanitizer char_to_alpha char_to_alnumus in
Mário Pereira's avatar
Mário Pereira committed
50
51
52
    let lsanitize = sanitizer char_to_lalpha char_to_alnumus in
    create_ident_printer ocaml_keywords ~sanitizer:isanitize,
    create_ident_printer ocaml_keywords ~sanitizer:lsanitize
Mário Pereira's avatar
Mário Pereira committed
53

Mário Pereira's avatar
Mário Pereira committed
54
  let forget_tvs () =
Mário Pereira's avatar
Mário Pereira committed
55
    forget_all iprinter
Mário Pereira's avatar
Mário Pereira committed
56
57

  let forget_id vs = forget_id iprinter vs
Mário Pereira's avatar
Mário Pereira committed
58
  let _forget_ids = List.iter forget_id
Mário Pereira's avatar
Mário Pereira committed
59
60
61
  let forget_var (id, _, _) = forget_id id
  let forget_vars = List.iter forget_var

Mário Pereira's avatar
Mário Pereira committed
62
63
64
65
66
  let forget_let_defn = function
  | Lvar (v,_) -> forget_pv v
  | Lsym (s,_,_) -> forget_rs s
  | Lrec rdl -> List.iter (fun fd -> forget_rs fd.rec_sym) rdl

Mário Pereira's avatar
Mário Pereira committed
67
68
69
70
71
72
73
  let rec forget_pat = function
    | Pwild -> ()
    | Pident id -> forget_id id
    | Papp (_, pl) | Ptuple pl -> List.iter forget_pat pl
    | Por (p1, p2) -> forget_pat p1; forget_pat p2
    | Pas (p, _) -> forget_pat p

Mário Pereira's avatar
Mário Pereira committed
74
75
76
77
  let print_ident fmt id =
    let s = id_unique iprinter id in
    fprintf fmt "%s" s

78
79
  let print_qident ~sanitizer info fmt id =
    try
80
      let _, _, q =
81
82
83
84
85
86
87
88
89
90
91
        try Pmodule.restore_path id
        with Not_found -> Theory.restore_path id in
      let s = String.concat "__" q in
      let s = Ident.sanitizer char_to_alpha char_to_alnumus s in
      let s = sanitizer s in
      let s = if is_ocaml_keyword s then s ^ "_renamed" else s in
      if Sid.mem id info.info_current_th.th_local ||
         Opt.fold (fun _ m -> Sid.mem id m.Pmodule.mod_local)
           false info.info_current_mo
      then fprintf fmt "%s" s
      else
92
        (* let fname = if lp = [] then info.info_fname else None in *)
93
94
95
96
97
98
99
100
        let m = Strings.capitalize "m" in
        fprintf fmt "%s.%s" m s
    with Not_found ->
      let s = id_unique ~sanitizer iprinter id in
      fprintf fmt "%s" s

  let print_lident = print_qident ~sanitizer:Strings.uncapitalize
  let print_uident = print_qident ~sanitizer:Strings.capitalize
Mário Pereira's avatar
Mário Pereira committed
101
102

  let print_tv fmt tv =
103
    fprintf fmt "'%s" (id_unique aprinter tv.tv_name)
Mário Pereira's avatar
Mário Pereira committed
104

105
106
107
  let protect_on b s =
    if b then "(" ^^ s ^^ ")" else s

Mário Pereira's avatar
Mário Pereira committed
108
109
  let star fmt () = fprintf fmt " *@ "

110
111
  (** Types *)

Mario Pereira's avatar
Mario Pereira committed
112
  let rec print_ty ?(paren=false) info fmt = function
113
    | Tvar tv ->
114
      print_tv fmt tv
Mário Pereira's avatar
Mário Pereira committed
115
    | Ttuple [] ->
116
      fprintf fmt "unit"
Mário Pereira's avatar
Mário Pereira committed
117
    | Ttuple tl ->
118
      fprintf fmt (protect_on paren "@[%a@]")
Mario Pereira's avatar
Mario Pereira committed
119
        (print_list star (print_ty ~paren:false info)) tl
Mário Pereira's avatar
Mário Pereira committed
120
121
122
    | Tapp (ts, [t1; t2]) when id_equal ts ts_func.ts_name ->
      fprintf fmt (protect_on paren "@[%a ->@ %a@]")
        (print_ty ~paren:true info) t1 (print_ty info) t2
Mário Pereira's avatar
Mário Pereira committed
123
    | Tapp (ts, tl) ->
Mario Pereira's avatar
Mario Pereira committed
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
      begin match query_syntax info.info_syn ts with
        | Some s -> syntax_arguments s (print_ty info) fmt tl
        | None   ->
          begin match tl with
            | [] ->
              print_ident fmt ts
            | [ty] ->
              fprintf fmt (protect_on paren "%a@ %a")
                (print_ty ~paren:true info) ty print_ident ts
            | tl ->
              fprintf fmt (protect_on paren "(%a)@ %a")
                (print_list comma (print_ty ~paren:false info)) tl
                print_ident ts
          end
      end

  let print_vsty info fmt (v, ty, _) =
    fprintf fmt "%a:@ %a" print_ident v (print_ty ~paren:false info) ty
142
143
144
145
146
147

  let print_tv_arg = print_tv
  let print_tv_args fmt = function
    | []   -> ()
    | [tv] -> fprintf fmt "%a@ " print_tv_arg tv
    | tvl  -> fprintf fmt "(%a)@ " (print_list comma print_tv_arg) tvl
Mário Pereira's avatar
Mário Pereira committed
148

Mario Pereira's avatar
Mario Pereira committed
149
150
  let print_vs_arg info fmt vs =
    fprintf fmt "@[(%a)@]" (print_vsty info) vs
Mário Pereira's avatar
Mário Pereira committed
151

Mário Pereira's avatar
Mário Pereira committed
152
153
154
155
156
157
158
159
160
161
162
163
164
  let print_path =
    print_list dot pp_print_string (* point-free *)

  let print_path_id fmt = function
    | [], id -> print_ident fmt id
    | p, id  -> fprintf fmt "%a.%a" print_path p print_ident id

  let print_theory_name fmt th =
    print_path_id fmt (th.th_path, th.th_name)

  let print_module_name fmt m =
    print_theory_name fmt m.mod_theory

Mário Pereira's avatar
Mário Pereira committed
165
166
167
168
169
170
171
172
173
  let get_record info rs =
    match Mid.find_opt rs.rs_name info.info_mo_known_map with
    | Some {pd_node = PDtype itdl} ->
      let itd = List.find (fun {itd_constructors=constr} ->
          List.exists (rs_equal rs) constr) itdl in
      List.filter (fun e -> not (rs_ghost e)) itd.itd_fields
    | _ -> []

  let rec print_pat info fmt = function
174
175
176
177
178
    | Pwild ->
       fprintf fmt "_"
    | Pident id ->
       print_ident fmt id
    | Pas (p, id) ->
Mário Pereira's avatar
Mário Pereira committed
179
       fprintf fmt "%a as %a" (print_pat info) p print_ident id
180
    | Por (p1, p2) ->
Mário Pereira's avatar
Mário Pereira committed
181
       fprintf fmt "%a | %a" (print_pat info) p1 (print_pat info) p2
182
    | Ptuple pl ->
Mário Pereira's avatar
Mário Pereira committed
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
      fprintf fmt "(%a)" (print_list comma (print_pat info)) pl
    | Papp (ls, pl) ->
      match query_syntax info.info_syn ls.ls_name, pl with
      | Some s, _ ->
        syntax_arguments s (print_pat info) fmt pl
      | None, pl ->
        let rs = restore_rs ls in
        let pjl = get_record info rs in
        match pjl, pl with
        | [], []  ->
          fprintf fmt "%a" (print_uident info) ls.ls_name
        | [], [p] ->
          fprintf fmt "%a %a"
            (print_uident info) ls.ls_name (print_pat info) p
        | [], _   ->
          fprintf fmt "%a (%a)"
            (print_uident info) ls.ls_name
            (print_list comma (print_pat info)) pl
        | _, _    ->
          let rec print_list2 sep sep_m print1 print2 fmt (l1, l2) =
          match l1, l2 with
          | x1 :: r1, x2 :: r2 ->
            print1 fmt x1; sep_m fmt (); print2 fmt x2; sep fmt ();
            print_list2 sep sep_m print1 print2 fmt (r1, r2)
          | _ -> ()
        in
        let print_rs info fmt rs =
          fprintf fmt "%a" (print_lident info) rs.rs_name in
        fprintf fmt "@[<hov 2>{ %a}@]"
          (print_list2 semi equal (print_rs info) (print_pat info)) (pjl, pl)
213

214
215
  (** Expressions *)

216
217
  let pv_name pv = pv.pv_vs.vs_name

Mario Pereira's avatar
Mario Pereira committed
218
219
  let ht_rs = Hrs.create 7 (* rec_rsym -> rec_sym *)

Mário Pereira's avatar
Mário Pereira committed
220
  let rec print_apply info fmt rs pvl =
221
    let isfield =
222
223
      match rs.rs_field with
      | None -> false
224
225
226
227
228
229
230
      | Some _ -> true in
    let isconstructor () =
      match Mid.find_opt rs.rs_name info.info_mo_known_map with
      | Some {pd_node = PDtype its} ->
        let is_constructor its =
          List.exists (rs_equal rs) its.itd_constructors in
        List.exists is_constructor its
Mário Pereira's avatar
Mário Pereira committed
231
      | _ -> false in
Mário Pereira's avatar
Mário Pereira committed
232
233
    match query_syntax info.info_convert rs.rs_name,
          query_syntax info.info_syn rs.rs_name, pvl with
Mário Pereira's avatar
Mário Pereira committed
234
235
236
237
238
239
240
    | Some s, _, _ ->
      let print_constant fmt e = match e.e_node with
        | Econst c ->
          let c = BigInt.to_int (Number.compute_int c) in
          fprintf fmt "%d" c
        | _ -> print_expr info fmt e in
      syntax_arguments s print_constant fmt pvl
Mário Pereira's avatar
Mário Pereira committed
241
242
    | _, Some s, _ ->
      syntax_arguments s (print_expr info) fmt pvl
Mário Pereira's avatar
Mário Pereira committed
243
244
245
    | _, _, tl when is_rs_tuple rs ->
      fprintf fmt "@[(%a)@]"
        (print_list comma (print_expr info)) tl
Mário Pereira's avatar
Mário Pereira committed
246
247
248
    | _, _, [] ->
      print_ident fmt rs.rs_name
    | _,  _, [t1] when isfield ->
249
      fprintf fmt "%a.%a" (print_expr info) t1 print_ident rs.rs_name
Mário Pereira's avatar
Mário Pereira committed
250
    | _, _, tl when isconstructor () ->
Mário Pereira's avatar
Mário Pereira committed
251
252
253
254
255
256
257
258
259
260
      let pjl = get_record info rs in
      if pjl = [] then
        fprintf fmt "@[<hov 2>%a (%a)@]"
          print_ident rs.rs_name (print_list comma (print_expr info)) tl
      else
        let rec print_list2 sep sep_m print1 print2 fmt (l1, l2) =
          match l1, l2 with
          | x1 :: r1, x2 :: r2 ->
            print1 fmt x1; sep_m fmt (); print2 fmt x2; sep fmt ();
            print_list2 sep sep_m print1 print2 fmt (r1, r2)
Mário Pereira's avatar
Mário Pereira committed
261
          | _ -> () in
Mário Pereira's avatar
Mário Pereira committed
262
        let print_rs info fmt rs =
Mário Pereira's avatar
Mário Pereira committed
263
          fprintf fmt "%a" (print_lident info) rs.rs_name in
Mário Pereira's avatar
Mário Pereira committed
264
        fprintf fmt "@[<hov 2>{ %a}@]"
Mário Pereira's avatar
Mário Pereira committed
265
          (print_list2 semi equal (print_rs info) (print_expr info)) (pjl, tl)
Mário Pereira's avatar
Mário Pereira committed
266
    | _, _, tl ->
Mário Pereira's avatar
Mário Pereira committed
267
268
      fprintf fmt "@[<hov 2>%a %a@]"
        print_ident rs.rs_name (print_list space (print_expr info)) tl
269

Mário Pereira's avatar
Mário Pereira committed
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
  and print_let_def info fmt = function
    | Lvar (pv, e) ->
      fprintf fmt "@[<hov 2>let %a =@ %a@]"
        (print_lident info) (pv_name pv) (print_expr info) e;
    | Lsym (rs, args, ef) ->
      fprintf fmt "@[<hov 2>let %a %a@ =@ @[%a@]@]"
        (print_lident info) rs.rs_name
        (print_list space (print_vs_arg info)) args
        (print_expr info) ef;
      forget_vars args
    | Lrec (rdef) ->
      let print_one fst fmt = function
        | { rec_sym = rs1; rec_args = args; rec_exp = e } ->
          fprintf fmt "@[<hov 2>%s %a@ %a@ =@ %a@]"
            (if fst then "let rec" else "and")
            (print_lident info) rs1.rs_name
            (print_list space (print_vs_arg info)) args
            (print_expr info) e;
          forget_vars args;
          forget_tvs ()
      in
      List.iter (fun fd -> Hrs.replace ht_rs fd.rec_rsym fd.rec_sym) rdef;
      print_list_next newline print_one fmt rdef;
      List.iter (fun fd -> Hrs.remove ht_rs fd.rec_rsym) rdef

295
  and print_enode info fmt = function
296
    | Econst c ->
Mário Pereira's avatar
Mário Pereira committed
297
298
      let n = Number.compute_int c in
      fprintf fmt "(Z.of_string \"%s\")" (BigInt.to_string n)
299
    | Evar pvs ->
Mário Pereira's avatar
Mário Pereira committed
300
      (print_lident info) fmt (pv_name pvs)
Mário Pereira's avatar
Mário Pereira committed
301
302
303
304
305
    | Elet (let_def, e) ->
      fprintf fmt "@[%a@] in@ %a"
        (print_let_def info) let_def
        (print_expr info) e;
      forget_let_defn let_def
306
    | Eabsurd ->
Mário Pereira's avatar
Mário Pereira committed
307
      fprintf fmt "assert false (* absurd *)"
308
    | Eapp (s, []) when rs_equal s rs_true ->
Mário Pereira's avatar
Mário Pereira committed
309
      fprintf fmt "true"
310
    | Eapp (s, []) when rs_equal s rs_false ->
Mário Pereira's avatar
Mário Pereira committed
311
312
313
314
      fprintf fmt "false"
    | Eapp (s, [e1; e2]) when rs_equal s rs_func_app ->
      fprintf fmt "@[<hov 1>%a %a@]"
        (print_expr info) e1 (print_expr info) e2
315
    | Eapp (s, pvl) ->
Mario Pereira's avatar
Mario Pereira committed
316
      print_apply info fmt (Hrs.find_def ht_rs s s) pvl
317
    | Ematch (e, pl) ->
Mário Pereira's avatar
Mário Pereira committed
318
      fprintf fmt "begin match @[%a@] with@\n@[<hov>%a@] end"
319
        (print_expr info) e (print_list newline (print_branch info)) pl
Mário Pereira's avatar
Mário Pereira committed
320
321
322
323
324
325
326
327
    | Eassign [(rho, rs, pv)] ->
      fprintf fmt "%a.%a <-@ %a"
        print_ident (pv_name rho) print_ident rs.rs_name
        print_ident (pv_name pv)
    | Eif (e1, e2, {e_node = Eblock []}) ->
      fprintf fmt
        "@[<hv>@[<hov 2>if@ %a@]@ then begin@;<1 2>@[%a@] end@]"
        (print_expr info) e1 (print_expr info) e2
328
329
330
331
    | Eif (e1, e2, e3) ->
      fprintf fmt
        "@[<hv>@[<hov 2>if@ %a@]@ then@;<1 2>@[%a@]@;<1 0>else@;<1 2>@[%a@]@]"
        (print_expr info) e1 (print_expr info) e2 (print_expr info) e3
332
    | Eblock [] ->
333
334
335
336
      fprintf fmt "()"
    | Eblock [e] ->
      print_expr info fmt e
    | Eblock el ->
337
338
339
340
      fprintf fmt "@[<hv>begin@;<1 2>@[%a@]@ end@]"
        (print_list semi (print_expr info)) el
    | Efun (varl, e) ->
      fprintf fmt "@[<hov 2>(fun %a ->@ %a)@]"
Mario Pereira's avatar
Mario Pereira committed
341
        (print_list space (print_vs_arg info)) varl (print_expr info) e
Mário Pereira's avatar
Mário Pereira committed
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
    | Ewhile (e1, e2) ->
      fprintf fmt "@[<hov 2>while %a do@ %a@ done@]"
        (print_expr info) e1 (print_expr info) e2
    | Eraise (Xident id, None) -> (* FIXME : check exceptions in driver *)
      fprintf fmt "raise %a" (print_uident info) id
    | Eraise (Xident id, Some e) ->
      fprintf fmt "(raise %a %a)"
        (print_uident info) id (print_expr info) e
    | Etuple _ -> (* TODO *) assert false
    | Efor (pv1, pv2, direction, pv3, e) ->
      let print_for_direction fmt = function
        | To -> fprintf fmt "to"
        | DownTo -> fprintf fmt "downto"
      in
      fprintf fmt "@[<hov 2>for %a = %a %a %a do@ @[%a@]@ done@]"
        (print_lident info) (pv_name pv1)
        (print_lident info) (pv_name pv2)
        print_for_direction direction
        (print_lident info) (pv_name pv3)
        (print_expr info) e
    | Etry _ -> (* TODO *) assert false
    | Enot _ -> (* TODO *) assert false
    | Ebinop _ -> (* TODO *) assert false
    | Ecast _ -> (* TODO *) assert false
    | Eassign _ -> (* TODO *) assert false
Mário Pereira's avatar
Mário Pereira committed
367

368
  and print_branch info fmt (p, e) =
Mário Pereira's avatar
Mário Pereira committed
369
370
    fprintf fmt "@[<hov 4>| %a ->@ @[%a@]@]"
      (print_pat info) p (print_expr info) e
371

372
373
  and print_expr info fmt e =
    print_enode info fmt e.e_node
Mário Pereira's avatar
Mário Pereira committed
374

Mario Pereira's avatar
Mario Pereira committed
375
  let print_type_decl info fmt its =
376
377
    let print_constr fmt (id, cs_args) =
      match cs_args with
378
379
380
381
382
383
384
      | [] ->
         fprintf fmt "@[<hov 4>| %a@]"
                 print_ident id (* FIXME: first letter must be uppercase
                                       -> print_uident *)
      | l ->
         fprintf fmt "@[<hov 4>| %a of %a@]"
                 print_ident id (* FIXME: print_uident *)
Mario Pereira's avatar
Mario Pereira committed
385
                 (print_list star (print_ty ~paren:false info)) l in
386
387
388
389
    let print_field fmt (is_mutable, id, ty) =
      fprintf fmt "%s%a: %a;"
              (if is_mutable then "mutable " else "")
              print_ident id
Mario Pereira's avatar
Mario Pereira committed
390
              (print_ty ~paren:false info) ty in
391
    let print_def fmt = function
392
393
394
395
396
397
398
399
400
      | None ->
        ()
      | Some (Ddata csl) ->
        fprintf fmt " =@\n%a" (print_list newline print_constr) csl
      | Some (Drecord fl) ->
        fprintf fmt " = %s{@\n%a@\n}"
          (if its.its_private then "private " else "")
          (print_list newline print_field) fl
      | Some (Dalias ty) ->
Mario Pereira's avatar
Mario Pereira committed
401
        fprintf fmt " =@ %a" (print_ty ~paren:false info) ty
402
    in
403
    fprintf fmt "@[<hov 2>%s %a%a%a@]"
404
405
406
      (if true then "type" else "and") (* FIXME: mutual recursive types *)
      print_tv_args its.its_args
      print_ident its.its_name  (* FIXME: first letter must be lowercase
407
                                   -> print_lident *)
408
      print_def its.its_def
409

410
  let print_decl info fmt = function
Mário Pereira's avatar
Mário Pereira committed
411
412
413
    | Dlet (ldef) ->
      print_let_def info fmt ldef;
      forget_tvs ();
Mario Pereira's avatar
Mario Pereira committed
414
      fprintf fmt "@\n@\n"
415
    | Dtype dl ->
Mario Pereira's avatar
Mario Pereira committed
416
       print_list newline (print_type_decl info) fmt dl;
417
       fprintf fmt "@\n@\n"
418
419
420
    | Dexn (xs, None) ->
       fprintf fmt "exception %a@\n@\n" print_ident xs.xs_name
    | Dexn (xs, Some t) ->
421
       fprintf fmt "@[<hov 2>exception %a of %a@]@\n@\n"
Mario Pereira's avatar
Mario Pereira committed
422
               print_ident xs.xs_name (print_ty ~paren:true info) t
Mário Pereira's avatar
Mário Pereira committed
423
424
end

425
426
427
428
429
430
431
432
433
434
435
436
437
let extract_module pargs ?old fmt ({mod_theory = th} as m) =
  ignore (pargs);
  ignore (old);
  ignore (m);
  let info = {
    info_syn          = pargs.Pdriver.syntax;
    info_convert      = pargs.Pdriver.converter;
    info_current_th   = th;
    info_current_mo   = Some m;
    info_th_known_map = th.th_known;
    info_mo_known_map = m.mod_known;
    info_fname        = None; (* TODO *)
  } in
Mário Pereira's avatar
Mário Pereira committed
438
  (* fprintf fmt "(\*@\n%a@\n*\)@\n" print_module m; *)
Mário Pereira's avatar
Mário Pereira committed
439
440
441
  fprintf fmt
    "(* This file has been generated from Why3 module %a *)@\n@\n"
    Print.print_module_name m;
442
  let mdecls = Translate.module_ info m in
443
  print_list nothing (Print.print_decl info) fmt mdecls;
Mário Pereira's avatar
Mário Pereira committed
444
  fprintf fmt "@."
445

446

447
448
449
450
let fg ?fname m =
  let mod_name = m.Pmodule.mod_theory.Theory.th_name.id_string in
  match fname with
  | None   -> mod_name ^ ".ml"
451
452
453
454
455
456
457
  | Some f ->
    (* TODO: replace with Filename.remove_extension
     * after migration to OCaml 4.04+ *)
    let remove_extension s =
      try Filename.chop_extension s
      with Invalid_argument _ -> s
    in
Mário Pereira's avatar
Mário Pereira committed
458
    let f = Filename.basename f in
459
    (remove_extension f) ^ "__" ^ mod_name ^ ".ml"
460

461
462
let () = Pdriver.register_printer "ocaml"
  ~desc:"printer for OCaml code" fg extract_module
463

464
465
(*
 * Local Variables:
466
 * compile-command: "make -C ../.. -j3 bin/why3extract.opt"
467
468
 * End:
 *)