Skip to content

Commit

Permalink
Prevent global cookies from disappearing (#41)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremiedimino authored Mar 20, 2018
1 parent d0ddde4 commit efce532
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
6 changes: 6 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
next
----

- Fix an issue where cookies set from the command line sometimes
disappeared

v1.0.8 2018-03-15 London
------------------------

Expand Down
12 changes: 10 additions & 2 deletions src/migrate_parsetree_driver.ml
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,19 @@ type cookies = (string, cookie) Hashtbl.t

let create_cookies () = Hashtbl.create 3

let global_cookie_table = create_cookies ()

let get_cookie table name version =
match
match Hashtbl.find table name with
| result -> Some result
| exception Not_found ->
match Ast_mapper.get_cookie name with
| None -> None
| Some expr -> Some (Cookie ((module OCaml_current), expr))
| None ->
match Hashtbl.find global_cookie_table name with
| result -> Some result
| exception Not_found -> None
with
| None -> None
| Some (Cookie (version', expr)) ->
Expand All @@ -46,6 +51,9 @@ let get_cookie table name version =
let set_cookie table name version expr =
Hashtbl.replace table name (Cookie (version, expr))

let set_global_cookie name version expr =
set_cookie global_cookie_table name version expr

let apply_cookies table =
Hashtbl.iter (fun name (Cookie (version, expr)) ->
Ast_mapper.set_cookie name
Expand Down Expand Up @@ -95,7 +103,7 @@ let () =
; pos_cnum = 0
};
let expr = Parse.expression lexbuf in
Ast_mapper.set_cookie name expr
set_global_cookie name (module OCaml_current) expr
in
registered_args :=
("--cookie", Arg.String set_cookie,
Expand Down
5 changes: 5 additions & 0 deletions src/migrate_parsetree_driver.mli
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ val set_cookie
-> 'types ocaml_version -> 'types get_expression
-> unit

val set_global_cookie
: string
-> 'types ocaml_version -> 'types get_expression
-> unit

(** {1 Registering rewriters} *)

type 'types rewriter = config -> cookies -> 'types get_mapper
Expand Down

0 comments on commit efce532

Please sign in to comment.