Skip to content

Commit

Permalink
Extract duplicate code into separate functions
Browse files Browse the repository at this point in the history
  • Loading branch information
karoliineh committed Jan 10, 2025
1 parent 1c5c27e commit f977c4d
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions src/cdomain/value/cdomains/intDomain0.ml
Original file line number Diff line number Diff line change
Expand Up @@ -555,26 +555,30 @@ module IntervalArith (Ints_t : IntOps.IntOps) = struct
let to_int (x1, x2) =
if Ints_t.equal x1 x2 then Some x1 else None

let find_thresholds lower_or_upper =
let ts = if get_interval_threshold_widening_constants () = "comparisons" then lower_or_upper else WideningThresholds.thresholds in
ResettableLazy.force ts

let upper_threshold u max_ik =
let ts = if get_interval_threshold_widening_constants () = "comparisons" then WideningThresholds.upper_thresholds else WideningThresholds.thresholds in
let ts = find_thresholds WideningThresholds.upper_thresholds in
let u = Ints_t.to_bigint u in
let max_ik' = Ints_t.to_bigint max_ik in
let t = WideningThresholds.Thresholds.find_first_opt (fun x -> Z.compare u x <= 0 && Z.compare x max_ik' <= 0) (ResettableLazy.force ts) in
let t = WideningThresholds.Thresholds.find_first_opt (fun x -> Z.compare u x <= 0 && Z.compare x max_ik' <= 0) ts in
BatOption.map_default Ints_t.of_bigint max_ik t
let lower_threshold l min_ik =
let ts = if get_interval_threshold_widening_constants () = "comparisons" then WideningThresholds.lower_thresholds else WideningThresholds.thresholds in
let ts = find_thresholds WideningThresholds.lower_thresholds in
let l = Ints_t.to_bigint l in
let min_ik' = Ints_t.to_bigint min_ik in
let t = WideningThresholds.Thresholds.find_last_opt (fun x -> Z.compare l x >= 0 && Z.compare x min_ik' >= 0) (ResettableLazy.force ts) in
let t = WideningThresholds.Thresholds.find_last_opt (fun x -> Z.compare l x >= 0 && Z.compare x min_ik' >= 0) ts in
BatOption.map_default Ints_t.of_bigint min_ik t
let is_upper_threshold u =
let ts = if get_interval_threshold_widening_constants () = "comparisons" then WideningThresholds.upper_thresholds else WideningThresholds.thresholds in
let u = Ints_t.to_bigint u in
WideningThresholds.Thresholds.exists (Z.equal u) (ResettableLazy.force ts)
let is_lower_threshold l =
let ts = if get_interval_threshold_widening_constants () = "comparisons" then WideningThresholds.lower_thresholds else WideningThresholds.thresholds in
let l = Ints_t.to_bigint l in
WideningThresholds.Thresholds.exists (Z.equal l) (ResettableLazy.force ts)

let is_threshold t ts =
let ts = find_thresholds ts in
let t = Ints_t.to_bigint t in
WideningThresholds.Thresholds.exists (Z.equal t) ts

let is_upper_threshold u = is_threshold u WideningThresholds.upper_thresholds
let is_lower_threshold l = is_threshold l WideningThresholds.lower_thresholds
end

module IntInvariant =
Expand Down

0 comments on commit f977c4d

Please sign in to comment.