summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Kolesa <d.kolesa@osg.samsung.com>2016-09-15 16:56:43 +0200
committerDaniel Kolesa <d.kolesa@osg.samsung.com>2016-10-07 11:54:23 +0200
commitaf7cc32343293f3ae5f4aa1102ad781e40413dbe (patch)
tree3e3267195ecc66fdf9c1096c0d84d9fd66fa5476
parentd20acef8313d65af71d737cfe75eabd1288b94f5 (diff)
eolian gen2: full type generator
-rw-r--r--src/bin/eolian2/main.c7
-rw-r--r--src/bin/eolian2/main.h2
-rw-r--r--src/bin/eolian2/types.c99
3 files changed, 101 insertions, 7 deletions
diff --git a/src/bin/eolian2/main.c b/src/bin/eolian2/main.c
index 88790b2723..731f1b1f52 100644
--- a/src/bin/eolian2/main.c
+++ b/src/bin/eolian2/main.c
@@ -202,12 +202,11 @@ _read_file(const char *fname)
202 return eina_strbuf_manage_new_length(cont, fs); 202 return eina_strbuf_manage_new_length(cont, fs);
203} 203}
204 204
205char *eo_gen_class_full_name_get(const Eolian_Class *cl) 205char *eo_gen_c_full_name_get(const char *nm)
206{ 206{
207 Eina_Stringshare *cln = eolian_class_full_name_get(cl); 207 if (!nm)
208 if (!cln)
209 return NULL; 208 return NULL;
210 char *buf = strdup(cln); 209 char *buf = strdup(nm);
211 if (!buf) 210 if (!buf)
212 return NULL; 211 return NULL;
213 for (char *p = strchr(buf, '.'); p; p = strchr(p, '.')) 212 for (char *p = strchr(buf, '.'); p; p = strchr(p, '.'))
diff --git a/src/bin/eolian2/main.h b/src/bin/eolian2/main.h
index 985e806ef0..b88ca6bcee 100644
--- a/src/bin/eolian2/main.h
+++ b/src/bin/eolian2/main.h
@@ -31,6 +31,6 @@ extern int _eolian_gen_log_dom;
31#endif 31#endif
32#define CRIT(...) EINA_LOG_DOM_CRIT(_eolian_gen_log_dom, __VA_ARGS__) 32#define CRIT(...) EINA_LOG_DOM_CRIT(_eolian_gen_log_dom, __VA_ARGS__)
33 33
34char *eo_gen_class_full_name_get(const Eolian_Class *cl); 34char *eo_gen_c_full_name_get(const char *nm);
35 35
36#endif 36#endif
diff --git a/src/bin/eolian2/types.c b/src/bin/eolian2/types.c
index a2970cef8d..5b59733222 100644
--- a/src/bin/eolian2/types.c
+++ b/src/bin/eolian2/types.c
@@ -3,7 +3,102 @@
3static Eina_Strbuf * 3static Eina_Strbuf *
4_type_generate(const Eolian_Typedecl *tp, Eina_Bool full, Eina_Bool legacy) 4_type_generate(const Eolian_Typedecl *tp, Eina_Bool full, Eina_Bool legacy)
5{ 5{
6 return NULL; 6 Eolian_Typedecl_Type tpt = eolian_typedecl_type_get(tp);
7 Eina_Strbuf *buf = eina_strbuf_new();
8 switch (tpt)
9 {
10 case EOLIAN_TYPEDECL_ALIAS:
11 {
12 Eina_Stringshare *tn = eolian_typedecl_c_type_get(tp);
13 eina_strbuf_append(buf, tn);
14 eina_stringshare_del(tn);
15 break;
16 }
17 case EOLIAN_TYPEDECL_STRUCT:
18 case EOLIAN_TYPEDECL_STRUCT_OPAQUE:
19 {
20 const Eolian_Struct_Type_Field *memb;
21 char *fn = eo_gen_c_full_name_get(eolian_typedecl_full_name_get(tp));
22 if (tpt == EOLIAN_TYPEDECL_STRUCT_OPAQUE || !full)
23 {
24 eina_strbuf_append_printf(buf, "typedf struct _%s %s", fn, fn);
25 free(fn);
26 break;
27 }
28 eina_strbuf_append_printf(buf, "typedef struct _%s\n{\n", fn);
29 Eina_Iterator *membs = eolian_typedecl_struct_fields_get(tp);
30 EINA_ITERATOR_FOREACH(membs, memb)
31 {
32 const Eolian_Type *mtp = eolian_typedecl_struct_field_type_get(memb);
33 Eina_Stringshare *ct = NULL;
34 if (eolian_type_type_get(mtp) == EOLIAN_TYPE_STATIC_ARRAY)
35 {
36 ct = eolian_type_c_type_get(eolian_type_base_type_get(mtp));
37 eina_strbuf_append_printf(buf, " %s%s%s[%zu];",
38 ct, strchr(ct, '*') ? "" : " ",
39 eolian_typedecl_struct_field_name_get(memb),
40 eolian_type_array_size_get(mtp));
41 }
42 else
43 {
44 ct = eolian_type_c_type_get(mtp);
45 eina_strbuf_append_printf(buf, " %s%s%s;",
46 ct, strchr(ct, '*') ? "" : " ",
47 eolian_typedecl_struct_field_name_get(memb));
48 }
49 eina_stringshare_del(ct);
50 eina_strbuf_append(buf, "\n");
51 }
52 eina_iterator_free(membs);
53 eina_strbuf_append_printf(buf, "} %s", fn);
54 free(fn);
55 break;
56 }
57 case EOLIAN_TYPEDECL_ENUM:
58 {
59 const Eolian_Enum_Type_Field *memb;
60 if (!full)
61 break;
62 eina_strbuf_append_printf(buf, "typedef enum\n{\n");
63 Eina_Iterator *membs = eolian_typedecl_enum_fields_get(tp);
64 Eina_Bool next = eina_iterator_next(membs, (void **)&memb);
65 while (next)
66 {
67 const Eolian_Expression *vale =
68 eolian_typedecl_enum_field_value_get(memb, EINA_FALSE);
69 Eina_Stringshare *membn =
70 eolian_typedecl_enum_field_c_name_get(memb);
71 if (!vale)
72 eina_strbuf_append_printf(buf, " %s", membn);
73 else
74 {
75 Eolian_Value val =
76 eolian_expression_eval(vale, EOLIAN_MASK_INT);
77 const char *lit = eolian_expression_value_to_literal(&val);
78 eina_strbuf_append_printf(buf, " %s = %s", membn, lit);
79 const char *exp = eolian_expression_serialize(vale);
80 if (exp && strcmp(lit, exp))
81 eina_strbuf_append_printf(buf, " /* %s */", exp);
82 eina_stringshare_del(exp);
83 eina_stringshare_del(lit);
84 }
85 eina_stringshare_del(membn);
86 next = eina_iterator_next(membs, (void **)&memb);
87 if (next)
88 eina_strbuf_append(buf, ",");
89 eina_strbuf_append(buf, "\n");
90 }
91 eina_iterator_free(membs);
92 char *fn = eo_gen_c_full_name_get(eolian_typedecl_full_name_get(tp));
93 eina_strbuf_append_printf(buf, "} %s", fn);
94 free(fn);
95 break;
96 }
97 default:
98 eina_strbuf_reset(buf);
99 break;
100 }
101 return buf;
7} 102}
8 103
9void eo_gen_types_header_gen(const char *eof, Eina_Strbuf *buf, 104void eo_gen_types_header_gen(const char *eof, Eina_Strbuf *buf,
@@ -48,7 +143,7 @@ Eina_Strbuf *eo_gen_class_typedef_gen(const char *eof)
48 const Eolian_Class *cl = eolian_class_get_by_file(eof); 143 const Eolian_Class *cl = eolian_class_get_by_file(eof);
49 if (!cl) 144 if (!cl)
50 return NULL; 145 return NULL;
51 char *clfn = eo_gen_class_full_name_get(cl); 146 char *clfn = eo_gen_c_full_name_get(eolian_class_full_name_get(cl));
52 if (!clfn) 147 if (!clfn)
53 return NULL; 148 return NULL;
54 Eina_Strbuf *ret = eina_strbuf_new(); 149 Eina_Strbuf *ret = eina_strbuf_new();