This repository has been archived by the owner on Jun 13, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtestGraph.ml
47 lines (46 loc) · 1.77 KB
/
testGraph.ml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
module G = TypeGraph.G
module Vertex = TypeGraph.Vertex
module Edge = TypeGraph.Edge
module GDot = struct
include G
let graph_attributes _ = []
let default_vertex_attributes _ = []
let vertex_label = function
| Vertex.Global -> "Global"
| Vertex.Instance qn -> "Instance " ^ Fmt.to_to_string IdlData.pp_qualified_name qn
| Vertex.Class qn -> "Class " ^ Fmt.to_to_string IdlData.pp_qualified_name qn
let vertex_name = function
| Vertex.Global -> "G"
| Vertex.Instance qn -> "I" ^ (BatString.join "_" qn)
| Vertex.Class qn -> "C" ^ (BatString.join "_" qn)
let vertex_attributes v = [ `Label (vertex_label v) ]
let get_subgraph _ = None
let default_edge_attributes _ = []
let edge_attributes (_, (et, em), _) =
[ `Style (match et with
| Edge.Attribute _ -> `Solid
| Edge.Result _ -> `Dashed);
`Color (match em with
| Edge.Good -> 0x000000
| Edge.Nondeterministic -> 0x0000FF
| Edge.Blacklisted -> 0xFF0000);
`Label (match et with
| Edge.Attribute name -> name
| Edge.Result name -> name)
]
end
module Dot = Graph.Graphviz.Dot(GDot)
let () =
let open Arg in
let files = ref [] and outfile = ref None and reduce_graph = ref false in
Arg.parse [("-o", String (fun x -> outfile := Some x), "Output file"); ("-r", Set reduce_graph, "Reduce graph")]
(fun arg -> files := arg :: !files)
"testGraph [-o output] filenames";
let defs = Webidl.flatten_from_files !files
in let graph = TypeGraph.build_reachability_graph defs
in match !outfile with
| None -> Dot.output_graph stdout graph
| Some fn ->
let chan = open_out fn in
Dot.output_graph chan graph;
close_out chan