Move analyzer type and ops from Utils to Config

Summary:
Move analyzer type and ops from Utils to Config, and simplify by
reducing interface.  There are very few uses so no need to pollute
global namespace.

Reviewed By: sblackshear

Differential Revision: D3541047

fbshipit-source-id: 2be56af
master
Josh Berdine 9 years ago committed by Facebook Github Bot 1
parent 9df3b8f653
commit 7e59032a42

@ -17,23 +17,21 @@ module CLOpt = CommandLineOption
module F = Format
type language = Clang | Java
type analyzer = Capture | Compile | Infer | Eradicate | Checkers | Tracing
type method_pattern = {
class_name : string;
method_name : string option;
parameters : (string list) option;
}
let string_to_analyzer =
[("capture", Capture); ("compile", Compile);
("infer", Infer); ("eradicate", Eradicate); ("checkers", Checkers); ("tracing", Tracing)]
type pattern =
| Method_pattern of language * method_pattern
| Source_contains of language * string
type clang_lang = C | CPP | OBJC | OBJCPP
type language = Clang | Java
let string_of_language = function
| Java -> "Java"
| Clang -> "C_CPP"
type clang_lang = C | CPP | OBJC | OBJCPP
let ml_bucket_symbols = [
("all", `MLeak_all);
@ -44,23 +42,27 @@ let ml_bucket_symbols = [
("unknown_origin", `MLeak_unknown);
]
type os_type = Unix | Win32 | Cygwin
type method_pattern = {
class_name : string;
method_name : string option;
parameters : (string list) option;
}
type pattern =
| Method_pattern of language * method_pattern
| Source_contains of language * string
type zip_library = {
zip_filename: string;
zip_channel: Zip.in_file Lazy.t;
models: bool;
}
let whitelisted_cpp_methods = [
["std"; "move"];
["std"; "forward"];
["std"; "min"];
["std"; "max"];
["std"; "__less"];
["google"; "CheckNotNull"];
]
(** Constant configuration values *)
@ -84,6 +86,8 @@ let backend_stats_dir_name = "backend_stats"
continues *)
let bound_error_allowed_in_procedure_call = true
let buck_generated_folder = "buck-out/gen"
let buck_infer_deps_file_name = "infer-deps.txt"
let captured_dir_name = "captured"
@ -93,6 +97,9 @@ let checks_disabled_by_default = [
"UNSAFE_GUARDED_BY_ACCESS";
]
(** Experimental: if true do some specialized analysis of concurrent constructs. *)
let csl_analysis = true
let default_failure_name = "ASSERTION_FAILURE"
let default_in_zip_results_dir = "infer"
@ -120,6 +127,14 @@ let inferconfig_file = ".inferconfig"
let ivar_attributes = "ivar_attributes"
(** letters used in the analysis output *)
let log_analysis_file = "F"
let log_analysis_procedure = "."
let log_analysis_wallclock_timeout = "T"
let log_analysis_symops_timeout = "S"
let log_analysis_recursion_timeout = "R"
let log_analysis_crash = "C"
(** Maximum level of recursion during the analysis, after which a timeout is generated *)
let max_recursion = 5
@ -168,9 +183,6 @@ let suppress_warnings_annotations_long = "suppress-warnings-annotations"
(** If true performs taint analysis *)
let taint_analysis = true
(** Experimental: if true do some specialized analysis of concurrent constructs. *)
let csl_analysis = true
(** Enable detailed tracing information during array abstraction *)
let trace_absarray = false
@ -181,15 +193,15 @@ let unsafe_unret = "<\"Unsafe_unretained\">"
let weak = "<\"Weak\">"
(** letters used in the analysis output *)
let log_analysis_file = "F"
let log_analysis_procedure = "."
let log_analysis_wallclock_timeout = "T"
let log_analysis_symops_timeout = "S"
let log_analysis_recursion_timeout = "R"
let log_analysis_crash = "C"
let whitelisted_cpp_methods = [
["std"; "move"];
["std"; "forward"];
["std"; "min"];
["std"; "max"];
["std"; "__less"];
["google"; "CheckNotNull"];
]
let buck_generated_folder = "buck-out/gen"
(** Compile time configuration values *)
@ -461,13 +473,13 @@ and (
analysis_path_regex_whitelist_options,
analysis_suppress_errors_options) =
let mk_filtering_options ~suffix ?(deprecated_suffix=[]) ~help ~meta =
let mk_option analyzer =
let long = Printf.sprintf "%s-%s" (string_of_analyzer analyzer) suffix in
let mk_option analyzer_name =
let long = Printf.sprintf "%s-%s" analyzer_name suffix in
let deprecated =
IList.map (Printf.sprintf "%s_%s" (string_of_analyzer analyzer)) deprecated_suffix in
let help_string = Printf.sprintf "%s (%s only)" help (string_of_analyzer analyzer) in
IList.map (Printf.sprintf "%s_%s" analyzer_name) deprecated_suffix in
let help_string = Printf.sprintf "%s (%s only)" help analyzer_name in
CLOpt.mk_string_list ~deprecated ~long ~exes:CLOpt.[Analyze] ~meta help_string in
IList.map (fun analyzer -> (analyzer, mk_option analyzer)) analyzers in
IList.map (fun (name, analyzer) -> (analyzer, mk_option name)) string_to_analyzer in
(
mk_filtering_options
~suffix:"blacklist-files-containing"
@ -501,7 +513,7 @@ and analysis_stops =
and analyzer =
CLOpt.mk_symbol_opt ~deprecated:["analyzer"] ~long:"analyzer" ~short:"a"
"Specify the analyzer for the path filtering"
~symbols:Utils.string_to_analyzer
~symbols:string_to_analyzer
and android_harness =
CLOpt.mk_bool ~deprecated:["harness"] ~long:"android-harness"

@ -14,10 +14,28 @@ open! Utils
time by system calls, environment variables, or command line options *)
(** Various kind of analyzers *)
type analyzer = Capture | Compile | Infer | Eradicate | Checkers | Tracing
(** Association list of analyzers and their names *)
val string_to_analyzer : (string * analyzer) list
type clang_lang = C | CPP | OBJC | OBJCPP
type language = Clang | Java
val string_of_language : language -> string
val ml_bucket_symbols :
(string * [ `MLeak_all | `MLeak_arc | `MLeak_cf | `MLeak_cpp | `MLeak_no_arc | `MLeak_unknown ])
list
type os_type = Unix | Win32 | Cygwin
type method_pattern = {
class_name : string;
method_name : string option;
@ -28,13 +46,6 @@ type pattern =
| Method_pattern of language * method_pattern
| Source_contains of language * string
type clang_lang = C | CPP | OBJC | OBJCPP
val ml_bucket_symbols :
(string * [ `MLeak_all | `MLeak_arc | `MLeak_cf | `MLeak_cpp | `MLeak_no_arc | `MLeak_unknown ])
list
type os_type = Unix | Win32 | Cygwin
type zip_library = {
zip_filename : string;
@ -43,7 +54,7 @@ type zip_library = {
}
(** Configuration values *)
(** Constant configuration values *)
val allow_missing_index_in_proc_call : bool
val anonymous_block_num_sep : string

@ -49,7 +49,8 @@ let () =
infer_py ::
Config.anon_args @
(match Config.analyzer with None -> [] | Some a ->
["--analyzer"; Utils.string_of_analyzer a]) @
["--analyzer";
IList.assoc (=) a (IList.map (fun (n,a) -> (a,n)) Config.string_to_analyzer)]) @
(match Config.blacklist with
| Some s when buck -> ["--blacklist-regex"; s]
| _ -> []) @

@ -253,10 +253,12 @@ let is_checker_enabled checker_name =
(* be reported on path/to/file.java both for infer and for eradicate *)
let test () =
let filters =
IList.map (fun analyzer -> (analyzer, create_filters analyzer)) analyzers in
IList.map
(fun (name, analyzer) -> (name, analyzer, create_filters analyzer))
Config.string_to_analyzer in
let matching_analyzers path =
IList.fold_left
(fun l (a, f) -> if f.path_filter path then a:: l else l)
(fun l (n, a, f) -> if f.path_filter path then (n,a) :: l else l)
[] filters in
directory_iter
(fun path ->
@ -264,9 +266,7 @@ let test () =
let source_file = (DB.source_file_from_string path) in
let matching = matching_analyzers source_file in
if matching <> [] then
let matching_s =
join_strings ", "
(IList.map string_of_analyzer matching) in
let matching_s = join_strings ", " (IList.map fst matching) in
L.stderr "%s -> {%s}@."
(DB.source_file_to_rel_path source_file)
matching_s)

@ -29,7 +29,7 @@ type filters =
val do_not_filter : filters
(** Create filters based on the config file *)
val create_filters : analyzer -> filters
val create_filters : Config.analyzer -> filters
val never_return_null_matcher : DB.source_file -> Procname.t -> bool
val suppress_warnings_matcher : DB.source_file -> Procname.t -> bool

@ -552,26 +552,6 @@ let directory_iter f path =
else
f path
type analyzer = Capture | Compile | Infer | Eradicate | Checkers | Tracing
let string_to_analyzer =
[("capture", Capture); ("compile", Compile);
("infer", Infer); ("eradicate", Eradicate); ("checkers", Checkers); ("tracing", Tracing)]
let analyzers = IList.map snd string_to_analyzer
let string_of_analyzer =
let analyzer_to_string = IList.map (fun (a,n) -> (n,a)) string_to_analyzer in
fun analyzer ->
IList.assoc ( = ) analyzer analyzer_to_string
exception Unknown_analyzer
let analyzer_of_string name =
try IList.assoc string_equal name string_to_analyzer
with Not_found -> raise Unknown_analyzer
let string_crc_hex32 s = Digest.to_hex (Digest.string s)
let string_append_crc_cutoff ?(cutoff=100) ?(key="") name =

@ -259,19 +259,6 @@ val directory_fold : ('a -> string -> 'a) -> 'a -> string -> 'a
(** Functional iter function over all the file of a directory *)
val directory_iter : (string -> unit) -> string -> unit
(** Various kind of analyzers *)
type analyzer = Capture | Compile | Infer | Eradicate | Checkers | Tracing
(** Association list of analyzers and their names *)
val string_to_analyzer : (string * analyzer) list
(** List of analyzers *)
val analyzers: analyzer list
val string_of_analyzer: analyzer -> string
val analyzer_of_string: string -> analyzer
val read_optional_json_file : string -> (Yojson.Basic.json, string) result
val write_json_to_file : string -> Yojson.Basic.json -> unit

Loading…
Cancel
Save