changeset 490:6470248790db bgo-commands-codegen

ongoing codegen work
author bgo-osimis
date Mon, 18 Feb 2019 15:38:05 +0100
parents f6b7f113cf27
children 8e7e151ef472
files Resources/CodeGeneration/playground.ts Resources/CodeGeneration/playground2.ts Resources/CodeGeneration/playground3.ts Resources/CodeGeneration/playground4.py Resources/CodeGeneration/runts.ps1 Resources/CodeGeneration/stonegentool.py Resources/CodeGeneration/template.in.h Resources/CodeGeneration/template.in.ts Resources/CodeGeneration/test/test1.jsonc Resources/CodeGeneration/test/test1_bogus_json.jsonc Resources/CodeGeneration/test/test1_bogus_schema.jsonc Resources/CodeGeneration/test_data/test1.jsonc Resources/CodeGeneration/test_data/test1.yaml Resources/CodeGeneration/test_data/test1_bogus_json.jsonc Resources/CodeGeneration/test_data/test1_bogus_schema.jsonc Resources/CodeGeneration/tsconfig.json
diffstat 16 files changed, 1073 insertions(+), 249 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Resources/CodeGeneration/playground.ts	Mon Feb 18 15:38:05 2019 +0100
@@ -0,0 +1,260 @@
+/*
+         1         2         3         4         5         6         7
+12345678901234567890123456789012345678901234567890123456789012345678901234567890
+*/
+
+namespace VsolStuff
+{
+  enum EnumMonth0
+  {
+    January,
+    February,
+    March
+  };
+
+  // interface Serializer
+  // {
+  //   Serialize(value: number): string;
+  //   Serialize(value: string): string;
+  //   Serialize(value: EnumMonth0): string;
+  // };
+  function printf(value: any):void
+  {
+    console.log(value)
+  }
+
+  // function StoneSerialize(value: string) : string;
+  // function StoneSerialize(value: number) : string;
+  // function StoneSerialize(value: EnumMonth0) : string;
+  function StoneSerialize<T>(value: T[]) : string;
+
+  function StoneSerialize<T>(value: T[] | EnumMonth0) : string
+  {
+    let valueType = typeof value;
+    printf(`About to serialize value. Type is ${valueType}`)
+    printf(`About to serialize value. Type is ${typeof value}`)
+    return "Choucroute";
+
+  }
+
+  function main():number
+  {
+    enum Color {Red = 1, Green = 2, Blue = 4}
+    let color: Color = Color.Green;
+    printf("---------------------------");
+    printf(`typeof color: ${typeof color}`);
+    printf("---------------------------");
+    let colors: Color[] = []
+    colors.push(Color.Green);
+    colors.push(Color.Red);
+    printf(`typeof colors: ${typeof colors}`);
+    printf(`Array.isArray(colors): ${Array.isArray(colors)}`);
+    printf("---------------------------");
+    
+
+    let toto:EnumMonth0[] = [];
+
+    toto.push(EnumMonth0.February);
+    toto.push(EnumMonth0.March);
+
+    printf(JSON.stringify(toto));
+
+    return 0;
+
+  }
+
+  main()
+
+//   string StoneSerialize_number(int32_t value)
+//   {
+
+//     Json::Value result(value);
+//     return result;
+//   }
+
+//   Json::Value StoneSerialize(double value)
+//   {
+//     Json::Value result(value);
+//     return result;
+//   }
+
+//   Json::Value StoneSerialize(bool value)
+//   {
+//     Json::Value result(value);
+//     return result;
+//   }
+
+//   Json::Value StoneSerialize(const std::string& value)
+//   {
+//     // the following is better than 
+//     Json::Value result(value.data(),value.data()+value.size());
+//     return result;
+//   }
+
+//   template<typename T>
+//   Json::Value StoneSerialize(const std::map<std::string,T>& value)
+//   {
+//     Json::Value result(Json::objectValue);
+
+//     for (std::map<std::string, T>::const_iterator it = value.cbegin();
+//       it != value.cend(); ++it)
+//     {
+//       // it->first it->second
+//       result[it->first] = StoneSerialize(it->second);
+//     }
+//     return result;
+//   }
+
+//   template<typename T>
+//   Json::Value StoneSerialize(const std::vector<T>& value)
+//   {
+//     Json::Value result(Json::arrayValue);
+//     for (size_t i = 0; i < value.size(); ++i)
+//     {
+//       result.append(StoneSerialize(value[i]));
+//     }
+//     return result;
+//   }
+
+//   enum EnumMonth0
+//   {
+//     January,
+//     February,
+//     March
+//   };
+
+//   std::string ToString(EnumMonth0 value)
+//   {
+//     switch(value)
+//     {
+//       case January: 
+//         return "January";
+//       case February:
+//         return "February";
+//       case March:
+//         return "March";
+//       default:
+//         {
+//           std::stringstream ss;
+//           ss << "Unrecognized EnumMonth0 value (" << static_cast<int64_t>(value) << ")";
+//           throw std::runtime_error(ss.str());
+//         }
+//     }
+//   }
+
+//   void FromString(EnumMonth0& value, std::string strValue)
+//   {
+//     if (strValue == "January" || strValue == "EnumMonth0_January")
+//     {
+//       return January;
+//     }
+//     else if (strValue == "February" || strValue == "EnumMonth0_February")
+//     {
+//       return February;
+//     }
+// #error Not implemented yet
+//   }
+
+//   Json::Value StoneSerialize(const EnumMonth0& value)
+//   {
+//     return StoneSerialize(ToString(value));
+//   }
+//   struct Message1
+//   {
+//     int32_t a;
+//     std::string b;
+//     EnumMonth0 c;
+//     bool d;
+//   };
+
+//   struct Message2
+//   {
+//     std::string toto;
+//     std::vector<Message1> tata;
+//     std::vector<std::string> tutu;
+//     std::map<std::string, std::string> titi;
+//     std::map<std::string, Message1> lulu;
+//   };
+
+//   Json::Value StoneSerialize(const Message1& value)
+//   {
+//     Json::Value result(Json::objectValue);
+//     result["a"] = StoneSerialize(value.a);
+//     result["b"] = StoneSerialize(value.b);
+//     result["c"] = StoneSerialize(value.c);
+//     result["d"] = StoneSerialize(value.d);
+//     return result;
+//   }
+    
+//   Json::Value StoneSerialize(const Message2& value)
+//   {
+//     Json::Value result(Json::objectValue);
+//     result["toto"] = StoneSerialize(value.toto);
+//     result["tata"] = StoneSerialize(value.tata);
+//     result["tutu"] = StoneSerialize(value.tutu);
+//     result["titi"] = StoneSerialize(value.titi);
+//     result["lulu"] = StoneSerialize(value.lulu);
+//     return result;
+//   }
+// }
+
+// int main()
+// {
+//   VsolStuff::Message1 msg1_0;
+//   msg1_0.a = 42;
+//   msg1_0.b = "Benjamin";
+//   msg1_0.c = VsolStuff::January;
+//   msg1_0.d = true;
+
+//   VsolStuff::Message1 msg1_1;
+//   msg1_1.a = 43;
+//   msg1_1.b = "Sandrine";
+//   msg1_1.c = VsolStuff::March;
+//   msg1_0.d = false;
+
+//   // std::string toto;
+//   // std::vector<Message1> tata;
+//   // std::vector<std::string> tutu;
+//   // std::map<int32_t, std::string> titi;
+//   // std::map<int32_t, Message1> lulu;
+
+//   VsolStuff::Message2 msg2_0;
+//   msg2_0.toto = "Prout zizi";
+//   msg2_0.tata.push_back(msg1_0);
+//   msg2_0.tata.push_back(msg1_1);
+//   msg2_0.tutu.push_back("Mercadet");
+//   msg2_0.tutu.push_back("Poisson");
+//   msg2_0.titi["44"] = "key 44";
+//   msg2_0.titi["45"] = "key 45";
+//   msg2_0.lulu["54"] = msg1_1;
+//   msg2_0.lulu["55"] = msg1_0;
+//   auto result = VsolStuff::StoneSerialize(msg2_0);
+//   auto resultStr = result.toStyledString();
+
+//   Json::Value readValue;
+
+//   Json::CharReaderBuilder builder;
+//   Json::CharReader* reader = builder.newCharReader();
+//   std::string errors;
+
+//   bool ok = reader->parse(
+//     resultStr.c_str(),
+//     resultStr.c_str() + resultStr.size(),
+//     &readValue,
+//     &errors
+//   );
+//   delete reader;
+
+//   if (!ok)
+//   {
+//     std::stringstream ss;
+//     ss << "Json parsing error: " << errors;
+//     throw std::runtime_error(ss.str());
+//   }
+//   std::cout << readValue.get("toto", "Default Value").asString() << std::endl;
+//   return 0;
+// }
+
+
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Resources/CodeGeneration/playground2.ts	Mon Feb 18 15:38:05 2019 +0100
@@ -0,0 +1,72 @@
+class Greeter {
+    greeting: string;
+    constructor(message: string) {
+        this.greeting = message;
+    }
+    greet() {
+        return "Hello, " + this.greeting;
+    }
+}
+enum Color {
+    Red,
+    Green,
+    Blue,
+};
+
+function ColorToString(value: Color)
+{
+    switch (value)
+    {
+        case Color.Red:
+            return "Red";
+        case Color.Green:
+            return "Green";
+        case Color.Blue:
+            return "Blue";
+        default:
+            throw new Error(`Unrecognized Color value(${value})`);
+    }
+}
+
+let color: Color = Color.Red;
+
+document.body.textContent = "<p>---------------------</p>"
+document.body.textContent += "<p>********************************</p>"
+
+class TestMessage {
+    s1: string;
+    s2: Array<string>;
+    s3: Array<Array<string>>;
+    s4: Map<string, number>;
+    s5: Map<number, Array<string>>;
+    s6: Color;
+    s7: boolean;
+}
+
+let tm = new TestMessage();
+tm.s2 = new Array<string>()
+tm.s2.push("toto");
+tm.s2.push("toto2");
+tm.s2.push("toto3");
+tm.s4 = new Map<string, number>();
+tm.s4["toto"] = 42;
+tm.s4["toto"] = 1999;
+tm.s4["tatata"] = 1999;
+tm.s6 = Color.Red;
+tm.s7 = true
+
+let txt = JSON.stringify(tm)
+let txtElem = document.createElement('textarea');
+txtElem.value = txt;
+
+document.body.appendChild(txtElem);
+
+let greeter = new Greeter("world");
+
+let button = document.createElement('button');
+button.textContent = "Say Hello";
+button.onclick = function() {
+    alert(greeter.greet());
+}
+
+document.body.appendChild(button);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Resources/CodeGeneration/playground3.ts	Mon Feb 18 15:38:05 2019 +0100
@@ -0,0 +1,275 @@
+/*
+         1         2         3         4         5         6         7
+12345678901234567890123456789012345678901234567890123456789012345678901234567890
+*/
+
+namespace VsolStuff {
+  export enum EnumMonth0 {
+    January,
+    February,
+    March
+  };
+
+  export class Message1 {
+    a: number;
+    b: string;
+    c: EnumMonth0;
+    d: boolean;
+    public StoneSerialize(): string {
+      let container: object = {};
+      container['type'] = 'Message1';
+      container['value'] = this;
+      return JSON.stringify(container);
+    }
+  };
+
+  export class Message2 {
+    toto: string;
+    tata: Message1[];
+    tutu: string[];
+    titi: Map<string, string>;
+    lulu: Map<string, Message1>;
+
+    public StoneSerialize(): string {
+      let container: object = {};
+      container['type'] = 'Message1';
+      container['value'] = this;
+      return JSON.stringify(container);
+    }
+  };
+}
+
+function printf(value: any): void {
+  console.log(value)
+}
+
+function main(): number {
+
+  let msg1_0 = new VsolStuff.Message1();
+  msg1_0.a = 42;
+  msg1_0.b = "Benjamin";
+  msg1_0.c = VsolStuff.EnumMonth0.January;
+  msg1_0.d = true;
+
+  let msg1_1 = new VsolStuff.Message1();
+  msg1_1.a = 43;
+  msg1_1.b = "Sandrine";
+  msg1_1.c = VsolStuff.EnumMonth0.March;
+  msg1_0.d = false;
+
+  // std::string toto;
+  // std::vector<Message1> tata;
+  // std::vector<std::string> tutu;
+  // std::map<int32_t, std::string> titi;
+  // std::map<int32_t, Message1> lulu;
+
+  let msg2_0 = new VsolStuff.Message2();
+  msg2_0.toto = "Prout zizi";
+  msg2_0.tata = new Array<VsolStuff.Message1>();
+  msg2_0.tata.push(msg1_0);
+  msg2_0.tata.push(msg1_1);
+  msg2_0.tutu.push("Mercadet");
+  msg2_0.tutu.push("Poisson");
+  msg2_0.titi["44"] = "key 44";
+  msg2_0.titi["45"] = "key 45";
+  msg2_0.lulu["54"] = msg1_1;
+  msg2_0.lulu["55"] = msg1_0;
+  let result:string = VsolStuff.StoneSerialize(msg2_0);
+  return 0;
+}
+
+main()
+
+//   string StoneSerialize_number(int32_t value)
+//   {
+
+//     Json::Value result(value);
+//     return result;
+//   }
+
+//   Json::Value StoneSerialize(double value)
+//   {
+//     Json::Value result(value);
+//     return result;
+//   }
+
+//   Json::Value StoneSerialize(bool value)
+//   {
+//     Json::Value result(value);
+//     return result;
+//   }
+
+//   Json::Value StoneSerialize(const std::string& value)
+//   {
+//     // the following is better than 
+//     Json::Value result(value.data(),value.data()+value.size());
+//     return result;
+//   }
+
+//   template<typename T>
+//   Json::Value StoneSerialize(const std::map<std::string,T>& value)
+//   {
+//     Json::Value result(Json::objectValue);
+
+//     for (std::map<std::string, T>::const_iterator it = value.cbegin();
+//       it != value.cend(); ++it)
+//     {
+//       // it->first it->second
+//       result[it->first] = StoneSerialize(it->second);
+//     }
+//     return result;
+//   }
+
+//   template<typename T>
+//   Json::Value StoneSerialize(const std::vector<T>& value)
+//   {
+//     Json::Value result(Json::arrayValue);
+//     for (size_t i = 0; i < value.size(); ++i)
+//     {
+//       result.append(StoneSerialize(value[i]));
+//     }
+//     return result;
+//   }
+
+//   enum EnumMonth0
+//   {
+//     January,
+//     February,
+//     March
+//   };
+
+//   std::string ToString(EnumMonth0 value)
+//   {
+//     switch(value)
+//     {
+//       case January: 
+//         return "January";
+//       case February:
+//         return "February";
+//       case March:
+//         return "March";
+//       default:
+//         {
+//           std::stringstream ss;
+//           ss << "Unrecognized EnumMonth0 value (" << static_cast<int64_t>(value) << ")";
+//           throw std::runtime_error(ss.str());
+//         }
+//     }
+//   }
+
+//   void FromString(EnumMonth0& value, std::string strValue)
+//   {
+//     if (strValue == "January" || strValue == "EnumMonth0_January")
+//     {
+//       return January;
+//     }
+//     else if (strValue == "February" || strValue == "EnumMonth0_February")
+//     {
+//       return February;
+//     }
+// #error Not implemented yet
+//   }
+
+//   Json::Value StoneSerialize(const EnumMonth0& value)
+//   {
+//     return StoneSerialize(ToString(value));
+//   }
+//   struct Message1
+//   {
+//     int32_t a;
+//     std::string b;
+//     EnumMonth0 c;
+//     bool d;
+//   };
+
+//   struct Message2
+//   {
+//     std::string toto;
+//     std::vector<Message1> tata;
+//     std::vector<std::string> tutu;
+//     std::map<std::string, std::string> titi;
+//     std::map<std::string, Message1> lulu;
+//   };
+
+//   Json::Value StoneSerialize(const Message1& value)
+//   {
+//     Json::Value result(Json::objectValue);
+//     result["a"] = StoneSerialize(value.a);
+//     result["b"] = StoneSerialize(value.b);
+//     result["c"] = StoneSerialize(value.c);
+//     result["d"] = StoneSerialize(value.d);
+//     return result;
+//   }
+
+//   Json::Value StoneSerialize(const Message2& value)
+//   {
+//     Json::Value result(Json::objectValue);
+//     result["toto"] = StoneSerialize(value.toto);
+//     result["tata"] = StoneSerialize(value.tata);
+//     result["tutu"] = StoneSerialize(value.tutu);
+//     result["titi"] = StoneSerialize(value.titi);
+//     result["lulu"] = StoneSerialize(value.lulu);
+//     return result;
+//   }
+// }
+
+// int main()
+// {
+//   VsolStuff::Message1 msg1_0;
+//   msg1_0.a = 42;
+//   msg1_0.b = "Benjamin";
+//   msg1_0.c = VsolStuff::January;
+//   msg1_0.d = true;
+
+//   VsolStuff::Message1 msg1_1;
+//   msg1_1.a = 43;
+//   msg1_1.b = "Sandrine";
+//   msg1_1.c = VsolStuff::March;
+//   msg1_0.d = false;
+
+//   // std::string toto;
+//   // std::vector<Message1> tata;
+//   // std::vector<std::string> tutu;
+//   // std::map<int32_t, std::string> titi;
+//   // std::map<int32_t, Message1> lulu;
+
+//   VsolStuff::Message2 msg2_0;
+//   msg2_0.toto = "Prout zizi";
+//   msg2_0.tata.push_back(msg1_0);
+//   msg2_0.tata.push_back(msg1_1);
+//   msg2_0.tutu.push_back("Mercadet");
+//   msg2_0.tutu.push_back("Poisson");
+//   msg2_0.titi["44"] = "key 44";
+//   msg2_0.titi["45"] = "key 45";
+//   msg2_0.lulu["54"] = msg1_1;
+//   msg2_0.lulu["55"] = msg1_0;
+//   auto result = VsolStuff::StoneSerialize(msg2_0);
+//   auto resultStr = result.toStyledString();
+
+//   Json::Value readValue;
+
+//   Json::CharReaderBuilder builder;
+//   Json::CharReader* reader = builder.newCharReader();
+//   std::string errors;
+
+//   bool ok = reader->parse(
+//     resultStr.c_str(),
+//     resultStr.c_str() + resultStr.size(),
+//     &readValue,
+//     &errors
+//   );
+//   delete reader;
+
+//   if (!ok)
+//   {
+//     std::stringstream ss;
+//     ss << "Json parsing error: " << errors;
+//     throw std::runtime_error(ss.str());
+//   }
+//   std::cout << readValue.get("toto", "Default Value").asString() << std::endl;
+//   return 0;
+// }
+
+
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Resources/CodeGeneration/playground4.py	Mon Feb 18 15:38:05 2019 +0100
@@ -0,0 +1,68 @@
+testYaml = """
+enum SomeEnum:
+ - january
+ - feb
+
+struct Message0:
+ a: string
+
+struct Message1:
+ a: string
+ b: int32
+ c: vector<Message0>
+ d: SomeEnum = january
+ e: SomeEnum= january
+ f: SomeEnum=january
+ g: SomeEnum =january
+  
+
+# github.com/AlDanial/cloc
+header2 : 
+  cloc_version       : 1.67
+  elapsed_seconds    : int32_t
+
+header : 
+  cloc_version       : 1.67
+  elapsed_seconds    : int32_t
+  cloc_url           : vector<map<string,int32>>
+  n_files            : 1
+  n_lines            : 3
+  files_per_second   : 221.393718659277
+  lines_per_second   : 664.181155977831
+  report_file        : IDL.idl.yaml
+IDL :
+  nFiles: 1
+  blank: 0
+  comment: 2
+  code: 1
+EnumSUM: 
+  - aaa
+  - bbb
+
+SUM: 
+  blank: 0
+  comment: 2
+  code: 1
+  nFiles: 1
+"""
+
+import yaml
+
+b = yaml.load(testYaml)
+print(b)
+
+c = {
+  'enum SomeEnum': ['january', 'feb'], 
+  'struct Message0': {'a': 'string'}, 
+  'struct Message1': {
+    'a': 'string', 
+    'b': 'int32', 
+    'c': 'vector<Message0>', 
+    'd': 'vector<map<string,int32>>', 
+    'e': 'SomeEnum= january', 
+    'f': 'SomeEnum=january', 
+    'g': 'SomeEnum =january'
+  }, 
+}
+
+print(c)
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Resources/CodeGeneration/runts.ps1	Mon Feb 18 15:38:05 2019 +0100
@@ -0,0 +1,19 @@
+# echo "+----------------------+"
+# echo "|    template.in.ts    |"
+# echo "+----------------------+"
+
+# tsc -t ES2015 .\template.in.ts; node .\template.in.js
+
+echo "+----------------------+"
+echo "|    playground.ts     |"
+echo "+----------------------+"
+
+tsc -t ES2015 .\playground.ts; node .\playground.js
+
+echo "+----------------------+"
+echo "|    playground3.ts     |"
+echo "+----------------------+"
+
+tsc -t ES2015 .\playground3.ts; node .\playground3.js
+
+
--- a/Resources/CodeGeneration/stonegentool.py	Mon Feb 18 07:46:59 2019 +0100
+++ b/Resources/CodeGeneration/stonegentool.py	Mon Feb 18 15:38:05 2019 +0100
@@ -22,7 +22,6 @@
 12345678901234567890123456789012345678901234567890123456789012345678901234567890
 """
 
-
 class GeneratedCode:
     def __init__(self):
 
@@ -81,27 +80,9 @@
         return json.loads(fileContent)
 
 
-def LoadSchema(filePath: str):
+def LoadSchemaFromJson(filePath: str):
     return JsonHelpers.loadJsonWithComments(filePath)
 
-
-# class Type:
-#   def __init__(self, canonicalTypeName:str, kind:str):
-#     allowedTypeKinds = ["primitive","enum","struct","collection"]
-#     """dependent type is the list of canonical types this type depends on.
-#        For instance, vector<map<string,int32>> depends on map<string,int32>
-#        that, in turn, depends on string and int32 that, in turn, depend on
-#        nothing"""
-#     self.canonicalTypeName = canonicalTypeName
-#     assert(kind in allowedTypeKinds)
-
-#   def setDependentTypes(self, dependentTypes:List[Type]) -> None:
-#     self.dependentTypes = dependentTypes
-
-#   def getDependentTypes(self) -> List[Type]:
-#     return self.dependentTypes
-
-
 def GetCppTypeNameFromCanonical(canonicalTypeName: str) -> str:
     # C++: prefix map vector and string with std::map, std::vector and
     # std::string
@@ -116,7 +97,6 @@
     retVal = retVal.replace("float64", "double")
     return retVal
 
-
 def GetTypeScriptTypeNameFromCanonical(canonicalTypeName: str) -> str:
     # TS: replace vector with Array and map with Map
     # string remains string
@@ -132,13 +112,11 @@
     retVal = retVal.replace("bool", "boolean")
     return retVal
 
-
 # class Schema:
 #   def __init__(self, root_prefix : str, defined_types : List[Type]):
 #     self.rootName : str = root_prefix
 #     self.definedTypes : str = defined_types
 
-
 def CheckTypeSchema(definedType: Dict) -> None:
     allowedDefinedTypeKinds = ["enum", "struct"]
     if not "name" in definedType:
@@ -169,7 +147,7 @@
             fieldName = field["name"]
             if not "type" in field:
                 raise Exception(
-                    f"field {fieldName} in type {name} " + "lacks the 'type' key"
+                    f"field {fieldName} in type {name} " + "has no 'type' key"
                 )
 
 
@@ -226,7 +204,8 @@
     return tokenList
 
 
-templateRegex = re.compile(r"([a-zA-Z0-9_]*[a-zA-Z0-9_]*)<([a-zA-Z0-9_,:<>]+)>")
+templateRegex = \
+  re.compile(r"([a-zA-Z0-9_]*[a-zA-Z0-9_]*)<([a-zA-Z0-9_,:<>]+)>")
 
 
 def ParseTemplateType(typeName) -> Tuple[bool, str, List[str]]:
@@ -249,27 +228,11 @@
         listOfDependentTypes = SplitListOfTypes(m.group(2))
         return (True, m.group(1), listOfDependentTypes)
 
-
-# def GetPrimitiveType(typeName : str) -> Type:
-#   if typeName in allTypes:
-#     return allTypes[typeName]
-#   else:
-#     primitiveTypes = ['int32', 'float32', 'float64', 'string']
-#     if not (typeName in primitiveTypes):
-#       raise Exception(f"Type {typeName} is unknown.")
-#     typeObject = Type(typeName,'primitive')
-#     # there are no dependent types in a primitive type --> Type object
-#     # constrution is finished at this point
-#     allTypes[typeName] = typeObject
-#     return typeObject
-
-
 def ProcessTypeTree(
     ancestors: List[str],
     genOrderQueue: List[str],
     structTypes: Dict[str, Dict],
-    typeName: str,
-) -> None:
+    typeName: str) -> None:
   if typeName in ancestors:
     raise Exception(
       f"Cyclic dependency chain found: the last of {ancestors} "
@@ -313,14 +276,23 @@
     genOrderQueue.append(typeName)
 
 def ProcessEnumerationType(outputStreams: GeneratedCode, typeDict: Dict) -> None:
-  tsText: StringIO = StringIO()
-  cppText: StringIO = StringIO()
+
+  # enumeration declarations
+  tsDeclText: StringIO = StringIO()
+  tsDeclText.write("enum %s\n" % typeDict["name"])
+  tsDeclText.write("{\n")
 
-  tsText.write("enum %s\n" % typeDict["name"])
-  tsText.write("{\n")
+  cppDeclText: StringIO = StringIO()
+  cppDeclText.write("enum %s\n" % typeDict["name"])
+  cppDeclText.write("{\n")
 
-  cppText.write("enum %s\n" % typeDict["name"])
-  cppText.write("{\n")
+  cppToStringText: StringIO = StringIO()
+  cppToStringText.write("enum %s\n" % typeDict["name"])
+  cppToStringText.write("{\n")
+
+  cppFromStringText: StringIO = StringIO()
+  cppFromStringText.write("enum %s\n" % typeDict["name"])
+  cppFromStringText.write("{\n")
 
   for i in range(len(typeDict["fields"])):
     field = typeDict["fields"][i]
@@ -336,8 +308,8 @@
         cppText.write(",")
     cppText.write("\n")
 
-    tsText.write("};\n\n")
-    cppText.write("};\n\n")
+  tsText.write("};\n\n")
+  cppText.write("};\n\n")
 
   outputStreams.tsEnums.write(tsText.getvalue())
   outputStreams.cppEnums.write(cppText.getvalue())
@@ -365,7 +337,6 @@
 
 
 
-
 def ProcessStructType(outputStreams: GeneratedCode, typeDict) -> None:
   tsText: StringIO = StringIO()
   cppText: StringIO = StringIO()
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Resources/CodeGeneration/template.in.h	Mon Feb 18 15:38:05 2019 +0100
@@ -0,0 +1,69 @@
+/*
+         1         2         3         4         5         6         7
+12345678901234567890123456789012345678901234567890123456789012345678901234567890
+*/
+
+#include <iostream>
+#include <string>
+#include <sstream>
+#include <assert.h>
+#include <json/json.h>
+
+
+namespace VsolStuff
+{
+  Json::Value StoneSerialize(int32_t value)
+  {
+    Json::Value result(value);
+    return result;
+  }
+
+  Json::Value StoneSerialize(double value)
+  {
+    Json::Value result(value);
+    return result;
+  }
+
+  Json::Value StoneSerialize(bool value)
+  {
+    Json::Value result(value);
+    return result;
+  }
+
+  Json::Value StoneSerialize(const std::string& value)
+  {
+    // the following is better than 
+    Json::Value result(value.data(),value.data()+value.size());
+    return result;
+  }
+    
+  template<typename T>
+  Json::Value StoneSerialize(const std::map<std::string,T>& value)
+  {
+    Json::Value result(Json::objectValue);
+
+    for (std::map<std::string, T>::const_iterator it = value.cbegin();
+      it != value.cend(); ++it)
+    {
+      // it->first it->second
+      result[it->first] = StoneSerialize(it->second);
+    }
+    return result;
+  }
+
+  template<typename T>
+  Json::Value StoneSerialize(const std::vector<T>& value)
+  {
+    Json::Value result(Json::arrayValue);
+    for (size_t i = 0; i < value.size(); ++i)
+    {
+      result.append(StoneSerialize(value[i]));
+    }
+    return result;
+  }
+
+  %enumerationscpp%
+
+  %structscpp%
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Resources/CodeGeneration/template.in.ts	Mon Feb 18 15:38:05 2019 +0100
@@ -0,0 +1,38 @@
+class Greeter {
+    greeting: string;
+    constructor(message: string) {
+        this.greeting = message;
+    }
+    greet() {
+        return "Hello, " + this.greeting;
+    }
+}
+enum Color { Red, Green, Blue };
+
+class TestMessage {
+    s1: string;
+    s2: Array<string>;
+    s3: Array<Array<string>>;
+    s4: Map<string, number>;
+    s5: Map<number, Array<string>>;
+    s6: Color;
+    s7: boolean;
+}
+
+let tm = new TestMessage();
+tm.s2 = new Array<string>()
+tm.s2.push("toto");
+tm.s2.push("toto2");
+tm.s2.push("toto3");
+tm.s4 = new Map<string, number>();
+tm.s4["toto"] = 42;
+tm.s4["toto"] = 1999;
+tm.s4["tatata"] = 1999;
+tm.s6 = Color.Red;
+tm.s7 = true
+
+let txt = JSON.stringify(tm)
+console.log(txt);
+
+let greeter = new Greeter("world");
+
--- a/Resources/CodeGeneration/test/test1.jsonc	Mon Feb 18 07:46:59 2019 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,87 +0,0 @@
-/*
-         1         2         3         4         5         6         7
-12345678901234567890123456789012345678901234567890123456789012345678901234567890
-*/
-{
-  "root_name":"test1",
-  "types": [
-    {
-      "name":"B",
-      "kind":"struct",
-      "fields": [
-        {
-          "name":"someAs",
-          "type":"vector<A>"
-        },
-        {
-          "name":"someInts",
-          "type":"vector<int32>"
-        }
-      ]
-    },
-    {
-      "name":"C",
-      "kind":"struct",
-      "fields": [
-        {
-          "name":"someBs",
-          "type":"vector<B>"
-        },
-        {
-          "name":"ddd",
-          "type":"vector<D>"
-        }
-      ]
-    },
-    {
-      "name":"A",
-      "kind":"struct",
-      "fields": [
-        {
-          "name":"someStrings",
-          "type":"vector<string>"
-        },
-        {
-          "name":"someInts2",
-          "type":"vector<int32>"
-        }
-      ]
-    },
-    {
-      "name":"MovieType",
-      "kind":"enum",
-      "fields": [
-        {
-          "name":"Romcom"
-        },
-        {
-          "name":"Horror"
-        },
-        {
-          "name":"ScienceFiction"
-        },
-        {
-          "name":"Vegetables"
-        }
-      ]
-    },
-    {
-      "name":"CrispType",
-      "kind":"enum",
-      "fields": [
-        {
-          "name":"SaltAndPepper"
-        },
-        {
-          "name":"CreamAndChives"
-        },
-        {
-          "name":"Paprika"
-        },
-        {
-          "name":"Barbecue"
-        }
-      ]
-    }
-  ]
-}
--- a/Resources/CodeGeneration/test/test1_bogus_json.jsonc	Mon Feb 18 07:46:59 2019 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,55 +0,0 @@
-{
-  "root_name":"test1",
-  "types": [
-    {
-      "name":"B",
-      "kind":"struct",
-      "fields": [
-        {
-          "name":"someAs",
-          "type":"vector<A>"
-        }},
-        {
-          "name":"someInts",
-          "type":"vector<int32>"
-        }
-      ]
-    },
-    {
-      "name":"A",
-      "kind":"struct",
-      "fields": [
-        {
-          "name":"someStrings",
-          "type":"vector<string>"
-        },
-        {
-          "name":"someInts2",
-          "type":"vector<int32>"
-        }
-      ]
-    },
-    {
-      "name":"MovieType",
-      "kind":"enum",
-      "fields": [
-        {
-          "name":"Romcom",
-        },
-        {
-          "name":"Horror",
-        },
-        {
-          "name":"ScienceFiction",
-        },
-        {
-          "name":"Vegetables",
-        }
-    }
-  ]
-}
-
-/*
-         1         2         3         4         5         6         7
-12345678901234567890123456789012345678901234567890123456789012345678901234567890
-*/
--- a/Resources/CodeGeneration/test/test1_bogus_schema.jsonc	Mon Feb 18 07:46:59 2019 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,56 +0,0 @@
-{
-  "root_name":"test1",
-  "types": [
-    {
-      "name":"B",
-      "kind":"struct",
-      "fields": [
-        {
-          "name":"someAs",
-          "type":"vector<A>"
-        },
-        {
-          "name":"someInts",
-          "type":"vector<int32>"
-        }
-      ]
-    },
-    {
-      "name":"A",
-      "kiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiind":"struct",
-      "fields": [
-        {
-          "name":"someStrings",
-          "type":"vector<string>"
-        },
-        {
-          "name":"someInts2",
-          "type":"vector<int32>"
-        }
-      ]
-    },
-    {
-      "name":"MovieType",
-      "kind":"enum",
-      "fields": [
-        {
-          "naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaame":"Romcom"
-        },
-        {
-          "name":"Horror"
-        },
-        {
-          "name":"ScienceFiction"
-        },
-        {
-          "name":"Vegetables"
-        }
-      ]
-    }
-  ]
-}
-
-/*
-         1         2         3         4         5         6         7
-12345678901234567890123456789012345678901234567890123456789012345678901234567890
-*/
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Resources/CodeGeneration/test_data/test1.jsonc	Mon Feb 18 15:38:05 2019 +0100
@@ -0,0 +1,87 @@
+/*
+         1         2         3         4         5         6         7
+12345678901234567890123456789012345678901234567890123456789012345678901234567890
+*/
+{
+  "root_name":"test1",
+  "types": [
+    {
+      "name":"B",
+      "kind":"struct",
+      "fields": [
+        {
+          "name":"someAs",
+          "type":"vector<A>"
+        },
+        {
+          "name":"someInts",
+          "type":"vector<int32>"
+        }
+      ]
+    },
+    {
+      "name":"C",
+      "kind":"struct",
+      "fields": [
+        {
+          "name":"someBs",
+          "type":"vector<B>"
+        },
+        {
+          "name":"ddd",
+          "type":"vector<D>"
+        }
+      ]
+    },
+    {
+      "name":"A",
+      "kind":"struct",
+      "fields": [
+        {
+          "name":"someStrings",
+          "type":"vector<string>"
+        },
+        {
+          "name":"someInts2",
+          "type":"vector<int32>"
+        }
+      ]
+    },
+    {
+      "name":"MovieType",
+      "kind":"enum",
+      "fields": [
+        {
+          "name":"Romcom"
+        },
+        {
+          "name":"Horror"
+        },
+        {
+          "name":"ScienceFiction"
+        },
+        {
+          "name":"Vegetables"
+        }
+      ]
+    },
+    {
+      "name":"CrispType",
+      "kind":"enum",
+      "fields": [
+        {
+          "name":"SaltAndPepper"
+        },
+        {
+          "name":"CreamAndChives"
+        },
+        {
+          "name":"Paprika"
+        },
+        {
+          "name":"Barbecue"
+        }
+      ]
+    }
+  ]
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Resources/CodeGeneration/test_data/test1.yaml	Mon Feb 18 15:38:05 2019 +0100
@@ -0,0 +1,30 @@
+#
+#        1         2         3         4         5         6         7         8
+# 345678901234567890123456789012345678901234567890123456789012345678901234567890
+#
+rootName: VsolMessages
+
+struct B:
+  someAs: vector<A>
+  someInts: vector<int32>
+
+struct C:
+  someBs: vector<B>
+  ddd:    vector<D>
+
+struct A:
+  someStrings: vector<string>
+  someInts2: vector<int32>
+  movies: vector<MovieType>
+
+enum MovieType:
+  - RomCom
+  - Horror
+  - ScienceFiction
+  - Vegetables
+
+enum CrispType:
+ - SaltAndPepper
+ - CreamAndChives
+ - Paprika
+ - Barbecue
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Resources/CodeGeneration/test_data/test1_bogus_json.jsonc	Mon Feb 18 15:38:05 2019 +0100
@@ -0,0 +1,55 @@
+{
+  "root_name":"test1",
+  "types": [
+    {
+      "name":"B",
+      "kind":"struct",
+      "fields": [
+        {
+          "name":"someAs",
+          "type":"vector<A>"
+        }},
+        {
+          "name":"someInts",
+          "type":"vector<int32>"
+        }
+      ]
+    },
+    {
+      "name":"A",
+      "kind":"struct",
+      "fields": [
+        {
+          "name":"someStrings",
+          "type":"vector<string>"
+        },
+        {
+          "name":"someInts2",
+          "type":"vector<int32>"
+        }
+      ]
+    },
+    {
+      "name":"MovieType",
+      "kind":"enum",
+      "fields": [
+        {
+          "name":"Romcom",
+        },
+        {
+          "name":"Horror",
+        },
+        {
+          "name":"ScienceFiction",
+        },
+        {
+          "name":"Vegetables",
+        }
+    }
+  ]
+}
+
+/*
+         1         2         3         4         5         6         7
+12345678901234567890123456789012345678901234567890123456789012345678901234567890
+*/
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Resources/CodeGeneration/test_data/test1_bogus_schema.jsonc	Mon Feb 18 15:38:05 2019 +0100
@@ -0,0 +1,56 @@
+{
+  "root_name":"test1",
+  "types": [
+    {
+      "name":"B",
+      "kind":"struct",
+      "fields": [
+        {
+          "name":"someAs",
+          "type":"vector<A>"
+        },
+        {
+          "name":"someInts",
+          "type":"vector<int32>"
+        }
+      ]
+    },
+    {
+      "name":"A",
+      "kiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiind":"struct",
+      "fields": [
+        {
+          "name":"someStrings",
+          "type":"vector<string>"
+        },
+        {
+          "name":"someInts2",
+          "type":"vector<int32>"
+        }
+      ]
+    },
+    {
+      "name":"MovieType",
+      "kind":"enum",
+      "fields": [
+        {
+          "naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaame":"Romcom"
+        },
+        {
+          "name":"Horror"
+        },
+        {
+          "name":"ScienceFiction"
+        },
+        {
+          "name":"Vegetables"
+        }
+      ]
+    }
+  ]
+}
+
+/*
+         1         2         3         4         5         6         7
+12345678901234567890123456789012345678901234567890123456789012345678901234567890
+*/
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Resources/CodeGeneration/tsconfig.json	Mon Feb 18 15:38:05 2019 +0100
@@ -0,0 +1,22 @@
+{
+  // "extends": "../../../../../orthanc-stone/Platforms/Wasm/tsconfig-stone",
+  "compilerOptions": {
+    // "outFile": "../../../WebApplication-build/to-embed/app.js",
+    // "module": "system",
+    // "sourceMap": false,
+    "lib": [
+      "es2017",
+      "es2017",
+      "dom",
+      "dom.iterable"
+    ]
+  },
+  "include": [
+    // "commands/*.ts",
+    // "logger.ts",
+    // "app.ts",
+    // "main.ts",
+    // "ui.ts",
+    // "popup.ts"
+  ]
+}