2007-02-07 00:59:16 -08:00
|
|
|
(***********************************************************************)
|
2012-08-01 07:47:00 -07:00
|
|
|
(* *)
|
2007-02-07 00:59:16 -08:00
|
|
|
(* ocamlbuild *)
|
|
|
|
(* *)
|
|
|
|
(* Nicolas Pouillard, Berke Durak, projet Gallium, INRIA Rocquencourt *)
|
|
|
|
(* *)
|
|
|
|
(* Copyright 2007 Institut National de Recherche en Informatique et *)
|
|
|
|
(* en Automatique. All rights reserved. This file is distributed *)
|
|
|
|
(* under the terms of the Q Public License version 1.0. *)
|
|
|
|
(* *)
|
|
|
|
(***********************************************************************)
|
|
|
|
|
2009-03-03 08:54:58 -08:00
|
|
|
|
2007-02-07 00:59:16 -08:00
|
|
|
(* Original author: Nicolas Pouillard *)
|
|
|
|
open Command
|
|
|
|
open Bool (* FIXME remove me *)
|
|
|
|
open Tags.Operators
|
|
|
|
|
2013-09-15 04:36:35 -07:00
|
|
|
type decl = {
|
|
|
|
tags: Tags.t;
|
|
|
|
flags: Command.spec;
|
2013-09-15 04:36:37 -07:00
|
|
|
deprecated: bool;
|
2013-09-15 04:36:35 -07:00
|
|
|
}
|
|
|
|
let flags_of_decl { flags; _ } = flags
|
|
|
|
let tags_of_decl { tags; _ } = tags
|
|
|
|
|
|
|
|
let all_decls = ref []
|
|
|
|
|
|
|
|
let of_tags matched_tags =
|
2007-02-07 00:59:16 -08:00
|
|
|
S begin
|
2013-09-15 04:36:37 -07:00
|
|
|
List.fold_left begin fun acc { tags; flags; _ } ->
|
2013-09-15 04:36:35 -07:00
|
|
|
if Tags.does_match matched_tags tags then flags :: acc
|
2007-02-07 00:59:16 -08:00
|
|
|
else acc
|
2013-09-15 04:36:35 -07:00
|
|
|
end [] !all_decls
|
2007-02-07 00:59:16 -08:00
|
|
|
end
|
|
|
|
|
|
|
|
let () = Command.tag_handler := of_tags
|
|
|
|
|
|
|
|
let of_tag_list x = of_tags (Tags.of_list x)
|
|
|
|
|
2013-09-15 04:36:35 -07:00
|
|
|
let add_decl decl =
|
|
|
|
all_decls := decl :: !all_decls
|
2007-02-07 00:59:16 -08:00
|
|
|
|
2013-09-15 04:36:37 -07:00
|
|
|
let flag ?(deprecated=false) tags flags =
|
2013-09-15 04:36:35 -07:00
|
|
|
let tags = Tags.of_list tags in
|
2013-09-15 04:36:37 -07:00
|
|
|
add_decl { tags; flags; deprecated }
|
2007-02-07 00:59:16 -08:00
|
|
|
|
2010-01-22 06:36:57 -08:00
|
|
|
let pflag tags ptag flags =
|
|
|
|
Param_tags.declare ptag
|
|
|
|
(fun param -> flag (Param_tags.make ptag param :: tags) (flags param))
|
|
|
|
|
2007-02-07 00:59:16 -08:00
|
|
|
let add x xs = x :: xs
|
|
|
|
let remove me = List.filter (fun x -> me <> x)
|
2007-02-26 09:05:30 -08:00
|
|
|
|
2013-09-15 04:36:37 -07:00
|
|
|
let pretty_print { tags; flags; deprecated } =
|
|
|
|
let sflag = Command.string_of_command_spec flags in
|
|
|
|
let header = if deprecated then "deprecated flag" else "flag" in
|
|
|
|
let pp fmt = Log.raw_dprintf (-1) fmt in
|
|
|
|
pp "@[<2>%s@ {. %a .}@ %S@]@\n@\n" header Tags.print tags sflag
|
|
|
|
|
2013-09-15 04:36:33 -07:00
|
|
|
let show_documentation () =
|
2013-09-15 04:36:37 -07:00
|
|
|
List.iter
|
|
|
|
(fun decl -> if not decl.deprecated then pretty_print decl)
|
|
|
|
!all_decls;
|
|
|
|
List.iter
|
|
|
|
(fun decl -> if decl.deprecated then pretty_print decl)
|
|
|
|
!all_decls;
|
2013-09-15 04:36:33 -07:00
|
|
|
let pp fmt = Log.raw_dprintf (-1) fmt in
|
|
|
|
pp "@."
|
2013-09-15 04:36:43 -07:00
|
|
|
|
|
|
|
let used_tags = ref Tags.empty
|
|
|
|
|
|
|
|
let mark_as_used tag =
|
|
|
|
used_tags := Tags.add tag !used_tags
|
|
|
|
|
|
|
|
let get_used_tags () =
|
|
|
|
List.fold_left (fun acc decl -> Tags.union acc decl.tags)
|
|
|
|
!used_tags !all_decls
|