Skip to content
This repository
branch: typer_improvem…
Fetching contributors…

Cannot retrieve contributors at this time

file 135 lines (118 sloc) 5.504 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
(*
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 relevant_options =
    { back_end : OpaEnv.available_back_end
    ; js_back_end : string
    ; closure : bool
    ; cps : bool
    ; cps_client : bool
    ; cps_toplevel_concurrency : bool
    ; explicit_instantiation : bool
    ; value_restriction : [`disabled | `normal | `strict] }

module S =
struct
  type t = relevant_options
  let pass = "CheckOptionsConsistency"
  let pp f _ = Format.pp_print_string f "<dummy>"
end

module R = ObjectFiles.Make(S)

let project options =
  { back_end = options.OpaEnv.back_end
  ; js_back_end =
      (let module B = (val options.OpaEnv.js_back_end : Qml2jsOptions.JsBackend) in
       B.name)
  ; closure = options.OpaEnv.closure
  ; cps = options.OpaEnv.cps
  ; cps_client = options.OpaEnv.cps_client
  ; cps_toplevel_concurrency = options.OpaEnv.cps_toplevel_concurrency
  ; explicit_instantiation = options.OpaEnv.explicit_instantiation
  ; value_restriction = options.OpaEnv.value_restriction }

let with_or_without = function
  | true -> "with"
  | false -> "without"
let would = function
  | true -> "wouldn't"
  | false -> "would"



(* ************************************************************************** *)
(** {b Descr}: String representing the status of the {b --value-restriction}
option invoked when a package is built. This function is used to report
inconsistency errors when some packages are compiled with different values
of the {b --value-restriction} option.
{b Visibility}: Not exported outside this module. *)
(* ************************************************************************** *)
let value_restiction_option_status = function
  | `disabled -> "disabled"
  | `normal -> "normal"
  | `strict -> "strict"



let diff package options1 options2 (*current options*) =
  if options1.back_end <> options2.back_end then
    OManager.serror "The package %s was compiled for backend %s, the current package would be compiled for %s@."
      package
      (OpaEnv.string_of_available_back_end options1.back_end)
      (OpaEnv.string_of_available_back_end options2.back_end);
  if options1.js_back_end <> options2.js_back_end then
    OManager.serror "The package %s was compiled for the js backend %s, the current package would be compiled for %s@."
      package
      options1.js_back_end
      options2.js_back_end;
  if options1.closure <> options2.closure then
    OManager.serror "The package %s was compiled %s closure, the current package %s."
      package
      (with_or_without options1.closure) (would options1.closure);
  if options1.cps <> options2.cps then
    OManager.serror "The package %s was compiled %s cps, the current package %s."
      package
      (with_or_without options1.cps) (would options1.cps);
  if options1.cps_client <> options2.cps_client then
    OManager.serror "The package %s was compiled %s client cps, the current package %s."
      package
      (with_or_without options1.cps_client) (would options1.cps_client);
  if options1.cps_toplevel_concurrency <> options2.cps_toplevel_concurrency then
    OManager.serror "The package %s was compiled %s toplevel concurrency for cps, the current package %s."
      package
      (with_or_without options1.cps_toplevel_concurrency) (would options1.cps_toplevel_concurrency);
  if options1.explicit_instantiation <> options2.explicit_instantiation then
    OManager.serror "The package %s was compiled %s ei, the current package %s."
      package
      (with_or_without options1.explicit_instantiation) (would options1.explicit_instantiation);
  (* Check that the value restriction option was identically set in all the
compiled packages. *)
  if options1.value_restriction <> options2.value_restriction then
    OManager.serror
      ("The package %s was compiled with value restriction set to %s, " ^^
       "the current package with %s." ^^
       "@[<2>@{<bright>Hint@}:@\n" ^^
       "Set --value-restriction option to the same value for all packages.@]")
      package
      (value_restiction_option_status options1.value_restriction)
      (value_restiction_option_status options2.value_restriction);
  if options1.back_end <> options2.back_end then
    OManager.serror
      ("The package %s was compiled for @{<bright>%s@} backend, " ^^
       "while you tried to compile the current one for @{<bright>%s@} backend" ^^
       "@[<2>@{<bright>Hint@}:@\n" ^^
       "Set --back-end option to the same value for all packages.@]")
      package
      (OpaEnv.string_of_available_back_end options1.back_end)
      (OpaEnv.string_of_available_back_end options2.back_end);
;;



let process_code ~options:options env =
  let my_options = project options in
  R.iter_with_name ~deep:true ~packages:true
    (fun (package,_) options ->
       if options <> my_options then
         diff package options my_options
    );
  R.save my_options;
  env
Something went wrong with that request. Please try again.