From a45395857da3efae0b15b1aacbf51a07674219dc Mon Sep 17 00:00:00 2001 From: cqc Date: Thu, 11 May 2023 18:56:57 -0500 Subject: [PATCH] sorry it's in such a bad state but this didn't go very far so hopefully i get farther with the other method and this branch is lost to history. but in case it's not, lol --- lib/dot_of_tast.ml | 28 ++++++++++++++++++++-------- notes.org | 12 ++++++++++++ 2 files changed, 32 insertions(+), 8 deletions(-) diff --git a/lib/dot_of_tast.ml b/lib/dot_of_tast.ml index 49e0db2..e9b7fee 100644 --- a/lib/dot_of_tast.ml +++ b/lib/dot_of_tast.ml @@ -719,6 +719,11 @@ let str_of_pat (pat : value general_pattern) = let str_of_ident = Ident.name let unique_str_of_ident = Ident.unique_name +let unique_str_of_ident_pat x = + match x.pat_desc with + | Tpat_var (s, _) -> F.str "%a" P.fmt_ident s + | _ -> str_of_pat x + let pp_value_binding_list ppf (vbl : Typedtree.value_binding list) = Fmt.pf ppf "%a" (Fmt.parens @@ -727,16 +732,21 @@ let pp_value_binding_list ppf (vbl : Typedtree.value_binding list) = let unique_node_count = ref 0 -let vertex_of_primary_value (exp : Typedtree.expression) : Gr.Vertex.t - = - (* sorry that the use of the word primary is so abusive *) +let vertex_of_exp (exp : Typedtree.expression) : Gr.Vertex.t = + (* primary isn't well defined here, it's whatever i choosen for src nodes atm *) match exp.exp_desc with | Texp_ident (path, _longident, _value_desc) -> { name = F.str "%a" P.fmt_path path; - attr = [ `Label (F.str "{{}|%s}" (str_of_exp exp)) ]; + attr = [ `Label (F.str "{{}|%s}" (str_of_exp exp)) ]; subgraph = None; } + | Texp_construct _ -> + { + Gr.Vertex.default with + name = F.str "_Texp_construct/%d" !unique_node_count; + attr = [ `Label (F.str "{%s}" (str_of_exp exp)) ]; + } | Texp_constant _ -> { Gr.Vertex.default with @@ -799,7 +809,7 @@ let graph_of_impl (s : Typedtree.structure) : Gr.t = let open Typedtree in match exp.exp_desc with | Texp_apply (_exp, list) -> - let src = vertex_of_primary_value exp in + let src = vertex_of_exp exp in (* Tast_iterator.default_iterator.expr iter exp *) (* skip _exp *) List.fold_left @@ -850,7 +860,7 @@ let graph_of_impl (s : Typedtree.structure) : Gr.t = let src = labeled_vertex (unique_str_of_ident param) - (F.str "{{<0>function %s}|{%s}}" + (F.str "{{function %s}|{%s}}" (unique_str_of_ident param) (fst (List.fold_left @@ -878,12 +888,14 @@ let graph_of_impl (s : Typedtree.structure) : Gr.t = `TailportRecord (F.str "%d" i); ]; }, - labeled_vertex (str_of_pat c_lhs) "{|LOL}" ); + labeled_vertex + (unique_str_of_ident_pat c_lhs) + "{|LOL}" ); Stack.pop_opt dst_stk |> ignore) cases; src | _ -> - let src = vertex_of_primary_value exp in + let src = vertex_of_exp exp in Stack.push (src, 0) dst_stk; Tast_iterator.default_iterator.expr iter exp; Stack.pop_opt dst_stk |> ignore; diff --git a/notes.org b/notes.org index 29b22ed..313156d 100644 --- a/notes.org +++ b/notes.org @@ -1,4 +1,16 @@ +* usage: +evaulate the following in ur ocaml toplevel (`$ ocaml`): + +``` +#use_output "dune ocaml top";; +Dot_of_tast.dot_of_tast "let rec fact n = if n = 0 then 1. else float n *. fact (n - 1)";; +``` + +run in shell to see output: +``` +$ xdot x.dot +``` ** current development pattern