1995-08-09 08:06:35 -07:00
|
|
|
(***********************************************************************)
|
|
|
|
(* *)
|
1996-04-30 07:53:58 -07:00
|
|
|
(* Objective Caml *)
|
1995-08-09 08:06:35 -07:00
|
|
|
(* *)
|
|
|
|
(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *)
|
|
|
|
(* *)
|
1996-04-30 07:53:58 -07:00
|
|
|
(* 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. *)
|
1995-08-09 08:06:35 -07:00
|
|
|
(* *)
|
|
|
|
(***********************************************************************)
|
|
|
|
|
|
|
|
(* $Id$ *)
|
|
|
|
|
1995-05-04 03:15:53 -07:00
|
|
|
(* Operations on module types *)
|
|
|
|
|
|
|
|
open Path
|
1996-09-23 04:33:27 -07:00
|
|
|
open Types
|
1995-05-04 03:15:53 -07:00
|
|
|
|
|
|
|
|
|
|
|
let rec scrape env mty =
|
|
|
|
match mty with
|
|
|
|
Tmty_ident p ->
|
1995-11-03 05:23:03 -08:00
|
|
|
begin try
|
1999-11-25 08:47:47 -08:00
|
|
|
scrape env (Env.find_modtype_expansion p env)
|
1995-11-03 05:23:03 -08:00
|
|
|
with Not_found ->
|
|
|
|
mty
|
1995-05-04 03:15:53 -07:00
|
|
|
end
|
|
|
|
| _ -> mty
|
|
|
|
|
|
|
|
let rec strengthen env mty p =
|
|
|
|
match scrape env mty with
|
|
|
|
Tmty_signature sg ->
|
|
|
|
Tmty_signature(strengthen_sig env sg p)
|
1995-08-23 04:55:54 -07:00
|
|
|
| Tmty_functor(param, arg, res) ->
|
|
|
|
Tmty_functor(param, arg, strengthen env res (Papply(p, Pident param)))
|
1995-05-04 03:15:53 -07:00
|
|
|
| mty ->
|
|
|
|
mty
|
|
|
|
|
|
|
|
and strengthen_sig env sg p =
|
|
|
|
match sg with
|
|
|
|
[] -> []
|
|
|
|
| (Tsig_value(id, desc) as sigelt) :: rem ->
|
|
|
|
sigelt :: strengthen_sig env rem p
|
|
|
|
| Tsig_type(id, decl) :: rem ->
|
|
|
|
let newdecl =
|
1995-09-26 13:23:29 -07:00
|
|
|
match decl.type_manifest with
|
|
|
|
None ->
|
2000-09-06 03:21:07 -07:00
|
|
|
{ decl with type_manifest =
|
|
|
|
Some(Btype.newgenty(Tconstr(Pdot(p, Ident.name id, nopos),
|
|
|
|
decl.type_params, ref Mnil))) }
|
1995-05-04 03:15:53 -07:00
|
|
|
| _ -> decl in
|
|
|
|
Tsig_type(id, newdecl) :: strengthen_sig env rem p
|
|
|
|
| (Tsig_exception(id, d) as sigelt) :: rem ->
|
|
|
|
sigelt :: strengthen_sig env rem p
|
|
|
|
| Tsig_module(id, mty) :: rem ->
|
|
|
|
Tsig_module(id, strengthen env mty (Pdot(p, Ident.name id, nopos))) ::
|
|
|
|
strengthen_sig (Env.add_module id mty env) rem p
|
|
|
|
(* Need to add the module in case it defines manifest module types *)
|
|
|
|
| Tsig_modtype(id, decl) :: rem ->
|
|
|
|
let newdecl =
|
|
|
|
match decl with
|
|
|
|
Tmodtype_abstract ->
|
|
|
|
Tmodtype_manifest(Tmty_ident(Pdot(p, Ident.name id, nopos)))
|
|
|
|
| Tmodtype_manifest _ ->
|
|
|
|
decl in
|
|
|
|
Tsig_modtype(id, newdecl) ::
|
|
|
|
strengthen_sig (Env.add_modtype id decl env) rem p
|
|
|
|
(* Need to add the module type in case it is manifest *)
|
1996-04-22 04:15:41 -07:00
|
|
|
| (Tsig_class(id, decl) as sigelt) :: rem ->
|
|
|
|
sigelt :: strengthen_sig env rem p
|
1998-06-24 12:22:26 -07:00
|
|
|
| (Tsig_cltype(id, decl) as sigelt) :: rem ->
|
|
|
|
sigelt :: strengthen_sig env rem p
|
1995-05-04 03:15:53 -07:00
|
|
|
|
|
|
|
(* In nondep_supertype, env is only used for the type it assigns to id.
|
|
|
|
Hence there is no need to keep env up-to-date by adding the bindings
|
|
|
|
traversed. *)
|
|
|
|
|
|
|
|
type variance = Co | Contra | Strict
|
|
|
|
|
1995-05-22 04:58:12 -07:00
|
|
|
let nondep_supertype env mid mty =
|
1995-05-04 03:15:53 -07:00
|
|
|
|
1996-04-22 04:15:41 -07:00
|
|
|
let rec nondep_mty va mty =
|
1995-05-04 03:15:53 -07:00
|
|
|
match mty with
|
|
|
|
Tmty_ident p ->
|
1997-04-01 12:53:02 -08:00
|
|
|
if Path.isfree mid p then
|
|
|
|
nondep_mty va (Env.find_modtype_expansion p env)
|
|
|
|
else mty
|
1995-05-04 03:15:53 -07:00
|
|
|
| Tmty_signature sg ->
|
1996-04-22 04:15:41 -07:00
|
|
|
Tmty_signature(nondep_sig va sg)
|
1995-05-04 03:15:53 -07:00
|
|
|
| Tmty_functor(param, arg, res) ->
|
|
|
|
let var_inv =
|
1996-04-22 04:15:41 -07:00
|
|
|
match va with Co -> Contra | Contra -> Co | Strict -> Strict in
|
|
|
|
Tmty_functor(param, nondep_mty var_inv arg, nondep_mty va res)
|
1995-05-04 03:15:53 -07:00
|
|
|
|
1996-04-22 04:15:41 -07:00
|
|
|
and nondep_sig va = function
|
1995-05-04 03:15:53 -07:00
|
|
|
[] -> []
|
|
|
|
| item :: rem ->
|
1996-04-22 04:15:41 -07:00
|
|
|
let rem' = nondep_sig va rem in
|
1995-05-04 03:15:53 -07:00
|
|
|
match item with
|
|
|
|
Tsig_value(id, d) ->
|
1995-10-17 03:02:47 -07:00
|
|
|
Tsig_value(id, {val_type = Ctype.nondep_type env mid d.val_type;
|
1996-04-22 04:15:41 -07:00
|
|
|
val_kind = d.val_kind}) :: rem'
|
1995-05-04 03:15:53 -07:00
|
|
|
| Tsig_type(id, d) ->
|
1997-03-09 08:52:49 -08:00
|
|
|
Tsig_type(id, Ctype.nondep_type_decl env mid id (va = Co) d) :: rem'
|
1995-05-04 03:15:53 -07:00
|
|
|
| Tsig_exception(id, d) ->
|
1995-10-17 03:02:47 -07:00
|
|
|
Tsig_exception(id, List.map (Ctype.nondep_type env mid) d) :: rem'
|
1995-05-04 03:15:53 -07:00
|
|
|
| Tsig_module(id, mty) ->
|
1996-04-22 04:15:41 -07:00
|
|
|
Tsig_module(id, nondep_mty va mty) :: rem'
|
1995-05-04 03:15:53 -07:00
|
|
|
| Tsig_modtype(id, d) ->
|
|
|
|
begin try
|
|
|
|
Tsig_modtype(id, nondep_modtype_decl d) :: rem'
|
|
|
|
with Not_found ->
|
1996-04-22 04:15:41 -07:00
|
|
|
match va with
|
1995-05-04 03:15:53 -07:00
|
|
|
Co -> Tsig_modtype(id, Tmodtype_abstract) :: rem'
|
|
|
|
| _ -> raise Not_found
|
|
|
|
end
|
1996-04-22 04:15:41 -07:00
|
|
|
| Tsig_class(id, d) ->
|
1998-06-24 12:22:26 -07:00
|
|
|
Tsig_class(id, Ctype.nondep_class_declaration env mid d) :: rem'
|
|
|
|
| Tsig_cltype(id, d) ->
|
|
|
|
Tsig_cltype(id, Ctype.nondep_cltype_declaration env mid d) :: rem'
|
1995-05-04 03:15:53 -07:00
|
|
|
|
|
|
|
and nondep_modtype_decl = function
|
|
|
|
Tmodtype_abstract -> Tmodtype_abstract
|
|
|
|
| Tmodtype_manifest mty -> Tmodtype_manifest(nondep_mty Strict mty)
|
|
|
|
|
|
|
|
in
|
|
|
|
nondep_mty Co mty
|