summaryrefslogtreecommitdiff
path: root/templates
diff options
context:
space:
mode:
authorCsaba Hruska <csaba.hruska@gmail.com>2015-09-16 00:41:36 +0200
committerCsaba Hruska <csaba.hruska@gmail.com>2015-09-16 00:41:36 +0200
commit4cf104ca45b4f3f278b3cc8275a9690be3c23fe2 (patch)
treebf178866caa589f3d4b2ccac15eb5cdcdce290ce /templates
parent32daa3c315949f63b39a69a5a663dd214c640e90 (diff)
add C++ backend
Diffstat (limited to 'templates')
-rw-r--r--templates/data.cpp.ede63
-rw-r--r--templates/data.hpp.ede51
-rw-r--r--templates/data.hs.ede11
-rw-r--r--templates/data.purs.ede4
4 files changed, 124 insertions, 5 deletions
diff --git a/templates/data.cpp.ede b/templates/data.cpp.ede
new file mode 100644
index 0000000..8e106a6
--- /dev/null
+++ b/templates/data.cpp.ede
@@ -0,0 +1,63 @@
1// generated file, do not modify!
2// {{ dateTime }}
3
4#include "{{ moduleName }}.hpp"
5
6template<> json toJSON<String>(String &v) {
7 return json(v);
8}
9
10template<> json toJSON<Float>(Float &v) {
11 return json(v);
12}
13
14template<> json toJSON<bool>(bool &v) {
15 return json(v);
16}
17
18template<> json toJSON<int>(int &v) {
19 return json(v);
20}
21
22template<> json toJSON<unsigned int>(unsigned int &v) {
23 return json(v);
24}
25
26template<typename any>
27json toJSON(std::vector<any> &v) {
28 json obj = json::array();
29 for (any i : v) {
30 obj.push_back(toJSON(i));
31 }
32 return obj;
33}
34
35template<typename k, typename v>
36json toJSON(std::map<k,v> &value) {
37 return json();
38}
39
40{% for t in definitions %}
41template<> json toJSON<{{ t.value.dataName }}>({{ t.value.dataName }} &v) {
42 json obj;
43 switch (v.tag) { {% for c in t.value.constructors %}
44 case ::{{ t.value.dataName }}::tag::{{ c.value.name }}:
45 obj["tag"] = "{{ c.value.name }}";{% if !(c.value.fields | empty) %}
46 {
47 auto tv = static_cast<::data::{{ c.value.name }}&>(v);{% for f in c.value.fields %}{% if c.value.fields | hasFieldNames %}
48 obj["{{ f.value.fieldName }}"] = toJSON(tv.{{ f.value.fieldName }});{% else %}
49 obj["arg{{ f.index0 }}"] = toJSON(tv._{{ f.index0 }});{% endif %}{% endfor %}
50 }{% endif %}
51 break;{% endfor %}
52 }
53 return obj;
54}
55{% endfor %}
56
57{#
58{% for c in t.value.constructors %}
59json data::{{ c.value.name }}::toJSON() {
60 return obj;
61}
62{% endif %}{% endfor %}{% endfor %}
63#} \ No newline at end of file
diff --git a/templates/data.hpp.ede b/templates/data.hpp.ede
new file mode 100644
index 0000000..10e1ff4
--- /dev/null
+++ b/templates/data.hpp.ede
@@ -0,0 +1,51 @@
1// generated file, do not modify!
2// {{ dateTime }}
3
4#ifndef HEADER_{{ moduleName }}_H
5#define HEADER_{{ moduleName }}_H
6
7#include <vector>
8#include <map>
9#include <string>
10
11#include "json.hpp"
12
13typedef int Int;
14typedef int Int32;
15typedef unsigned int Word;
16typedef unsigned int Word32;
17typedef float Float;
18typedef bool Bool;
19typedef std::string String;
20
21using json = nlohmann::json;
22
23template<typename T>
24json toJSON(T &v);
25
26{% for m in imports %}
27#include "{{ m.value }}.hpp"
28{% endfor %}
29
30{% for t in dataAndType %}
31{% case t.value | constType %}
32{% when "DataDef" %}
33class {{ t.value.dataName }} {
34 public:
35 enum class tag { {% for c in t.value.constructors %}
36 {{ c.value.name }}{% if !c.last %},{% endif %}{% endfor %}
37 } tag;
38};
39namespace data { {% for c in t.value.constructors %}{% if !(c.value.fields | empty) %}
40 class {{ c.value.name }} : public ::{{ t.value.dataName }} {
41 public:{% for f in c.value.fields %}{% if c.value.fields | hasFieldNames %}
42 {{ f.value.fieldType | cppType }} {{ f.value.fieldName }};{% else %}
43 {{ f.value.fieldType | cppType | parens }} _{{ f.index0 }};{% endif %}{% endfor %}
44 };{% endif %}{% endfor %}
45}
46{% when "TypeAlias" %}
47typedef {{ t.value.aliasType | cppType }} {{ t.value.aliasName }};
48
49{% endcase %}
50{% endfor %}
51#endif
diff --git a/templates/data.hs.ede b/templates/data.hs.ede
index fccd7dc..54a148b 100644
--- a/templates/data.hs.ede
+++ b/templates/data.hs.ede
@@ -15,6 +15,10 @@ import Data.Aeson hiding (Value,Bool)
15import Data.Aeson.Types hiding (Value,Bool) 15import Data.Aeson.Types hiding (Value,Bool)
16import Control.Monad 16import Control.Monad
17 17
18{% for m in imports %}
19import {{ m.value }}
20{% endfor %}
21
18{% for t in dataAndType %} 22{% for t in dataAndType %}
19{% case t.value | constType %} 23{% case t.value | constType %}
20{% when "DataDef" %} 24{% when "DataDef" %}
@@ -33,17 +37,14 @@ type {{ t.value.aliasName }} = {{ t.value.aliasType | hsType }}
33 37
34{% endfor %} 38{% endfor %}
35 39
36(.-) :: Text -> Text -> Pair
37a .- b = a .= b
38
39{% for t in definitions %} 40{% for t in definitions %}
40instance ToJSON {{ t.value.dataName }} where 41instance ToJSON {{ t.value.dataName }} where
41 toJSON v = case v of{% for c in t.value.constructors %}{% if c.value.fields | hasFieldNames %} 42 toJSON v = case v of{% for c in t.value.constructors %}{% if c.value.fields | hasFieldNames %}
42 {{ c.value.name }}{..} -> object 43 {{ c.value.name }}{..} -> object
43 [ "tag" .- "{{ c.value.name }}"{% for f in c.value.fields %} 44 [ "tag" .= ("{{ c.value.name }}" :: Text){% for f in c.value.fields %}
44 , "{{ f.value.fieldName }}" .= {{ f.value.fieldName }}{% endfor %} 45 , "{{ f.value.fieldName }}" .= {{ f.value.fieldName }}{% endfor %}
45 ]{% else %} 46 ]{% else %}
46 {{ c.value.name }}{% for f in c.value.fields %} arg{{ f.index0 }}{% endfor %} -> object [ "tag" .- "{{ c.value.name }}"{% for f in c.value.fields %}, "arg{{ f.index0 }}" .= arg{{ f.index0 }}{% endfor %}]{% endif %}{% endfor %} 47 {{ c.value.name }}{% for f in c.value.fields %} arg{{ f.index0 }}{% endfor %} -> object [ "tag" .= ("{{ c.value.name }}" :: Text){% for f in c.value.fields %}, "arg{{ f.index0 }}" .= arg{{ f.index0 }}{% endfor %}]{% endif %}{% endfor %}
47 48
48instance FromJSON {{ t.value.dataName }} where 49instance FromJSON {{ t.value.dataName }} where
49 parseJSON (Object obj) = do 50 parseJSON (Object obj) = do
diff --git a/templates/data.purs.ede b/templates/data.purs.ede
index 957fff4..0474931 100644
--- a/templates/data.purs.ede
+++ b/templates/data.purs.ede
@@ -16,6 +16,10 @@ import Data.Argonaut.Printer (printJson)
16import Data.Argonaut.Encode (EncodeJson, encodeJson) 16import Data.Argonaut.Encode (EncodeJson, encodeJson)
17import Data.Argonaut.Decode (DecodeJson, decodeJson) 17import Data.Argonaut.Decode (DecodeJson, decodeJson)
18 18
19{% for m in imports %}
20import {{ m.value }}
21{% endfor %}
22
19{% for t in dataAndType %} 23{% for t in dataAndType %}
20{% case t.value | constType %} 24{% case t.value | constType %}
21{% when "DataDef" %} 25{% when "DataDef" %}