summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Kolesa <d.kolesa@osg.samsung.com>2016-09-20 14:22:05 +0200
committerDaniel Kolesa <d.kolesa@osg.samsung.com>2016-10-07 11:54:23 +0200
commit45b867ae0579cd35d4585ab41c43513e6ecd21f3 (patch)
tree925d2b6495cc3512c9c88756ce2a1a6bb2af7b25
parent12c3bdee3e4fd046f3c2c5b8a8361d1975277215 (diff)
eolian gen2: generate fully functional eo headers
-rw-r--r--src/bin/eolian2/headers.c126
1 files changed, 115 insertions, 11 deletions
diff --git a/src/bin/eolian2/headers.c b/src/bin/eolian2/headers.c
index cfa4a1e50b..69dc94f3ae 100644
--- a/src/bin/eolian2/headers.c
+++ b/src/bin/eolian2/headers.c
@@ -1,6 +1,6 @@
1#include "main.h" 1#include "main.h"
2 2
3const char * 3static const char *
4_cl_type_str_get(const Eolian_Class *cl, Eina_Bool uc) 4_cl_type_str_get(const Eolian_Class *cl, Eina_Bool uc)
5{ 5{
6 switch (eolian_class_type_get(cl)) 6 switch (eolian_class_type_get(cl))
@@ -17,10 +17,116 @@ _cl_type_str_get(const Eolian_Class *cl, Eina_Bool uc)
17 } 17 }
18} 18}
19 19
20static const char *
21_get_add_star(Eolian_Function_Type ftype, Eolian_Parameter_Dir pdir)
22{
23 if (ftype == EOLIAN_PROP_GET)
24 return "*";
25 if ((pdir == EOLIAN_OUT_PARAM) || (pdir == EOLIAN_INOUT_PARAM))
26 return "*";
27 return "";
28}
29
20static void 30static void
21_gen_func(const Eolian_Class *cl, const Eolian_Function *fid, 31_gen_func(const Eolian_Function *fid, Eolian_Function_Type ftype,
22 Eolian_Function_Type ftype, Eina_Strbuf *buf) 32 Eina_Strbuf *buf, char *cnameu, Eina_Bool legacy)
23{ 33{
34 Eina_Stringshare *fcn = eolian_function_full_c_name_get(fid, ftype, legacy);
35 if (!fcn)
36 return;
37
38 Eina_Bool var_as_ret = EINA_FALSE;
39 const Eolian_Type *rtp = eolian_function_return_type_get(fid, ftype);
40 if (ftype == EOLIAN_PROP_GET && !rtp)
41 {
42 void *d1, *d2;
43 Eina_Iterator *itr = eolian_property_values_get(fid, ftype);
44 if (eina_iterator_next(itr, &d1) && !eina_iterator_next(itr, &d2))
45 {
46 rtp = eolian_parameter_type_get((Eolian_Function_Parameter *)d1);
47 var_as_ret = EINA_TRUE;
48 }
49 eina_iterator_free(itr);
50 }
51
52 Eolian_Object_Scope fsc = eolian_function_scope_get(fid, ftype);
53
54 if (eolian_function_is_beta(fid))
55 eina_strbuf_append_printf(buf, "#ifdef %s_BETA\n", cnameu);
56 if (fsc == EOLIAN_SCOPE_PROTECTED)
57 eina_strbuf_append_printf(buf, "#ifdef %s_PROTECTED\n", cnameu);
58
59 eina_strbuf_append(buf, "EOAPI ");
60 if (rtp)
61 {
62 Eina_Stringshare *rtps = eolian_type_c_type_get(rtp);
63 eina_strbuf_append(buf, rtps);
64 if (rtps[strlen(rtps) - 1] != '*')
65 eina_strbuf_append_char(buf, ' ');
66 eina_stringshare_del(rtps);
67 }
68 else
69 eina_strbuf_append(buf, "void ");
70
71 eina_strbuf_append(buf, fcn);
72 eina_stringshare_del(fcn);
73
74 eina_strbuf_append_char(buf, '(');
75 if ((ftype == EOLIAN_PROP_GET) || eolian_function_object_is_const(fid)
76 || eolian_function_is_class(fid))
77 {
78 eina_strbuf_append(buf, "const ");
79 }
80 eina_strbuf_append(buf, "Eo *obj");
81
82 {
83 Eolian_Function_Parameter *pr = NULL;
84 Eina_Iterator *itr = eolian_property_keys_get(fid, ftype);
85 EINA_ITERATOR_FOREACH(itr, pr)
86 {
87 const Eolian_Type *prt = eolian_parameter_type_get(pr);
88 const char *prn = eolian_parameter_name_get(pr);
89 Eina_Stringshare *prtn = eolian_type_c_type_get(prt);
90 eina_strbuf_append_printf(buf, ", %s %s", prtn, prn);
91 eina_stringshare_del(prtn);
92 }
93 eina_iterator_free(itr);
94 }
95
96 if (!var_as_ret)
97 {
98 Eina_Iterator *itr = NULL;
99 if (ftype == EOLIAN_PROP_GET || ftype == EOLIAN_PROP_SET)
100 itr = eolian_property_values_get(fid, ftype);
101 else
102 itr = eolian_function_parameters_get(fid);
103
104 Eolian_Function_Parameter *pr = NULL;
105 EINA_ITERATOR_FOREACH(itr, pr)
106 {
107 const Eolian_Type *prt = eolian_parameter_type_get(pr);
108 const char *prn = eolian_parameter_name_get(pr);
109 Eina_Stringshare *prtn = eolian_type_c_type_get(prt);
110
111 eina_strbuf_append(buf, ", ");
112 eina_strbuf_append(buf, prtn);
113 if (!strchr(prtn, '*'))
114 eina_strbuf_append_char(buf, ' ');
115 eina_strbuf_append(buf,
116 _get_add_star(ftype, eolian_parameter_direction_get(pr)));
117 eina_strbuf_append(buf, prn);
118 eina_stringshare_del(prtn);
119 }
120
121 eina_iterator_free(itr);
122 }
123
124 eina_strbuf_append(buf, ");\n");
125
126 if (eolian_function_is_beta(fid))
127 eina_strbuf_append_printf(buf, "#endif\n");
128 if (fsc == EOLIAN_SCOPE_PROTECTED)
129 eina_strbuf_append_printf(buf, "#endif\n");
24} 130}
25 131
26void 132void
@@ -71,14 +177,14 @@ eo_gen_header_gen(const Eolian_Class *cl, Eina_Strbuf *buf, Eina_Bool legacy)
71 { 177 {
72 case EOLIAN_PROP_GET: 178 case EOLIAN_PROP_GET:
73 case EOLIAN_PROP_SET: 179 case EOLIAN_PROP_SET:
74 _gen_func(cl, fid, ftype, buf); 180 _gen_func(fid, ftype, buf, cnameu, legacy);
75 break; 181 break;
76 case EOLIAN_PROPERTY: 182 case EOLIAN_PROPERTY:
77 _gen_func(cl, fid, EOLIAN_PROP_SET, buf); 183 _gen_func(fid, EOLIAN_PROP_SET, buf, cnameu, legacy);
78 _gen_func(cl, fid, EOLIAN_PROP_GET, buf); 184 _gen_func(fid, EOLIAN_PROP_GET, buf, cnameu, legacy);
79 break; 185 break;
80 default: 186 default:
81 _gen_func(cl, fid, EOLIAN_UNRESOLVED, buf); 187 _gen_func(fid, EOLIAN_UNRESOLVED, buf, cnameu, legacy);
82 } 188 }
83 } 189 }
84 eina_iterator_free(itr); 190 eina_iterator_free(itr);
@@ -99,15 +205,13 @@ events:
99 205
100 if (eolian_event_is_beta(ev)) 206 if (eolian_event_is_beta(ev))
101 { 207 {
102 eina_strbuf_append_printf(buf, "\n#ifndef %s_BETA\n", cnameu); 208 eina_strbuf_append_printf(buf, "\n#ifdef %s_BETA\n", cnameu);
103 eina_strbuf_append_printf(buf, "#define %s_BETA\n", cnameu);
104 } 209 }
105 if (evs == EOLIAN_SCOPE_PROTECTED) 210 if (evs == EOLIAN_SCOPE_PROTECTED)
106 { 211 {
107 if (!eolian_event_is_beta(ev)) 212 if (!eolian_event_is_beta(ev))
108 eina_strbuf_append_char(buf, '\n'); 213 eina_strbuf_append_char(buf, '\n');
109 eina_strbuf_append_printf(buf, "#ifndef %s_PROTECTED\n", cnameu); 214 eina_strbuf_append_printf(buf, "#ifdef %s_PROTECTED\n", cnameu);
110 eina_strbuf_append_printf(buf, "#define %s_PROTECTED\n", cnameu);
111 } 215 }
112 216
113 if (!eolian_event_is_beta(ev) && evs == EOLIAN_SCOPE_PUBLIC) 217 if (!eolian_event_is_beta(ev) && evs == EOLIAN_SCOPE_PUBLIC)