diff options
author | Fabrice Le Fessant <fabrice@lefessant.net> | 2016-07-12 20:14:50 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-07-12 20:14:50 +0200 |
commit | 18cd8a6c0123e4ba6e7858d5bf2e7ed1e86316ef (patch) | |
tree | 82f180a9afd228dcbd341cc351cd8699e6fd4bc8 /typing | |
parent | 1e7b1d9f17a2021595674b0180934269050df0c3 (diff) | |
parent | d9f43d733ee9765e955abc5b24b2c6dc20f2c4fc (diff) | |
download | ocaml-18cd8a6c0123e4ba6e7858d5bf2e7ed1e86316ef.tar.gz |
Merge pull request #647 from lefessan/2016-06-29-compilation-hooks
Add hooks on some compilation phases
Diffstat (limited to 'typing')
-rw-r--r-- | typing/typemod.ml | 22 | ||||
-rw-r--r-- | typing/typemod.mli | 8 |
2 files changed, 26 insertions, 4 deletions
diff --git a/typing/typemod.ml b/typing/typemod.ml index e4aad88ac4..44e653ff26 100644 --- a/typing/typemod.ml +++ b/typing/typemod.ml @@ -47,6 +47,13 @@ type error = exception Error of Location.t * Env.t * error exception Error_forward of Location.error +module ImplementationHooks = Misc.MakeHooks(struct + type t = Typedtree.structure * Typedtree.module_coercion + end) +module InterfaceHooks = Misc.MakeHooks(struct + type t = Typedtree.signature + end) + open Typedtree let fst3 (x,_,_) = x @@ -1477,7 +1484,13 @@ let type_toplevel_phrase env s = let iter = Builtin_attributes.emit_external_warnings in iter.Ast_iterator.structure iter s end; - type_structure ~toplevel:true false None env s Location.none + let (str, sg, env) = + type_structure ~toplevel:true false None env s Location.none in + let (str, _coerce) = ImplementationHooks.apply_hooks + { Misc.sourcefile = "//toplevel//" } (str, Tcoerce_none) + in + (str, sg, env) + let type_module_alias = type_module ~alias:true true false None let type_module = type_module true false None let type_structure = type_structure false None @@ -1641,17 +1654,20 @@ let type_implementation sourcefile outputprefix modulename initial_env ast = (Some sourcefile) initial_env None; raise e +let type_implementation sourcefile outputprefix modulename initial_env ast = + ImplementationHooks.apply_hooks { Misc.sourcefile } + (type_implementation sourcefile outputprefix modulename initial_env ast) let save_signature modname tsg outputprefix source_file initial_env cmi = Cmt_format.save_cmt (outputprefix ^ ".cmti") modname (Cmt_format.Interface tsg) (Some source_file) initial_env (Some cmi) -let type_interface env ast = +let type_interface sourcefile env ast = begin let iter = Builtin_attributes.emit_external_warnings in iter.Ast_iterator.signature iter ast end; - transl_signature env ast + InterfaceHooks.apply_hooks { Misc.sourcefile } (transl_signature env ast) (* "Packaging" of several compilation units into one unit having them as sub-modules. *) diff --git a/typing/typemod.mli b/typing/typemod.mli index 975a5a6852..40172bccbd 100644 --- a/typing/typemod.mli +++ b/typing/typemod.mli @@ -30,7 +30,7 @@ val type_implementation: string -> string -> string -> Env.t -> Parsetree.structure -> Typedtree.structure * Typedtree.module_coercion val type_interface: - Env.t -> Parsetree.signature -> Typedtree.signature + string -> Env.t -> Parsetree.signature -> Typedtree.signature val transl_signature: Env.t -> Parsetree.signature -> Typedtree.signature val check_nongen_schemes: @@ -79,3 +79,9 @@ exception Error of Location.t * Env.t * error exception Error_forward of Location.error val report_error: Env.t -> formatter -> error -> unit + + +module ImplementationHooks : Misc.HookSig + with type t = Typedtree.structure * Typedtree.module_coercion +module InterfaceHooks : Misc.HookSig + with type t = Typedtree.signature |