ocamlbuild: turn the flags.ml structure into a record to ease adding metadata

I plan to add at least documentation and deprecation information to
each flagset, so structuring it as a record is important.

git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@14140 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
master
Gabriel Scherer 2013-09-15 11:36:35 +00:00
parent 9d89a6b2a5
commit 53d1c7c63d
1 changed files with 21 additions and 15 deletions

View File

@ -15,24 +15,34 @@
open Command
open Bool (* FIXME remove me *)
open Tags.Operators
let all_flags = ref []
let of_tags tags =
type decl = {
tags: Tags.t;
flags: Command.spec;
}
let flags_of_decl { flags; _ } = flags
let tags_of_decl { tags; _ } = tags
let all_decls = ref []
let of_tags matched_tags =
S begin
List.fold_left begin fun acc (xtags, xflags) ->
if Tags.does_match tags xtags then xflags :: acc
List.fold_left begin fun acc { tags; flags } ->
if Tags.does_match matched_tags tags then flags :: acc
else acc
end [] !all_flags
end [] !all_decls
end
let () = Command.tag_handler := of_tags
let of_tag_list x = of_tags (Tags.of_list x)
let set_flags tags flags =
all_flags := (tags, flags) :: !all_flags
let add_decl decl =
all_decls := decl :: !all_decls
let flag tags flags = set_flags (Tags.of_list tags) flags
let flag tags flags =
let tags = Tags.of_list tags in
add_decl { tags; flags }
let pflag tags ptag flags =
Param_tags.declare ptag
@ -41,14 +51,10 @@ let pflag tags ptag flags =
let add x xs = x :: xs
let remove me = List.filter (fun x -> me <> x)
let get_flags () = !all_flags
let show_documentation () =
let pp fmt = Log.raw_dprintf (-1) fmt in
let flags = get_flags () in
List.iter begin fun (tags, flag) ->
let sflag = Command.string_of_command_spec flag in
List.iter begin fun { tags; flags } ->
let sflag = Command.string_of_command_spec flags in
pp "@[<2>flag@ {. %a .}@ %S@]@\n@\n" Tags.print tags sflag
end flags;
end !all_decls;
pp "@."