1 (**************************************************************************)
2 (* *)
3 (* OCaml *)
4 (* *)
5 (* Fabrice Le Fessant, INRIA Saclay *)
6 (* *)
7 (* Copyright 2012 Institut National de Recherche en Informatique et *)
8 (* en Automatique. *)
9 (* *)
10 (* All rights reserved. This file is distributed under the terms of *)
11 (* the GNU Lesser General Public License version 2.1, with the *)
12 (* special exception on linking described in the file LICENSE. *)
13 (* *)
14 (**************************************************************************)
15
16 (** cmt and cmti files format. *)
17
18 open Misc
19
20 (** The layout of a cmt file is as follows:
21 <cmt> := \{<cmi>\} <cmt magic> \{cmt infos\} \{<source info>\}
22 where <cmi> is the cmi file format:
23 <cmi> := <cmi magic> <cmi info>.
24 More precisely, the optional <cmi> part must be present if and only if
25 the file is:
26 - a cmti, or
27 - a cmt, for a ml file which has no corresponding mli (hence no
28 corresponding cmti).
29
30 Thus, we provide a common reading function for cmi and cmt(i)
31 files which returns an option for each of the three parts: cmi
32 info, cmt info, source info. *)
33
34 open Typedtree
35
36 type binary_annots =
37 | Packed of Types.signature * string list
38 | Implementation of structure
39 | Interface of signature
40 | Partial_implementation of binary_part array
41 | Partial_interface of binary_part array
42
43 and binary_part =
44 | Partial_structure of structure
45 | Partial_structure_item of structure_item
46 | Partial_expression of expression
47 | Partial_pattern of pattern
48 | Partial_class_expr of class_expr
49 | Partial_signature of signature
50 | Partial_signature_item of signature_item
51 | Partial_module_type of module_type
52
53 type cmt_infos = {
54 cmt_modname : modname;
55 cmt_annots : binary_annots;
56 cmt_value_dependencies :
57 (Types.value_description * Types.value_description) list;
58 cmt_comments : (string * Location.t) list;
59 cmt_args : string array;
60 cmt_sourcefile : string option;
61 cmt_builddir : string;
62 cmt_loadpath : string list;
63 cmt_source_digest : string option;
64 cmt_initial_env : Env.t;
65 cmt_imports : crcs;
66 cmt_interface_digest : Digest.t option;
67 cmt_use_summaries : bool;
68 }
69
70 type error =
71 Not_a_typedtree of string
72
73 exception Error of error
74
75 (** [read filename] opens filename, and extract both the cmi_infos, if
76 it exists, and the cmt_infos, if it exists. Thus, it can be used
77 with .cmi, .cmt and .cmti files.
78
79 .cmti files always contain a cmi_infos at the beginning. .cmt files
80 only contain a cmi_infos at the beginning if there is no associated
81 .cmti file.
82 *)
83 val read : string -> Cmi_format.cmi_infos option * cmt_infos option
84
85 val read_cmt : string -> cmt_infos
86 val read_cmi : string -> Cmi_format.cmi_infos
87
88 (** [save_cmt filename modname binary_annots sourcefile initial_env cmi]
89 writes a cmt(i) file. *)
90 val save_cmt :
91 string -> (* filename.cmt to generate *)
92 string -> (* module name *)
93 binary_annots ->
94 string option -> (* source file *)
95 Env.t -> (* initial env *)
96 Cmi_format.cmi_infos option -> (* if a .cmi was generated *)
97 unit
98
99 (* Miscellaneous functions *)
100
101 val read_magic_number : in_channel -> string
102
103 val clear: unit -> unit
104
105 val add_saved_type : binary_part -> unit
106 val get_saved_types : unit -> binary_part list
107 val set_saved_types : binary_part list -> unit
108
109 val record_value_dependency:
110 Types.value_description -> Types.value_description -> unit
111
112
113 (*
114
115 val is_magic_number : string -> bool
116 val read : in_channel -> Env.cmi_infos option * t
117 val write_magic_number : out_channel -> unit
118 val write : out_channel -> t -> unit
119
120 val find : string list -> string -> string
121 val read_signature : 'a -> string -> Types.signature * 'b list * 'c list
122
123 *)
124