Skip to content
This repository
tag: v1025
Fetching contributors…

Cannot retrieve contributors at this time

file 65 lines (52 sloc) 2.355 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
(*
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/>.
*)
(* depends *)
module String = Base.String
module Random = Base.Random

(* shorthands *)
module Q = QmlAst
module Cons = QmlAstCons.TypedExpr


let () = Random.ensure_init ()

let set_executable_id = Opacapi.Opabsl.BslInit.set_executable_id
let set_cleaning_default_value = Opacapi.Opabsl.BslJsIdent.set_cleaning_default_value

let add_bypass_application bypass_typer gamma annotmap bypass arguments code =
  let annotmap, bypass =
    Cons.bypass annotmap bypass (Option.get (bypass_typer bypass)) in
  let annotmap, app =
    Cons.apply gamma annotmap bypass arguments in
  let ident = Ident.next "__dummy" in
  let gamma = QmlTypes.Env.Ident.add ident (QmlTypes.Scheme.id (Q.TypeRecord (Q.TyRow ([],None)))) gamma in
  let label = Annot.nolabel "pass_InitializeBslValues" in
  gamma, annotmap, Q.NewVal (label, [ident, app]) :: code

let process_code bypass_typer gamma annotmap code =

  (* generating the server id *)
  let annotmap, id =
    Cons.string annotmap (
      #<If:DIFFING>
        "the_executable_id_is_not_supported_in_diffing_mode"
      #<Else>
        String.random 32
      #<End>
    ) in
  let gamma, annotmap, code = add_bypass_application bypass_typer gamma annotmap set_executable_id [id] code in

  (* setting the default value of cleaning *)
  let gamma, annotmap, code =
    try
      let annotmap, cleaning =
        Cons.bool (annotmap,gamma) (ObjectFiles.Arg.is_fully_separated ()) in
      add_bypass_application bypass_typer gamma annotmap set_cleaning_default_value [cleaning] code
    with QmlTyperException.Exception _ ->
      (* if bool is not defined, we are in --no-stdlib, so we don't care about cleaning *)
      gamma, annotmap, code in

  gamma, annotmap, code
Something went wrong with that request. Please try again.