Clean up command line argument filtering.

master
Rohan Jacob-Rao 10 years ago
parent 9b3f291b99
commit 9643bdb1c6

@ -787,6 +787,12 @@ let filename_to_relative root fname =
remainder remainder
(* Type of command-line arguments before processing *)
type arg_list = (string * Arg.spec * string option * string) list
let arg_desc_filter options_to_keep =
list_filter (function (option_name, _, _, _) -> list_mem string_equal option_name options_to_keep)
let base_arg_desc = let base_arg_desc =
[ [
"-results_dir", "-results_dir",

@ -388,11 +388,17 @@ val do_outf : outfile option ref -> (outfile -> unit) -> unit
(** close an outfile *) (** close an outfile *)
val close_outf : outfile -> unit val close_outf : outfile -> unit
(* Type of command-line arguments before processing *)
type arg_list = (string * Arg.spec * string option * string) list
(* Filter arguments by name, i.e. keep those whose name appears in the name list *)
val arg_desc_filter : string list -> arg_list -> arg_list
(** Basic command-line arguments *) (** Basic command-line arguments *)
val base_arg_desc : (string * Arg.spec * string option * string) list val base_arg_desc : arg_list
(** Reserved command-line arguments *) (** Reserved command-line arguments *)
val reserved_arg_desc : (string * Arg.spec * string option * string) list val reserved_arg_desc : arg_list
(** Escape a string for use in a CSV or XML file: replace reserved characters with escape sequences *) (** Escape a string for use in a CSV or XML file: replace reserved characters with escape sequences *)
module Escape : sig module Escape : sig

@ -16,66 +16,61 @@ module L = Logging
open CFrontend_utils open CFrontend_utils
let arg_desc = let arg_desc =
let base_arg = Config.dotty_cfg_libs := false; (* default behavior for this frontend *)
let options_to_keep = ["-results_dir"] in let desc =
Config.dotty_cfg_libs := false; (* default behavior for this frontend *) (Utils.arg_desc_filter ["-results_dir"] Utils.base_arg_desc) @
let filter arg_desc = [
List.filter (fun desc -> let (option_name, _, _, _) = desc in List.mem option_name options_to_keep) arg_desc in "-c",
let desc = Arg.String (fun cfile -> CFrontend_config.source_file := Some cfile),
(filter Utils.base_arg_desc) @ Some "cfile",
[ "C File to translate";
"-c", "-x",
Arg.String (fun cfile -> CFrontend_config.source_file := Some cfile), Arg.String (fun lang -> CFrontend_config.lang_from_string lang),
Some "cfile", Some "cfile",
"C File to translate"; "Language (c, objective-c, c++, objc-++)";
"-x", "-ast",
Arg.String (fun lang -> CFrontend_config.lang_from_string lang), Arg.String (fun file -> CFrontend_config.ast_file := Some file),
Some "cfile", Some "file",
"Language (c, objective-c, c++, objc-++)"; "AST file for the translation";
"-ast", "-dotty_cfg_libs",
Arg.String (fun file -> CFrontend_config.ast_file := Some file), Arg.Unit (fun _ -> Config.dotty_cfg_libs := true),
Some "file", None,
"AST file for the translation"; "Prints the cfg of the code coming from the libraries";
"-dotty_cfg_libs", "-no_headers",
Arg.Unit (fun _ -> Config.dotty_cfg_libs := true), Arg.Unit (fun _ -> CFrontend_config.no_translate_libs := true),
None, None,
"Prints the cfg of the code coming from the libraries"; "Do not translate code in header files (default)";
"-no_headers", "-headers",
Arg.Unit (fun _ -> CFrontend_config.no_translate_libs := true), Arg.Unit (fun _ -> CFrontend_config.no_translate_libs := false),
None, None,
"Do not translate code in header files (default)"; "Translate code in header files";
"-headers", "-testing_mode",
Arg.Unit (fun _ -> CFrontend_config.no_translate_libs := false), Arg.Unit (fun _ -> CFrontend_config.testing_mode := true),
None, None,
"Translate code in header files"; "Mode for testing, where no libraries are translated, including enums defined in the libraries";
"-testing_mode", "-debug",
Arg.Unit (fun _ -> CFrontend_config.testing_mode := true), Arg.Unit (fun _ -> CFrontend_config.debug_mode := true),
None, None,
"Mode for testing, where no libraries are translated, including enums defined in the libraries"; "Enables debug mode";
"-debug", "-stats",
Arg.Unit (fun _ -> CFrontend_config.debug_mode := true), Arg.Unit (fun _ -> CFrontend_config.stats_mode := true),
None, None,
"Enables debug mode"; "Enables stats mode";
"-stats", "-project_root",
Arg.Unit (fun _ -> CFrontend_config.stats_mode := true), Arg.String (fun s ->
None, Config.project_root := Some (Utils.filename_to_absolute s)),
"Enables stats mode"; Some "dir",
"-project_root", "Toot directory of the project";
Arg.String (fun s -> "-fobjc-arc",
Config.project_root := Some (Utils.filename_to_absolute s)), Arg.Unit (fun s -> Config.arc_mode := true),
Some "dir", None,
"Toot directory of the project"; "Translate with Objective-C Automatic Reference Counting (ARC)";
"-fobjc-arc", "-models_mode",
Arg.Unit (fun s -> Config.arc_mode := true), Arg.Unit (fun _ -> CFrontend_config.models_mode := true),
None, None,
"Translate with Objective-C Automatic Reference Counting (ARC)"; "Mode for computing the models";
"-models_mode", ] in
Arg.Unit (fun _ -> CFrontend_config.models_mode := true), Utils.Arg2.create_options_desc false "Parsing Options" desc
None,
"Mode for computing the models";
] in
Utils.Arg2.create_options_desc false "Parsing Options" desc in
base_arg
let usage = let usage =
"\nUsage: InferClang -c C Files -ast AST Files -results_dir <output-dir> [options] \n" "\nUsage: InferClang -c C Files -ast AST Files -results_dir <output-dir> [options] \n"

@ -14,24 +14,20 @@ module L = Logging
open Utils open Utils
let arg_desc = let arg_desc =
let base_arg = let options_to_keep = ["-results_dir"; "-project_root"] in
let options_to_keep = ["-results_dir"; "-project_root"] in let desc =
let filter arg_desc = (arg_desc_filter options_to_keep base_arg_desc) @
list_filter (fun desc -> let (option_name, _, _, _) = desc in list_mem string_equal option_name options_to_keep) arg_desc in [
let desc = "-models", Arg.String (fun filename -> JClasspath.add_models filename), Some "paths", "set the path to the jar containing the models";
(filter base_arg_desc) @ "-debug", Arg.Unit (fun () -> JConfig.debug_mode := true), None, "write extra translation information";
[ "-dependencies", Arg.Unit (fun _ -> JConfig.dependency_mode := true), None, "translate all the dependencies during the capture";
"-models", Arg.String (fun filename -> JClasspath.add_models filename), Some "paths", "set the path to the jar containing the models"; "-no-static_final", Arg.Unit (fun () -> JTrans.no_static_final := true), None, "no special treatment for static final fields";
"-debug", Arg.Unit (fun () -> JConfig.debug_mode := true), None, "write extra translation information"; "-tracing", Arg.Unit (fun () -> JConfig.translate_checks := true), None,
"-dependencies", Arg.Unit (fun _ -> JConfig.dependency_mode := true), None, "translate all the dependencies during the capture"; "Translate JVM checks";
"-no-static_final", Arg.Unit (fun () -> JTrans.no_static_final := true), None, "no special treatment for static final fields"; "-verbose_out", Arg.String (fun path -> JClasspath.set_verbose_out path), None,
"-tracing", Arg.Unit (fun () -> JConfig.translate_checks := true), None, "Set the path to the javac verbose output"
"Translate JVM checks"; ] in
"-verbose_out", Arg.String (fun path -> JClasspath.set_verbose_out path), None, Arg2.create_options_desc false "Parsing Options" desc
"Set the path to the javac verbose output"
] in
Arg2.create_options_desc false "Parsing Options" desc in
base_arg
let usage = let usage =
"Usage: InferJava -d compilation_dir -sources filename\n" "Usage: InferJava -d compilation_dir -sources filename\n"

@ -10,11 +10,8 @@ open Utils
let arg_desc = let arg_desc =
let options_to_keep = ["-results_dir"; "-project_root"] in let options_to_keep = ["-results_dir"; "-project_root"] in
let filter arg_desc = list_filter
(fun desc -> let (option_name, _, _, _) = desc in list_mem string_equal option_name options_to_keep)
arg_desc in
let desc = let desc =
filter base_arg_desc @ arg_desc_filter options_to_keep base_arg_desc @
[ [
"-c", "-c",
Arg.String (fun cfile -> LConfig.source_filename := Some cfile), Arg.String (fun cfile -> LConfig.source_filename := Some cfile),

Loading…
Cancel
Save