Skip to content

Commit

Permalink
[annot] Simplify spec parsing
Browse files Browse the repository at this point in the history
Summary: With the move to `Yojson.Safe`, we can simplify parsing.

Reviewed By: rgrig

Differential Revision: D55479552

fbshipit-source-id: fb91c63803e3d37572e16ea556fc3551d20716e9
  • Loading branch information
hajduakos authored and facebook-github-bot committed Mar 28, 2024
1 parent afc0f30 commit e1850ff
Showing 1 changed file with 11 additions and 28 deletions.
39 changes: 11 additions & 28 deletions infer/src/checkers/annotationReachability.ml
Original file line number Diff line number Diff line change
Expand Up @@ -429,39 +429,22 @@ module ExpensiveAnnotationSpec = struct
}
end

(* parse user-defined specs from .inferconfig *)
let parse_user_defined_specs = function
| `List user_specs ->
let parse_user_spec json =
let open Yojson.Safe in
let sources = Util.member "sources" json |> Util.to_list |> List.map ~f:Util.to_string in
let sinks = Util.member "sinks" json |> Util.to_list |> List.map ~f:Util.to_string in
let sanitizers =
match Util.member "sanitizers" json with
| `List s ->
List.map ~f:Util.to_string s
| _ ->
L.user_warning "Expected a list of strings as sanitizers, ignoring.\n" ;
[]
in
(sources, sinks, sanitizers)
in
List.map ~f:parse_user_spec user_specs
| _ ->
L.user_warning "Expected a list as custom annotations, ignoring.\n" ;
[]
type user_defined_spec =
{sources: string list; sinks: string list; sanitizers: string list [@yojson.default []]}
[@@deriving of_yojson]

type user_defined_specs = user_defined_spec list [@@deriving of_yojson]

let annot_specs =
let parse_one_spec (str_src_annots, str_snk_annots, str_sanitizer_annots) =
List.map
~f:(fun str_snk_annot ->
StandardAnnotationSpec.from_annotations str_src_annots str_snk_annot str_sanitizer_annots )
str_snk_annots
let make_standard_spec_from_user_spec {sources; sinks; sanitizers} =
List.map ~f:(fun sink -> StandardAnnotationSpec.from_annotations sources sink sanitizers) sinks
in
let user_defined_specs =
parse_user_defined_specs Config.annotation_reachability_custom_pairs
|> List.map ~f:parse_one_spec
let specs =
try user_defined_specs_of_yojson Config.annotation_reachability_custom_pairs
with _ -> L.die ExternalError "Could not parse annotation reachability custom pairs@."
in
List.map specs ~f:make_standard_spec_from_user_spec
in
let user_defined_specs = List.concat user_defined_specs in
[ (Language.Clang, CxxAnnotationSpecs.from_config ())
Expand Down

0 comments on commit e1850ff

Please sign in to comment.