X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=blobdiff_plain;f=helm%2Fsoftware%2Fhelena%2Fsrc%2Fautomath%2FautCrg.ml;h=fe562480d68db7be0d5721b55865eebe45f8310a;hb=3e5683b1efeb08431c8bb34718920384bfe6625a;hp=025459d2e6df9c9595064ed356c585b5a6ccfce1;hpb=251534dbf294c645d2121df2d9ce240011fa0c91;p=helm.git diff --git a/helm/software/helena/src/automath/autCrg.ml b/helm/software/helena/src/automath/autCrg.ml index 025459d2e..fe562480d 100644 --- a/helm/software/helena/src/automath/autCrg.ml +++ b/helm/software/helena/src/automath/autCrg.ml @@ -9,20 +9,19 @@ \ / This software is distributed as is, NO WARRANTY. V_______________________________________________________________ *) -module U = NUri -module K = U.UriHash -module C = Cps -module G = Options -module E = Entity -module N = Level -module A = Aut -module D = Crg +module U = NUri +module UH = U.UriHash +module C = Cps +module G = Options +module N = Level +module E = Entity +module S = Status +module A = Aut +module D = Crg (* qualified identifier: uri, name, qualifiers *) type qid = D.uri * D.id * D.id list -type context = E.attrs * D.term list - type context_node = qid option (* context node: None = root *) type status = { @@ -30,76 +29,79 @@ type status = { node: context_node; (* current context node *) nodes: context_node list; (* context node list *) line: int; (* line number *) - mk_uri: G.uri_generator; (* uri generator *) + mk_uri: G.uri_generator; (* uri generator *) } -type resolver = Local of int - | Global of context - let henv_size, hcnt_size = 7000, 4300 (* hash tables initial sizes *) -let henv = K.create henv_size (* optimized global environment *) +let henv = UH.create henv_size (* optimized global environment *) -let hcnt = K.create hcnt_size (* optimized context *) +let hcnt = UH.create hcnt_size (* optimized context *) (* Internal functions *******************************************************) -let empty_cnt = D.ESort +let empty_cnt = D.empty_lenv + +let alpha id = + if id.[0] >= '0' && id.[0] <= '9' then !G.alpha ^ id else id -let add_abst cnt id w = - D.EBind (cnt, [E.Name (id, true)], D.Abst (N.infinite, w)) +let add_abst cnt id d w = + let id = if !G.alpha <> "" then alpha id else id in + let a = E.node_attrs ~name:(id, true) ~degr:(succ d) () in + D.EBind (cnt, a, D.Abst (N.two, w)) -let mk_lref f i = f (D.TLRef ([], i)) +let mk_lref f a i = f a.E.n_degr (D.TLRef (E.empty_node, i)) -let id_of_name (id, _, _) = id +let id_of_name (id, _, _) = + if !G.alpha <> "" then alpha id else id -let mk_qid f st id path = +let mk_qid f lst id path = let str = String.concat "/" path in let str = Filename.concat str id in - let str = st.mk_uri str in + let str = lst.mk_uri str in f (U.uri_of_string str, id, path) let uri_of_qid (uri, _, _) = uri -let complete_qid f st (id, is_local, qs) = - let f path = C.list_rev_append (mk_qid f st id) path ~tail:qs in +let complete_qid f lst (id, is_local, qs) = + let f path = C.list_rev_append (mk_qid f lst id) path ~tail:qs in let rec skip f = function | phd :: ptl, qshd :: _ when phd = qshd -> f ptl | _ :: ptl, _ :: _ -> skip f (ptl, qs) | _ -> f [] in - if is_local then f st.path else skip f (st.path, qs) + if is_local then f lst.path else skip f (lst.path, qs) -let relax_qid f st (_, id, path) = +let relax_qid f lst (_, id, path) = let f = function - | _ :: tl -> C.list_rev (mk_qid f st id) tl + | _ :: tl -> C.list_rev (mk_qid f lst id) tl | [] -> assert false in C.list_rev f path -let relax_opt_qid f st = function +let relax_opt_qid f lst = function | None -> f None - | Some qid -> let f qid = f (Some qid) in relax_qid f st qid + | Some qid -> let f qid = f (Some qid) in relax_qid f lst qid -let resolve_gref err f st qid = - try let age, cnt = K.find henv (uri_of_qid qid) in f qid age cnt - with Not_found -> err qid +let resolve_gref err f lst qid = + try let a, cnt = UH.find henv (uri_of_qid qid) in f qid a cnt + with Not_found -> err qid -let resolve_gref_relaxed f st qid = +let resolve_gref_relaxed f lst qid = (* this is not tail recursive *) - let rec err qid = relax_qid (resolve_gref err f st) st qid in - resolve_gref err f st qid + let rec err qid = relax_qid (resolve_gref err f lst) lst qid in + resolve_gref err f lst qid -let get_cnt err f st = function +let get_cnt err f lst = function | None -> f empty_cnt | Some qid as node -> - try let cnt = K.find hcnt (uri_of_qid qid) in f cnt + try let cnt = UH.find hcnt (uri_of_qid qid) in f cnt with Not_found -> err node -let get_cnt_relaxed f st = +let get_cnt_relaxed f lst = (* this is not tail recursive *) - let rec err node = relax_opt_qid (get_cnt err f st) st node in - get_cnt err f st st.node + let rec err node = relax_opt_qid (get_cnt err f lst) lst node in + get_cnt err f lst lst.node let push_abst f a w lenv = let bw = D.Abst (N.infinite, w) in @@ -108,132 +110,135 @@ let push_abst f a w lenv = let add_proj e t = match e with | D.ESort -> t | D.EBind (D.ESort, a, b) -> D.TBind (a, b, t) - | _ -> D.TProj ([], e, t) - -let lenv_of_cnt cnt = cnt + | _ -> D.TProj (E.empty_node, e, t) (* this is not tail recursive in the GRef branch *) -let rec xlate_term f st lenv = function - | A.Sort s -> - let f h = f (D.TSort ([], h)) in +let rec xlate_term f st lst y lenv = function + | A.Sort s -> + let f h = f 0 (D.TSort (E.empty_node, h)) in if s then f 0 else f 1 | A.Appl (v, t) -> - let f vv tt = f (D.TAppl ([], vv, tt)) in - let f vv = xlate_term (f vv) st lenv t in - xlate_term f st lenv v + let f vv d tt = f d (D.TAppl (E.empty_node, vv, tt)) in + let f _ vv = xlate_term (f vv) st lst y lenv t in + xlate_term f st lst false lenv v | A.Abst (name, w, t) -> - let f ww = - let a = [E.Name (name, true)] in - let f tt = - let b = D.Abst (N.infinite, ww) in - f (D.TBind (a, b, tt)) + let name = if !G.alpha <> "" then alpha name else name in + let f dw ww = + let a = E.node_attrs ~name:(name, true) () in + let f dt tt = +(* let a = {a with E.n_degr = dt} in *) + let l = if !G.cc then match y, dt with + | true, _ -> N.one + | _ , 0 -> N.one + | _ , 1 -> N.unknown st.S.lenv + | _ , 2 -> N.two + | _ -> assert false + else N.infinite + in + let b = D.Abst (l, ww) in + f dt (D.TBind (a, b, tt)) in - let f lenv = xlate_term f st lenv t in - push_abst f a ww lenv + let f lenv = xlate_term f st lst y lenv t in + push_abst f {a with E.n_degr = succ dw} ww lenv in - xlate_term f st lenv w + xlate_term f st lst true lenv w | A.GRef (name, args) -> - let map1 args a = - let f id _ = A.GRef ((id, true, []), []) :: args in - E.name C.err f a - in + let map1 args (id, _) = A.GRef ((id, true, []), []) :: args in let map2 f arg args = - let f arg = f (D.EAppl (args, [], arg)) in - xlate_term f st lenv arg + let f _ arg = f (D.EAppl (args, E.empty_node, arg)) in + xlate_term f st lst false lenv arg in - let g qid age cnt = - let gref = D.TGRef ([age], uri_of_qid qid) in - if cnt = D.ESort then f gref else + let g qid a cnt = + let gref = D.TGRef (a, uri_of_qid qid) in + if cnt = D.ESort then f a.E.n_degr gref else let f = function - | D.EAppl (D.ESort, a, v) -> f (D.TAppl (a, v, gref)) - | args -> f (D.TProj ([], args, gref)) + | D.EAppl (D.ESort, b, v) -> f a.E.n_degr (D.TAppl (b, v, gref)) + | args -> f a.E.n_degr (D.TProj (E.empty_node, args, gref)) in let f args = C.list_fold_right f map2 args D.ESort in - D.sub_list_strict (D.fold_attrs f map1 args) cnt args + D.sub_list_strict (D.fold_names f map1 args) cnt args in - let g qid = resolve_gref_relaxed g st qid in - let err () = complete_qid g st name in + let g qid = resolve_gref_relaxed g lst qid in + let err () = complete_qid g lst name in D.resolve_lref err (mk_lref f) (id_of_name name) lenv -let xlate_entity err f st = function +let xlate_entity err f st lst = function | A.Section (Some (_, name)) -> - err {st with path = name :: st.path; nodes = st.node :: st.nodes} + err {lst with path = name :: lst.path; nodes = lst.node :: lst.nodes} | A.Section None -> - begin match st.path, st.nodes with + begin match lst.path, lst.nodes with | _ :: ptl, nhd :: ntl -> - err {st with path = ptl; node = nhd; nodes = ntl} + err {lst with path = ptl; node = nhd; nodes = ntl} | _ -> assert false end | A.Context None -> - err {st with node = None} + err {lst with node = None} | A.Context (Some name) -> - let f name = err {st with node = Some name} in - complete_qid f st name + let f name = err {lst with node = Some name} in + complete_qid f lst name | A.Block (name, w) -> let f qid = let f cnt = - let f ww = - K.add hcnt (uri_of_qid qid) (add_abst cnt name ww); - err {st with node = Some qid} + let f d ww = + UH.add hcnt (uri_of_qid qid) (add_abst cnt name d ww); + err {lst with node = Some qid} in - xlate_term f st cnt w + xlate_term f st lst true cnt w in - get_cnt_relaxed f st + get_cnt_relaxed f lst in - complete_qid f st (name, true, []) + complete_qid f lst (name, true, []) | A.Decl (name, w) -> - let f cnt = - let lenv = lenv_of_cnt cnt in + let f lenv = let f qid = - let f ww = - let age = E.Apix st.line in - K.add henv (uri_of_qid qid) (age, cnt); + let f d ww = + let a = E.node_attrs ~apix:lst.line ~degr:(succ d) () in + UH.add henv (uri_of_qid qid) (a, lenv); let t = add_proj lenv ww in (* print_newline (); CrgOutput.pp_term print_string t; *) - let b = E.Abst (N.infinite, t) in - let entity = [age], uri_of_qid qid, b in - f {st with line = succ st.line} entity + let b = E.Abst t in + let entity = E.empty_root, a, uri_of_qid qid, b in + f {lst with line = succ lst.line} entity in - xlate_term f st lenv w + xlate_term f st lst true lenv w in - complete_qid f st (name, true, []) + complete_qid f lst (name, true, []) in - get_cnt_relaxed f st + get_cnt_relaxed (D.sta f) lst | A.Def (name, w, trans, v) -> - let f cnt = - let lenv = lenv_of_cnt cnt in + let f lenv = let f qid = - let f ww = - let f vv = - let age = E.Apix st.line in - K.add henv (uri_of_qid qid) (age, cnt); - let t = add_proj lenv (D.TCast ([], ww, vv)) in + let f _ ww = + let f d vv = + let na = E.node_attrs ~apix:lst.line ~degr:d () in + UH.add henv (uri_of_qid qid) (na, lenv); + let t = add_proj lenv (D.TCast (E.empty_node, ww, vv)) in (* print_newline (); CrgOutput.pp_term print_string t; *) let b = E.Abbr t in - let a = age :: if trans then [] else [E.Meta [E.Private]] in - let entity = a, uri_of_qid qid, b in - f {st with line = succ st.line} entity + let ra = if trans then E.empty_root else E.root_attrs ~meta:[E.Private] () in + let entity = ra, na, uri_of_qid qid, b in + f {lst with line = succ lst.line} entity in - xlate_term f st lenv v + xlate_term f st lst false lenv v in - xlate_term f st lenv w + xlate_term f st lst true lenv w in - complete_qid f st (name, true, []) + complete_qid f lst (name, true, []) in - get_cnt_relaxed f st + get_cnt_relaxed f lst (* Interface functions ******************************************************) let initial_status () = - K.clear henv; K.clear hcnt; { - path = []; node = None; nodes = []; line = 1; mk_uri = G.get_mk_uri () + UH.clear henv; UH.clear hcnt; { + path = []; node = None; nodes = []; line = 1; mk_uri = G.get_mk_uri (); } -let refresh_status st = {st with +let refresh_status lst = {lst with mk_uri = G.get_mk_uri () }