From 6ebff9d388ef9489ee71427c6adf48447e0c5ec6 Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Wed, 6 Jun 2018 21:34:47 +0700 Subject: [PATCH] Move Value.t list functions to Value.L Signed-off-by: Rudi Grinberg --- src/action.ml | 10 +++++----- src/inline_tests.ml | 2 +- src/string_with_vars.ml | 2 +- src/super_context.ml | 14 +++++++------- src/value.ml | 25 ++++++++++++++----------- src/value.mli | 14 ++++++++------ 6 files changed, 36 insertions(+), 31 deletions(-) diff --git a/src/action.ml b/src/action.ml index 8c4c2d66..63a0e0b8 100644 --- a/src/action.ml +++ b/src/action.ml @@ -274,9 +274,9 @@ end let prog_and_args_of_values p ~dir = match p with | [] -> (Unresolved.Program.Search "", []) - | Value.Path p :: xs -> (This p, Value.to_strings ~dir xs) + | Value.Path p :: xs -> (This p, Value.L.to_strings ~dir xs) | String s :: xs -> - (Unresolved.Program.of_string ~dir s, Value.to_strings ~dir xs) + (Unresolved.Program.of_string ~dir s, Value.L.to_strings ~dir xs) module SW = String_with_vars @@ -327,7 +327,7 @@ module Unexpanded = struct let strings = expand ~mode:Many ~l:(fun x -> [x]) - ~r:Value.to_strings + ~r:Value.L.to_strings let path e = let error_loc = @@ -410,8 +410,8 @@ module Unexpanded = struct | Unexpanded x -> Right x let string = expand ~mode:Single ~map:Value.to_string - let strings = expand ~mode:Many ~map:Value.to_strings - let cat_strings = expand ~mode:Many ~map:Value.concat + let strings = expand ~mode:Many ~map:Value.L.to_strings + let cat_strings = expand ~mode:Many ~map:Value.L.concat let path x = let error_loc = String_with_vars.loc x in expand ~mode:Single ~map:(Value.to_path ~error_loc) x diff --git a/src/inline_tests.ml b/src/inline_tests.ml index 3c202834..2b140231 100644 --- a/src/inline_tests.ml +++ b/src/inline_tests.ml @@ -209,7 +209,7 @@ include Sub_system.Register_end_point( let target = Path.relative inline_test_dir main_module_filename in let source_modules = Module.Name.Map.values source_modules in let files ml_kind = - Value.paths ( + Value.L.paths ( List.filter_map source_modules ~f:(fun m -> Module.file m ~dir ml_kind)) in diff --git a/src/string_with_vars.ml b/src/string_with_vars.ml index be89e754..e63d4876 100644 --- a/src/string_with_vars.ml +++ b/src/string_with_vars.ml @@ -160,7 +160,7 @@ let partial_expand t ~mode ~dir ~f = | Some ([] | _::_::_ as e) when not t.quoted -> invalid_multivalue syntax ~var t e | Some t -> - loop (List.rev_append (Value.to_strings ~dir t) acc_text) acc items + loop (List.rev_append (Value.L.to_strings ~dir t) acc_text) acc items | None -> loop [] (it :: commit_text acc_text acc) items end in diff --git a/src/super_context.ml b/src/super_context.ml index 1cc820a0..bf93fb09 100644 --- a/src/super_context.ml +++ b/src/super_context.ml @@ -287,7 +287,7 @@ let create | Some p -> path p in let cflags = context.ocamlc_cflags in - let strings = Value.strings in + let strings = Value.L.strings in let vars = [ "-verbose" , [] ; "CPP" , strings (context.c_compiler :: cflags @ ["-E"]) @@ -707,7 +707,7 @@ module Action = struct let path = Path.relative dir s in let data = Build.lines_of path - >>^ Value.strings + >>^ Value.L.strings in add_ddep acc ~key data end @@ -715,7 +715,7 @@ module Action = struct let path = Path.relative dir s in let data = Build.strings path - >>^ Value.strings + >>^ Value.L.strings in add_ddep acc ~key data end @@ -737,7 +737,7 @@ module Action = struct match targets_written_by_user with | Infer -> Loc.fail loc "You cannot use ${@} with inferred rules." | Alias -> Loc.fail loc "You cannot use ${@} in aliases." - | Static l -> Some (Value.paths l) + | Static l -> Some (Value.L.paths l) end | _ -> match String.lsplit2 var ~on:':' with @@ -746,8 +746,8 @@ module Action = struct | x -> let exp = expand loc key var x in Option.iter exp ~f:(fun vs -> - acc.sdeps <- - Path.Set.union (Path.Set.of_list (Value.paths_only vs)) acc.sdeps; + acc.sdeps <- Path.Set.union (Path.Set.of_list + (Value.L.paths_only vs)) acc.sdeps; ); exp) in @@ -769,7 +769,7 @@ module Action = struct [Value.String ""] | dep :: _ -> [Path dep]) - | "^" -> Some (Value.paths deps_written_by_user) + | "^" -> Some (Value.L.paths deps_written_by_user) | _ -> None) let run sctx ~loc ?(extra_vars=String.Map.empty) diff --git a/src/value.ml b/src/value.ml index 0eb9b3e3..9d8cf9fd 100644 --- a/src/value.ml +++ b/src/value.ml @@ -11,21 +11,24 @@ let to_string t ~dir = | String s -> s | Path p -> string_of_path ~dir p -let to_strings t ~dir = List.map t ~f:(to_string ~dir) - let to_path ?error_loc t ~dir = match t with | String s -> Path.relative ?error_loc dir s | Path p -> p -let strings = List.map ~f:(fun x -> String x) -let paths = List.map ~f:(fun x -> Path x) +module L = struct + let to_strings t ~dir = List.map t ~f:(to_string ~dir) -let concat ts ~dir = - List.map ~f:(to_string ~dir) ts - |> String.concat ~sep:" " + let concat ts ~dir = + List.map ~f:(to_string ~dir) ts + |> String.concat ~sep:" " -let paths_only = - List.filter_map ~f:(function - | String _ -> None - | Path p -> Some p) + let paths_only = + List.filter_map ~f:(function + | String _ -> None + | Path p -> Some p) + + let strings = List.map ~f:(fun x -> String x) + + let paths = List.map ~f:(fun x -> Path x) +end diff --git a/src/value.mli b/src/value.mli index de89de48..d2a7b845 100644 --- a/src/value.mli +++ b/src/value.mli @@ -6,14 +6,16 @@ type t = val to_string : t -> dir:Path.t -> string -val to_strings : t list -> dir:Path.t -> string list - val to_path : ?error_loc:Loc.t -> t -> dir:Path.t -> Path.t -val strings : string list -> t list +module L : sig + val strings : string list -> t list -val paths : Path.t list -> t list + val paths : Path.t list -> t list -val paths_only : t list -> Path.t list + val paths_only : t list -> Path.t list -val concat : t list -> dir:Path.t -> string + val concat : t list -> dir:Path.t -> string + + val to_strings : t list -> dir:Path.t -> string list +end