[clang] Adding option analyzer to InferPrint in inferiOS to avoid analysing generated files

master
Dulma Rodriguez 10 years ago
parent 393f5aad1e
commit 41fe321582

@ -8,6 +8,8 @@ open Utils
(** Name of the infer configuration file *)
let inferconfig_file = ".inferconfig"
let inferconfig_home = ref None
(** Look up a key in a json file containing a list of strings *)
let lookup_string_list key json =
Yojson.Basic.Util.filter_member key [json]
@ -42,7 +44,11 @@ type filter_config =
let load_filters analyzer =
try
let json = Yojson.Basic.from_file inferconfig_file in
let json =
match !inferconfig_home with
| Some dir ->
Yojson.Basic.from_file (Filename.concat dir inferconfig_file)
| None -> Yojson.Basic.from_file inferconfig_file in
let inferconfig =
{
whitelist = lookup_string_list (analyzer ^ "_whitelist") json;
@ -54,7 +60,6 @@ let load_filters analyzer =
Some inferconfig
with Sys_error _ -> None
let is_matching patterns =
fun source_file ->
let path = DB.source_file_to_rel_path source_file in
@ -79,7 +84,6 @@ module FileContainsStringMatcher = struct
| End_of_file -> false in
loop ()
let create_matcher s_patterns =
if s_patterns = [] then
default_matcher
@ -98,7 +102,6 @@ module FileContainsStringMatcher = struct
pattern_found
end
let filters_from_inferconfig inferconfig : filters =
let path_filter =
let whitelist_filter : path_filter =
@ -191,7 +194,6 @@ module NeverReturnNull = struct
Format.fprintf fmt "Source contains (%s) {\n%a}\n"
(Sil.string_of_language language) pp_source_contains sc
let detect_language assoc =
let rec loop = function
| [] ->
@ -202,7 +204,6 @@ module NeverReturnNull = struct
| _:: tl -> loop tl in
loop assoc
let detect_pattern assoc =
let language = detect_language assoc in
let is_method_pattern key = list_exists (string_equal key) ["class"; "method"]
@ -217,7 +218,6 @@ module NeverReturnNull = struct
| _:: tl -> loop tl in
loop assoc
let create_pattern (assoc : (string * Yojson.Basic.json) list) =
let collect_params l =
let collect accu = function
@ -247,14 +247,12 @@ module NeverReturnNull = struct
| Source_contains (language, sc) ->
Source_contains (language, create_string_contains sc assoc)
let rec translate accu (json : Yojson.Basic.json) : pattern list =
match json with
| `Assoc l -> (create_pattern l):: accu
| `List l -> list_fold_left translate accu l
| _ -> assert false
let create_method_matcher language m_patterns =
if language <> Sil.Java then assert false
else
@ -284,7 +282,6 @@ module NeverReturnNull = struct
class_patterns
with Not_found -> false
let create_file_matcher language patterns =
let s_patterns, m_patterns =
let collect (s_patterns, m_patterns) = function
@ -300,7 +297,6 @@ module NeverReturnNull = struct
fun source_file proc_name ->
m_matcher source_file proc_name || s_matcher source_file proc_name
let load_matcher language =
try
let patterns =
@ -313,10 +309,8 @@ module NeverReturnNull = struct
with Sys_error _ ->
default_matcher
end (* of module NeverReturnNull *)
(* This function loads and list the path that are being filtered by the analyzer. The results *)
(* are of the form: path/to/file.java -> {infer, eradicate} meaning that analysis results will *)
(* be reported on path/to/file.java both for infer and for eradicate *)

@ -6,6 +6,8 @@
(** Filter type for a source file *)
type path_filter = DB.source_file -> bool
val inferconfig_home : string option ref
(** Filter type for an error name. *)
type error_filter = Localise.t -> bool

@ -105,6 +105,8 @@ let arg_desc =
.inferconfig lives).";
"-analyzer", Arg.String (fun s -> analyzer := Some (Utils.analyzer_of_string s)), Some "analyzer",
"setup the analyzer for the path filtering";
"-inferconfig_home", Arg.String (fun s -> Inferconfig.inferconfig_home := Some s), Some "dir",
"Path to the .inferconfig file";
] in
Arg2.create_options_desc false "Options" desc in
let reserved_arg =

Loading…
Cancel
Save