2 ||M|| This file is part of HELM, an Hypertextual, Electronic
3 ||A|| Library of Mathematics, developed at the Computer Science
4 ||T|| Department, University of Bologna, Italy.
6 ||T|| HELM is free software; you can redistribute it and/or
7 ||A|| modify it under the terms of the GNU General Public License
8 \ / version 2 or (at your option) any later version.
9 \ / This software is distributed as is, NO WARRANTY.
10 V_______________________________________________________________ *)
17 module BE = BrgEnvironment
18 module BR = BrgReduction
20 (* Internal functions *******************************************************)
24 let warn s = L.warn (pred level) s
26 let message1 st1 m t1 =
27 L.et_items1 "In the environment" m st1 t1
30 let s = s ^ " the term" in
31 L.log st BR.specs (pred level) (message1 s m t)
33 let error1 err s m t =
36 let message2 m1 t1 m2 t2 =
37 let sm2, st2 = "In the environment", "the term" in
38 let sm1, st1 = "is valid, but in the environment", "it must be of type" in
39 L.et_items2 sm2 m2 st2 t2 ~sc2:sm1 ~c2:m1 st1 t1
41 let error2 err m1 t1 m2 t2 =
42 err (message2 m1 t1 m2 t2)
48 let assert_convertibility err f st m u t =
50 if !G.ct >= level then warn "Asserting convertibility for cast"
52 if BR.are_convertible st m zero u m one t then f () else
55 let assert_applicability err f st m x v t =
56 let mode, msg = if x then None, "extended" else one, "restricted" in
58 if !G.ct >= level then warn ("Asserting " ^ msg ^ " applicability")
60 match BR.xwhd st m mode t with
61 | mw, B.Bind (_, B.Abst (true, n, w), _) ->
62 if !G.cc && not (N.assert_not_zero st n) then error1 err "not a function" m t
65 if !G.ct >= level then warn "Asserting convertibility for application"
67 if BR.are_convertible st mw zero w m one v then f () else
71 error1 err "not a function" m t
72 | _ -> assert false (**)
74 let rec b_validate err f st m y =
76 if !G.ct >= level then log1 st "Now checking" m y
81 begin match BR.get m i with
85 error1 err "reference to excluded variable" m y
88 begin match BE.get_entity uri with
90 | _, _, _, E.Abbr _ -> f ()
92 error1 err "reference to unknown entry" m y
95 let f () = b_validate err f st (BR.push m y b) t in
97 | B.Abst (_, n, u) -> validate err f st m u
98 | B.Abbr v -> validate err f st m v
101 | B.Appl (x, v, t) ->
102 let f () = assert_applicability err f st m x v t in
103 let f () = b_validate err f st m t in
104 validate err f st m v
106 let f () = assert_convertibility err f st m u t in
107 let f () = b_validate err f st m t in
108 validate err f st m u
110 (* Interface functions ******************************************************)
112 and validate err f st m t = b_validate err f st m t