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 HLog.debug 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)))
82 | LexiconAst.Number_alias (_, dsc) ->
83 let desc,f = DisambiguateChoices.lookup_num_by_dsc dsc in
86 fst (OCic2NCic.convert_term
87 (UriManager.uri_of_string "cic:/xxx/x.con")
88 (match f with `Num_interp f -> f num | _ -> assert false)))
89 | LexiconAst.Ident_alias (name, uri) ->
91 (fun l->assert(l = []);
92 let uri = UriManager.uri_of_string uri in
93 fst (OCic2NCic.convert_term uri (CicUtil.term_of_uri uri)))
100 LexiconAst.Symbol_alias (__Implicit,-1,"Fake Implicit")
102 LexiconAst.Symbol_alias (__Closed_Implicit,-1,"Fake Closed Implicit")
105 let lookup_in_library
106 interactive_user_uri_choice input_or_locate_uri item
108 let mk_ident_alias id u =
109 LexiconAst.Ident_alias (id,UriManager.string_of_uri u)
111 let mk_num_alias instance =
113 (fun dsc,_ -> LexiconAst.Number_alias (instance,dsc))
114 (DisambiguateChoices.lookup_num_choices())
116 let mk_symbol_alias symb ino (dsc, _,_) =
117 LexiconAst.Symbol_alias (symb,ino,dsc)
119 let dbd = LibraryDb.instance () in
120 let choices_of_id id =
121 let uris = Whelp.locate ~dbd id in
126 ~title:("URI matching \"" ^ id ^ "\" unknown.")
133 interactive_user_uri_choice ~selection_mode:`MULTIPLE
134 ?ok:(Some "Try selected.")
135 ?enable_button_for_non_vars:(Some true)
136 ~title:"Ambiguous input."
137 ~msg: ("Ambiguous input \"" ^ id ^
138 "\". Please, choose one or more interpretations:")
143 | DisambiguateTypes.Id id ->
144 let uris = choices_of_id id in
145 List.map (mk_ident_alias id) uris
146 | DisambiguateTypes.Symbol (symb, ino) ->
148 List.map (mk_symbol_alias symb ino)
149 (TermAcicContent.lookup_interpretations symb)
151 TermAcicContent.Interpretation_not_found -> [])
152 | DisambiguateTypes.Num instance -> mk_num_alias instance
155 (** @param term not meaningful when context is given *)
156 let disambiguate_term expty text prefix_len lexicon_status_ref context metasenv
158 let lexicon_status = !lexicon_status_ref in
159 let (diff, metasenv, subst, cic, _) =
161 (CicDisambiguate.disambiguate_term
162 ~aliases:lexicon_status.LexiconEngine.aliases
163 ~expty ~universe:(Some lexicon_status.LexiconEngine.multi_aliases)
165 ~mk_choice:cic_mk_choice
167 ~description_of_alias:LexiconAst.description_of_alias
168 ~context ~metasenv ~subst:[] (text,prefix_len,term))
170 let lexicon_status = LexiconEngine.set_proof_aliases lexicon_status diff in
171 lexicon_status_ref := lexicon_status;
172 metasenv,(*subst,*) cic
175 let disambiguate_nterm expty lexicon_status context metasenv subst thing
177 let diff, metasenv, subst, cic =
179 (NCicDisambiguate.disambiguate_term
180 ~coercion_db:(NCicCoercion.db ())
181 ~aliases:lexicon_status.LexiconEngine.aliases
183 ~universe:(Some lexicon_status.LexiconEngine.multi_aliases)
185 ~mk_choice:ncic_mk_choice
187 ~description_of_alias:LexiconAst.description_of_alias
188 ~context ~metasenv ~subst thing)
190 let lexicon_status = LexiconEngine.set_proof_aliases lexicon_status diff in
191 metasenv, subst, lexicon_status, cic
195 (** disambiguate_lazy_term (circa): term -> (unit -> status) * lazy_term
196 * rationale: lazy_term will be invoked in different context to obtain a term,
197 * each invocation will disambiguate the term and can add aliases. Once all
198 * disambiguations have been performed, the first returned function can be
199 * used to obtain the resulting aliases *)
200 let disambiguate_lazy_term expty text prefix_len lexicon_status_ref term =
201 (fun context metasenv ugraph ->
202 let lexicon_status = !lexicon_status_ref in
203 let (diff, metasenv, _, cic, ugraph) =
205 (CicDisambiguate.disambiguate_term
207 ~mk_choice:cic_mk_choice
209 ~description_of_alias:LexiconAst.description_of_alias
210 ~initial_ugraph:ugraph ~aliases:lexicon_status.LexiconEngine.aliases
211 ~universe:(Some lexicon_status.LexiconEngine.multi_aliases)
212 ~context ~metasenv ~subst:[]
213 (text,prefix_len,term) ~expty) in
214 let lexicon_status = LexiconEngine.set_proof_aliases lexicon_status diff in
215 lexicon_status_ref := lexicon_status;
216 cic, metasenv, ugraph)
219 let disambiguate_pattern
220 text prefix_len lexicon_status_ref (wanted, hyp_paths, goal_path)
222 let interp path =CicDisambiguate.interpretate_path [] path in
223 let goal_path = HExtlib.map_option interp goal_path in
224 let hyp_paths = List.map (fun (name, path) -> name, interp path) hyp_paths in
230 disambiguate_lazy_term None text prefix_len lexicon_status_ref wanted
234 (wanted, hyp_paths, goal_path)
237 let disambiguate_reduction_kind text prefix_len lexicon_status_ref = function
238 | `Unfold (Some t) ->
240 disambiguate_lazy_term None text prefix_len lexicon_status_ref t in
245 | `Whd as kind -> kind
248 let disambiguate_auto_params
249 disambiguate_term metasenv context (terms, params)
251 let metasenv, terms =
253 (fun t (metasenv, terms) ->
254 let metasenv,t = disambiguate_term context metasenv t in
255 metasenv,t::terms) terms (metasenv, [])
257 metasenv, (terms, params)
260 let disambiguate_just disambiguate_term context metasenv =
263 let metasenv,t = disambiguate_term context metasenv t in
266 let metasenv,params = disambiguate_auto_params disambiguate_term metasenv
269 metasenv, `Auto params
272 let rec disambiguate_tactic
273 lexicon_status_ref context metasenv goal (text,prefix_len,tactic)
275 let disambiguate_term_hint =
277 List.find (fun (x,_,_) -> Some x = goal) metasenv
279 disambiguate_term (Some expty) text prefix_len lexicon_status_ref in
280 let disambiguate_term =
281 disambiguate_term None text prefix_len lexicon_status_ref in
282 let disambiguate_pattern =
283 disambiguate_pattern text prefix_len lexicon_status_ref in
284 let disambiguate_reduction_kind =
285 disambiguate_reduction_kind text prefix_len lexicon_status_ref in
286 let disambiguate_lazy_term =
287 disambiguate_lazy_term None text prefix_len lexicon_status_ref in
288 let disambiguate_tactic metasenv tac =
289 disambiguate_tactic lexicon_status_ref context metasenv goal (text,prefix_len,tac)
291 let disambiguate_auto_params m p =
292 disambiguate_auto_params disambiguate_term m context p
295 (* Higher order tactics *)
296 | GrafiteAst.Progress (loc,tac) ->
297 let metasenv,tac = disambiguate_tactic metasenv tac in
298 metasenv,GrafiteAst.Progress (loc,tac)
299 | GrafiteAst.Solve (loc,tacl) ->
302 (fun tac (metasenv,tacl) ->
303 let metasenv,tac = disambiguate_tactic metasenv tac in
307 metasenv,GrafiteAst.Solve (loc,tacl)
308 | GrafiteAst.Try (loc,tac) ->
309 let metasenv,tac = disambiguate_tactic metasenv tac in
310 metasenv,GrafiteAst.Try (loc,tac)
311 | GrafiteAst.First (loc,tacl) ->
314 (fun tac (metasenv,tacl) ->
315 let metasenv,tac = disambiguate_tactic metasenv tac in
319 metasenv,GrafiteAst.First (loc,tacl)
320 | GrafiteAst.Seq (loc,tacl) ->
323 (fun tac (metasenv,tacl) ->
324 let metasenv,tac = disambiguate_tactic metasenv tac in
328 metasenv,GrafiteAst.Seq (loc,tacl)
329 | GrafiteAst.Repeat (loc,tac) ->
330 let metasenv,tac = disambiguate_tactic metasenv tac in
331 metasenv,GrafiteAst.Repeat (loc,tac)
332 | GrafiteAst.Do (loc,n,tac) ->
333 let metasenv,tac = disambiguate_tactic metasenv tac in
334 metasenv,GrafiteAst.Do (loc,n,tac)
335 | GrafiteAst.Then (loc,tac,tacl) ->
336 let metasenv,tac = disambiguate_tactic metasenv tac in
339 (fun tac (metasenv,tacl) ->
340 let metasenv,tac = disambiguate_tactic metasenv tac in
344 metasenv,GrafiteAst.Then (loc,tac,tacl)
345 (* First order tactics *)
346 | GrafiteAst.Absurd (loc, term) ->
347 let metasenv,cic = disambiguate_term context metasenv term in
348 metasenv,GrafiteAst.Absurd (loc, cic)
349 | GrafiteAst.Apply (loc, term) ->
350 let metasenv,cic = disambiguate_term context metasenv term in
351 metasenv,GrafiteAst.Apply (loc, cic)
352 | GrafiteAst.ApplyRule (loc, term) ->
353 let metasenv,cic = disambiguate_term_hint context metasenv term in
354 metasenv,GrafiteAst.ApplyRule (loc, cic)
355 | GrafiteAst.ApplyP (loc, term) ->
356 let metasenv,cic = disambiguate_term context metasenv term in
357 metasenv,GrafiteAst.ApplyP (loc, cic)
358 | GrafiteAst.ApplyS (loc, term, params) ->
359 let metasenv, params = disambiguate_auto_params metasenv params in
360 let metasenv,cic = disambiguate_term context metasenv term in
361 metasenv,GrafiteAst.ApplyS (loc, cic, params)
362 | GrafiteAst.Assumption loc ->
363 metasenv,GrafiteAst.Assumption loc
364 | GrafiteAst.AutoBatch (loc,params) ->
365 let metasenv, params = disambiguate_auto_params metasenv params in
366 metasenv,GrafiteAst.AutoBatch (loc,params)
367 | GrafiteAst.Cases (loc, what, pattern, idents) ->
368 let metasenv,what = disambiguate_term context metasenv what in
369 let pattern = disambiguate_pattern pattern in
370 metasenv,GrafiteAst.Cases (loc, what, pattern, idents)
371 | GrafiteAst.Change (loc, pattern, with_what) ->
372 let with_what = disambiguate_lazy_term with_what in
373 let pattern = disambiguate_pattern pattern in
374 metasenv,GrafiteAst.Change (loc, pattern, with_what)
375 | GrafiteAst.Clear (loc,id) ->
376 metasenv,GrafiteAst.Clear (loc,id)
377 | GrafiteAst.ClearBody (loc,id) ->
378 metasenv,GrafiteAst.ClearBody (loc,id)
379 | GrafiteAst.Compose (loc, t1, t2, times, spec) ->
380 let metasenv,t1 = disambiguate_term context metasenv t1 in
383 | None -> metasenv, None
385 let m, t2 = disambiguate_term context metasenv t2 in
388 metasenv, GrafiteAst.Compose (loc, t1, t2, times, spec)
389 | GrafiteAst.Constructor (loc,n) ->
390 metasenv,GrafiteAst.Constructor (loc,n)
391 | GrafiteAst.Contradiction loc ->
392 metasenv,GrafiteAst.Contradiction loc
393 | GrafiteAst.Cut (loc, ident, term) ->
394 let metasenv,cic = disambiguate_term context metasenv term in
395 metasenv,GrafiteAst.Cut (loc, ident, cic)
396 | GrafiteAst.Decompose (loc, names) ->
397 metasenv,GrafiteAst.Decompose (loc, names)
398 | GrafiteAst.Demodulate (loc, params) ->
399 let metasenv, params = disambiguate_auto_params metasenv params in
400 metasenv,GrafiteAst.Demodulate (loc, params)
401 | GrafiteAst.Destruct (loc, Some terms) ->
402 let map term (metasenv, terms) =
403 let metasenv, term = disambiguate_term context metasenv term in
404 metasenv, term :: terms
406 let metasenv, terms = List.fold_right map terms (metasenv, []) in
407 metasenv, GrafiteAst.Destruct(loc, Some terms)
408 | GrafiteAst.Destruct (loc, None) ->
409 metasenv,GrafiteAst.Destruct(loc,None)
410 | GrafiteAst.Exact (loc, term) ->
411 let metasenv,cic = disambiguate_term context metasenv term in
412 metasenv,GrafiteAst.Exact (loc, cic)
413 | GrafiteAst.Elim (loc, what, Some using, pattern, specs) ->
414 let metasenv,what = disambiguate_term context metasenv what in
415 let metasenv,using = disambiguate_term context metasenv using in
416 let pattern = disambiguate_pattern pattern in
417 metasenv,GrafiteAst.Elim (loc, what, Some using, pattern, specs)
418 | GrafiteAst.Elim (loc, what, None, pattern, specs) ->
419 let metasenv,what = disambiguate_term context metasenv what in
420 let pattern = disambiguate_pattern pattern in
421 metasenv,GrafiteAst.Elim (loc, what, None, pattern, specs)
422 | GrafiteAst.ElimType (loc, what, Some using, specs) ->
423 let metasenv,what = disambiguate_term context metasenv what in
424 let metasenv,using = disambiguate_term context metasenv using in
425 metasenv,GrafiteAst.ElimType (loc, what, Some using, specs)
426 | GrafiteAst.ElimType (loc, what, None, specs) ->
427 let metasenv,what = disambiguate_term context metasenv what in
428 metasenv,GrafiteAst.ElimType (loc, what, None, specs)
429 | GrafiteAst.Exists loc ->
430 metasenv,GrafiteAst.Exists loc
431 | GrafiteAst.Fail loc ->
432 metasenv,GrafiteAst.Fail loc
433 | GrafiteAst.Fold (loc,red_kind, term, pattern) ->
434 let pattern = disambiguate_pattern pattern in
435 let term = disambiguate_lazy_term term in
436 let red_kind = disambiguate_reduction_kind red_kind in
437 metasenv,GrafiteAst.Fold (loc, red_kind, term, pattern)
438 | GrafiteAst.FwdSimpl (loc, hyp, names) ->
439 metasenv,GrafiteAst.FwdSimpl (loc, hyp, names)
440 | GrafiteAst.Fourier loc ->
441 metasenv,GrafiteAst.Fourier loc
442 | GrafiteAst.Generalize (loc,pattern,ident) ->
443 let pattern = disambiguate_pattern pattern in
444 metasenv,GrafiteAst.Generalize (loc,pattern,ident)
445 | GrafiteAst.IdTac loc ->
446 metasenv,GrafiteAst.IdTac loc
447 | GrafiteAst.Intros (loc, specs) ->
448 metasenv,GrafiteAst.Intros (loc, specs)
449 | GrafiteAst.Inversion (loc, term) ->
450 let metasenv,term = disambiguate_term context metasenv term in
451 metasenv,GrafiteAst.Inversion (loc, term)
452 | GrafiteAst.LApply (loc, linear, depth, to_what, what, ident) ->
453 let f term (metasenv, to_what) =
454 let metasenv, term = disambiguate_term context metasenv term in
455 metasenv, term :: to_what
457 let metasenv, to_what = List.fold_right f to_what (metasenv, []) in
458 let metasenv, what = disambiguate_term context metasenv what in
459 metasenv,GrafiteAst.LApply (loc, linear, depth, to_what, what, ident)
460 | GrafiteAst.Left loc ->
461 metasenv,GrafiteAst.Left loc
462 | GrafiteAst.LetIn (loc, term, name) ->
463 let metasenv,term = disambiguate_term context metasenv term in
464 metasenv,GrafiteAst.LetIn (loc,term,name)
465 | GrafiteAst.Reduce (loc, red_kind, pattern) ->
466 let pattern = disambiguate_pattern pattern in
467 let red_kind = disambiguate_reduction_kind red_kind in
468 metasenv,GrafiteAst.Reduce(loc, red_kind, pattern)
469 | GrafiteAst.Reflexivity loc ->
470 metasenv,GrafiteAst.Reflexivity loc
471 | GrafiteAst.Replace (loc, pattern, with_what) ->
472 let pattern = disambiguate_pattern pattern in
473 let with_what = disambiguate_lazy_term with_what in
474 metasenv,GrafiteAst.Replace (loc, pattern, with_what)
475 | GrafiteAst.Rewrite (loc, dir, t, pattern, names) ->
476 let metasenv,term = disambiguate_term context metasenv t in
477 let pattern = disambiguate_pattern pattern in
478 metasenv,GrafiteAst.Rewrite (loc, dir, term, pattern, names)
479 | GrafiteAst.Right loc ->
480 metasenv,GrafiteAst.Right loc
481 | GrafiteAst.Ring loc ->
482 metasenv,GrafiteAst.Ring loc
483 | GrafiteAst.Split loc ->
484 metasenv,GrafiteAst.Split loc
485 | GrafiteAst.Symmetry loc ->
486 metasenv,GrafiteAst.Symmetry loc
487 | GrafiteAst.Transitivity (loc, term) ->
488 let metasenv,cic = disambiguate_term context metasenv term in
489 metasenv,GrafiteAst.Transitivity (loc, cic)
491 | GrafiteAst.Assume (loc, id, term) ->
492 let metasenv,cic = disambiguate_term context metasenv term in
493 metasenv,GrafiteAst.Assume (loc, id, cic)
494 | GrafiteAst.Suppose (loc, term, id, term') ->
495 let metasenv,cic = disambiguate_term context metasenv term in
498 None -> metasenv,None
500 let metasenv,t = disambiguate_term context metasenv t in
502 metasenv,GrafiteAst.Suppose (loc, cic, id, cic')
503 | GrafiteAst.Bydone (loc,just) ->
505 disambiguate_just disambiguate_term context metasenv just
507 metasenv,GrafiteAst.Bydone (loc, just)
508 | GrafiteAst.We_need_to_prove (loc,term,id,term') ->
509 let metasenv,cic = disambiguate_term context metasenv term in
512 None -> metasenv,None
514 let metasenv,t = disambiguate_term context metasenv t in
516 metasenv,GrafiteAst.We_need_to_prove (loc,cic,id,cic')
517 | GrafiteAst.By_just_we_proved (loc,just,term',id,term'') ->
519 disambiguate_just disambiguate_term context metasenv just in
520 let metasenv,cic' = disambiguate_term context metasenv term' in
523 None -> metasenv,None
525 let metasenv,t = disambiguate_term context metasenv t in
527 metasenv,GrafiteAst.By_just_we_proved (loc,just,cic',id,cic'')
528 | GrafiteAst.We_proceed_by_cases_on (loc, term, term') ->
529 let metasenv,cic = disambiguate_term context metasenv term in
530 let metasenv,cic' = disambiguate_term context metasenv term' in
531 metasenv,GrafiteAst.We_proceed_by_cases_on (loc, cic, cic')
532 | GrafiteAst.We_proceed_by_induction_on (loc, term, term') ->
533 let metasenv,cic = disambiguate_term context metasenv term in
534 let metasenv,cic' = disambiguate_term context metasenv term' in
535 metasenv,GrafiteAst.We_proceed_by_induction_on (loc, cic, cic')
536 | GrafiteAst.Byinduction (loc, term, id) ->
537 let metasenv,cic = disambiguate_term context metasenv term in
538 metasenv,GrafiteAst.Byinduction(loc, cic, id)
539 | GrafiteAst.Thesisbecomes (loc, term) ->
540 let metasenv,cic = disambiguate_term context metasenv term in
541 metasenv,GrafiteAst.Thesisbecomes (loc, cic)
542 | GrafiteAst.ExistsElim (loc, just, id1, term1, id2, term2) ->
544 disambiguate_just disambiguate_term context metasenv just in
545 let metasenv,cic' = disambiguate_term context metasenv term1 in
546 let cic''= disambiguate_lazy_term term2 in
547 metasenv,GrafiteAst.ExistsElim(loc, just, id1, cic', id2, cic'')
548 | GrafiteAst.AndElim (loc, just, id, term1, id1, term2) ->
550 disambiguate_just disambiguate_term context metasenv just in
551 let metasenv,cic'= disambiguate_term context metasenv term1 in
552 let metasenv,cic''= disambiguate_term context metasenv term2 in
553 metasenv,GrafiteAst.AndElim(loc, just, id, cic', id1, cic'')
554 | GrafiteAst.Case (loc, id, params) ->
555 let metasenv,params' =
557 (fun (id,term) (metasenv,params) ->
558 let metasenv,cic = disambiguate_term context metasenv term in
559 metasenv,(id,cic)::params
560 ) params (metasenv,[])
562 metasenv,GrafiteAst.Case(loc, id, params')
563 | GrafiteAst.RewritingStep (loc, term1, term2, term3, cont) ->
566 None -> metasenv,None
568 let metasenv,t = disambiguate_term context metasenv t in
569 metasenv,Some (start,t) in
570 let metasenv,cic'= disambiguate_term context metasenv term2 in
574 let metasenv,term = disambiguate_term context metasenv term in
575 metasenv, `SolveWith term
577 let metasenv, params = disambiguate_auto_params metasenv params in
578 metasenv,`Auto params
580 let metasenv,t = disambiguate_term context metasenv t in
582 | `Proof as t -> metasenv,t in
583 metasenv,GrafiteAst.RewritingStep (loc, cic, cic', cic'', cont)
585 let disambiguate_obj lexicon_status ?baseuri metasenv (text,prefix_len,obj) =
588 match baseuri with Some x -> x | None -> raise BaseUriNotSetYet
592 | CicNotationPt.Inductive (_,(name,_,_,_)::_)
593 | CicNotationPt.Record (_,name,_,_) -> name ^ ".ind"
594 | CicNotationPt.Theorem (_,name,_,_) -> name ^ ".con"
595 | CicNotationPt.Inductive _ -> assert false
597 UriManager.uri_of_string (baseuri ^ "/" ^ name)
600 (NCicLibrary.clear_cache ();
601 NCicEnvironment.invalidate ();
605 | Some (Cic.CurrentProof (_,metasenv, _, ty,_,_)) ->
607 CicTypeChecker.type_of_aux' metasenv [] ty CicUniv.empty_ugraph
610 | Some (Cic.Constant (_,_, ty,_,_)) ->
612 CicTypeChecker.type_of_aux' [] [] ty CicUniv.empty_ugraph
615 | _ -> CicUniv.empty_ugraph
619 prerr_endline "PRIMA COERCIONS";
620 let _,l = CicUniv.do_rank graph in
622 prerr_endline (CicUniv.string_of_universe k ^ " = " ^ string_of_int
623 (CicUniv.get_rank k))) l;
628 (fun graph (_,_,l) ->
630 (fun graph (uri,_,_) ->
631 let _,g = CicTypeChecker.typecheck uri in
632 CicUniv.merge_ugraphs ~base_ugraph:graph ~increment:(g,uri))
634 graph (CoercDb.to_list ())
636 ignore(CicUniv.do_rank graph);
640 prerr_endline "DOPO COERCIONS";
641 let _,l = CicUniv.do_rank graph in
643 prerr_endline (CicUniv.string_of_universe k ^ " = " ^ string_of_int
644 (CicUniv.get_rank k))) l;
648 prerr_endline "INIZIO NUOVA DISAMBIGUAZIONE";
649 let time = Unix.gettimeofday () in
652 NCicDisambiguate.disambiguate_obj
653 ~lookup_in_library:lookup_in_library
654 ~description_of_alias:LexiconAst.description_of_alias
655 ~mk_choice:ncic_mk_choice
657 ~uri:(OCic2NCic.nuri_of_ouri uri)
658 ~coercion_db:(NCicCoercion.db ())
659 ~aliases:lexicon_status.LexiconEngine.aliases
660 ~universe:(Some lexicon_status.LexiconEngine.multi_aliases)
661 (text,prefix_len,obj)
664 let time = Unix.gettimeofday () -. time in
665 (* NCicTypeChecker.typecheck_obj obj; *)
666 prerr_endline ("NUOVA DISAMBIGUAZIONE OK: "^ string_of_float time);
669 let u,i,m,_,o = obj in
673 prerr_endline (NCicPp.ppobj obj)
675 prerr_endline ("NUOVA DISAMBIGUAZIONE AMBIGUO!!!!!!!!! "))
677 | MultiPassDisambiguator.DisambiguationError (_,s) ->
678 prerr_endline ("ERRORE NUOVA DISAMBIGUAZIONE ("
679 ^UriManager.string_of_uri uri^
682 (List.map (fun _,_,x,_ -> snd (Lazy.force x)) (List.flatten s)))
683 (* | exn -> prerr_endline (Printexc.to_string exn) *)
690 (* let time = Unix.gettimeofday () in *)
693 let (diff, metasenv, _, cic, _) =
695 (CicDisambiguate.disambiguate_obj
697 ~mk_choice:cic_mk_choice
699 ~description_of_alias:LexiconAst.description_of_alias
700 ~aliases:lexicon_status.LexiconEngine.aliases
701 ~universe:(Some lexicon_status.LexiconEngine.multi_aliases)
703 (text,prefix_len,obj)) in
707 let time = Unix.gettimeofday () -. time in
708 prerr_endline ("VECCHIA DISAMBIGUAZIONE ("^
709 UriManager.string_of_uri uri ^"): " ^ string_of_float time);
711 (* try_new (Some cic); *)
714 let lexicon_status = LexiconEngine.set_proof_aliases lexicon_status diff in
715 lexicon_status, metasenv, cic
718 | Sys.Break as exn -> raise exn
725 let disambiguate_command lexicon_status ?baseuri metasenv (text,prefix_len,cmd)=
727 | GrafiteAst.NObj(loc,obj) -> lexicon_status, metasenv, GrafiteAst.NObj(loc,obj)
728 | GrafiteAst.Index(loc,key,uri) ->
729 let lexicon_status_ref = ref lexicon_status in
730 let disambiguate_term =
731 disambiguate_term None text prefix_len lexicon_status_ref [] in
732 let disambiguate_term_option metasenv =
734 None -> metasenv,None
736 let metasenv,t = disambiguate_term metasenv t in
739 let metasenv,key = disambiguate_term_option metasenv key in
740 !lexicon_status_ref, metasenv,GrafiteAst.Index(loc,key,uri)
741 | GrafiteAst.PreferCoercion (loc,t) ->
742 let lexicon_status_ref = ref lexicon_status in
743 let disambiguate_term =
744 disambiguate_term None text prefix_len lexicon_status_ref [] in
745 let metasenv,t = disambiguate_term metasenv t in
746 !lexicon_status_ref, metasenv, GrafiteAst.PreferCoercion (loc,t)
747 | GrafiteAst.Coercion (loc,t,b,a,s) ->
748 let lexicon_status_ref = ref lexicon_status in
749 let disambiguate_term =
750 disambiguate_term None text prefix_len lexicon_status_ref [] in
751 let metasenv,t = disambiguate_term metasenv t in
752 !lexicon_status_ref, metasenv, GrafiteAst.Coercion (loc,t,b,a,s)
753 | GrafiteAst.UnificationHint (loc, t, n) ->
754 let lexicon_status_ref = ref lexicon_status in
755 let disambiguate_term =
756 disambiguate_term None text prefix_len lexicon_status_ref [] in
757 let metasenv,t = disambiguate_term metasenv t in
758 !lexicon_status_ref, metasenv, GrafiteAst.UnificationHint (loc,t,n)
759 | GrafiteAst.Default _
761 | GrafiteAst.Include _
764 | GrafiteAst.Set _ as cmd ->
765 lexicon_status,metasenv,cmd
766 | GrafiteAst.Obj (loc,obj) ->
767 let lexicon_status,metasenv,obj =
768 disambiguate_obj lexicon_status ?baseuri metasenv (text,prefix_len,obj)in
769 lexicon_status, metasenv, GrafiteAst.Obj (loc,obj)
770 | GrafiteAst.Relation (loc,id,a,aeq,refl,sym,trans) ->
771 let lexicon_status_ref = ref lexicon_status in
772 let disambiguate_term =
773 disambiguate_term None text prefix_len lexicon_status_ref [] in
774 let disambiguate_term_option metasenv =
776 None -> metasenv,None
778 let metasenv,t = disambiguate_term metasenv t in
781 let metasenv,a = disambiguate_term metasenv a in
782 let metasenv,aeq = disambiguate_term metasenv aeq in
783 let metasenv,refl = disambiguate_term_option metasenv refl in
784 let metasenv,sym = disambiguate_term_option metasenv sym in
785 let metasenv,trans = disambiguate_term_option metasenv trans in
786 !lexicon_status_ref, metasenv,
787 GrafiteAst.Relation (loc,id,a,aeq,refl,sym,trans)
789 let disambiguate_macro
790 lexicon_status_ref metasenv context (text,prefix_len, macro)
792 let disambiguate_term = disambiguate_term None text prefix_len lexicon_status_ref in
793 let disambiguate_reduction_kind =
794 disambiguate_reduction_kind text prefix_len lexicon_status_ref in
796 | GrafiteAst.WMatch (loc,term) ->
797 let metasenv,term = disambiguate_term context metasenv term in
798 metasenv,GrafiteAst.WMatch (loc,term)
799 | GrafiteAst.WInstance (loc,term) ->
800 let metasenv,term = disambiguate_term context metasenv term in
801 metasenv,GrafiteAst.WInstance (loc,term)
802 | GrafiteAst.WElim (loc,term) ->
803 let metasenv,term = disambiguate_term context metasenv term in
804 metasenv,GrafiteAst.WElim (loc,term)
805 | GrafiteAst.WHint (loc,term) ->
806 let metasenv,term = disambiguate_term context metasenv term in
807 metasenv,GrafiteAst.WHint (loc,term)
808 | GrafiteAst.Check (loc,term) ->
809 let metasenv,term = disambiguate_term context metasenv term in
810 metasenv,GrafiteAst.Check (loc,term)
811 | GrafiteAst.Eval (loc,kind,term) ->
812 let metasenv, term = disambiguate_term context metasenv term in
813 let kind = disambiguate_reduction_kind kind in
814 metasenv,GrafiteAst.Eval (loc,kind,term)
815 | GrafiteAst.AutoInteractive (loc, params) ->
816 let metasenv, params =
817 disambiguate_auto_params disambiguate_term metasenv context params in
818 metasenv, GrafiteAst.AutoInteractive (loc, params)
820 | GrafiteAst.WLocate _
821 | GrafiteAst.Inline _ as macro ->