3 * This file is part of HELM, an Hypertextual, Electronic
4 * Library of Mathematics, developed at the Computer Science
5 * Department, University of Bologna, Italy.
7 * HELM is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
12 * HELM is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with HELM; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
22 * For details, see the HELM World-Wide-Web page,
23 * http://helm.cs.unibo.it/
28 exception BaseUriNotSetYet
31 (CicNotationPt.term, CicNotationPt.term,
32 CicNotationPt.term GrafiteAst.reduction, string)
36 (Cic.term, Cic.lazy_term, Cic.lazy_term GrafiteAst.reduction, string)
39 let singleton msg = function
43 Printf.sprintf "GrafiteDisambiguate.singleton (%s): %u interpretations"
46 prerr_endline debug; assert false
48 let __Implicit = "__Implicit__"
49 let __Closed_Implicit = "__Closed_Implicit__"
51 let cic_mk_choice = function
52 | LexiconAst.Symbol_alias (name, _, dsc) ->
53 if name = __Implicit then
54 dsc, `Sym_interp (fun _ -> Cic.Implicit None)
55 else if name = __Closed_Implicit then
56 dsc, `Sym_interp (fun _ -> Cic.Implicit (Some `Closed))
58 DisambiguateChoices.cic_lookup_symbol_by_dsc name dsc
59 | LexiconAst.Number_alias (_, dsc) ->
60 DisambiguateChoices.lookup_num_by_dsc dsc
61 | LexiconAst.Ident_alias (name, uri) ->
63 (fun l->assert(l = []);CicUtil.term_of_uri (UriManager.uri_of_string uri))
66 let ncic_mk_choice = function
67 | LexiconAst.Symbol_alias (name, _, dsc) ->
68 if name = __Implicit then
69 dsc, `Sym_interp (fun _ -> NCic.Implicit `Term)
70 else if name = __Closed_Implicit then
71 dsc, `Sym_interp (fun _ -> NCic.Implicit `Closed)
73 DisambiguateChoices.lookup_symbol_by_dsc
74 ~mk_implicit:(function
75 | true -> NCic.Implicit `Closed
76 | false -> NCic.Implicit `Term)
78 (NCic.Appl l)::tl -> NCic.Appl (l@tl) | l -> NCic.Appl l)
79 ~term_of_uri:(fun uri ->
80 fst (OCic2NCic.convert_term uri (CicUtil.term_of_uri uri)))
81 ~term_of_nref:(fun nref -> NCic.Const nref)
83 | LexiconAst.Number_alias (_, dsc) ->
85 let desc,f = DisambiguateChoices.nlookup_num_by_dsc dsc in
87 (fun num -> match f with `Num_interp f -> f num | _ -> assert false)
89 DisambiguateChoices.Choice_not_found _ ->
90 let desc,f = DisambiguateChoices.lookup_num_by_dsc dsc in
93 fst (OCic2NCic.convert_term
94 (UriManager.uri_of_string "cic:/xxx/x.con")
95 (match f with `Num_interp f -> f num | _ -> assert false))))
96 | LexiconAst.Ident_alias (name, uri) ->
98 (fun l->assert(l = []);
100 let nref = NReference.reference_of_string uri in
103 NReference.IllFormedReference _ ->
104 let uri = UriManager.uri_of_string uri in
105 fst (OCic2NCic.convert_term uri (CicUtil.term_of_uri uri)))
112 LexiconAst.Symbol_alias (__Implicit,-1,"Fake Implicit")
114 LexiconAst.Symbol_alias (__Closed_Implicit,-1,"Fake Closed Implicit")
117 let lookup_in_library
118 interactive_user_uri_choice input_or_locate_uri item
120 let mk_ident_alias id u =
121 LexiconAst.Ident_alias (id,UriManager.string_of_uri u)
123 let mk_num_alias instance =
125 (fun dsc,_ -> LexiconAst.Number_alias (instance,dsc))
126 (DisambiguateChoices.lookup_num_choices())
128 let mk_symbol_alias symb ino (dsc, _,_) =
129 LexiconAst.Symbol_alias (symb,ino,dsc)
131 let dbd = LibraryDb.instance () in
132 let choices_of_id id =
133 let uris = Whelp.locate ~dbd id in
138 ~title:("URI matching \"" ^ id ^ "\" unknown.")
145 interactive_user_uri_choice ~selection_mode:`MULTIPLE
146 ?ok:(Some "Try selected.")
147 ?enable_button_for_non_vars:(Some true)
148 ~title:"Ambiguous input."
149 ~msg: ("Ambiguous input \"" ^ id ^
150 "\". Please, choose one or more interpretations:")
155 | DisambiguateTypes.Id id ->
156 let uris = choices_of_id id in
157 List.map (mk_ident_alias id) uris
158 | DisambiguateTypes.Symbol (symb, ino) ->
160 List.map (mk_symbol_alias symb ino)
161 (TermAcicContent.lookup_interpretations symb)
163 TermAcicContent.Interpretation_not_found -> [])
164 | DisambiguateTypes.Num instance -> mk_num_alias instance
167 let nlookup_in_library
168 interactive_user_uri_choice input_or_locate_uri item
171 | DisambiguateTypes.Id id ->
173 let references = NCicLibrary.resolve id in
175 (fun u -> LexiconAst.Ident_alias (id,NReference.string_of_reference u)
177 lookup_in_library interactive_user_uri_choice input_or_locate_uri item
179 NCicEnvironment.ObjectNotFound _ ->
180 lookup_in_library interactive_user_uri_choice input_or_locate_uri item)
181 | _ -> lookup_in_library interactive_user_uri_choice input_or_locate_uri item
184 let fix_instance item l =
186 DisambiguateTypes.Symbol (_,n) ->
189 LexiconAst.Symbol_alias (s,_,d) -> LexiconAst.Symbol_alias (s,n,d)
192 | DisambiguateTypes.Num n ->
195 LexiconAst.Number_alias (_,d) -> LexiconAst.Number_alias (n,d)
198 | DisambiguateTypes.Id _ -> l
202 (** @param term not meaningful when context is given *)
203 let disambiguate_term expty text prefix_len lexicon_status_ref context metasenv
205 let lexicon_status = !lexicon_status_ref in
206 let (diff, metasenv, subst, cic, _) =
208 (CicDisambiguate.disambiguate_term
209 ~aliases:lexicon_status#lstatus.LexiconEngine.aliases
210 ~expty ~universe:(Some lexicon_status#lstatus.LexiconEngine.multi_aliases)
212 ~mk_choice:cic_mk_choice
213 ~mk_implicit ~fix_instance
214 ~description_of_alias:LexiconAst.description_of_alias
215 ~context ~metasenv ~subst:[] (text,prefix_len,term))
217 let lexicon_status = LexiconEngine.set_proof_aliases lexicon_status diff in
218 lexicon_status_ref := lexicon_status;
219 metasenv,(*subst,*) cic
222 let disambiguate_nterm expty estatus context metasenv subst thing
224 let diff, metasenv, subst, cic =
226 (NCicDisambiguate.disambiguate_term
228 ~aliases:estatus#lstatus.LexiconEngine.aliases
230 ~universe:(Some estatus#lstatus.LexiconEngine.multi_aliases)
231 ~lookup_in_library:nlookup_in_library
232 ~mk_choice:ncic_mk_choice
233 ~mk_implicit ~fix_instance
234 ~description_of_alias:LexiconAst.description_of_alias
235 ~context ~metasenv ~subst thing)
237 let estatus = LexiconEngine.set_proof_aliases estatus diff in
238 metasenv, subst, estatus, cic
242 (** disambiguate_lazy_term (circa): term -> (unit -> status) * lazy_term
243 * rationale: lazy_term will be invoked in different context to obtain a term,
244 * each invocation will disambiguate the term and can add aliases. Once all
245 * disambiguations have been performed, the first returned function can be
246 * used to obtain the resulting aliases *)
247 let disambiguate_lazy_term expty text prefix_len lexicon_status_ref term =
248 (fun context metasenv ugraph ->
249 let lexicon_status = !lexicon_status_ref in
250 let (diff, metasenv, _, cic, ugraph) =
252 (CicDisambiguate.disambiguate_term
254 ~mk_choice:cic_mk_choice
255 ~mk_implicit ~fix_instance
256 ~description_of_alias:LexiconAst.description_of_alias
257 ~initial_ugraph:ugraph ~aliases:lexicon_status#lstatus.LexiconEngine.aliases
258 ~universe:(Some lexicon_status#lstatus.LexiconEngine.multi_aliases)
259 ~context ~metasenv ~subst:[]
260 (text,prefix_len,term) ~expty) in
261 let lexicon_status = LexiconEngine.set_proof_aliases lexicon_status diff in
262 lexicon_status_ref := lexicon_status;
263 cic, metasenv, ugraph)
266 let disambiguate_pattern
267 text prefix_len lexicon_status_ref (wanted, hyp_paths, goal_path)
269 let interp path =CicDisambiguate.interpretate_path [] path in
270 let goal_path = HExtlib.map_option interp goal_path in
271 let hyp_paths = List.map (fun (name, path) -> name, interp path) hyp_paths in
277 disambiguate_lazy_term None text prefix_len lexicon_status_ref wanted
281 (wanted, hyp_paths, goal_path)
285 CicNotationPt.term Disambiguate.disambiguator_input option *
286 (string * NCic.term) list * NCic.term option
288 let disambiguate_npattern (text, prefix_len, (wanted, hyp_paths, goal_path)) =
289 let interp path = NCicDisambiguate.disambiguate_path path in
290 let goal_path = HExtlib.map_option interp goal_path in
291 let hyp_paths = List.map (fun (name, path) -> name, interp path) hyp_paths in
293 match wanted with None -> None | Some x -> Some (text,prefix_len,x)
295 (wanted, hyp_paths, goal_path)
298 let disambiguate_reduction_kind text prefix_len lexicon_status_ref = function
299 | `Unfold (Some t) ->
301 disambiguate_lazy_term None text prefix_len lexicon_status_ref t in
306 | `Whd as kind -> kind
309 let disambiguate_auto_params
310 disambiguate_term metasenv context (oterms, params)
313 | None -> metasenv, (None, params)
315 let metasenv, terms =
317 (fun t (metasenv, terms) ->
318 let metasenv,t = disambiguate_term context metasenv t in
319 metasenv,t::terms) terms (metasenv, [])
321 metasenv, (Some terms, params)
324 let disambiguate_just disambiguate_term context metasenv =
327 let metasenv,t = disambiguate_term context metasenv t in
330 let metasenv,params = disambiguate_auto_params disambiguate_term metasenv
333 metasenv, `Auto params
336 let rec disambiguate_tactic
337 lexicon_status_ref context metasenv goal (text,prefix_len,tactic)
339 let disambiguate_term_hint =
341 List.find (fun (x,_,_) -> Some x = goal) metasenv
343 disambiguate_term (Some expty) text prefix_len lexicon_status_ref in
344 let disambiguate_term =
345 disambiguate_term None text prefix_len lexicon_status_ref in
346 let disambiguate_pattern =
347 disambiguate_pattern text prefix_len lexicon_status_ref in
348 let disambiguate_reduction_kind =
349 disambiguate_reduction_kind text prefix_len lexicon_status_ref in
350 let disambiguate_lazy_term =
351 disambiguate_lazy_term None text prefix_len lexicon_status_ref in
352 let disambiguate_tactic metasenv tac =
353 disambiguate_tactic lexicon_status_ref context metasenv goal (text,prefix_len,tac)
355 let disambiguate_auto_params m p =
356 disambiguate_auto_params disambiguate_term m context p
359 (* Higher order tactics *)
360 | GrafiteAst.Progress (loc,tac) ->
361 let metasenv,tac = disambiguate_tactic metasenv tac in
362 metasenv,GrafiteAst.Progress (loc,tac)
363 | GrafiteAst.Solve (loc,tacl) ->
366 (fun tac (metasenv,tacl) ->
367 let metasenv,tac = disambiguate_tactic metasenv tac in
371 metasenv,GrafiteAst.Solve (loc,tacl)
372 | GrafiteAst.Try (loc,tac) ->
373 let metasenv,tac = disambiguate_tactic metasenv tac in
374 metasenv,GrafiteAst.Try (loc,tac)
375 | GrafiteAst.First (loc,tacl) ->
378 (fun tac (metasenv,tacl) ->
379 let metasenv,tac = disambiguate_tactic metasenv tac in
383 metasenv,GrafiteAst.First (loc,tacl)
384 | GrafiteAst.Seq (loc,tacl) ->
387 (fun tac (metasenv,tacl) ->
388 let metasenv,tac = disambiguate_tactic metasenv tac in
392 metasenv,GrafiteAst.Seq (loc,tacl)
393 | GrafiteAst.Repeat (loc,tac) ->
394 let metasenv,tac = disambiguate_tactic metasenv tac in
395 metasenv,GrafiteAst.Repeat (loc,tac)
396 | GrafiteAst.Do (loc,n,tac) ->
397 let metasenv,tac = disambiguate_tactic metasenv tac in
398 metasenv,GrafiteAst.Do (loc,n,tac)
399 | GrafiteAst.Then (loc,tac,tacl) ->
400 let metasenv,tac = disambiguate_tactic metasenv tac in
403 (fun tac (metasenv,tacl) ->
404 let metasenv,tac = disambiguate_tactic metasenv tac in
408 metasenv,GrafiteAst.Then (loc,tac,tacl)
409 (* First order tactics *)
410 | GrafiteAst.Absurd (loc, term) ->
411 let metasenv,cic = disambiguate_term context metasenv term in
412 metasenv,GrafiteAst.Absurd (loc, cic)
413 | GrafiteAst.Apply (loc, term) ->
414 let metasenv,cic = disambiguate_term context metasenv term in
415 metasenv,GrafiteAst.Apply (loc, cic)
416 | GrafiteAst.ApplyRule (loc, term) ->
417 let metasenv,cic = disambiguate_term_hint context metasenv term in
418 metasenv,GrafiteAst.ApplyRule (loc, cic)
419 | GrafiteAst.ApplyP (loc, term) ->
420 let metasenv,cic = disambiguate_term context metasenv term in
421 metasenv,GrafiteAst.ApplyP (loc, cic)
422 | GrafiteAst.ApplyS (loc, term, params) ->
423 let metasenv, params = disambiguate_auto_params metasenv params in
424 let metasenv,cic = disambiguate_term context metasenv term in
425 metasenv,GrafiteAst.ApplyS (loc, cic, params)
426 | GrafiteAst.Assumption loc ->
427 metasenv,GrafiteAst.Assumption loc
428 | GrafiteAst.AutoBatch (loc,params) ->
429 let metasenv, params = disambiguate_auto_params metasenv params in
430 metasenv,GrafiteAst.AutoBatch (loc,params)
431 | GrafiteAst.Cases (loc, what, pattern, idents) ->
432 let metasenv,what = disambiguate_term context metasenv what in
433 let pattern = disambiguate_pattern pattern in
434 metasenv,GrafiteAst.Cases (loc, what, pattern, idents)
435 | GrafiteAst.Change (loc, pattern, with_what) ->
436 let with_what = disambiguate_lazy_term with_what in
437 let pattern = disambiguate_pattern pattern in
438 metasenv,GrafiteAst.Change (loc, pattern, with_what)
439 | GrafiteAst.Clear (loc,id) ->
440 metasenv,GrafiteAst.Clear (loc,id)
441 | GrafiteAst.ClearBody (loc,id) ->
442 metasenv,GrafiteAst.ClearBody (loc,id)
443 | GrafiteAst.Compose (loc, t1, t2, times, spec) ->
444 let metasenv,t1 = disambiguate_term context metasenv t1 in
447 | None -> metasenv, None
449 let m, t2 = disambiguate_term context metasenv t2 in
452 metasenv, GrafiteAst.Compose (loc, t1, t2, times, spec)
453 | GrafiteAst.Constructor (loc,n) ->
454 metasenv,GrafiteAst.Constructor (loc,n)
455 | GrafiteAst.Contradiction loc ->
456 metasenv,GrafiteAst.Contradiction loc
457 | GrafiteAst.Cut (loc, ident, term) ->
458 let metasenv,cic = disambiguate_term context metasenv term in
459 metasenv,GrafiteAst.Cut (loc, ident, cic)
460 | GrafiteAst.Decompose (loc, names) ->
461 metasenv,GrafiteAst.Decompose (loc, names)
462 | GrafiteAst.Demodulate (loc, params) ->
463 let metasenv, params = disambiguate_auto_params metasenv params in
464 metasenv,GrafiteAst.Demodulate (loc, params)
465 | GrafiteAst.Destruct (loc, Some terms) ->
466 let map term (metasenv, terms) =
467 let metasenv, term = disambiguate_term context metasenv term in
468 metasenv, term :: terms
470 let metasenv, terms = List.fold_right map terms (metasenv, []) in
471 metasenv, GrafiteAst.Destruct(loc, Some terms)
472 | GrafiteAst.Destruct (loc, None) ->
473 metasenv,GrafiteAst.Destruct(loc,None)
474 | GrafiteAst.Exact (loc, term) ->
475 let metasenv,cic = disambiguate_term context metasenv term in
476 metasenv,GrafiteAst.Exact (loc, cic)
477 | GrafiteAst.Elim (loc, what, Some using, pattern, specs) ->
478 let metasenv,what = disambiguate_term context metasenv what in
479 let metasenv,using = disambiguate_term context metasenv using in
480 let pattern = disambiguate_pattern pattern in
481 metasenv,GrafiteAst.Elim (loc, what, Some using, pattern, specs)
482 | GrafiteAst.Elim (loc, what, None, pattern, specs) ->
483 let metasenv,what = disambiguate_term context metasenv what in
484 let pattern = disambiguate_pattern pattern in
485 metasenv,GrafiteAst.Elim (loc, what, None, pattern, specs)
486 | GrafiteAst.ElimType (loc, what, Some using, specs) ->
487 let metasenv,what = disambiguate_term context metasenv what in
488 let metasenv,using = disambiguate_term context metasenv using in
489 metasenv,GrafiteAst.ElimType (loc, what, Some using, specs)
490 | GrafiteAst.ElimType (loc, what, None, specs) ->
491 let metasenv,what = disambiguate_term context metasenv what in
492 metasenv,GrafiteAst.ElimType (loc, what, None, specs)
493 | GrafiteAst.Exists loc ->
494 metasenv,GrafiteAst.Exists loc
495 | GrafiteAst.Fail loc ->
496 metasenv,GrafiteAst.Fail loc
497 | GrafiteAst.Fold (loc,red_kind, term, pattern) ->
498 let pattern = disambiguate_pattern pattern in
499 let term = disambiguate_lazy_term term in
500 let red_kind = disambiguate_reduction_kind red_kind in
501 metasenv,GrafiteAst.Fold (loc, red_kind, term, pattern)
502 | GrafiteAst.FwdSimpl (loc, hyp, names) ->
503 metasenv,GrafiteAst.FwdSimpl (loc, hyp, names)
504 | GrafiteAst.Fourier loc ->
505 metasenv,GrafiteAst.Fourier loc
506 | GrafiteAst.Generalize (loc,pattern,ident) ->
507 let pattern = disambiguate_pattern pattern in
508 metasenv,GrafiteAst.Generalize (loc,pattern,ident)
509 | GrafiteAst.IdTac loc ->
510 metasenv,GrafiteAst.IdTac loc
511 | GrafiteAst.Intros (loc, specs) ->
512 metasenv,GrafiteAst.Intros (loc, specs)
513 | GrafiteAst.Inversion (loc, term) ->
514 let metasenv,term = disambiguate_term context metasenv term in
515 metasenv,GrafiteAst.Inversion (loc, term)
516 | GrafiteAst.LApply (loc, linear, depth, to_what, what, ident) ->
517 let f term (metasenv, to_what) =
518 let metasenv, term = disambiguate_term context metasenv term in
519 metasenv, term :: to_what
521 let metasenv, to_what = List.fold_right f to_what (metasenv, []) in
522 let metasenv, what = disambiguate_term context metasenv what in
523 metasenv,GrafiteAst.LApply (loc, linear, depth, to_what, what, ident)
524 | GrafiteAst.Left loc ->
525 metasenv,GrafiteAst.Left loc
526 | GrafiteAst.LetIn (loc, term, name) ->
527 let metasenv,term = disambiguate_term context metasenv term in
528 metasenv,GrafiteAst.LetIn (loc,term,name)
529 | GrafiteAst.Reduce (loc, red_kind, pattern) ->
530 let pattern = disambiguate_pattern pattern in
531 let red_kind = disambiguate_reduction_kind red_kind in
532 metasenv,GrafiteAst.Reduce(loc, red_kind, pattern)
533 | GrafiteAst.Reflexivity loc ->
534 metasenv,GrafiteAst.Reflexivity loc
535 | GrafiteAst.Replace (loc, pattern, with_what) ->
536 let pattern = disambiguate_pattern pattern in
537 let with_what = disambiguate_lazy_term with_what in
538 metasenv,GrafiteAst.Replace (loc, pattern, with_what)
539 | GrafiteAst.Rewrite (loc, dir, t, pattern, names) ->
540 let metasenv,term = disambiguate_term context metasenv t in
541 let pattern = disambiguate_pattern pattern in
542 metasenv,GrafiteAst.Rewrite (loc, dir, term, pattern, names)
543 | GrafiteAst.Right loc ->
544 metasenv,GrafiteAst.Right loc
545 | GrafiteAst.Ring loc ->
546 metasenv,GrafiteAst.Ring loc
547 | GrafiteAst.Split loc ->
548 metasenv,GrafiteAst.Split loc
549 | GrafiteAst.Symmetry loc ->
550 metasenv,GrafiteAst.Symmetry loc
551 | GrafiteAst.Transitivity (loc, term) ->
552 let metasenv,cic = disambiguate_term context metasenv term in
553 metasenv,GrafiteAst.Transitivity (loc, cic)
555 | GrafiteAst.Assume (loc, id, term) ->
556 let metasenv,cic = disambiguate_term context metasenv term in
557 metasenv,GrafiteAst.Assume (loc, id, cic)
558 | GrafiteAst.Suppose (loc, term, id, term') ->
559 let metasenv,cic = disambiguate_term context metasenv term in
562 None -> metasenv,None
564 let metasenv,t = disambiguate_term context metasenv t in
566 metasenv,GrafiteAst.Suppose (loc, cic, id, cic')
567 | GrafiteAst.Bydone (loc,just) ->
569 disambiguate_just disambiguate_term context metasenv just
571 metasenv,GrafiteAst.Bydone (loc, just)
572 | GrafiteAst.We_need_to_prove (loc,term,id,term') ->
573 let metasenv,cic = disambiguate_term context metasenv term in
576 None -> metasenv,None
578 let metasenv,t = disambiguate_term context metasenv t in
580 metasenv,GrafiteAst.We_need_to_prove (loc,cic,id,cic')
581 | GrafiteAst.By_just_we_proved (loc,just,term',id,term'') ->
583 disambiguate_just disambiguate_term context metasenv just in
584 let metasenv,cic' = disambiguate_term context metasenv term' in
587 None -> metasenv,None
589 let metasenv,t = disambiguate_term context metasenv t in
591 metasenv,GrafiteAst.By_just_we_proved (loc,just,cic',id,cic'')
592 | GrafiteAst.We_proceed_by_cases_on (loc, term, term') ->
593 let metasenv,cic = disambiguate_term context metasenv term in
594 let metasenv,cic' = disambiguate_term context metasenv term' in
595 metasenv,GrafiteAst.We_proceed_by_cases_on (loc, cic, cic')
596 | GrafiteAst.We_proceed_by_induction_on (loc, term, term') ->
597 let metasenv,cic = disambiguate_term context metasenv term in
598 let metasenv,cic' = disambiguate_term context metasenv term' in
599 metasenv,GrafiteAst.We_proceed_by_induction_on (loc, cic, cic')
600 | GrafiteAst.Byinduction (loc, term, id) ->
601 let metasenv,cic = disambiguate_term context metasenv term in
602 metasenv,GrafiteAst.Byinduction(loc, cic, id)
603 | GrafiteAst.Thesisbecomes (loc, term) ->
604 let metasenv,cic = disambiguate_term context metasenv term in
605 metasenv,GrafiteAst.Thesisbecomes (loc, cic)
606 | GrafiteAst.ExistsElim (loc, just, id1, term1, id2, term2) ->
608 disambiguate_just disambiguate_term context metasenv just in
609 let metasenv,cic' = disambiguate_term context metasenv term1 in
610 let cic''= disambiguate_lazy_term term2 in
611 metasenv,GrafiteAst.ExistsElim(loc, just, id1, cic', id2, cic'')
612 | GrafiteAst.AndElim (loc, just, id, term1, id1, term2) ->
614 disambiguate_just disambiguate_term context metasenv just in
615 let metasenv,cic'= disambiguate_term context metasenv term1 in
616 let metasenv,cic''= disambiguate_term context metasenv term2 in
617 metasenv,GrafiteAst.AndElim(loc, just, id, cic', id1, cic'')
618 | GrafiteAst.Case (loc, id, params) ->
619 let metasenv,params' =
621 (fun (id,term) (metasenv,params) ->
622 let metasenv,cic = disambiguate_term context metasenv term in
623 metasenv,(id,cic)::params
624 ) params (metasenv,[])
626 metasenv,GrafiteAst.Case(loc, id, params')
627 | GrafiteAst.RewritingStep (loc, term1, term2, term3, cont) ->
630 None -> metasenv,None
632 let metasenv,t = disambiguate_term context metasenv t in
633 metasenv,Some (start,t) in
634 let metasenv,cic'= disambiguate_term context metasenv term2 in
638 let metasenv,term = disambiguate_term context metasenv term in
639 metasenv, `SolveWith term
641 let metasenv, params = disambiguate_auto_params metasenv params in
642 metasenv,`Auto params
644 let metasenv,t = disambiguate_term context metasenv t in
646 | `Proof as t -> metasenv,t in
647 metasenv,GrafiteAst.RewritingStep (loc, cic, cic', cic'', cont)
649 let disambiguate_obj estatus ?baseuri metasenv (text,prefix_len,obj) =
652 match baseuri with Some x -> x | None -> raise BaseUriNotSetYet
656 | CicNotationPt.Inductive (_,(name,_,_,_)::_)
657 | CicNotationPt.Record (_,name,_,_) -> name ^ ".ind"
658 | CicNotationPt.Theorem (_,name,_,_,_) -> name ^ ".con"
659 | CicNotationPt.Inductive _ -> assert false
661 UriManager.uri_of_string (baseuri ^ "/" ^ name)
665 (NCicLibrary.clear_cache ();
666 NCicEnvironment.invalidate ();
670 | Some (Cic.CurrentProof (_,metasenv, _, ty,_,_)) ->
672 CicTypeChecker.type_of_aux' metasenv [] ty CicUniv.empty_ugraph
675 | Some (Cic.Constant (_,_, ty,_,_)) ->
677 CicTypeChecker.type_of_aux' [] [] ty CicUniv.empty_ugraph
680 | _ -> CicUniv.empty_ugraph
684 prerr_endline "PRIMA COERCIONS";
685 let _,l = CicUniv.do_rank graph in
687 prerr_endline (CicUniv.string_of_universe k ^ " = " ^ string_of_int
688 (CicUniv.get_rank k))) l;
693 (fun graph (_,_,l) ->
695 (fun graph (uri,_,_) ->
696 let _,g = CicTypeChecker.typecheck uri in
697 CicUniv.merge_ugraphs ~base_ugraph:graph ~increment:(g,uri))
699 graph (CoercDb.to_list (CoercDb.dump ()))
701 ignore(CicUniv.do_rank graph);
705 prerr_endline "DOPO COERCIONS";
706 let _,l = CicUniv.do_rank graph in
708 prerr_endline (CicUniv.string_of_universe k ^ " = " ^ string_of_int
709 (CicUniv.get_rank k))) l;
713 prerr_endline "INIZIO NUOVA DISAMBIGUAZIONE";
714 let time = Unix.gettimeofday () in
717 NCicDisambiguate.disambiguate_obj
719 ~lookup_in_library:nlookup_in_library
720 ~description_of_alias:LexiconAst.description_of_alias
721 ~mk_choice:ncic_mk_choice
723 ~uri:(OCic2NCic.nuri_of_ouri uri)
724 ~aliases:estatus#lstatus.LexiconEngine.aliases
725 ~universe:(Some estatus#lstatus.LexiconEngine.multi_aliases)
726 (text,prefix_len,obj)
729 let time = Unix.gettimeofday () -. time in
730 (* NCicTypeChecker.typecheck_obj obj; *)
731 prerr_endline ("NUOVA DISAMBIGUAZIONE OK: "^ string_of_float time);
734 let u,i,m,_,o = obj in
738 prerr_endline (NCicPp.ppobj obj)
740 prerr_endline ("NUOVA DISAMBIGUAZIONE AMBIGUO!!!!!!!!! "))
742 | MultiPassDisambiguator.DisambiguationError (_,s) ->
743 prerr_endline ("ERRORE NUOVA DISAMBIGUAZIONE ("
744 ^UriManager.string_of_uri uri^
747 (List.map (fun _,_,x,_ -> snd (Lazy.force x)) (List.flatten s)))
748 (* | exn -> prerr_endline (Printexc.to_string exn) *)
756 (* let time = Unix.gettimeofday () in *)
759 let (diff, metasenv, _, cic, _) =
761 (CicDisambiguate.disambiguate_obj
763 ~mk_choice:cic_mk_choice
764 ~mk_implicit ~fix_instance
765 ~description_of_alias:LexiconAst.description_of_alias
766 ~aliases:estatus#lstatus.LexiconEngine.aliases
767 ~universe:(Some estatus#lstatus.LexiconEngine.multi_aliases)
769 (text,prefix_len,obj))
774 let time = Unix.gettimeofday () -. time in
775 prerr_endline ("VECCHIA DISAMBIGUAZIONE ("^
776 UriManager.string_of_uri uri ^"): " ^ string_of_float time);
778 (* try_new (Some cic); *)
781 let estatus = LexiconEngine.set_proof_aliases estatus diff in
782 estatus, metasenv, cic
785 | Sys.Break as exn -> raise exn
791 let disambiguate_nobj estatus ?baseuri (text,prefix_len,obj) =
794 match baseuri with Some x -> x | None -> raise BaseUriNotSetYet
798 | CicNotationPt.Inductive (_,(name,_,_,_)::_)
799 | CicNotationPt.Record (_,name,_,_) -> name ^ ".ind"
800 | CicNotationPt.Theorem (_,name,_,_,_) -> name ^ ".con"
801 | CicNotationPt.Inductive _ -> assert false
803 UriManager.uri_of_string (baseuri ^ "/" ^ name)
805 let diff, _, _, cic =
807 (NCicDisambiguate.disambiguate_obj
808 ~lookup_in_library:nlookup_in_library
809 ~description_of_alias:LexiconAst.description_of_alias
810 ~mk_choice:ncic_mk_choice
811 ~mk_implicit ~fix_instance
812 ~uri:(OCic2NCic.nuri_of_ouri uri)
814 ~aliases:estatus#lstatus.LexiconEngine.aliases
815 ~universe:(Some estatus#lstatus.LexiconEngine.multi_aliases)
816 (text,prefix_len,obj)) in
817 let estatus = LexiconEngine.set_proof_aliases estatus diff in
821 let disambiguate_command estatus ?baseuri metasenv (text,prefix_len,cmd)=
823 | GrafiteAst.Index(loc,key,uri) ->
824 let lexicon_status_ref = ref estatus in
825 let disambiguate_term =
826 disambiguate_term None text prefix_len lexicon_status_ref [] in
827 let disambiguate_term_option metasenv =
829 None -> metasenv,None
831 let metasenv,t = disambiguate_term metasenv t in
834 let metasenv,key = disambiguate_term_option metasenv key in
835 !lexicon_status_ref,metasenv,GrafiteAst.Index(loc,key,uri)
836 | GrafiteAst.Select (loc,uri) ->
837 estatus, metasenv, GrafiteAst.Select(loc,uri)
838 | GrafiteAst.Pump(loc,i) ->
839 estatus, metasenv, GrafiteAst.Pump(loc,i)
840 | GrafiteAst.PreferCoercion (loc,t) ->
841 let lexicon_status_ref = ref estatus in
842 let disambiguate_term =
843 disambiguate_term None text prefix_len lexicon_status_ref [] in
844 let metasenv,t = disambiguate_term metasenv t in
845 !lexicon_status_ref, metasenv, GrafiteAst.PreferCoercion (loc,t)
846 | GrafiteAst.Coercion (loc,t,b,a,s) ->
847 let lexicon_status_ref = ref estatus in
848 let disambiguate_term =
849 disambiguate_term None text prefix_len lexicon_status_ref [] in
850 let metasenv,t = disambiguate_term metasenv t in
851 !lexicon_status_ref, metasenv, GrafiteAst.Coercion (loc,t,b,a,s)
852 | GrafiteAst.Inverter (loc,n,indty,params) ->
853 let lexicon_status_ref = ref estatus in
854 let disambiguate_term =
855 disambiguate_term None text prefix_len lexicon_status_ref [] in
856 let metasenv,indty = disambiguate_term metasenv indty in
857 !lexicon_status_ref, metasenv, GrafiteAst.Inverter (loc,n,indty,params)
858 | GrafiteAst.Default _
860 | GrafiteAst.Include _
863 | GrafiteAst.Set _ as cmd ->
865 | GrafiteAst.Obj (loc,obj) ->
866 let estatus,metasenv,obj =
867 disambiguate_obj estatus ?baseuri metasenv (text,prefix_len,obj)in
868 estatus, metasenv, GrafiteAst.Obj (loc,obj)
869 | GrafiteAst.Relation (loc,id,a,aeq,refl,sym,trans) ->
870 let lexicon_status_ref = ref estatus in
871 let disambiguate_term =
872 disambiguate_term None text prefix_len lexicon_status_ref [] in
873 let disambiguate_term_option metasenv =
875 None -> metasenv,None
877 let metasenv,t = disambiguate_term metasenv t in
880 let metasenv,a = disambiguate_term metasenv a in
881 let metasenv,aeq = disambiguate_term metasenv aeq in
882 let metasenv,refl = disambiguate_term_option metasenv refl in
883 let metasenv,sym = disambiguate_term_option metasenv sym in
884 let metasenv,trans = disambiguate_term_option metasenv trans in
885 !lexicon_status_ref, metasenv,
886 GrafiteAst.Relation (loc,id,a,aeq,refl,sym,trans)
888 let disambiguate_macro
889 lexicon_status_ref metasenv context (text,prefix_len, macro)
891 let disambiguate_term = disambiguate_term None text prefix_len lexicon_status_ref in
892 let disambiguate_reduction_kind =
893 disambiguate_reduction_kind text prefix_len lexicon_status_ref in
895 | GrafiteAst.WMatch (loc,term) ->
896 let metasenv,term = disambiguate_term context metasenv term in
897 metasenv,GrafiteAst.WMatch (loc,term)
898 | GrafiteAst.WInstance (loc,term) ->
899 let metasenv,term = disambiguate_term context metasenv term in
900 metasenv,GrafiteAst.WInstance (loc,term)
901 | GrafiteAst.WElim (loc,term) ->
902 let metasenv,term = disambiguate_term context metasenv term in
903 metasenv,GrafiteAst.WElim (loc,term)
904 | GrafiteAst.WHint (loc,term) ->
905 let metasenv,term = disambiguate_term context metasenv term in
906 metasenv,GrafiteAst.WHint (loc,term)
907 | GrafiteAst.Check (loc,term) ->
908 let metasenv,term = disambiguate_term context metasenv term in
909 metasenv,GrafiteAst.Check (loc,term)
910 | GrafiteAst.Eval (loc,kind,term) ->
911 let metasenv, term = disambiguate_term context metasenv term in
912 let kind = disambiguate_reduction_kind kind in
913 metasenv,GrafiteAst.Eval (loc,kind,term)
914 | GrafiteAst.AutoInteractive (loc, params) ->
915 let metasenv, params =
916 disambiguate_auto_params disambiguate_term metasenv context params in
917 metasenv, GrafiteAst.AutoInteractive (loc, params)
919 | GrafiteAst.WLocate _
920 | GrafiteAst.Inline _ as macro ->