]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/software/lambda-delta/lib/log.ml
some renaming and some interfaces improved
[helm.git] / helm / software / lambda-delta / lib / log.ml
index 78e57fdfaf9433a115cf262fd5baa2172e803f73..e50fa254da8a71567804fe080f6f975bb8a68a89 100644 (file)
@@ -14,47 +14,79 @@ module F = Format
 module C = Cps
 
 type ('a, 'b) item = Term of 'a * 'b
-                   | Context of 'a
+                   | LEnv of 'a
                    | Warn of string
                   | String of string
+                   | Loc
+
+type ('a, 'b) message = ('a, 'b) item list
 
 type ('a, 'b) specs = {
-   pp_term   : F.formatter -> 'a -> 'b -> unit;
-   pp_context: F.formatter -> 'a -> unit
+   pp_term: 'a -> F.formatter -> 'b -> unit;
+   pp_lenv: F.formatter -> 'a -> unit
 }
 
 let level = ref 0
 
+let loc = ref 0
+
 (* Internal functions *******************************************************)
 
-let init =
-   let started = ref false in
-   fun () ->
-      if !started then () else 
-      begin P.printf "\n"; started := true end
+let std = F.std_formatter
+
+let err = F.err_formatter
 
 let pp_items frm st l items =   
-   let pp_item = function
-      | Term (c, t) -> st.pp_context frm c; st.pp_term frm c t
-      | Context c   -> st.pp_context frm c
-      | Warn s      -> F.fprintf frm "@[%s\n@]" s
-      | String s    -> F.fprintf frm "@[%s @]" s
+   let pp_item frm = function
+      | Term (c, t) -> F.fprintf frm "@,%a" (st.pp_term c) t
+      | LEnv c      -> F.fprintf frm "%a" st.pp_lenv c
+      | Warn s      -> F.fprintf frm "@,%s" s
+      | String s    -> F.fprintf frm "%s " s
+      | Loc         -> F.fprintf frm " (line %u)" !loc 
    in
-   if !level >= l then List.iter pp_item items
+   let iter map frm l = List.iter (map frm) l in
+   if !level >= l then F.fprintf frm "%a" (iter pp_item) items
 
 (* Interface functions ******************************************************)
 
-let warn msg = 
-   init (); P.printf " %s\n" msg; flush stdout
+let box l = 
+   if !level >= l then
+   begin F.fprintf std "@,@[<v 2>%s" "  "; F.pp_print_if_newline std () end
+
+let unbox l = if !level >= l then F.fprintf std "@]"
+
+let flush l = if !level >= l then F.fprintf std "@]@."
+
+let box_err () = F.fprintf err "@[<v>"
 
-let log st l items = pp_items F.std_formatter st l items
+let flush_err () = F.fprintf err "@]@."
 
-let error st items = pp_items F.err_formatter st 0 items
+let log st l items = pp_items std st l items
+
+let error st items = pp_items err st 0 items
 
 let items1 s = [Warn s]
 
-let ct_items1 s c t =
-   [Warn s; Term (c, t)]
+let t_items1 st c t =
+   [Warn st; Term (c, t)]
+
+let et_items1 sc c st t =
+   [Warn sc; LEnv c; Warn st; Term (c, t)]
+
+let et_items2 sc1 c1 st1 t1 ?sc2 ?c2 st2 t2 =
+   let tl = match sc2, c2 with
+      | Some sc2, Some c2 -> et_items1 sc2 c2 st2 t2
+      | None, None        -> t_items1 st2 c1 t2
+      | _                 -> assert false
+   in
+   et_items1 sc1 c1 st1 t1 @ tl  
+
+let et_items3 sc1 c1 st1 t1 ?sc2 ?c2 st2 t2 ?sc3 ?c3 st3 t3 =
+   let tl = match sc3, c3 with
+      | Some sc3, Some c3 -> et_items1 sc3 c3 st3 t3
+      | None, None        -> t_items1 st3 c1 t3 
+      | _                 -> assert false
+   in   
+   et_items2 sc1 c1 st1 t1 ?sc2 ?c2 st2 t2 @ tl 
 
-let ct_items2 s1 c1 t1 s2 c2 t2 =
-   [Warn s1; Term (c1, t1); Warn s2; Term (c2, t2)]
+let warn msg = F.fprintf std "@,%s" msg