package pfff

  1. Overview
  2. Docs
Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source

Source file graph_code_export.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
(* Yoann Padioleau
 *
 * Copyright (C) 2018 Yoann Padioleau
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public License
 * version 2.1 as published by the Free Software Foundation, with the
 * special exception on linking described in file license.txt.
 * 
 * This library is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the file
 * license.txt for more details.
 *)

module G = Graph_code
module J = Json_type

(*****************************************************************************)
(* Prelude *)
(*****************************************************************************)

(*****************************************************************************)
(* Helpers *)
(*****************************************************************************)
let string_of_entity_kind kind =
  Entity_code.string_of_entity_kind kind

let json_short_of_node (str, kind) =
  J.Array [
    J.String str;
    J.String (string_of_entity_kind kind);
  ]

let json_of_node g (str, kind) =
  J.Object [
    "name_kind", json_short_of_node (str, kind);
    "location", J.String (
      try G.file_of_node (str, kind) g
      (* 'Dir' entities have no location for example *)
      with Not_found -> "UNKNOWN LOCATION"
    );
  ]


(*****************************************************************************)
(* Main entry point *)
(*****************************************************************************)

let graph_to_json g =
  J.Object [
    "nodes", J.Array (
      G.all_nodes g |> List.map (json_of_node g)
    );
    "edges_Use", J.Array (
      G.all_use_edges g |> List.map (fun (src, dst) ->
        J.Object [
          "src", json_short_of_node src;
          "dst", json_short_of_node dst;
        ]
      )
    );
    "edges_Has", J.String "TODO";
  ]

OCaml

Innovation. Community. Security.