<commit_before>(*
 * Copyright (c) Facebook, Inc. and its affiliates.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 *)

open! IStd
module F = Format
module ConfigName = FbGKInteraction.ConfigName

module Branch = struct
  type t = True | False | Top

  let pp f = function
    | True ->
        F.pp_print_string f "true branch"
    | False ->
        F.pp_print_string f "false branch"
    | Top ->
        AbstractDomain.TopLiftedUtils.pp_top f


  let leq ~lhs ~rhs =
    match (lhs, rhs) with True, True | False, False | _, Top -> true | _, _ -> false


  let join x y = match (x, y) with True, True -> True | False, False -> False | _, _ -> Top

  let widen ~prev ~next ~num_iters:_ = join prev next

  let top = Top

  let is_top = function Top -> true | True | False -> false

  let neg = function True -> False | False -> True | Top -> Top
end

module ConfigChecks = AbstractDomain.SafeInvertedMap (ConfigName) (Branch)

module UncheckedCallee = struct
  type t =
    | Direct of {callee: Procname.t; location: Location.t}
    | Indirect of {callee: Procname.t; location: Location.t}
  [@@deriving compare]

  let pp f = function
    | Direct {callee; location} ->
        F.fprintf f "%a is called at %a" Procname.pp callee Location.pp location
    | Indirect {callee; location} ->
        F.fprintf f "%a is indirectly called from %a" Procname.pp callee Location.pp location


  let get_location = function Direct {location} | Indirect {location} -> location

  let replace_location location = function
    | Direct {callee} | Indirect {callee} ->
        Indirect {callee; location}


  let report {InterproceduralAnalysis.proc_desc; err_log} x =
    let desc = F.asprintf "%a without config check" pp x in
    let trace =
      (* TODO *)
      []
    in
    Reporting.log_issue proc_desc err_log ~loc:(get_location x) ~ltr:trace ConfigImpactAnalysis
      IssueType.config_impact_analysis desc
end

module UncheckedCallees = struct
  include AbstractDomain.FiniteSet (UncheckedCallee)

  let report analysis_data unchecked_callees =
    iter (UncheckedCallee.report analysis_data) unchecked_callees


  let replace_location location x = map (UncheckedCallee.replace_location location) x<commit_msg>[ConfigImpact] Add inter-procedural trace<commit_after>(*
 * Copyright (c) Facebook, Inc. and its affiliates.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 *)

open! IStd
module F = Format
module ConfigName = FbGKInteraction.ConfigName

module Branch = struct
  type t = True | False | Top

  let pp f = function
    | True ->
        F.pp_print_string f "true branch"
    | False ->
        F.pp_print_string f "false branch"
    | Top ->
        AbstractDomain.TopLiftedUtils.pp_top f


  let leq ~lhs ~rhs =
    match (lhs, rhs) with True, True | False, False | _, Top -> true | _, _ -> false


  let join x y = match (x, y) with True, True -> True | False, False -> False | _, _ -> Top

  let widen ~prev ~next ~num_iters:_ = join prev next

  let top = Top

  let is_top = function Top -> true | True | False -> false

  let neg = function True -> False | False -> True | Top -> Top
end

module ConfigChecks = AbstractDomain.SafeInvertedMap (ConfigName) (Branch)

module UncheckedCallee = struct
  type t =
    | Direct of {callee: Procname.t; location: Location.t}
    | Indirect of {callee: Procname.t; location: Location.t; trace: t [@compare.ignore]}
  [@@deriving compare]

  let get_location = function Direct {location} | Indirect {location} -> location

  let pp_common ~with_location f x =
    ( match x with
    | Direct {callee} ->
        F.fprintf f "%a is called" Procname.pp callee
    | Indirect {callee} ->
        F.fprintf f "%a is indirectly called" Procname.pp callee ) ;
    if with_location then F.fprintf f " at %a" Location.pp (get_location x)


  let pp f x = pp_common ~with_location:true f x

  let pp_without_location f x = pp_common ~with_location:false f x

  let replace_location location x =
    match x with Direct {callee} | Indirect {callee} -> Indirect {callee; location; trace= x}


  let rec make_err_trace x =
    let desc = F.asprintf "%a" pp_without_location x in
    let trace_elem = Errlog.make_trace_element 0 (get_location x) desc [] in
    match x with Direct _ -> [trace_elem] | Indirect {trace} -> trace_elem :: make_err_trace trace


  let report {InterproceduralAnalysis.proc_desc; err_log} x =
    let desc = F.asprintf "%a without config check" pp x in
    Reporting.log_issue proc_desc err_log ~loc:(get_location x) ~ltr:(make_err_trace x)
      ConfigImpactAnalysis IssueType.config_impact_analysis desc
end

module UncheckedCallees = struct
  include AbstractDomain.FiniteSet (UncheckedCallee)

  let report analysis_data unchecked_callees =
    iter (UncheckedCallee.report analysis_data) unchecked_callees


  let replace_location location x = map (UncheckedCallee.replace_location location) x
{'fraction_non_alphanumeric': 0.09076464746772592, 'fraction_numerical': 0.00019860973187686197, 'mean_word_length': 3.2896081771720613, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3619378', 'n_tokens_mistral': 1599, 'n_tokens_neox': 1541, 'n_words': 554}