ppx_compare ProcCfg

Reviewed By: sblackshear

Differential Revision: D4232404

fbshipit-source-id: 7f0e191
master
Josh Berdine 9 years ago committed by Facebook Github Bot
parent 85d15bcc49
commit bbd5ef385d

@ -15,7 +15,7 @@ module F = Format
file). Defines useful wrappers that allows us to do tricks like turn a forward cfg into a file). Defines useful wrappers that allows us to do tricks like turn a forward cfg into a
backward one, or view a cfg as having a single instruction per node. *) backward one, or view a cfg as having a single instruction per node. *)
type index = Node_index | Instr_index of int type index = Node_index | Instr_index of int [@@deriving compare]
module type Node = sig module type Node = sig
type t type t
@ -25,7 +25,7 @@ module type Node = sig
val id : t -> id val id : t -> id
val loc : t -> Location.t val loc : t -> Location.t
val underlying_id : t -> Procdesc.Node.id val underlying_id : t -> Procdesc.Node.id
val id_compare : id -> id -> int val compare_id : id -> id -> int
val pp_id : F.formatter -> id -> unit val pp_id : F.formatter -> id -> unit
end end
@ -37,7 +37,7 @@ module DefaultNode = struct
let id = Procdesc.Node.get_id let id = Procdesc.Node.get_id
let loc = Procdesc.Node.get_loc let loc = Procdesc.Node.get_loc
let underlying_id = id let underlying_id = id
let id_compare = Procdesc.Node.compare_id let compare_id = Procdesc.Node.compare_id
let pp_id = Procdesc.Node.pp_id let pp_id = Procdesc.Node.pp_id
end end
@ -53,16 +53,12 @@ module InstrNode = struct
let loc t = Procdesc.Node.get_loc t let loc t = Procdesc.Node.get_loc t
let index_compare index1 index2 = match index1, index2 with let compare_index = compare_index
| Node_index, Node_index -> 0
| Instr_index i1, Instr_index i2 -> int_compare i1 i2
| Node_index, Instr_index _ -> 1
| Instr_index _, Node_index -> -1
let id_compare (id1, index1) (id2, index2) = let compare_id (id1, index1) (id2, index2) =
let n = Procdesc.Node.compare_id id1 id2 in let n = Procdesc.Node.compare_id id1 id2 in
if n <> 0 then n if n <> 0 then n
else index_compare index1 index2 else compare_index index1 index2
let pp_id fmt (id, index) = match index with let pp_id fmt (id, index) = match index with
| Node_index -> Procdesc.Node.pp_id fmt id | Node_index -> Procdesc.Node.pp_id fmt id
@ -234,10 +230,10 @@ end
module NodeIdMap (CFG : S) = Map.Make(struct module NodeIdMap (CFG : S) = Map.Make(struct
type t = CFG.id type t = CFG.id
let compare = CFG.id_compare let compare = CFG.compare_id
end) end)
module NodeIdSet (CFG : S) = Set.Make(struct module NodeIdSet (CFG : S) = Set.Make(struct
type t = CFG.id type t = CFG.id
let compare = CFG.id_compare let compare = CFG.compare_id
end) end)

@ -21,7 +21,7 @@ module type Node = sig
val id : t -> id val id : t -> id
val loc : t -> Location.t val loc : t -> Location.t
val underlying_id : t -> Procdesc.Node.id val underlying_id : t -> Procdesc.Node.id
val id_compare : id -> id -> int val compare_id : id -> id -> int
val pp_id : Format.formatter -> id -> unit val pp_id : Format.formatter -> id -> unit
end end

@ -25,7 +25,7 @@ module MockNode = struct
let loc _ = assert false let loc _ = assert false
let underlying_id _ = assert false let underlying_id _ = assert false
let kind _ = Procdesc.Node.Stmt_node "" let kind _ = Procdesc.Node.Stmt_node ""
let id_compare = int_compare let compare_id = int_compare
let pp_id fmt i = let pp_id fmt i =
F.fprintf fmt "%i" i F.fprintf fmt "%i" i
end end
@ -35,13 +35,13 @@ module MockProcCfg = struct
include (MockNode : module type of MockNode with type t := node) include (MockNode : module type of MockNode with type t := node)
type t = (node * node list) list type t = (node * node list) list
let id_compare = int_compare let compare_id = int_compare
let succs t n = let succs t n =
try try
let node_id = id n in let node_id = id n in
IList.find IList.find
(fun (node, _) -> id_compare (id node) node_id = 0) (fun (node, _) -> compare_id (id node) node_id = 0)
t t
|> snd |> snd
with Not_found -> [] with Not_found -> []
@ -51,7 +51,7 @@ module MockProcCfg = struct
let node_id = id n in let node_id = id n in
IList.filter IList.filter
(fun (_, succs) -> (fun (_, succs) ->
IList.exists (fun node -> id_compare (id node) node_id = 0) succs) IList.exists (fun node -> compare_id (id node) node_id = 0) succs)
t t
|> IList.map fst |> IList.map fst
with Not_found -> [] with Not_found -> []

Loading…
Cancel
Save