Commit 4248dececcd3396438bea71dd9b7927f67b2e73f

Authored by totoro
1 parent 8bc8f772

add the support of type generation by densaku

hayamiki_generator.aproj
@@ -489,6 +489,7 @@ @@ -489,6 +489,7 @@
489 <Compile Include="src\generation\choices_selector.anubis" /> 489 <Compile Include="src\generation\choices_selector.anubis" />
490 <Compile Include="src\generation\columns.anubis" /> 490 <Compile Include="src\generation\columns.anubis" />
491 <Compile Include="src\generation\create_table.anubis" /> 491 <Compile Include="src\generation\create_table.anubis" />
  492 + <Compile Include="src\generation\densaku.anubis" />
492 <Compile Include="src\generation\fields.anubis" /> 493 <Compile Include="src\generation\fields.anubis" />
493 <Compile Include="src\generation\files.anubis" /> 494 <Compile Include="src\generation\files.anubis" />
494 <Compile Include="src\generation\fn_delete.anubis" /> 495 <Compile Include="src\generation\fn_delete.anubis" />
hayamiki_lib @ 523830e5bcc
1 -Subproject commit 27f3d0f6b93aa27fbbd34993a72cef1fb36b347f 1 +Subproject commit 523830e5bcc852cc87262ed92f96d7a0ec0d0032
src/generation/densaku.anubis 0 → 100644
  1 +/*
  2 + * Created by PyramIDE.
  3 + * User: フランスのトトロ aka (David RENÉ)
  4 + * Date: 26/01/2017
  5 + * Time: 00:14
  6 + * © Calexium
  7 + */
  8 +
  9 +read hayamiki_lib/types/hayamiki.anubis
  10 +read tools/basis.anubis
  11 +read tools/streams.anubis
  12 +read system/string.anubis
  13 +read fields.anubis
  14 +read columns.anubis
  15 +read tools/ISO-8601.anubis
  16 +
  17 +define List(String)
  18 +/**
  19 + */
  20 + _generate_densaku_type
  21 + (
  22 + List(HK_Model_Column) columns,
  23 + List(String) so_far
  24 + )=
  25 + if columns is
  26 + {
  27 + [] then reverse(so_far),
  28 + [h . t ] then
  29 + since h is hk_column(name, col_type, _, _),
  30 + _generate_densaku_type(t, [ " component("+fill(to_densaku_type(col_type), 12) + ", \"" + name +"\")". so_far])
  31 + }.
  32 +
  33 +public define Maybe(One)
  34 + generate_densaku_type
  35 + (
  36 + Stream stream,
  37 + HK_Table table
  38 + )=
  39 + since table is hk_table(name, short_name, model, display),
  40 + since model is hk_model(columns, show_string),
  41 + with type_name = to_upper(name, 1), //make the first character to upper case to able to be a Anubis Type.
  42 +
  43 + //generate the type of the HK_Table that contain all components
  44 + if write_string(stream,
  45 + " ds_type(\""+type_name+"\", [\n"+
  46 + " alternative(\""+name+"\", [\n"+ //head of the type declaration
  47 + join(",\n",_generate_densaku_type(columns, []))+ //all components of the type
  48 + " ])\n"+
  49 + " ]),\n") is //end of declaration
  50 + {
  51 + failure then println("can't write type "+type_name); failure,
  52 + success(_) then success(unique)
  53 + }.
  54 +
  55 +public define Maybe(One)
  56 +/*
  57 + */
  58 + generate_densaku_type
  59 + (
  60 + HK_Table table,
  61 + String dest_dir,
  62 + Bool use_densaku
  63 + )=
  64 + if use_densaku then
  65 + with file_name = dest_dir+"database/generated/densaku_type.anubis",
  66 + if file(file_name, append) is
  67 + {
  68 + failure then println("can't create file "+file_name);failure,
  69 + success(fd) then
  70 + with strm = make_stream(fd),
  71 + generate_densaku_type(strm, table)
  72 + }
  73 + else
  74 + success(unique)
  75 +.
  76 +
  77 +public define One
  78 + make_densaku_header
  79 + (
  80 + String dest_dir,
  81 + Bool use_densaku
  82 + )=
  83 + if use_densaku then
  84 + with file_name = dest_dir+"database/generated/densaku_type.anubis",
  85 + if file(file_name, new) is
  86 + {
  87 + failure then unique,
  88 + success(fd) then
  89 + with strm = make_stream(fd),
  90 + forget(write_string(strm,
  91 +"/*
  92 + * Created by 早見木 (Hayamiki).
  93 + * Types & Messages generator written by フランスのトトロ aka (David RENÉ)
  94 + * Date: "+_Int_to_ISO_8601_date(now)+"
  95 + * Time: "+_Int_to_ISO_8601_time(now)+"
  96 + *
  97 + */
  98 +
  99 +read densaku_lib/types/densaku.anubis
  100 +
  101 +public define List(DS_Type) hayamiki_types_list =
  102 + [\n"))
  103 + }
  104 + else
  105 + unique
  106 +.
  107 +
  108 +public define One
  109 + close_densaku_file
  110 + (
  111 + String dest_dir,
  112 + Bool use_densaku
  113 + )=
  114 + if use_densaku then
  115 + with file_name = dest_dir+"database/generated/densaku_type.anubis",
  116 + if file(file_name, append) is
  117 + {
  118 + failure then unique,
  119 + success(fd) then
  120 + with strm = make_stream(fd),
  121 + forget(write_string(strm,
  122 +" ]
  123 +.\n"))
  124 + }
  125 + else
  126 + unique
  127 +.
src/generation/fields.anubis
@@ -36,6 +36,29 @@ public define String @@ -36,6 +36,29 @@ public define String
36 password_field(_) then "String", 36 password_field(_) then "String",
37 text_field then "String" 37 text_field then "String"
38 }. 38 }.
  39 +
  40 +public define String
  41 +/** Return the corresponding Anubis type of the field
  42 + */
  43 + to_densaku_type
  44 + (
  45 + HK_Model_Field t
  46 + ) =
  47 + if t is
  48 + {
  49 + //anubis(_T) then "ByteArray",
  50 + p_key then "extern_type(\"DB_id\", \"calexium_lib/model/db_types.anubis\")",
  51 + //binary then "ByteArray",
  52 + boolean_field then "bool",
  53 + date_field(_) then "extern_type(\"DB_date\", \"calexium_lib/model/db_types.anubis\")",
  54 + time_field(_) then "extern_type(\"DB_time\", \"calexium_lib/model/db_types.anubis\")",
  55 + datetime_field(_) then "extern_type(\"DB_datetime\", \"calexium_lib/model/db_types.anubis\")",
  56 + foreign_key(_,_) then "int",
  57 + integer_field(_) then "int",
  58 + char_field(_,_) then "string",
  59 + password_field(_) then "string",
  60 + text_field then "string"
  61 + }.
39 62
40 public define String 63 public define String
41 to_SQL_CREATE 64 to_SQL_CREATE
src/generation/files.anubis
@@ -17,6 +17,7 @@ read tools/streams.anubis @@ -17,6 +17,7 @@ read tools/streams.anubis
17 read tools/ISO-8601.anubis 17 read tools/ISO-8601.anubis
18 read generation/header.anubis 18 read generation/header.anubis
19 read generation/types.anubis 19 read generation/types.anubis
  20 +read generation/densaku.anubis
20 read generation/create_table.anubis 21 read generation/create_table.anubis
21 read generation/menu.anubis 22 read generation/menu.anubis
22 read generation/fn_delete.anubis 23 read generation/fn_delete.anubis
@@ -27,8 +28,9 @@ read check.anubis @@ -27,8 +28,9 @@ read check.anubis
27 define Maybe(One) 28 define Maybe(One)
28 generate_table 29 generate_table
29 ( 30 (
30 - HK_Table org_table, //table to generate  
31 - String dest_dir //root directory of the generation 31 + HK_Table org_table, //table to generate
  32 + String dest_dir, //root directory of the generation
  33 + Bool use_densaku //if true, this means the types are constructed by densaku for generating also the messages
32 ) 34 )
33 = 35 =
34 since org_table is hk_table(name, short_name, old_model, display), 36 since org_table is hk_table(name, short_name, old_model, display),
@@ -49,7 +51,8 @@ define Maybe(One) @@ -49,7 +51,8 @@ define Maybe(One)
49 success(fd) then 51 success(fd) then
50 with strm = make_stream(fd), 52 with strm = make_stream(fd),
51 if generate_header(strm, columns) is { failure then failure, success(_) then 53 if generate_header(strm, columns) is { failure then failure, success(_) then
52 - if generate_type(strm, table) is { failure then failure, success(_) then 54 + if generate_densaku_type(table, dest_dir, use_densaku) is { failure then failure, success(_) then
  55 + if generate_type(strm, table, use_densaku) is { failure then failure, success(_) then
53 if generate_get_default(strm, table) is { failure then failure, success(_) then 56 if generate_get_default(strm, table) is { failure then failure, success(_) then
54 if generate_extract_web_arg(strm, table) is { failure then failure, success(_) then 57 if generate_extract_web_arg(strm, table) is { failure then failure, success(_) then
55 if generate_extract_db_cursor(strm, table) is { failure then failure, success(_) then 58 if generate_extract_db_cursor(strm, table) is { failure then failure, success(_) then
@@ -64,24 +67,25 @@ define Maybe(One) @@ -64,24 +67,25 @@ define Maybe(One)
64 if generate_choices_selector(strm, table) is { failure then failure, success(_) then 67 if generate_choices_selector(strm, table) is { failure then failure, success(_) then
65 if generate_VT_all_view(strm, table) is { failure then failure, success(_) then 68 if generate_VT_all_view(strm, table) is { failure then failure, success(_) then
66 if generate_VT_all_edit(strm, table) is { failure then failure, success(_) then 69 if generate_VT_all_edit(strm, table) is { failure then failure, success(_) then
67 - success(unique)}}}}}}}}}}}}}}}} 70 + success(unique)}}}}}}}}}}}}}}}}}
68 }. 71 }.
69 72
70 define One 73 define One
71 make_all_tables 74 make_all_tables
72 ( 75 (
73 List(HK_Table) tables, //list of the table model description 76 List(HK_Table) tables, //list of the table model description
74 - String dest_dir 77 + String dest_dir,
  78 + Bool use_densaku
75 ) 79 )
76 = 80 =
77 if tables is 81 if tables is
78 { 82 {
79 [] then println("Generation finished"), 83 [] then println("Generation finished"),
80 [h . t] then 84 [h . t] then
81 - if generate_table(h, dest_dir) is 85 + if generate_table(h, dest_dir, use_densaku) is
82 { 86 {
83 failure then println("Generation error") 87 failure then println("Generation error")
84 - success(_) then make_all_tables(t, dest_dir) 88 + success(_) then make_all_tables(t, dest_dir, use_densaku)
85 } 89 }
86 }. 90 }.
87 91
@@ -89,13 +93,18 @@ define One @@ -89,13 +93,18 @@ define One
89 make_all_tables 93 make_all_tables
90 ( 94 (
91 List(HK_App) apps, 95 List(HK_App) apps,
92 - String dest_dir 96 + String dest_dir,
  97 + Bool use_densaku
93 98
94 )= 99 )=
  100 + make_densaku_header(dest_dir, use_densaku);
  101 +
95 map_forget((HK_App app) |-> since app is hk_app(app_name, _, _, tables), 102 map_forget((HK_App app) |-> since app is hk_app(app_name, _, _, tables),
96 println("generating tables for App ["+app_name+"]"); 103 println("generating tables for App ["+app_name+"]");
97 - make_all_tables(tables, dest_dir), apps).  
98 - 104 + make_all_tables(tables, dest_dir, use_densaku), apps);
  105 +
  106 + close_densaku_file(dest_dir, use_densaku)
  107 +.
99 108
100 define Maybe(One) 109 define Maybe(One)
101 generate_vtm_file 110 generate_vtm_file
@@ -115,7 +124,7 @@ define Maybe(One) @@ -115,7 +124,7 @@ define Maybe(One)
115 if write_string(make_stream(fd), 124 if write_string(make_stream(fd),
116 "/* 125 "/*
117 * Created by 早見木 (Hayamiki). 126 * Created by 早見木 (Hayamiki).
118 - * User: Automaton 127 + * Database generator written by フランスのトトロ aka (David RENÉ)
119 * Date: "+_Int_to_ISO_8601_date(now)+" 128 * Date: "+_Int_to_ISO_8601_date(now)+"
120 * Time: "+_Int_to_ISO_8601_time(now)+" 129 * Time: "+_Int_to_ISO_8601_time(now)+"
121 * 130 *
@@ -194,7 +203,8 @@ define Maybe(One) @@ -194,7 +203,8 @@ define Maybe(One)
194 generate_model_files 203 generate_model_files
195 ( 204 (
196 HK_Database db, //database model description 205 HK_Database db, //database model description
197 - String destination_dir 206 + String destination_dir,
  207 + Bool use_densaku
198 )= 208 )=
199 209
200 if check_database(db) is 210 if check_database(db) is
@@ -203,7 +213,7 @@ define Maybe(One) @@ -203,7 +213,7 @@ define Maybe(One)
203 success(database) then 213 success(database) then
204 since database is hk_database(name, apps), 214 since database is hk_database(name, apps),
205 println("Generating models for Database "+name); 215 println("Generating models for Database "+name);
206 - make_all_tables(apps, destination_dir); 216 + make_all_tables(apps, destination_dir, use_densaku);
207 println("Generating VTM for Database "+name); 217 println("Generating VTM for Database "+name);
208 make_vtm(apps, destination_dir); 218 make_vtm(apps, destination_dir);
209 println("Generating create for Database "+name); 219 println("Generating create for Database "+name);
src/generation/header.anubis
@@ -45,7 +45,7 @@ public define Maybe(One) @@ -45,7 +45,7 @@ public define Maybe(One)
45 if write_string(stream, 45 if write_string(stream,
46 "/* 46 "/*
47 * Created by 早見木 (Hayamiki). 47 * Created by 早見木 (Hayamiki).
48 - * User: Automat 48 + * Database generator written by フランスのトトロ aka (David RENÉ)
49 * Date: "+_Int_to_ISO_8601_date(now)+" 49 * Date: "+_Int_to_ISO_8601_date(now)+"
50 * Time: "+_Int_to_ISO_8601_time(now)+" 50 * Time: "+_Int_to_ISO_8601_time(now)+"
51 * 51 *
src/generation/types.anubis
@@ -34,22 +34,32 @@ public define Maybe(One) @@ -34,22 +34,32 @@ public define Maybe(One)
34 generate_type 34 generate_type
35 ( 35 (
36 Stream stream, 36 Stream stream,
37 - HK_Table table 37 + HK_Table table,
  38 + Bool use_densaku
38 )= 39 )=
39 since table is hk_table(name, short_name, model, display), 40 since table is hk_table(name, short_name, model, display),
40 since model is hk_model(columns, show_string), 41 since model is hk_model(columns, show_string),
41 with type_name = to_upper(name, 1), //make the first character to upper case to able to be a Anubis Type. 42 with type_name = to_upper(name, 1), //make the first character to upper case to able to be a Anubis Type.
42 43
43 - //generate the type of the HK_Table that contain all components  
44 - if write_string(stream,  
45 - "\n\npublic type "+type_name+":\n "+name+"\n (\n"+ //head of the type declaration  
46 - join(",\n",_generate_type(columns, []))+ //all components of the type  
47 - "\n ).\n") is //end of declaration  
48 - {  
49 - failure then println("can't write type "+type_name); failure,  
50 - success(_) then success(unique)  
51 - }. 44 + //if we use densaku for generating the type, we insert the read of that type after densaku generation
  45 + if use_densaku then
  46 + write_string(stream,
  47 + "\n\nread types/generated/ "+to_lower(type_name)+".anubis\n") //read of the type declaration
  48 +
  49 + else
52 50
  51 + //generate the type of the HK_Table that contain all components
  52 + if write_string(stream,
  53 + "\n\npublic type "+type_name+":\n "+name+"\n (\n"+ //head of the type declaration
  54 + join(",\n",_generate_type(columns, []))+ //all components of the type
  55 + "\n ).\n") is //end of declaration
  56 + {
  57 + failure then println("can't write type "+type_name); failure,
  58 + success(_) then success(unique)
  59 + }
  60 +.
  61 +
  62 +
53 define List(String) 63 define List(String)
54 /** 64 /**
55 */ 65 */
@@ -28,7 +28,7 @@ global define One @@ -28,7 +28,7 @@ global define One
28 if load_hk_generator is 28 if load_hk_generator is
29 { 29 {
30 failure then println("Hayamiki generator can't be load"), 30 failure then println("Hayamiki generator can't be load"),
31 - success(hk_gen) then forget(hk_gen.generate_model_files(the_database_description, "")) 31 + success(hk_gen) then forget(hk_gen.generate_model_files(the_database_description, "", true))
32 }. 32 }.
33 33
34 global define One 34 global define One