Module 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 Types.signature * string list| Implementation of Typedtree.structure| Interface of Typedtree.signature| Partial_implementation of Cmt_format.binary_part array| Partial_interface of Cmt_format.binary_part array
and binary_part = | Partial_structure of Typedtree.structure| Partial_structure_item of Typedtree.structure_item| Partial_expression of Typedtree.expression| Partial_pattern : 'k Typedtree.pattern_category * 'k Typedtree.general_pattern -> Cmt_format.binary_part| Partial_class_expr of Typedtree.class_expr| Partial_signature of Typedtree.signature| Partial_signature_item of Typedtree.signature_item| Partial_module_type of Typedtree.module_type
type cmt_infos = {cmt_modname : Compilation_unit.t;cmt_annots : Cmt_format.binary_annots;cmt_declaration_dependencies : (Cmt_format.dependency_kind * Typedtree.Uid.t * Typedtree.Uid.t) list;cmt_comments : (string * Location.t) list;cmt_args : string array;cmt_sourcefile : string option;cmt_builddir : string;cmt_loadpath : Load_path.paths;cmt_source_digest : string option;cmt_initial_env : Env.t;cmt_imports : Import_info.t array;cmt_interface_digest : Stdlib.Digest.t option;cmt_use_summaries : bool;cmt_uid_to_decl : Typedtree.item_declaration Shape.Uid.Tbl.t;cmt_impl_shape : Shape.t option;cmt_ident_occurrences : (Longident.t Location.loc * Shape_reduce.result) array;
}exception Error of Cmt_format.errorval read :
string ->
Cmi_format.cmi_infos_lazy option * 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 -> Cmt_format.cmt_infosval read_cmi : string -> Cmi_format.cmi_infos_lazyval save_cmt :
Unit_info.Artifact.t ->
Compilation_unit.t ->
Cmt_format.binary_annots ->
Env.t ->
Cmi_format.cmi_infos_lazy option ->
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 : Cmt_format.binary_part -> unitval get_saved_types : unit -> Cmt_format.binary_part listval set_saved_types : Cmt_format.binary_part list -> unitval record_declaration_dependency :
(Cmt_format.dependency_kind * Typedtree.Uid.t * Typedtree.Uid.t) ->
unitval index_occurrences :
Cmt_format.binary_annots ->
(Longident.t Location.loc * Shape_reduce.result) arrayval iter_declarations :
Cmt_format.binary_annots ->
f:(Shape.Uid.t -> 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 get_declaration_dependencies :
unit ->
(Cmt_format.dependency_kind * Typedtree.Uid.t * Typedtree.Uid.t) list