Module Ocaml_typing.Cmt_format
cmt and cmti files format.
The layout of a cmt file is as follows: <cmt> := {<cmi>} <cmt magic> {cmt infos} {<source info>} where <cmi> is the cmi file format: <cmi> := <cmi magic> <cmi info>. More precisely, the optional <cmi> part must be present if and only if the file is:
- a cmti, or
- a cmt, for a ml file which has no corresponding mli (hence no corresponding cmti).
Thus, we provide a common reading function for cmi and cmt(i) files which returns an option for each of the three parts: cmi info, cmt info, source info.
type binary_annots = | Packed of Ocaml_typing.Types.signature * string list| Implementation of Ocaml_typing.Typedtree.structure| Interface of Ocaml_typing.Typedtree.signature| Partial_implementation of Ocaml_typing.Cmt_format.binary_part array| Partial_interface of Ocaml_typing.Cmt_format.binary_part array
and binary_part = | Partial_structure of Ocaml_typing.Typedtree.structure| Partial_structure_item of Ocaml_typing.Typedtree.structure_item| Partial_expression of Ocaml_typing.Typedtree.expression| Partial_pattern : 'k Ocaml_typing.Typedtree.pattern_category * 'k Ocaml_typing.Typedtree.general_pattern -> Ocaml_typing.Cmt_format.binary_part| Partial_class_expr of Ocaml_typing.Typedtree.class_expr| Partial_signature of Ocaml_typing.Typedtree.signature| Partial_signature_item of Ocaml_typing.Typedtree.signature_item| Partial_module_type of Ocaml_typing.Typedtree.module_type
type cmt_infos = {cmt_modname : Ocaml_typing.Compilation_unit.t;cmt_annots : Ocaml_typing.Cmt_format.binary_annots;cmt_declaration_dependencies : (Ocaml_typing.Cmt_format.dependency_kind * Ocaml_typing.Typedtree.Uid.t * Ocaml_typing.Typedtree.Uid.t) list;cmt_comments : (string * Ocaml_parsing.Location.t) list;cmt_args : string array;cmt_sourcefile : string option;cmt_builddir : string;cmt_loadpath : Ocaml_utils.Load_path.paths;cmt_source_digest : string option;cmt_initial_env : Ocaml_typing.Env.t;cmt_imports : Ocaml_typing.Import_info.t array;cmt_interface_digest : Stdlib.Digest.t option;cmt_use_summaries : bool;cmt_uid_to_decl : Ocaml_typing.Typedtree.item_declaration Ocaml_typing.Shape.Uid.Tbl.t;cmt_impl_shape : Ocaml_typing.Shape.t option;cmt_ident_occurrences : (Ocaml_parsing.Longident.t Ocaml_parsing.Location.loc * Ocaml_typing.Shape_reduce.result) array;
}exception Error of Ocaml_typing.Cmt_format.errorval read :
string ->
Ocaml_typing.Cmi_format.cmi_infos_lazy option
* Ocaml_typing.Cmt_format.cmt_infos optionread filename opens filename, and extract both the cmi_infos, if it exists, and the cmt_infos, if it exists. Thus, it can be used with .cmi, .cmt and .cmti files.
.cmti files always contain a cmi_infos at the beginning. .cmt files only contain a cmi_infos at the beginning if there is no associated .cmti file.
val read_cmt : string -> Ocaml_typing.Cmt_format.cmt_infosval read_cmi : string -> Ocaml_typing.Cmi_format.cmi_infos_lazyval save_cmt :
Ocaml_typing.Unit_info.Artifact.t ->
Ocaml_typing.Compilation_unit.t ->
Ocaml_typing.Cmt_format.binary_annots ->
Ocaml_typing.Env.t ->
Ocaml_typing.Cmi_format.cmi_infos_lazy option ->
Ocaml_typing.Shape.t option ->
unitsave_cmt filename modname binary_annots sourcefile initial_env cmi writes a cmt(i) file.
val read_magic_number : Stdlib.in_channel -> stringval add_saved_type : Ocaml_typing.Cmt_format.binary_part -> unitval get_saved_types : unit -> Ocaml_typing.Cmt_format.binary_part listval set_saved_types : Ocaml_typing.Cmt_format.binary_part list -> unitval get_declaration_dependencies :
unit ->
(Ocaml_typing.Cmt_format.dependency_kind
* Ocaml_typing.Typedtree.Uid.t
* Ocaml_typing.Typedtree.Uid.t)
listval record_declaration_dependency :
(Ocaml_typing.Cmt_format.dependency_kind
* Ocaml_typing.Typedtree.Uid.t
* Ocaml_typing.Typedtree.Uid.t) ->
unitval index_occurrences :
Ocaml_typing.Cmt_format.binary_annots ->
(Ocaml_parsing.Longident.t Ocaml_parsing.Location.loc
* Ocaml_typing.Shape_reduce.result)
arrayval iter_declarations :
Ocaml_typing.Cmt_format.binary_annots ->
f:
(Ocaml_typing.Shape.Uid.t ->
Ocaml_typing.Typedtree.item_declaration ->
unit) ->
unitWhether only the summary of the environment should be stored. This is based on whether the environment variable OCAML_BINANNOT_WITHENV is set
val iter_on_declarations :
f:
(Ocaml_typing.Types.Uid.t ->
Ocaml_typing.Typedtree.item_declaration ->
unit) ->
Ocaml_typing.Tast_iterator.iteratorval iter_on_occurrences :
f:
(namespace:Ocaml_typing.Shape.Sig_component_kind.t ->
Ocaml_typing.Env.t ->
Ocaml_typing.Path.t ->
Ocaml_parsing.Longident.t Ocaml_parsing.Location.loc ->
unit) ->
Ocaml_typing.Tast_iterator.iterator