2016-02-18 07:11:59 -08:00
|
|
|
(**************************************************************************)
|
|
|
|
(* *)
|
|
|
|
(* OCaml *)
|
|
|
|
(* *)
|
|
|
|
(* Jerome Vouillon, projet Cristal, INRIA Rocquencourt *)
|
|
|
|
(* OCaml port by John Malecki and Xavier Leroy *)
|
|
|
|
(* *)
|
|
|
|
(* Copyright 1996 Institut National de Recherche en Informatique et *)
|
|
|
|
(* en Automatique. *)
|
|
|
|
(* *)
|
|
|
|
(* All rights reserved. This file is distributed under the terms of *)
|
|
|
|
(* the GNU Lesser General Public License version 2.1, with the *)
|
|
|
|
(* special exception on linking described in the file LICENSE. *)
|
|
|
|
(* *)
|
|
|
|
(**************************************************************************)
|
1996-11-29 08:55:09 -08:00
|
|
|
|
|
|
|
open Env
|
|
|
|
|
1997-03-25 07:29:39 -08:00
|
|
|
type error =
|
|
|
|
Module_not_found of Path.t
|
|
|
|
|
|
|
|
exception Error of error
|
|
|
|
|
1996-11-29 08:55:09 -08:00
|
|
|
let env_cache =
|
2009-05-20 04:52:42 -07:00
|
|
|
(Hashtbl.create 59 : ((Env.summary * Subst.t), Env.t) Hashtbl.t)
|
1996-11-29 08:55:09 -08:00
|
|
|
|
|
|
|
let reset_cache () =
|
|
|
|
Hashtbl.clear env_cache;
|
|
|
|
Env.reset_cache()
|
|
|
|
|
2009-05-20 04:52:42 -07:00
|
|
|
let rec env_from_summary sum subst =
|
1996-11-29 08:55:09 -08:00
|
|
|
try
|
2009-05-20 04:52:42 -07:00
|
|
|
Hashtbl.find env_cache (sum, subst)
|
1996-11-29 08:55:09 -08:00
|
|
|
with Not_found ->
|
|
|
|
let env =
|
|
|
|
match sum with
|
|
|
|
Env_empty ->
|
|
|
|
Env.empty
|
|
|
|
| Env_value(s, id, desc) ->
|
2013-09-04 08:12:37 -07:00
|
|
|
Env.add_value id (Subst.value_description subst desc)
|
|
|
|
(env_from_summary s subst)
|
1996-11-29 08:55:09 -08:00
|
|
|
| Env_type(s, id, desc) ->
|
2013-09-17 07:28:31 -07:00
|
|
|
Env.add_type ~check:false id
|
|
|
|
(Subst.type_declaration subst desc)
|
|
|
|
(env_from_summary s subst)
|
2014-05-04 16:08:45 -07:00
|
|
|
| Env_extension(s, id, desc) ->
|
2020-05-06 09:24:13 -07:00
|
|
|
Env.add_extension ~check:false ~rebind:false id
|
2014-05-04 16:08:45 -07:00
|
|
|
(Subst.extension_constructor subst desc)
|
2013-09-17 07:28:31 -07:00
|
|
|
(env_from_summary s subst)
|
2018-02-08 09:51:47 -08:00
|
|
|
| Env_module(s, id, pres, desc) ->
|
|
|
|
Env.add_module_declaration ~check:false id pres
|
2019-04-12 03:34:04 -07:00
|
|
|
(Subst.module_declaration Keep subst desc)
|
2013-09-27 10:05:39 -07:00
|
|
|
(env_from_summary s subst)
|
1996-11-29 08:55:09 -08:00
|
|
|
| Env_modtype(s, id, desc) ->
|
2019-04-12 03:34:04 -07:00
|
|
|
Env.add_modtype id (Subst.modtype_declaration Keep subst desc)
|
2013-09-04 08:12:37 -07:00
|
|
|
(env_from_summary s subst)
|
1996-11-29 08:55:09 -08:00
|
|
|
| Env_class(s, id, desc) ->
|
2013-09-04 08:12:37 -07:00
|
|
|
Env.add_class id (Subst.class_declaration subst desc)
|
|
|
|
(env_from_summary s subst)
|
1998-06-24 12:22:26 -07:00
|
|
|
| Env_cltype (s, id, desc) ->
|
2013-09-04 08:12:37 -07:00
|
|
|
Env.add_cltype id (Subst.cltype_declaration subst desc)
|
|
|
|
(env_from_summary s subst)
|
2018-09-18 06:49:18 -07:00
|
|
|
| Env_open(s, path) ->
|
2009-05-20 04:52:42 -07:00
|
|
|
let env = env_from_summary s subst in
|
|
|
|
let path' = Subst.module_path subst path in
|
2018-09-18 06:49:18 -07:00
|
|
|
begin match Env.open_signature Asttypes.Override path' env with
|
2020-06-23 07:36:55 -07:00
|
|
|
| Ok env -> env
|
|
|
|
| Error `Functor -> assert false
|
|
|
|
| Error `Not_found -> raise (Error (Module_not_found path'))
|
2016-09-27 15:40:13 -07:00
|
|
|
end
|
2018-02-08 09:51:47 -08:00
|
|
|
| Env_functor_arg(Env_module(s, id, pres, desc), id')
|
|
|
|
when Ident.same id id' ->
|
2016-01-12 14:53:59 -08:00
|
|
|
Env.add_module_declaration ~check:false
|
2019-04-12 03:34:04 -07:00
|
|
|
id pres (Subst.module_declaration Keep subst desc)
|
2013-09-30 06:54:59 -07:00
|
|
|
~arg:true (env_from_summary s subst)
|
2013-09-29 19:10:21 -07:00
|
|
|
| Env_functor_arg _ -> assert false
|
2016-05-10 16:38:34 -07:00
|
|
|
| Env_constraints(s, map) ->
|
2018-07-23 05:19:41 -07:00
|
|
|
Path.Map.fold
|
2016-05-10 16:38:34 -07:00
|
|
|
(fun path info ->
|
|
|
|
Env.add_local_type (Subst.type_path subst path)
|
|
|
|
(Subst.type_declaration subst info))
|
|
|
|
map (env_from_summary s subst)
|
2019-07-17 18:11:41 -07:00
|
|
|
| Env_copy_types s ->
|
2018-04-20 05:28:56 -07:00
|
|
|
let env = env_from_summary s subst in
|
2019-07-17 18:11:41 -07:00
|
|
|
Env.make_copy_of_types env env
|
2018-09-18 06:49:18 -07:00
|
|
|
| Env_persistent (s, id) ->
|
|
|
|
let env = env_from_summary s subst in
|
|
|
|
Env.add_persistent_structure id env
|
2018-10-12 02:20:21 -07:00
|
|
|
| Env_value_unbound (s, str, reason) ->
|
|
|
|
let env = env_from_summary s subst in
|
|
|
|
Env.enter_unbound_value str reason env
|
|
|
|
| Env_module_unbound (s, str, reason) ->
|
|
|
|
let env = env_from_summary s subst in
|
|
|
|
Env.enter_unbound_module str reason env
|
1996-11-29 08:55:09 -08:00
|
|
|
in
|
2009-05-20 04:52:42 -07:00
|
|
|
Hashtbl.add env_cache (sum, subst) env;
|
1996-11-29 08:55:09 -08:00
|
|
|
env
|
1997-03-25 07:08:47 -08:00
|
|
|
|
2012-07-12 04:02:18 -07:00
|
|
|
let env_of_only_summary env =
|
|
|
|
Env.env_of_only_summary env_from_summary env
|
|
|
|
|
1997-03-25 07:29:39 -08:00
|
|
|
(* Error report *)
|
|
|
|
|
2000-03-06 14:12:09 -08:00
|
|
|
open Format
|
1997-03-25 07:29:39 -08:00
|
|
|
|
2000-03-06 14:12:09 -08:00
|
|
|
let report_error ppf = function
|
|
|
|
| Module_not_found p ->
|
|
|
|
fprintf ppf "@[Cannot find module %a@].@." Printtyp.path p
|
2020-03-13 04:59:34 -07:00
|
|
|
|
|
|
|
let () =
|
|
|
|
Location.register_error_of_exn
|
|
|
|
(function
|
|
|
|
| Error err -> Some (Location.error_of_printer_file report_error err)
|
|
|
|
| _ -> None
|
|
|
|
)
|