jon.recoil.org

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:

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 =
  1. | Packed of Ocaml_typing.Types.signature * string list
  2. | Implementation of Ocaml_typing.Typedtree.structure
  3. | Interface of Ocaml_typing.Typedtree.signature
  4. | Partial_implementation of Ocaml_typing.Cmt_format.binary_part array
  5. | Partial_interface of Ocaml_typing.Cmt_format.binary_part array
type dependency_kind =
  1. | Definition_to_declaration
  2. | Declaration_to_declaration
type cmt_infos = {
  1. cmt_modname : Ocaml_typing.Compilation_unit.t;
  2. cmt_annots : Ocaml_typing.Cmt_format.binary_annots;
  3. cmt_declaration_dependencies : (Ocaml_typing.Cmt_format.dependency_kind * Ocaml_typing.Typedtree.Uid.t * Ocaml_typing.Typedtree.Uid.t) list;
  4. cmt_comments : (string * Ocaml_parsing.Location.t) list;
  5. cmt_args : string array;
  6. cmt_sourcefile : string option;
  7. cmt_builddir : string;
  8. cmt_loadpath : Ocaml_utils.Load_path.paths;
  9. cmt_source_digest : string option;
  10. cmt_initial_env : Ocaml_typing.Env.t;
  11. cmt_imports : Ocaml_typing.Import_info.t array;
  12. cmt_interface_digest : Stdlib.Digest.t option;
  13. cmt_use_summaries : bool;
  14. cmt_uid_to_decl : Ocaml_typing.Typedtree.item_declaration Ocaml_typing.Shape.Uid.Tbl.t;
  15. cmt_impl_shape : Ocaml_typing.Shape.t option;
  16. cmt_ident_occurrences : (Ocaml_parsing.Longident.t Ocaml_parsing.Location.loc * Ocaml_typing.Shape_reduce.result) array;
}
type error =
  1. | Not_a_typedtree of string

read 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_infos

save_cmt filename modname binary_annots sourcefile initial_env cmi writes a cmt(i) file.

val read_magic_number : Stdlib.in_channel -> string
val clear : unit -> unit
val add_saved_type : Ocaml_typing.Cmt_format.binary_part -> unit
val get_saved_types : unit -> Ocaml_typing.Cmt_format.binary_part list
val set_saved_types : Ocaml_typing.Cmt_format.binary_part list -> unit
val need_to_clear_env : bool

Whether only the summary of the environment should be stored. This is based on whether the environment variable OCAML_BINANNOT_WITHENV is set