152
153
components of signatures. For types, retain only their arity,
153
154
making them abstract otherwise. *)
155
let approx_modtype transl_mty init_env smty =
157
let rec approx_mty env smty =
158
match smty.pmty_desc with
161
let (path, info) = Env.lookup_modtype lid env in
164
raise(Error(smty.pmty_loc, Unbound_modtype lid))
166
| Pmty_signature ssg ->
167
Tmty_signature(approx_sig env ssg)
168
| Pmty_functor(param, sarg, sres) ->
169
let arg = approx_mty env sarg in
170
let (id, newenv) = Env.enter_module param arg env in
171
let res = approx_mty newenv sres in
172
Tmty_functor(id, arg, res)
173
| Pmty_with(sbody, constraints) ->
176
and approx_sig env ssg =
180
match item.psig_desc with
181
| Psig_type sdecls ->
182
let decls = Typedecl.approx_type_decl env sdecls in
183
let rem = approx_sig env srem in
184
map_rec' (fun rs (id, info) -> Tsig_type(id, info, rs)) decls rem
185
| Psig_module(name, smty) ->
186
let mty = approx_mty env smty in
187
let (id, newenv) = Env.enter_module name mty env in
188
Tsig_module(id, mty, Trec_not) :: approx_sig newenv srem
189
| Psig_recmodule sdecls ->
193
(Ident.create name, approx_mty env smty))
196
List.fold_left (fun env (id, mty) -> Env.add_module id mty env)
198
map_rec (fun rs (id, mty) -> Tsig_module(id, mty, rs)) decls
199
(approx_sig newenv srem)
200
| Psig_modtype(name, sinfo) ->
201
let info = approx_mty_info env sinfo in
202
let (id, newenv) = Env.enter_modtype name info env in
203
Tsig_modtype(id, info) :: approx_sig newenv srem
205
let (path, mty) = type_module_path env item.psig_loc lid in
206
let sg = extract_sig_open env item.psig_loc mty in
207
let newenv = Env.open_signature path sg env in
208
approx_sig newenv srem
209
| Psig_include smty ->
210
let mty = transl_mty init_env smty in
211
let sg = Subst.signature Subst.identity
212
(extract_sig env smty.pmty_loc mty) in
213
let newenv = Env.add_signature sg env in
214
sg @ approx_sig newenv srem
215
| Psig_class sdecls | Psig_class_type sdecls ->
216
let decls = Typeclass.approx_class_declarations env sdecls in
217
let rem = approx_sig env srem in
220
(fun rs (i1, d1, i2, d2, i3, d3) ->
221
[Tsig_cltype(i1, d1, rs);
222
Tsig_type(i2, d2, rs);
223
Tsig_type(i3, d3, rs)])
228
and approx_mty_info env sinfo =
232
| Pmodtype_manifest smty ->
233
Tmodtype_manifest(approx_mty env smty)
235
in approx_mty init_env smty
156
let rec approx_modtype env smty =
157
match smty.pmty_desc with
160
let (path, info) = Env.lookup_modtype lid env in
163
raise(Error(smty.pmty_loc, Unbound_modtype lid))
165
| Pmty_signature ssg ->
166
Tmty_signature(approx_sig env ssg)
167
| Pmty_functor(param, sarg, sres) ->
168
let arg = approx_modtype env sarg in
169
let (id, newenv) = Env.enter_module param arg env in
170
let res = approx_modtype newenv sres in
171
Tmty_functor(id, arg, res)
172
| Pmty_with(sbody, constraints) ->
173
approx_modtype env sbody
175
and approx_sig env ssg =
179
match item.psig_desc with
180
| Psig_type sdecls ->
181
let decls = Typedecl.approx_type_decl env sdecls in
182
let rem = approx_sig env srem in
183
map_rec' (fun rs (id, info) -> Tsig_type(id, info, rs)) decls rem
184
| Psig_module(name, smty) ->
185
let mty = approx_modtype env smty in
186
let (id, newenv) = Env.enter_module name mty env in
187
Tsig_module(id, mty, Trec_not) :: approx_sig newenv srem
188
| Psig_recmodule sdecls ->
192
(Ident.create name, approx_modtype env smty))
195
List.fold_left (fun env (id, mty) -> Env.add_module id mty env)
197
map_rec (fun rs (id, mty) -> Tsig_module(id, mty, rs)) decls
198
(approx_sig newenv srem)
199
| Psig_modtype(name, sinfo) ->
200
let info = approx_modtype_info env sinfo in
201
let (id, newenv) = Env.enter_modtype name info env in
202
Tsig_modtype(id, info) :: approx_sig newenv srem
204
let (path, mty) = type_module_path env item.psig_loc lid in
205
let sg = extract_sig_open env item.psig_loc mty in
206
let newenv = Env.open_signature path sg env in
207
approx_sig newenv srem
208
| Psig_include smty ->
209
let mty = approx_modtype env smty in
210
let sg = Subst.signature Subst.identity
211
(extract_sig env smty.pmty_loc mty) in
212
let newenv = Env.add_signature sg env in
213
sg @ approx_sig newenv srem
214
| Psig_class sdecls | Psig_class_type sdecls ->
215
let decls = Typeclass.approx_class_declarations env sdecls in
216
let rem = approx_sig env srem in
219
(fun rs (i1, d1, i2, d2, i3, d3) ->
220
[Tsig_cltype(i1, d1, rs);
221
Tsig_type(i2, d2, rs);
222
Tsig_type(i3, d3, rs)])
227
and approx_modtype_info env sinfo =
231
| Pmodtype_manifest smty ->
232
Tmodtype_manifest(approx_modtype env smty)
237
234
(* Additional validity checks on type definitions arising from
238
235
recursive modules *)