@@ -6,113 +6,13 @@ open Common open Pos open Error
66open Parsing open Syntax
77open Export.Coq
88
9- let unused_mappings = ref ! erase
10-
11- let check_that_unused_mappings_is_not_empty() = if StrSet. is_empty ! unused_mappings && not (StrSet. is_empty ! erase)
12- then print_string " Sadly, unused_mappings is empty."
13- else print_string " unused_mappings is, indeed, non-empty"
14-
15-
16- (* * Set encoding. *)
17-
18- let map_qid_builtin = ref QidMap. empty
19-
20- let set_encoding : string -> unit = fun f ->
21- let found = Array. make nb_builtins false in
22- let consume = function
23- | {elt =P_builtin (n ,lp_qid );pos} ->
24- begin match index_of_name n with
25- | Some i ->
26- if Logger. log_enabled() then
27- log " builtin \" %s\" = %a" n Pretty. qident lp_qid;
28- builtin.(i) < - lp_qid.elt;
29- found.(i) < - true ;
30- let b = builtin_of_index i in
31- map_qid_builtin := QidMap. add lp_qid.elt b ! map_qid_builtin;
32- if b = El || b = Prf then
33- (if Logger. log_enabled() then log " erase %s" (snd lp_qid.elt);
34- erase := StrSet. add (snd lp_qid.elt) ! erase)
35- | None -> fatal pos " Unknown builtin."
36- end
37- | {pos;_} -> fatal pos " Invalid command."
38- in
39- Stream. iter consume (Parser. parse_file f);
40- Array. iteri
41- (fun i b ->
42- if not b then
43- let pos =
44- Some {fname= Some f;start_line= 0 ;start_col= 0 ;end_line= 0 ;end_col= 0 }
45- in fatal pos " Builtin %s undefined." (name_of_index i))
46- found
47-
48- (* * Basic printing functions. We use Printf for efficiency reasons. *)
49- let out = Printf. printf
50-
51- let char = output_char
52- let string = output_string
53-
54- let prefix pre elt oc x = string oc pre; elt oc x
55- let suffix elt suf oc x = elt oc x; string oc suf
56-
57- let list elt sep oc xs =
58- match xs with
59- | [] -> ()
60- | x ::xs -> elt oc x; List. iter (prefix sep elt oc) xs
61-
62- (* * Translation of identifiers. *)
63-
64- let translate_ident : string -> string = fun s ->
65- try StrMap. find s ! rmap with Not_found -> s
66-
67- let raw_ident oc s = string oc (translate_ident s)
68-
69- let ident oc {elt;_} = raw_ident oc elt
9+ (* Initialised to Export.Coq.erase in main.ml *)
10+ let unused_mappings = ref StrSet. empty
7011
7112let untouched_ident oc ({elt;_} : p_ident ) = string oc elt
7213
73- let param_id oc idopt =
74- match idopt with
75- | Some id -> ident oc id
76- | None -> char oc '_'
77-
78- let param_ids = list param_id " "
79-
80- let raw_path = list string " ."
81-
82- let path oc {elt;_} = raw_path oc elt
83-
84- let qident oc {elt =(mp ,s );_} =
85- match mp with
86- | [] -> raw_ident oc s
87- | _ ::_ -> raw_path oc mp; char oc '.' ; raw_ident oc s
88-
89- (* * Translation of terms. *)
90-
91- let stt = Stdlib. ref true
92- let use_implicits = Stdlib. ref false
93- let use_notations = Stdlib. ref true
94-
95- (* redefinition of p_get_args ignoring P_Wrap's. *)
96- let p_get_args : p_term -> p_term * p_term list = fun t ->
97- let rec p_get_args t acc =
98- match t.elt with
99- | P_Appl (t , u ) -> p_get_args t (u::acc)
100- | P_Wrap t -> p_get_args t acc
101- | _ -> t, acc
102- in p_get_args t []
103-
104- let app t default cases =
105- let h, ts = p_get_args t in
106- if ! stt then
107- match h.elt with
108- | P_Iden ({elt;_} ,expl ) ->
109- begin match QidMap. find_opt elt ! map_qid_builtin with
110- | None -> default h ts
111- | Some builtin -> cases h ts expl builtin
112- end
113- | _ -> default h ts
114- else default h ts
115-
14+ (* Export.Coq.term but for each identifier encountered, update unused_mappings.
15+ The other difference is that we assume use_notations = true, use_implicits = false*)
11616let rec term ?(implicits =true ) oc t =
11717 (* if Logger.log_enabled() then
11818 log "pp %a" (* Pos.short t.pos*) Pretty.term t;*)
@@ -149,21 +49,17 @@ let rec term ?(implicits=true) oc t =
14949 | P_Appl _ ->
15050 let default h ts = paren oc h ~implicits ; char oc ' ' ; list (paren ~implicits ) " " oc ts in
15151 app t default
152- (fun h ts expl builtin ->
153- match ! use_notations, ! use_implicits && not expl, builtin, ts with
154- | _ , _ , (El |Prf ), [u] -> term oc u ~implicits
155- | _ , _ , (Arr |Imp ), [u;v] -> arrow oc u v ~implicits
156- | _, _, All , [_;{elt= P_Wrap ({elt= P_Abst ([_] as xs,u);_});_}]
157- | _, true , All , [{elt= P_Wrap ({elt= P_Abst ([_] as xs,u);_});_}]
158- -> prod oc xs u ~implicits
159- | _, _, Ex , [_;{elt= P_Wrap ({elt= P_Abst ([x],u);_});_}]
160- | _ , true , Ex , [{elt= P_Wrap ({elt= P_Abst ([x],u);_});_}] ->
52+ (fun h ts _ builtin ->
53+ match builtin, ts with
54+ | (El |Prf ), [u] -> term oc u ~implicits
55+ | (Arr |Imp ), [u;v] -> arrow oc u v ~implicits
56+ | All , [_;{elt= P_Wrap ({elt= P_Abst ([_] as xs,u);_});_}] -> prod oc xs u ~implicits
57+ | Ex , [_;{elt= P_Wrap ({elt= P_Abst ([x],u);_});_}] ->
16158 string oc " exists " ; raw_params oc x ~implicits ; string oc " , " ; term oc u ~implicits
162- | true , _, Eq , [_;u;v]
163- | true , true , Eq , [u;v] -> paren oc u ~implicits ; string oc " = " ; paren oc v ~implicits
164- | true , _ , Or , [u;v] -> paren oc u ~implicits ; string oc " \\ / " ; paren oc v ~implicits
165- | true , _ , And , [u;v] -> paren oc u ~implicits ; string oc " /\\ " ; paren oc v ~implicits
166- | true , _ , Not , [u] -> string oc " ~ " ; paren oc u ~implicits
59+ | Eq , [_;u;v] -> paren oc u ~implicits ; string oc " = " ; paren oc v ~implicits
60+ | Or , [u;v] -> paren oc u ~implicits ; string oc " \\ / " ; paren oc v ~implicits
61+ | And , [u;v] -> paren oc u ~implicits ; string oc " /\\ " ; paren oc v ~implicits
62+ | Not , [u] -> string oc " ~ " ; paren oc u ~implicits
16763 | _ -> default h ts)
16864
16965and arrow ?(implicits =true ) oc u v = paren oc u ~implicits ; string oc " -> " ; term oc v ~implicits
@@ -209,11 +105,13 @@ and typopt ?(implicits=true) oc t = Option.iter (prefix " : " (term ~implicits)
209105
210106let is_lem x = is_opaq x || is_priv x
211107
108+ (* Store the last unmapped object *)
212109type unmapped_def_kind =
213110| UMLem of string
214111| UMDef of string
215-
216112let last_unmapped = ref (UMLem " " )
113+
114+ (* List of unmapped axioms with their type *)
217115let axlist : (string*p_term) list ref = ref []
218116
219117(* Identify types, possibly parametrized *)
@@ -242,12 +140,16 @@ let command oc {elt; pos} =
242140 else p_sym_arg
243141 in
244142 begin match QidMap. find_opt ([] ,p_sym_nam.elt) ! map_erased_qid_coq with
245- (* Instead of erasing mapped terms, check their type *)
143+ (* Instead of erasing mapped terms, check their type *)
246144 | Some s ->
247145 unused_mappings := StrSet. remove p_sym_nam.elt ! unused_mappings;
248146 if List. mem p_sym_nam.elt ignore_mappings
249147 then ()
250148 else
149+ (* remove implicit arguments, as they cannot be parsed by tactics.
150+ types have no implicit arguments in the first place and should not start
151+ with an @ (example: (list term) is a valid mapping for a type and won't work
152+ with an @ in front) *)
251153 let s = match p_sym_typ with
252154 | Some t when not (is_Set t) && not (String. starts_with ~prefix: " @" s) -> " @" ^ s
253155 | _ -> s
@@ -265,7 +167,10 @@ let command oc {elt; pos} =
265167 | None ->
266168 begin match p_sym_def, p_sym_trm, p_sym_arg, p_sym_typ with
267169 | true , Some _ , _ , Some _ when List. exists is_lem p_sym_mod ->
268- (* Do not translate lemmas to avoid nested proofs but still print them. *)
170+ (* Do not translate lemmas to avoid nested proofs. *)
171+ (* Also, use the last unmapped object to catch definitions mapped without the
172+ definitional lemma or the converse *)
173+ (* Notice that, for lemmas, the condition s ^ "_def" <> ... is always true. *)
269174 begin match ! last_unmapped with
270175 | UMLem s | UMDef s when s ^ " _def" <> p_sym_nam.elt ->
271176 string oc " idtac \" Error: " ; untouched_ident oc p_sym_nam ;
@@ -336,16 +241,18 @@ Ltac conclusion := match goal with
336241
337242Goal True.\n "
338243
244+ (* the $(BASE) library name *)
339245let base = ref " "
340246
247+ (* the $(REQUIRING) files to import *)
341248let requiring = ref " "
342249
343250let lpfile name = ! base ^ " _" ^ name ^ " .lp"
344251
252+ (* read all lp files in a list *)
345253let chainread oc = List. iter (fun name -> ast oc (Parser. parse_file (lpfile name)))
346254
347- let outputfile = ! base ^ " _checkmappings.v"
348-
255+ (* Error printing for an unmapped axiom *)
349256let unmappedaxiom oc (name ,typ ) = string oc (name ^ " of type " ) ; term oc typ
350257
351258let generate_check_file_in oc =
0 commit comments