1996-11-29 08:55:09 -08:00
|
|
|
(***********************************************************************)
|
|
|
|
(* *)
|
|
|
|
(* Objective Caml *)
|
|
|
|
(* *)
|
|
|
|
(* Jerome Vouillon, projet Cristal, INRIA Rocquencourt *)
|
|
|
|
(* Objective Caml port by John Malecki and Xavier Leroy *)
|
|
|
|
(* *)
|
|
|
|
(* Copyright 1996 Institut National de Recherche en Informatique et *)
|
1999-11-17 10:59:06 -08:00
|
|
|
(* en Automatique. All rights reserved. This file is distributed *)
|
|
|
|
(* under the terms of the Q Public License version 1.0. *)
|
1996-11-29 08:55:09 -08:00
|
|
|
(* *)
|
|
|
|
(***********************************************************************)
|
|
|
|
|
|
|
|
(* $Id$ *)
|
|
|
|
|
|
|
|
open Misc
|
|
|
|
open Types
|
|
|
|
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()
|
|
|
|
|
|
|
|
let extract_sig env mty =
|
|
|
|
match Mtype.scrape env mty with
|
|
|
|
Tmty_signature sg -> sg
|
|
|
|
| _ -> fatal_error "Envaux.extract_sig"
|
|
|
|
|
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) ->
|
2009-05-20 04:52:42 -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) ->
|
2009-05-20 04:52:42 -07:00
|
|
|
Env.add_type id (Subst.type_declaration subst desc) (env_from_summary s subst)
|
1996-11-29 08:55:09 -08:00
|
|
|
| Env_exception(s, id, desc) ->
|
2009-05-20 04:52:42 -07:00
|
|
|
Env.add_exception id (Subst.exception_declaration subst desc) (env_from_summary s subst)
|
1996-11-29 08:55:09 -08:00
|
|
|
| Env_module(s, id, desc) ->
|
2009-05-20 04:52:42 -07:00
|
|
|
Env.add_module id (Subst.modtype subst desc) (env_from_summary s subst)
|
1996-11-29 08:55:09 -08:00
|
|
|
| Env_modtype(s, id, desc) ->
|
2009-05-20 04:52:42 -07:00
|
|
|
Env.add_modtype id (Subst.modtype_declaration subst desc) (env_from_summary s subst)
|
1996-11-29 08:55:09 -08:00
|
|
|
| Env_class(s, id, desc) ->
|
2009-05-20 04:52:42 -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) ->
|
2009-05-20 04:52:42 -07:00
|
|
|
Env.add_cltype id (Subst.cltype_declaration subst desc) (env_from_summary s subst)
|
1996-11-29 08:55:09 -08: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
|
1996-11-29 08:55:09 -08:00
|
|
|
let mty =
|
2010-01-22 04:48:24 -08:00
|
|
|
try
|
2009-05-20 04:52:42 -07:00
|
|
|
Env.find_module path' env
|
1996-11-29 08:55:09 -08:00
|
|
|
with Not_found ->
|
2009-05-20 04:52:42 -07:00
|
|
|
raise (Error (Module_not_found path'))
|
1997-03-25 07:29:39 -08:00
|
|
|
in
|
2009-05-20 04:52:42 -07:00
|
|
|
Env.open_signature path' (extract_sig env mty) 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
|
|
|
|
|
|
|
let env_of_event =
|
|
|
|
function
|
|
|
|
None -> Env.empty
|
2009-05-20 04:52:42 -07:00
|
|
|
| Some ev -> env_from_summary ev.Instruct.ev_typenv ev.Instruct.ev_typsubst
|
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
|