From 42e9e48d4f37546ab4d79393ed32ed67f5f2e0c1 Mon Sep 17 00:00:00 2001 From: totoro Date: Thu, 6 Apr 2017 00:59:27 +0200 Subject: [PATCH] add generation of graphviz file --- densaku.aproj | 5 +++++ src/generation/files.anubis | 5 +++++ src/generation/graphviz/graphviz_header.anubis | 43 +++++++++++++++++++++++++++++++++++++++++++ src/generation/graphviz/graphviz_main.anubis | 35 +++++++++++++++++++++++++++++++++++ src/generation/graphviz/graphviz_type.anubis | 161 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/generation/types.anubis | 1 + 6 files changed, 250 insertions(+), 0 deletions(-) create mode 100644 src/generation/graphviz/graphviz_header.anubis create mode 100644 src/generation/graphviz/graphviz_main.anubis create mode 100644 src/generation/graphviz/graphviz_type.anubis diff --git a/densaku.aproj b/densaku.aproj index 30ecc6e..ba84aec 100644 --- a/densaku.aproj +++ b/densaku.aproj @@ -103,6 +103,7 @@ + @@ -164,6 +165,7 @@ + @@ -561,6 +563,9 @@ + + + diff --git a/src/generation/files.anubis b/src/generation/files.anubis index 514a706..3c4f501 100644 --- a/src/generation/files.anubis +++ b/src/generation/files.anubis @@ -13,6 +13,7 @@ read tools/basis.anubis read types_checking.anubis read generation/types.anubis //generate all types and the message for these types read generation/messages.anubis //generate all messages collection +read generation/graphviz/graphviz_main.anubis public define Maybe(One) generate_message_files @@ -57,6 +58,10 @@ public define Maybe(One) println("Generating messages collection"); make_all_messages(messages, destination_dir); + + println("Generating graphviz"); + forget(make_graphviz_types(types, destination_dir)); + writeString(ini, "TYPES", "SHA1", current_types_SHA1); writeString(ini, "MESSAGES", "SHA1", current_messages_SHA1); writeIniInfo(ini); diff --git a/src/generation/graphviz/graphviz_header.anubis b/src/generation/graphviz/graphviz_header.anubis new file mode 100644 index 0000000..a230fcb --- /dev/null +++ b/src/generation/graphviz/graphviz_header.anubis @@ -0,0 +1,43 @@ +/* + * Created by PyramIDE. + * User: フランスのトトロ aka (David RENÉ) + * Date: 05/04/2017 + * Time: 20:37 + * © Calexium + */ + +read tools/basis.anubis +read tools/streams.anubis +read tools/ISO-8601.anubis +read system/string.anubis + +public define Maybe(One) + generate_graphviz_header + ( + Stream stream + )= + write_string(stream, +"/* + * Created by 伝作 (Densaku). + * Types & Messages generator written by フランスのトトロ aka (David RENÉ) + * Date: "+_Int_to_ISO_8601_date(now)+" + * Time: "+_Int_to_ISO_8601_time(now)+" + * + */ + +digraph DS { + splines=true; + edge [color=gray50, fontname=\"verdana\", fontsize=10] + node [shape=none, bgcolor=gray40, fontname=\"verdana\", fontsize=10] + +" + ) +. + +public define Maybe(One) + generate_graphviz_footer + ( + Stream stream + )= + write_string(stream,"\n}\n") +. diff --git a/src/generation/graphviz/graphviz_main.anubis b/src/generation/graphviz/graphviz_main.anubis new file mode 100644 index 0000000..44a01b3 --- /dev/null +++ b/src/generation/graphviz/graphviz_main.anubis @@ -0,0 +1,35 @@ +/* + * Created by PyramIDE. + * User: フランスのトトロ aka (David RENÉ) + * Date: 05/04/2017 + * Time: 20:33 + * © Calexium + */ + +read tools/basis.anubis +read tools/streams.anubis +read densaku_lib/types/densaku.anubis +read generation/graphviz/graphviz_header.anubis +read generation/graphviz/graphviz_type.anubis + +public define Maybe(One) + make_graphviz_types + ( + List(DS_Type) types, + String destination_dir + )= + with file_name = destination_dir+"types/generated/graphviz.gv", + + if file(file_name, new) is + { + failure then println("can't create file "+file_name);failure, + success(fd) then + with strm = make_stream(fd), + + if generate_graphviz_header(strm) is { failure then failure, success(_) then + if generate_graphviz_types(strm, types) is { failure then failure, success(_) then + if generate_graphviz_footer(strm) is { failure then failure, success(_) then + success(unique) + }}} + } +. diff --git a/src/generation/graphviz/graphviz_type.anubis b/src/generation/graphviz/graphviz_type.anubis new file mode 100644 index 0000000..39298be --- /dev/null +++ b/src/generation/graphviz/graphviz_type.anubis @@ -0,0 +1,161 @@ +/* + * Created by PyramIDE. + * User: フランスのトトロ aka (David RENÉ) + * Date: 05/04/2017 + * Time: 20:48 + * © Calexium + */ + +read tools/basis.anubis +read tools/streams.anubis +read densaku_lib/types/densaku.anubis +read generation/graphviz/graphviz_type.anubis + + +public define One + generate_graphviz_DS_Anubis_Type_relation + ( + DS_Anubis_Type anb_type, + String type_name, + String alternative_name, + String component_name, + Var(String) type_relation + )= + + if anb_type is + { + one then unique, + bool then unique, + int then unique, + word8 then unique, + word16 then unique, + word32 then unique, + string then unique, + float then unique, +// float32 then "Float32", reserved for future implementation in Anubis (still under construction in Anubis) +// float64 then "Float64", reserved for future implementation in Anubis (still under construction in Anubis) + ds_type(foreign_type_name) then + type_relation <- *type_relation + " "+type_name+":"+alternative_name+"_"+component_name+" -> "+foreign_type_name+":TYPE\n", +// println("* "+*type_relation), + extern_type(foreign_type_name, read) then + type_relation <- *type_relation + " "+type_name+":"+alternative_name+"_"+component_name+" -> "+foreign_type_name+":TYPE\n", +// println("* "+*type_relation), + } +. + +public define String + generate_graphviz_DS_Anubis_Type_color + ( + DS_Anubis_Type anb_type + )= + + if anb_type is + { + one then "darkviolet", + bool then "darkviolet", + int then "darkviolet", + word8 then "darkviolet", + word16 then "darkviolet", + word32 then "darkviolet", + string then "darkviolet", + float then "darkviolet", +// float32 then "Float32", reserved for future implementation in Anubis (still under construction in Anubis) +// float64 then "Float64", reserved for future implementation in Anubis (still under construction in Anubis) + ds_type(type_name) then "mediumblue", + extern_type(type_name, read) then "mediumblue", + } +. + +public define String + generate_graphviz_DS_Component_list + ( + List(DS_Component) components, + String type_name, + String alternative_name, + Var(String) type_relation + )= + + if components is + { + [] then + //close the alternative with ")" + " )\n", + [h . t] then + since h is component(b_list, anb_type, name, _), + generate_graphviz_DS_Anubis_Type_relation(anb_type, type_name, alternative_name, name, type_relation); + with line_head = if b_list is list then + // <- TYPE -> + " List("+dump(anb_type)+")" + else + " "+dump(anb_type)+"", + + //construct the complete line + line_head+""+name+"\n" + + + generate_graphviz_DS_Component_list(t, type_name, alternative_name, type_relation) + } +. + +public define String + generate_graphviz_DS_Alternative_list + ( + List(DS_Alternative) ds_alts, + String type_name, + Var(String) type_relation + )= + with prefix = "\n ", + if ds_alts is + { + [] then println("empty");"\n", + [h . t] then + if h is + { + enum(name, _comment) then + "\n "+name+"\n"+ + generate_graphviz_DS_Alternative_list(t, type_name, type_relation), + + alternative(name, comment, components) then + "\n "+name+" (\n"+ + //dump(components, true, type_length, name_length)+ + generate_graphviz_DS_Component_list(components, type_name, name, type_relation)+ + generate_graphviz_DS_Alternative_list(t, type_name, type_relation) + } + } +. + +public define String + generate_graphviz_type + ( + DS_Type _ds_type, //list of type description + String indent + )= + since _ds_type is ds_type(type_name, _, ds_alts), + with type_relation = var(""), + + with start = "\n\n"+ + " "+type_name+" [ label=<\n"+ + " \n"+ + " \n"+ + generate_graphviz_DS_Alternative_list(ds_alts, type_name, type_relation)+ + "
"+type_name+"
\n"+ + " >];\n"+ + "\n", + start+*type_relation +. + +public define Maybe(One) + generate_graphviz_types + ( + Stream stream, + List(DS_Type) types //list of type description + )= + + map_forget((DS_Type type) |-> + since type is ds_type(type_name, _, ds_alts), + println("generating graphviz for Type ["+type_name+"]"); + write_string(stream, + generate_graphviz_type(type, " ")) + , + types); + success(unique) +. diff --git a/src/generation/types.anubis b/src/generation/types.anubis index ef49aa5..36423cb 100644 --- a/src/generation/types.anubis +++ b/src/generation/types.anubis @@ -8,6 +8,7 @@ read generation/types_header.anubis read generation/types_messages.anubis +read generation/graphviz/graphviz_main.anubis read system/files.anubis read system/string.anubis -- libgit2 0.21.4