Skip to content
Snippets Groups Projects
Commit c6bcd39f authored by Loïc Correnson's avatar Loïc Correnson
Browse files

[wp] refactoring code

parent 29e8e7c4
No related branches found
No related tags found
No related merge requests found
...@@ -28,91 +28,57 @@ module WConf = Why3.Whyconf ...@@ -28,91 +28,57 @@ module WConf = Why3.Whyconf
(* -------------------------------------------------------------------------- *) (* -------------------------------------------------------------------------- *)
type _theory = string * string list
let create_why3_env loadpath = let create_why3_env loadpath =
let main = WConf.get_main (WConf.read_config None) in let main = WConf.get_main @@ WConf.read_config None in
let loadpathes = (WConf.loadpath (main))@loadpath in W.Env.create_env @@ WConf.loadpath main @ F.to_string_list loadpath
W.Env.create_env loadpathes
let extract_path thname =
let extract_last_segments (str_list : string list) = let segments = String.split_on_char '.' thname in
List.map (fun str -> match List.rev segments with
let segments = String.split_on_char '.' str in | hd :: tl -> hd, List.rev tl
match List.rev segments with | [] -> "", []
| hd :: tl -> (hd, List.rev tl)
| [] -> ("", []) (* For debug only*)
) str_list let pp_id fmt (id: W.Ident.ident) =
Format.pp_print_string fmt id.id_string
let get_name_from_ident (ident) =
let ident_printer = W.Ident.create_ident_printer [] in let import_theory env thname =
W.Ident.id_unique (ident_printer) ident let theory_name, theory_path = extract_path thname in
try
let theory = W.Env.read_theory env theory_path theory_name in
let open_theories_of_user (env) (theories) = List.iter (fun (tdecl : T.tdecl) ->
List.iter match tdecl.td_node with
(fun (theory_name, theory_path) -> | Decl decl ->
try begin
let theory = (W.Env.read_theory env (theory_path) (theory_name)) in match decl.d_node with
List.iter ( fun (tdecl : T.tdecl) -> | Dtype ts ->
match tdecl.td_node with L.debug ~level:0 "Decl and type %a.@" pp_id ts.ts_name
| Decl decl -> | Ddata ddatas ->
(match (decl.d_node : W.Decl.decl_node) with List.iter
| Dtype dtype -> L.debug ~level:0 "Decl and type, named : %s.@" (get_name_from_ident dtype.ts_name); (fun ((ts, _) : W.Decl.data_decl) ->
| Ddata ddatas -> L.debug ~level:0 "Decl and data %a.@" pp_id ts.ts_name
List.iter (fun ((tysymbol, _) : W.Decl.data_decl) -> ) ddatas
L.debug ~level:0 "Decl and dtata, named : %s.@" (get_name_from_ident tysymbol.ts_name); | Dparam ls ->
) ddatas; L.debug ~level:0 "Decl and dparam %a.@" pp_id ls.ls_name
| Dparam dparam -> L.debug ~level:0 "Decl and dparam, named : %s.@" (get_name_from_ident dparam.ls_name); | Dlogic dlogics ->
| Dlogic dlogics -> List.iter
List.iter (fun ((ls,_):W.Decl.logic_decl) -> (fun ((ls,_):W.Decl.logic_decl) ->
L.debug ~level:0 "Decl and dlogic, named : %s.@" (get_name_from_ident ls.ls_name); L.debug ~level:0 "Decl and dlogic %a.@" pp_id ls.ls_name
) dlogics; ) dlogics
| _ -> L.debug ~level:0 "Decl but whatever") | _ -> L.debug ~level:0 "Decl but whatever"
| Use _ -> L.debug ~level:0 "Use" end
| Clone _ -> L.debug ~level:0 "Clone" | Use _ -> L.debug ~level:0 "Use"
| Meta _ -> L.debug ~level:0 "Meta" | Clone _ -> L.debug ~level:0 "Clone"
) theory.th_decls; | Meta _ -> L.debug ~level:0 "Meta"
) theory.th_decls
with W.Env.LibraryNotFound paths -> with W.Env.LibraryNotFound _ ->
L.debug ~level:0 "Library %s not found at %s " theory_name (String.concat "." paths); L.error "Library %s not found" thname
) (extract_last_segments theories)
let open_modules_of_user (env) (modules) =
List.iter
(fun (theory_name, theory_path) ->
try
let pmodule = (W.Pmodule.read_module env (theory_path) (theory_name)) in
List.iter ( fun (modunit : W.Pmodule.mod_unit) ->
L.debug ~level:0 "Meta";
) pmodule.mod_units;
with W.Env.LibraryNotFound paths ->
L.debug ~level:0 "Library %s not found at %s " theory_name (String.concat "." paths);
) (extract_last_segments modules)
let () = let () =
Boot.Main.extend Boot.Main.extend
begin fun () -> begin fun () ->
let user_libraries = L.Library.get () in let env = create_why3_env @@ L.Library.get () in
(* DEBUG ONLY *) List.iter (import_theory env) @@ L.Import.get ()
List.iter (fun dir ->
L.debug ~level:0 " + LIBS %s@." dir
) (F.to_string_list user_libraries) ;
(* DEBUG ONLY *)
let user_theories = L.Import.get () in
List.iter (fun thy ->
L.debug ~level:0 " + THY %s@." thy
) user_theories ;
let user_libraries = L.Library.get () in
let user_theories = L.Import.get () in
let env = create_why3_env (F.to_string_list user_libraries) in
open_theories_of_user (env) (user_theories);
end end
(* -------------------------------------------------------------------------- *) (* -------------------------------------------------------------------------- *)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment