summaryrefslogtreecommitdiff
path: root/src/bin/eolian/headers.c
diff options
context:
space:
mode:
authorDaniel Kolesa <d.kolesa@osg.samsung.com>2017-08-30 15:12:01 +0200
committerDaniel Kolesa <d.kolesa@osg.samsung.com>2017-08-30 15:34:49 +0200
commit93c93328ac8390bea8039b023950290cc3750080 (patch)
treee92ba7c19d61c743afb4166a54c4407a32a9e933 /src/bin/eolian/headers.c
parentfd93caf4b224928d139314876f4c269578c3a7b6 (diff)
eolian gen: clean up param gen
Diffstat (limited to 'src/bin/eolian/headers.c')
-rw-r--r--src/bin/eolian/headers.c134
1 files changed, 54 insertions, 80 deletions
diff --git a/src/bin/eolian/headers.c b/src/bin/eolian/headers.c
index 71d66f3..a0c6879 100644
--- a/src/bin/eolian/headers.c
+++ b/src/bin/eolian/headers.c
@@ -11,6 +11,58 @@ _get_add_star(Eolian_Function_Type ftype, Eolian_Parameter_Dir pdir)
11 return ""; 11 return "";
12} 12}
13 13
14int
15eo_gen_type_c_params_gen(Eina_Strbuf *buf, Eolian_Function_Parameter *pr, Eolian_Function_Type ftype, int *rpid)
16{
17 const Eolian_Type *prt = eolian_parameter_type_get(pr);
18 const Eolian_Typedecl *ptd = eolian_type_typedecl_get(prt);
19 const char *prn = eolian_parameter_name_get(pr);
20 Eina_Stringshare *prtn = eolian_type_c_type_get(prt, EOLIAN_C_TYPE_PARAM);
21
22 if (ptd && (eolian_typedecl_type_get(ptd) == EOLIAN_TYPEDECL_FUNCTION_POINTER))
23 {
24 eina_strbuf_append_printf(buf, "void *%s_data, %s %s, Eina_Free_Cb %s_free_cb",
25 prn, prtn, prn, prn);
26 eina_stringshare_del(prtn);
27 *rpid = 1;
28 return 3;
29 }
30
31 eina_strbuf_append(buf, prtn);
32 if (prtn[strlen(prtn) - 1] != '*')
33 eina_strbuf_append_char(buf, ' ');
34 eina_strbuf_append(buf, _get_add_star(ftype, eolian_parameter_direction_get(pr)));
35 eina_strbuf_append(buf, prn);
36 eina_stringshare_del(prtn);
37 *rpid = 0;
38 return 1;
39}
40
41static void
42_gen_params(Eina_Iterator *itr, Eina_Strbuf *buf, Eina_Strbuf **flagbuf, int *nidx, Eolian_Function_Type ftype)
43{
44 Eolian_Function_Parameter *pr;
45 EINA_ITERATOR_FOREACH(itr, pr)
46 {
47 int rpid = 0;
48 if (*nidx)
49 eina_strbuf_append(buf, ", ");
50 *nidx += eo_gen_type_c_params_gen(buf, pr, ftype, &rpid);
51
52 if (!eolian_parameter_is_nonull(pr))
53 continue;
54
55 if (!*flagbuf)
56 {
57 *flagbuf = eina_strbuf_new();
58 eina_strbuf_append_printf(*flagbuf, " EINA_ARG_NONNULL(%d", *nidx - rpid);
59 }
60 else
61 eina_strbuf_append_printf(*flagbuf, ", %d", *nidx - rpid);
62 }
63 eina_iterator_free(itr);
64}
65
14static void 66static void
15_gen_func(const Eolian_Unit *src, const Eolian_Function *fid, 67_gen_func(const Eolian_Unit *src, const Eolian_Function *fid,
16 Eolian_Function_Type ftype, Eina_Strbuf *buf, char *cname, 68 Eolian_Function_Type ftype, Eina_Strbuf *buf, char *cname,
@@ -70,7 +122,6 @@ _gen_func(const Eolian_Unit *src, const Eolian_Function *fid,
70 eina_strbuf_append(buf, fcn); 122 eina_strbuf_append(buf, fcn);
71 eina_stringshare_del(fcn); 123 eina_stringshare_del(fcn);
72 124
73 Eina_Bool first = EINA_TRUE;
74 Eina_Strbuf *flagbuf = NULL; 125 Eina_Strbuf *flagbuf = NULL;
75 int nidx = !legacy || !eolian_function_is_class(fid); 126 int nidx = !legacy || !eolian_function_is_class(fid);
76 127
@@ -86,35 +137,9 @@ _gen_func(const Eolian_Unit *src, const Eolian_Function *fid,
86 eina_strbuf_append_printf(buf, "%s *obj", cname); 137 eina_strbuf_append_printf(buf, "%s *obj", cname);
87 else 138 else
88 eina_strbuf_append(buf, "Eo *obj"); 139 eina_strbuf_append(buf, "Eo *obj");
89 first = EINA_FALSE;
90 } 140 }
91 141
92 { 142 _gen_params(eolian_property_keys_get(fid, ftype), buf, &flagbuf, &nidx, EOLIAN_PROPERTY);
93 Eolian_Function_Parameter *pr = NULL;
94 Eina_Iterator *itr = eolian_property_keys_get(fid, ftype);
95 EINA_ITERATOR_FOREACH(itr, pr)
96 {
97 const Eolian_Type *prt = eolian_parameter_type_get(pr);
98 const char *prn = eolian_parameter_name_get(pr);
99 Eina_Stringshare *prtn = eolian_type_c_type_get(prt, EOLIAN_C_TYPE_PARAM);
100 ++nidx;
101 if (!first)
102 eina_strbuf_append(buf, ", ");
103 eina_strbuf_append_printf(buf, "%s %s", prtn, prn);
104 eina_stringshare_del(prtn);
105 first = EINA_FALSE;
106 if (!eolian_parameter_is_nonull(pr))
107 continue;
108 if (!flagbuf)
109 {
110 flagbuf = eina_strbuf_new();
111 eina_strbuf_append_printf(flagbuf, " EINA_ARG_NONNULL(%d", nidx);
112 }
113 else
114 eina_strbuf_append_printf(flagbuf, ", %d", nidx);
115 }
116 eina_iterator_free(itr);
117 }
118 143
119 if (!var_as_ret) 144 if (!var_as_ret)
120 { 145 {
@@ -123,58 +148,7 @@ _gen_func(const Eolian_Unit *src, const Eolian_Function *fid,
123 itr = eolian_property_values_get(fid, ftype); 148 itr = eolian_property_values_get(fid, ftype);
124 else 149 else
125 itr = eolian_function_parameters_get(fid); 150 itr = eolian_function_parameters_get(fid);
126 151 _gen_params(itr, buf, &flagbuf, &nidx, ftype);
127 Eolian_Function_Parameter *pr = NULL;
128 EINA_ITERATOR_FOREACH(itr, pr)
129 {
130 const Eolian_Type *prt = eolian_parameter_type_get(pr);
131 const Eolian_Typedecl *ptd = eolian_type_typedecl_get(prt);
132 const char *prn = eolian_parameter_name_get(pr);
133 Eina_Stringshare *prtn = eolian_type_c_type_get(prt, EOLIAN_C_TYPE_PARAM);
134
135 if (ptd && eolian_typedecl_type_get(ptd) == EOLIAN_TYPEDECL_FUNCTION_POINTER)
136 {
137 nidx += 3;
138 if (!first)
139 eina_strbuf_append(buf, ", ");
140 eina_strbuf_append_printf(buf, "void *%s_data, %s %s, Eina_Free_Cb %s_free_cb",
141 prn, prtn, prn, prn);
142 eina_stringshare_del(prtn);
143 if (!eolian_parameter_is_nonull(pr))
144 continue;
145 if (!flagbuf)
146 {
147 flagbuf = eina_strbuf_new();
148 eina_strbuf_append_printf(flagbuf, " EINA_ARG_NONNULL(%d", nidx - 1);
149 }
150 else
151 eina_strbuf_append_printf(flagbuf, ", %d", nidx - 1);
152 continue;
153 }
154
155 ++nidx;
156 if (!first)
157 eina_strbuf_append(buf, ", ");
158 eina_strbuf_append(buf, prtn);
159 if (prtn[strlen(prtn) - 1] != '*')
160 eina_strbuf_append_char(buf, ' ');
161 eina_strbuf_append(buf,
162 _get_add_star(ftype, eolian_parameter_direction_get(pr)));
163 eina_strbuf_append(buf, prn);
164 eina_stringshare_del(prtn);
165 first = EINA_FALSE;
166 if (!eolian_parameter_is_nonull(pr))
167 continue;
168 if (!flagbuf)
169 {
170 flagbuf = eina_strbuf_new();
171 eina_strbuf_append_printf(flagbuf, " EINA_ARG_NONNULL(%d", nidx);
172 }
173 else
174 eina_strbuf_append_printf(flagbuf, ", %d", nidx);
175 }
176
177 eina_iterator_free(itr);
178 } 152 }
179 153
180 if (flagbuf) 154 if (flagbuf)