Skip to content
This repository
tag: v671
Fetching contributors…

Cannot retrieve contributors at this time

file 283 lines (239 sloc) 9.242 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283
(*
Copyright © 2011 MLstate

This file is part of OPA.

OPA is free software: you can redistribute it and/or modify it under the
terms of the GNU Affero General Public License, version 3, as published by
the Free Software Foundation.

OPA is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for
more details.

You should have received a copy of the GNU Affero General Public License
along with OPA. If not, see <http://www.gnu.org/licenses/>.
*)
(**)

(**
Type alias for lisibility.
*)
type package_name = string (* foo *)
type package = package_name * FilePos.pos
type filename = string (* path/foo.opx *)
type basename = string (* foo.opx *)
type hash = string
type content = string

type 'code_elt parsed_code = (filename * content * 'code_elt list) list

module Package :
sig
  type t = package
  val compare : t -> t -> int
  val equal : t -> t -> bool

  (**
Prints the name of the package
*)
  val pp : Format.formatter -> package -> unit

  (**
Prints the name of the package and its position
(the position where the package was imported)
*)
  val pp_full : Format.formatter -> package -> unit
end
module PackageTbl : Hashtbl.S with type key = Package.t

(** {6 Current package} *)
(**
Get informations about the current packages being compiling.
If linking mode, or not separated mode, returns informations
of a dummy linking_packages, with an ["", nopos]
*)

val get_current_package : unit -> package
val get_current_package_name : unit -> package_name

(**
These two functions returns are injections from package to string
(ie there are no collisions) that 'remove' specials characters
that may appears in package names but that are not valid in js/caml
*)
val get_current_package_name_as_a_valid_ident : ?will_be_prefixed:bool -> unit -> string
val get_package_name_as_a_valid_ident : ?will_be_prefixed:bool -> package_name -> string
val get_package_as_a_valid_ident : ?will_be_prefixed:bool -> package -> string

(**
Not for casual user. Should be called only by the corresponding pass.
*)
val end_of_separate_compilation : unit -> unit
val global_compilation : unit -> bool (** true if we are not separated or if we are after the end of separate compilation *)
val last_pass : string
val no_init : bool ref (* used by qmlCompilers because it links but doesn't init *)

(**
Get the opx directory corresponding to the compilation of the current package.
If we are in linking mode, or if the separation mode is not activated, the
function returns [None]
*)
val get_compilation_directory : unit -> filename option
val get_compilation_directory_or_current_dir : unit -> filename

(**
Set extra paths, from the -I command line options
*)
val set_extrapaths : no_stdlib:bool -> filename list -> unit

(**
Set plugins version, from the loaded plugins
*)
val set_bsl_plugins : (basename * hash) list -> unit

(**
test existence of a package given known or given extrapath
*)
val exists_package : ?extrapath:string list -> string -> bool

(**
expand syntax of import directives, for package or plugins
*)
val expand_glob :
  ?mode:[`package|`plugin] -> Package.t list -> (package_name * FilePos.pos) -> Package.t list

(**
[load_conf filename] load the configuration of packaging architecture
for the current project. Used with --autobuild option, this may speed-up
refactoring and packaging of big projects.
*)
val load_conf : filename -> unit

(**
[load filename content code]
check the validity of the 'Package' declarations from the code, and removes them
loads the dependency of the given code, and update the current package
It check the existence of .opx but doesn't load anything
*)
val load :
  ?extrajs:string list ->
  no_stdlib:bool ->
  ('code_elt -> ([< `declaration | `import ] * package_name * FilePos.pos) option) ->
  ('code_elt list -> float option StringMap.t) ->
  'code_elt parsed_code ->
  ('code_elt parsed_code -> unit) ->
  unit

(**
Fold on all the dependencies of the current package in the order of dependencies
@param packages when [true], also fold on the packages that are linked
default is [false]
@param deep when [true], fold on the transitive dependencies
default is [false]
[filename] is the name of the directory containing all the information about the package
(stdlib.core.opx for instance)
*)
val fold_dir : ?packages:bool -> ?deep:bool -> ('a -> filename -> 'a) -> 'a -> 'a
val fold_dir_name : ?packages:bool -> ?deep:bool -> ('a -> filename -> package -> 'a) -> 'a -> 'a
val fold_name : ?packages:bool -> ?deep:bool -> ('a -> package -> 'a) -> 'a -> 'a
val iter_dir : ?packages:bool -> ?deep:bool -> (filename -> unit) -> unit
val iter_dir_name : ?packages:bool -> ?deep:bool -> (filename -> package -> unit) -> unit
val iter_name : ?packages:bool -> ?deep:bool -> (package -> unit) -> unit

(**
What the passes that need object files provide
[t] is the type t to be stored
[pass] is just the name of the pass
The type t is going to be marshalled, so you may need to be refresh
them when you load them
*)
module type S =
sig
  type t
  val pass : string (* don't use wierd chars in here, it will be a filename *)
  val pp : Format.formatter -> t -> unit
end

(**
What the following functor provides:
[save] saves the given object in the current package
[fold] to get the content of the object files
*)
(* could avoid the functorization *)
(* actual loading happens lazily, not at functor application *)
module type R =
sig
  type 'a wrapper
  type t

  (**
All the iteration functions take the parameter and iterate in the same order
as [fold_dir].

packages: packages linked in the command line only
deep: transitive dependencies
*)

  val iter_with_name : (?packages:bool -> ?deep:bool -> (package -> t -> unit) -> unit) wrapper
  val fold_with_name : (?packages:bool -> ?deep:bool -> (package -> 'acc -> t -> 'acc) -> 'acc -> 'acc) wrapper
  val iter_with_dir : (?packages:bool -> ?deep:bool -> (filename -> t -> unit) -> unit) wrapper
  val fold_with_dir : (?packages:bool -> ?deep:bool -> (filename -> 'a -> t -> 'a) -> 'a -> 'a) wrapper
  val iter : (?packages:bool -> ?deep:bool -> (t -> unit) -> unit) wrapper
  val fold : (?packages:bool -> ?deep:bool -> ('acc -> t -> 'acc) -> 'acc -> 'acc) wrapper

  (**
Save the current information to the disk
Only the information about the current package should be saved, not the
whole environment that results from merging the environment of the dependencies with
the current environment
*)
  val save : (t -> unit) wrapper
end

module Make : functor (S:S) -> R with type t = S.t and type 'a wrapper = 'a

(** same as Make but with Client/Server variant *)
module MakeClientServer : functor (S:S) -> R with type t = S.t and type 'a wrapper = side:[`client | `server] -> 'a

(**
Compilation mode.
Used as a global imperative state of the compiler.
Set by the arg parser, and then, read by any pass which need to select its process
according to the current mode.
*)
type compilation_mode = [
  | `prelude
  | `init
  | `linking
  | `compilation
]

(** Returns the current compilation mode. *)
val compilation_mode : unit -> compilation_mode

module Arg :
sig
  (**
Concatenation of all specs in interaction with this module.

+ [-c] Compile the current package
+ [--package] Add package for linking.
*)
  val public_options : (Base.Arg.key * Base.Arg.spec * Base.Arg.doc) list
  val private_options : (Base.Arg.key * Base.Arg.spec * Base.Arg.doc) list

  (**
Since the anonfun of the compiler may add directly packages to link with,
the function add_link_package is also exported.
This is possible to call opa with a few opx files, for relinking.
*)
  val add_link_package : filename -> unit

  (**
Used by the pass_CheckOptions to know if there is nothing to do.
*)
  val no_packages : unit -> bool

  (**
Used by some passes in the transitional period,
or for some tests, or qmljs in command line.
*)
  val is_separated : unit -> bool

  (** same as above *)
  val is_fully_separated : unit -> bool

  (**
Option used for producing some dependencies graphs.
*)
  val is_opadep : unit -> bool
end

(**
{5 Warnings}
*)
val warning_set : WarningClass.Set.t


(**
The packages that contain values that the compiler can call
*)
val stdlib_packages : package -> bool
val stdlib_package_names : package_name -> bool

(**
Loads the js extra lib with the given basename
*)
val find_js_file_content_digest : basename -> filename * content * hash

(**
Used by the rest of the compiler to tells objectFiles
that the current package has been compiled successfully
and so must not be deleted
*)
val compilation_is_successfull : unit -> unit

(**
Turn off separated compilation.
This function should be used only by tools not using a separated compilation at all,
and not using the standard Arg of this module.
*)
val turn_separated_off : unit -> unit
Something went wrong with that request. Please try again.