Skip to content
This repository
Newer
Older
100644 278 lines (235 sloc) 9.11 kb
fccc6851 » MLstate
2011-06-21 Initial open-source release
1 (*
2 Copyright © 2011 MLstate
3
4 This file is part of OPA.
5
6 OPA is free software: you can redistribute it and/or modify it under the
7 terms of the GNU Affero General Public License, version 3, as published by
8 the Free Software Foundation.
9
10 OPA is distributed in the hope that it will be useful, but WITHOUT ANY
11 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for
13 more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with OPA. If not, see <http://www.gnu.org/licenses/>.
17 *)
18 (**)
19
20 (**
21 Type alias for lisibility.
22 *)
23 type package_name = string (* foo *)
24 type package = package_name * FilePos.pos
25 type filename = string (* path/foo.opx *)
26 type basename = string (* foo.opx *)
27 type hash = string
28 type content = string
29
30 type 'code_elt parsed_code = (filename * content * 'code_elt list) list
31
32 module Package :
33 sig
34 type t = package
35 val compare : t -> t -> int
36 val equal : t -> t -> bool
37
38 (**
39 Prints the name of the package
40 *)
41 val pp : Format.formatter -> package -> unit
42
43 (**
44 Prints the name of the package and its position
45 (the position where the package was imported)
46 *)
47 val pp_full : Format.formatter -> package -> unit
48 end
49 module PackageTbl : Hashtbl.S with type key = Package.t
50
51 (** {6 Current package} *)
52 (**
53 Get informations about the current packages being compiling.
54 If linking mode, or not separated mode, returns informations
55 of a dummy linking_packages, with an ["", nopos]
56 *)
57
58 val get_current_package : unit -> package
59 val get_current_package_name : unit -> package_name
60
61 (**
62 These two functions returns are injections from package to string
63 (ie there are no collisions) that 'remove' specials characters
64 that may appears in package names but that are not valid in js/caml
65 *)
66 val get_current_package_name_as_a_valid_ident : ?will_be_prefixed:bool -> unit -> string
67 val get_package_name_as_a_valid_ident : ?will_be_prefixed:bool -> package_name -> string
68 val get_package_as_a_valid_ident : ?will_be_prefixed:bool -> package -> string
69
70 (**
71 Not for casual user. Should be called only by the corresponding pass.
72 *)
73 val end_of_separate_compilation : unit -> unit
74 val global_compilation : unit -> bool (** true if we are not separated or if we are after the end of separate compilation *)
75 val last_pass : string
76 val no_init : bool ref (* used by qmlCompilers because it links but doesn't init *)
77
78 (**
79 Get the opx directory corresponding to the compilation of the current package.
80 If we are in linking mode, or if the separation mode is not activated, the
81 function returns [None]
82 *)
83 val get_compilation_directory : unit -> filename option
84 val get_compilation_directory_or_current_dir : unit -> filename
85
86 (**
87 Set extra paths, from the -I command line options
88 *)
89 val set_extrapaths : no_stdlib:bool -> filename list -> unit
90
91 (**
92 Set plugins version, from the loaded plugins
93 *)
94 val set_bsl_plugins : (basename * hash) list -> unit
95
96 (**
97 expand syntax of import directives, for package or plugins
98 *)
99 val expand_glob :
100 ?mode:[`package|`plugin] -> Package.t list -> (package_name * FilePos.pos) -> Package.t list
101
102 (**
103 [load_conf filename] load the configuration of packaging architecture
104 for the current project. Used with --autobuild option, this may speed-up
105 refactoring and packaging of big projects.
106 *)
107 val load_conf : filename -> unit
108
109 (**
110 [load filename content code]
111 check the validity of the 'Package' declarations from the code, and removes them
112 loads the dependency of the given code, and update the current package
113 It check the existence of .opx but doesn't load anything
114 *)
115 val load :
116 ?extrajs:string list ->
117 no_stdlib:bool ->
118 ('code_elt -> ([< `declaration | `import ] * package_name * FilePos.pos) option) ->
119 ('code_elt list -> float option StringMap.t) ->
120 'code_elt parsed_code ->
121 ('code_elt parsed_code -> unit) ->
122 unit
123
124 (**
125 Fold on all the dependencies of the current package in the order of dependencies
126 @param packages when [true], also fold on the packages that are linked
127 default is [false]
128 @param deep when [true], fold on the transitive dependencies
129 default is [false]
130 [filename] is the name of the directory containing all the information about the package
131 (stdlib.core.opx for instance)
132 *)
133 val fold_dir : ?packages:bool -> ?deep:bool -> ('a -> filename -> 'a) -> 'a -> 'a
134 val fold_dir_name : ?packages:bool -> ?deep:bool -> ('a -> filename -> package -> 'a) -> 'a -> 'a
135 val fold_name : ?packages:bool -> ?deep:bool -> ('a -> package -> 'a) -> 'a -> 'a
136 val iter_dir : ?packages:bool -> ?deep:bool -> (filename -> unit) -> unit
137 val iter_dir_name : ?packages:bool -> ?deep:bool -> (filename -> package -> unit) -> unit
138 val iter_name : ?packages:bool -> ?deep:bool -> (package -> unit) -> unit
139
140 (**
141 What the passes that need object files provide
142 [t] is the type t to be stored
143 [pass] is just the name of the pass
144 The type t is going to be marshalled, so you may need to be refresh
145 them when you load them
146 *)
147 module type S =
148 sig
149 type t
150 val pass : string (* don't use wierd chars in here, it will be a filename *)
151 val pp : Format.formatter -> t -> unit
152 end
153
154 (**
155 What the following functor provides:
156 [save] saves the given object in the current package
157 [fold] to get the content of the object files
158 *)
159 (* could avoid the functorization *)
160 (* actual loading happens lazily, not at functor application *)
161 module type R =
162 sig
163 type 'a wrapper
164 type t
165
166 (**
167 All the iteration functions take the parameter and iterate in the same order
168 as [fold_dir].
169
170 packages: packages linked in the command line only
171 deep: transitive dependencies
172 *)
173
174 val iter_with_name : (?packages:bool -> ?deep:bool -> (package -> t -> unit) -> unit) wrapper
175 val fold_with_name : (?packages:bool -> ?deep:bool -> (package -> 'acc -> t -> 'acc) -> 'acc -> 'acc) wrapper
176 val iter_with_dir : (?packages:bool -> ?deep:bool -> (filename -> t -> unit) -> unit) wrapper
177 val fold_with_dir : (?packages:bool -> ?deep:bool -> (filename -> 'a -> t -> 'a) -> 'a -> 'a) wrapper
178 val iter : (?packages:bool -> ?deep:bool -> (t -> unit) -> unit) wrapper
179 val fold : (?packages:bool -> ?deep:bool -> ('acc -> t -> 'acc) -> 'acc -> 'acc) wrapper
180
181 (**
182 Save the current information to the disk
183 Only the information about the current package should be saved, not the
184 whole environment that results from merging the environment of the dependencies with
185 the current environment
186 *)
187 val save : (t -> unit) wrapper
188 end
189
190 module Make : functor (S:S) -> R with type t = S.t and type 'a wrapper = 'a
191
192 (** same as Make but with Client/Server variant *)
193 module MakeClientServer : functor (S:S) -> R with type t = S.t and type 'a wrapper = side:[`client | `server] -> 'a
194
195 (**
196 Compilation mode.
197 Used as a global imperative state of the compiler.
198 Set by the arg parser, and then, read by any pass which need to select its process
199 according to the current mode.
200 *)
201 type compilation_mode = [
202 | `prelude
203 | `init
204 | `linking
205 | `compilation
206 ]
207
208 (** Returns the current compilation mode. *)
209 val compilation_mode : unit -> compilation_mode
210
211 module Arg :
212 sig
213 (**
214 Concatenation of all specs in interaction with this module.
215
216 + [-c] Compile the current package
217 + [--package] Add package for linking.
218 *)
219 val public_options : (Base.Arg.key * Base.Arg.spec * Base.Arg.doc) list
220 val private_options : (Base.Arg.key * Base.Arg.spec * Base.Arg.doc) list
221
222 (**
223 Since the anonfun of the compiler may add directly packages to link with,
224 the function add_link_package is also exported.
225 This is possible to call opa with a few opx files, for relinking.
226 *)
227 val add_link_package : filename -> unit
228
229 (**
230 Used by the pass_CheckOptions to know if there is nothing to do.
231 *)
232 val no_packages : unit -> bool
233
234 (**
235 Used by some passes in the transitional period,
236 or for some tests, or qmljs in command line.
237 *)
238 val is_separated : unit -> bool
239
240 (** same as above *)
241 val is_fully_separated : unit -> bool
242
243 (**
244 Option used for producing some dependencies graphs.
245 *)
246 val is_opadep : unit -> bool
247 end
248
249 (**
250 {5 Warnings}
251 *)
252 val warning_set : WarningClass.Set.t
253
254
255 (**
256 The packages that contain values that the compiler can call
257 *)
258 val stdlib_packages : package -> bool
259 val stdlib_package_names : package_name -> bool
260
261 (**
262 Loads the js extra lib with the given basename
263 *)
264 val find_js_file_content_digest : basename -> filename * content * hash
265
266 (**
267 Used by the rest of the compiler to tells objectFiles
268 that the current package has been compiled successfully
269 and so must not be deleted
270 *)
271 val compilation_is_successfull : unit -> unit
272
273 (**
274 Turn off separated compilation.
275 This function should be used only by tools not using a separated compilation at all,
276 and not using the standard Arg of this module.
277 *)
278 val turn_separated_off : unit -> unit
Something went wrong with that request. Please try again.