1 (* Copyright (C) 2004-2005, HELM Team.
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/
30 let alias_diff ~from status =
31 let module Map = DisambiguateTypes.Environment in
33 (fun domain_item (description1,_ as codomain_item) acc ->
35 let description2,_ = Map.find domain_item from.aliases in
36 if description1 <> description2 then
37 (domain_item,codomain_item)::acc
42 (domain_item,codomain_item)::acc)
46 let profiler = HExtlib.profile "alias_diff (conteggiato anche in include)" in
47 fun ~from status -> profiler.HExtlib.profile (alias_diff ~from) status
49 let set_proof_aliases status new_aliases =
50 let commands_of_aliases =
52 (fun alias -> GrafiteAst.Alias (DisambiguateTypes.dummy_floc, alias))
57 | GrafiteAst.Ident_alias (_, suri) ->
58 let buri = UriManager.buri_of_uri (UriManager.uri_of_string suri) in
59 Some (LibraryNoDb.Dependency buri)
63 List.fold_left (fun acc (d,c) -> DisambiguateTypes.Environment.add d c acc)
64 status.aliases new_aliases in
66 List.fold_left (fun acc (d,c) -> DisambiguateTypes.Environment.cons d c acc)
67 status.multi_aliases new_aliases in
69 { status with multi_aliases = multi_aliases ; aliases = aliases}
71 if new_aliases = [] then
75 DisambiguatePp.aliases_of_domain_and_codomain_items_list new_aliases
77 let status = add_moo_content (commands_of_aliases aliases) new_status in
78 let status = add_metadata (deps_of_aliases aliases) status in
81 (** given a uri and a type list (the contructors types) builds a list of pairs
82 * (name,uri) that is used to generate automatic aliases **)
83 let extract_alias types uri =
85 fun (acc,i) (name, _, _, cl) ->
86 (name, UriManager.uri_of_uriref uri i None) ::
88 fun (acc,j) (name,_) ->
89 (((name,UriManager.uri_of_uriref uri i
90 (Some j)) :: acc) , j+1)
97 DisambiguateTypes.Id name,
98 (UriManager.string_of_uri uri, fun _ _ _ -> CicUtil.term_of_uri uri))
100 let add_aliases_for_inductive_def status types uri =
101 let aliases = build_aliases (extract_alias types uri) in
102 set_proof_aliases status aliases
104 let add_alias_for_constant status uri =
105 let name = UriManager.name_of_uri uri in
106 let new_env = build_aliases [(name,uri)] in
107 set_proof_aliases status new_env
109 let add_aliases_for_object status uri =
111 Cic.InductiveDefinition (types,_,_,_) ->
112 add_aliases_for_inductive_def status types uri
113 | Cic.Constant _ -> add_alias_for_constant status uri
115 | Cic.CurrentProof _ -> assert false
117 let add_obj uri obj lemmas status =
118 List.fold_left add_alias_for_constant
119 (add_aliases_for_object status uri obj) lemmas
122 let profiler = HExtlib.profile "add_obj" in
123 fun uri obj status -> profiler.HExtlib.profile (add_obj uri obj) status
125 let add_coercion status uri compounds =
126 let status = {status with coercions = uri :: status.coercions} in
127 List.fold_left add_alias_for_constant status compounds
131 type t = UriManager.uri * string
132 let compare (u1, _) (u2, _) = UriManager.compare u1 u2
137 type t = CicNotation.notation_id
138 let compare = Pervasives.compare
141 module UriSet = Set.Make (OrderedUri)
142 module IdSet = Set.Make (OrderedId)
144 (** @return l2 \ l1 *)
145 let uri_list_diff l2 l1 =
146 let module S = UriManager.UriSet in
147 let s1 = List.fold_left (fun set uri -> S.add uri set) S.empty l1 in
148 let s2 = List.fold_left (fun set uri -> S.add uri set) S.empty l2 in
149 let diff = S.diff s2 s1 in
150 S.fold (fun uri uris -> uri :: uris) diff []
152 (** @return l2 \ l1 *)
153 let id_list_diff l2 l1 =
154 let module S = IdSet in
155 let s1 = List.fold_left (fun set uri -> S.add uri set) S.empty l1 in
156 let s2 = List.fold_left (fun set uri -> S.add uri set) S.empty l2 in
157 let diff = S.diff s2 s1 in
158 S.fold (fun uri uris -> uri :: uris) diff []
160 let time_travel ~present ~past =
161 let objs_to_remove = uri_list_diff present.objects past.objects in
162 let coercions_to_remove = uri_list_diff present.coercions past.coercions in
163 let notation_to_remove =
164 id_list_diff present.notation_ids past.notation_ids
166 let debug_list = ref [] in
168 (fun uri -> LibrarySync.remove_coercion uri)
170 List.iter LibrarySync.remove_obj objs_to_remove;
171 List.iter CicNotation.remove_notation notation_to_remove
174 LibrarySync.remove_all_coercions ();
175 LibraryObjects.reset_defaults ();
177 aliases = DisambiguateTypes.Environment.empty;
178 multi_aliases = DisambiguateTypes.Environment.empty;
179 moo_content_rev = [];
181 proof_status = No_proof;
182 options = no_options;