1 (* Copyright (C) 2000, 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://cs.unibo.it/helm/.
30 type context_node = M.qid option (* context node: None = root *)
32 type context = (M.qid, context_node) H.t (* context: son, parent *)
35 genv: M.environment; (* global environment *)
36 path: M.id list; (* current section path *)
37 cnt: context; (* context *)
38 node: context_node; (* current context node *)
39 explicit: bool (* need explicit context root? *)
42 type resolver = Local of int
46 let initial_status = {
47 genv = []; path = []; cnt = H.create 11; node = None; explicit = true
50 let complete_qid f st (id, is_local, qs) =
51 let f qs = f (id, qs) in
52 if is_local then Cps.list_rev_append f st.path ~tail:qs else f qs
54 let resolve_gref f st lenv gref =
55 let rec get_local f i = function
57 | (name, _) :: _ when name = gref -> f (Some i)
58 | _ :: tl -> get_local f (succ i) tl
60 let rec get_global f = function
62 | (args, name, _, _) :: _ when name = gref -> f (Some args)
63 | _ :: tl -> get_global f tl
66 | Some args -> f (Global args)
67 | None -> f Unresolved
70 | Some i -> f (Local i)
71 | None -> get_global g st.genv
75 let rec xlate_term f st lenv = function
76 | A.Sort sort -> f (M.Sort sort)
78 let f vv tt = f (M.Appl (vv, tt)) in
79 let f vv = xlate_term (f vv) st lenv t in
80 xlate_term f st lenv v
81 | A.Abst (name, w, t) ->
83 let f name = (name, w) :: lenv in
84 complete_qid f st (name, true, [])
86 let f ww tt = f (M.Abst (name, ww, tt)) in
87 let f ww = xlate_term (f ww) st (add name ww lenv) t in
88 xlate_term f st lenv w
89 | A.GRef (name, args) ->
91 | Local i -> f (M.LRef i)
93 let map1 f = xlate_term f st lenv in
94 let map2 f (name, _) = f (M.GRef (name, [])) in
96 let f args = f (M.GRef (name, args)) in
97 let f defs = Cps.list_rev_map_append f map2 defs ~tail in
98 Cps.list_sub_strict f defs args
100 Cps.list_map f map1 args
101 | Unresolved -> assert false
103 let f name = resolve_gref (f name) st lenv name in
104 complete_qid f st name