summaryrefslogtreecommitdiff
path: root/src/bin/eolian_cxx
diff options
context:
space:
mode:
authorSavio Sena <savio@expertisesolutions.com.br>2014-09-12 16:50:09 -0300
committerSavio Sena <savio@expertisesolutions.com.br>2014-09-12 16:50:09 -0300
commit6500c996699e1a4ab768768ffa821ace6c3c392c (patch)
tree3dec297d71e853dbfe308488e8e2636b3b72fce8 /src/bin/eolian_cxx
parentfa01f747a8638eae2467396ee903444973246556 (diff)
eolian-cxx: Refactored eolian_cxx to cope with new Eolian API.
Diffstat (limited to 'src/bin/eolian_cxx')
-rw-r--r--src/bin/eolian_cxx/convert.cc328
-rw-r--r--src/bin/eolian_cxx/convert_comments.cc9
-rw-r--r--src/bin/eolian_cxx/convert_comments.hh21
-rw-r--r--src/bin/eolian_cxx/eolian_cxx.cc7
4 files changed, 162 insertions, 203 deletions
diff --git a/src/bin/eolian_cxx/convert.cc b/src/bin/eolian_cxx/convert.cc
index 56f2c06869..2cf87256db 100644
--- a/src/bin/eolian_cxx/convert.cc
+++ b/src/bin/eolian_cxx/convert.cc
@@ -23,7 +23,7 @@ namespace eolian_cxx {
23extern efl::eina::log_domain domain; 23extern efl::eina::log_domain domain;
24 24
25static efl::eolian::parameters_container_type 25static efl::eolian::parameters_container_type
26convert_eolian_parameters(Eina_Iterator *parameters, 26_convert_eolian_parameters(Eina_Iterator *parameters,
27 Eolian_Function_Type func_type) 27 Eolian_Function_Type func_type)
28{ 28{
29 if (parameters == NULL) return {}; 29 if (parameters == NULL) return {};
@@ -46,126 +46,113 @@ convert_eolian_parameters(Eina_Iterator *parameters,
46} 46}
47 47
48static efl::eolian::parameters_container_type 48static efl::eolian::parameters_container_type
49convert_eolian_parameters(Eolian_Function const& func, getter_t func_type) 49_convert_eolian_parameters(Eolian_Function const& func, getter_t func_type)
50{ 50{
51 return convert_eolian_parameters 51 return _convert_eolian_parameters
52 (::eolian_function_parameters_get(&func), func_type.value); 52 (::eolian_function_parameters_get(&func), func_type.value);
53} 53}
54 54
55static efl::eolian::parameters_container_type 55static efl::eolian::parameters_container_type
56convert_eolian_parameters(Eina_Iterator *parameters, getter_t func_type) 56_convert_eolian_parameters(Eina_Iterator *parameters, getter_t func_type)
57{ 57{
58 return convert_eolian_parameters(parameters, func_type.value); 58 return _convert_eolian_parameters(parameters, func_type.value);
59} 59}
60 60
61static efl::eolian::parameters_container_type 61static efl::eolian::parameters_container_type
62convert_eolian_parameters(Eina_Iterator *parameters, setter_t func_type) 62_convert_eolian_parameters(Eina_Iterator *parameters, setter_t func_type)
63{ 63{
64 return convert_eolian_parameters(parameters, func_type.value); 64 return _convert_eolian_parameters(parameters, func_type.value);
65} 65}
66 66
67static efl::eolian::parameters_container_type 67static efl::eolian::parameters_container_type
68convert_eolian_parameters(Eolian_Function const& func) 68_convert_eolian_parameters(Eolian_Function const& func)
69{ 69{
70 assert(function_type(func) != EOLIAN_PROPERTY); 70 assert(function_op_type(func) != EOLIAN_PROPERTY);
71 return convert_eolian_parameters 71 return _convert_eolian_parameters
72 (::eolian_function_parameters_get(&func), function_type(func)); 72 (::eolian_function_parameters_get(&func), function_op_type(func));
73} 73}
74 74
75static efl::eolian::functions_container_type 75static efl::eolian::eo_function
76convert_eolian_property_to_functions(Eolian_Class const& klass) 76_convert_property_set_to_function(Eolian_Class const& klass,
77 Eolian_Function const& prop_)
77{ 78{
78 efl::eolian::functions_container_type container;
79 std::string cxx_classname = safe_lower(class_name(klass));
80 Eina_Iterator *properties =
81 ::eolian_class_functions_get(&klass, EOLIAN_PROPERTY); // XXX
82 void *curr;
83 std::string prefix(class_prefix(klass)); 79 std::string prefix(class_prefix(klass));
84 EINA_ITERATOR_FOREACH(properties, curr) 80 efl::eolian::eo_function set_ =
85 { 81 {
86 Eolian_Function *prop_ = static_cast<Eolian_Function*>(curr); 82 efl::eolian::eo_function::regular_,
87 if (property_is_getter(*prop_)) 83 function_name(prop_) + "_set",
88 { 84 function_impl(prop_, prefix) + "_set",
89 efl::eolian::parameters_container_type params 85 function_return_type(prop_, eolian_cxx::setter),
90 = convert_eolian_parameters(*prop_, eolian_cxx::getter); 86 _convert_eolian_parameters(::eolian_function_parameters_get(&prop_),
91 87 eolian_cxx::setter),
92 efl::eolian::eo_function get_; 88 convert_comments_function(klass, prop_, eolian_cxx::setter)
93 get_.type = efl::eolian::eo_function::regular_; 89 };
94 get_.name = function_name(*prop_) + "_get"; 90 efl::eolian::parameters_container_type keys =
95 get_.impl = function_impl(*prop_, prefix) + "_get"; 91 _convert_eolian_parameters(::eolian_property_keys_get(&prop_),
92 eolian_cxx::setter);
93 if (!keys.empty())
94 {
95 keys.reserve(keys.size() + set_.params.size());
96 keys.insert(keys.end(), set_.params.begin(),
97 set_.params.end());
98 set_.params = keys;
99 }
100 return set_;
101}
96 102
97 efl::eolian::eolian_type_instance ret = 103static efl::eolian::eo_function
98 function_return_type(*prop_, eolian_cxx::getter); 104_convert_property_get_to_function(Eolian_Class const& klass,
105 Eolian_Function const& prop_)
106{
107 std::string prefix(class_prefix(klass));
108 efl::eolian::eo_function get_ =
109 {
110 efl::eolian::eo_function::regular_,
111 function_name(prop_) + "_get",
112 function_impl(prop_, prefix) + "_get",
113 function_return_type(prop_, eolian_cxx::getter),
114 _convert_eolian_parameters(prop_, eolian_cxx::getter),
115 convert_comments_function(klass, prop_, eolian_cxx::getter)
116 };
99 117
100 // if the getter has a single parameter and a void return 118 // if the getter has a single parameter and a void return
101 // it is transformed into a getter with no parameters 119 // it is transformed into a getter with no parameters
102 // that actually returns what would be the first argument. 120 // that actually returns what would be the first argument.
103 if (params.size() == 1 && efl::eolian::type_is_void(ret) && 121 if (get_.params.size() == 1 && efl::eolian::type_is_void(get_.ret) &&
104 !function_return_is_explicit_void(*prop_, eolian_cxx::getter)) 122 !function_return_is_explicit_void(prop_, eolian_cxx::getter))
105 { 123 {
106 get_.ret = params[0].type; 124 get_.ret = get_.params[0].type;
107 get_.params.clear(); 125 get_.params.clear();
108 } 126 }
109 else // otherwise just create the described getter 127 else // otherwise just create the described getter
110 { 128 {
111 get_.ret = ret; 129 std::transform
112 get_.params = params; 130 (get_.params.begin(), get_.params.end(), get_.params.begin(),
113 std::transform 131 [](efl::eolian::eo_parameter const& param)
114 (params.begin(), params.end(), get_.params.begin(), 132 {
115 [](efl::eolian::eo_parameter const& param) 133 efl::eolian::eolian_type getter_param_type =
116 { 134 type_to_native(param.type);
117 efl::eolian::eolian_type getter_param_type = 135 getter_param_type.native += "*";
118 type_to_native(param.type); 136 return efl::eolian::eo_parameter
119 getter_param_type.native += "*"; 137 { { getter_param_type }, param.name };
120 return efl::eolian::eo_parameter 138 });
121 { { getter_param_type }, param.name }; 139 }
122 }); 140 efl::eolian::parameters_container_type keys =
123 } 141 _convert_eolian_parameters(::eolian_property_keys_get(&prop_),
124 efl::eolian::parameters_container_type keys = 142 eolian_cxx::getter);
125 convert_eolian_parameters(::eolian_property_keys_get(prop_), 143 if (!keys.empty())
126 eolian_cxx::getter); 144 {
127 if (!keys.empty()) 145 keys.reserve(keys.size() + get_.params.size());
128 { 146 keys.insert(keys.end(), get_.params.begin(),
129 keys.reserve(keys.size() + get_.params.size()); 147 get_.params.end());
130 keys.insert(keys.end(), get_.params.begin(), 148 get_.params = keys;
131 get_.params.end());
132 get_.params = keys;
133 }
134 get_.comment = convert_comments_function(*prop_, eolian_cxx::getter);
135 container.push_back(get_);
136 }
137 if (property_is_setter(*prop_))
138 {
139 efl::eolian::eo_function set_;
140 set_.type = efl::eolian::eo_function::regular_;
141 set_.name = function_name(*prop_) + "_set";
142 set_.impl = function_impl(*prop_, prefix) + "_set";
143 efl::eolian::parameters_container_type keys =
144 convert_eolian_parameters(::eolian_property_keys_get(prop_),
145 eolian_cxx::setter);
146 efl::eolian::parameters_container_type params =
147 convert_eolian_parameters(::eolian_function_parameters_get(prop_),
148 eolian_cxx::setter);
149 set_.params = params;
150 if (!keys.empty())
151 {
152 keys.reserve(keys.size() + set_.params.size());
153 keys.insert(keys.end(), set_.params.begin(),
154 set_.params.end());
155 set_.params = keys;
156 }
157 set_.ret = function_return_type(*prop_, eolian_cxx::setter);
158 set_.comment = convert_comments_function(*prop_, eolian_cxx::setter);
159 container.push_back(set_);
160 }
161 } 149 }
162 eina_iterator_free(properties); 150 return get_;
163 return container;
164} 151}
165 152
166std::string get_class_name(std::string const& name) 153static std::string
154_convert_class_name(std::string const& name)
167{ 155{
168 // "eo_base" is the Eolian name for EO_BASE_CLASS.
169 return (name == "eo_base" || name == "eo::base" || name == "") 156 return (name == "eo_base" || name == "eo::base" || name == "")
170 ? "efl::eo::base" 157 ? "efl::eo::base"
171 : name; 158 : name;
@@ -188,103 +175,18 @@ convert_eolian_inheritances(efl::eolian::eo_class& cls, Eolian_Class const& klas
188 { 175 {
189 // First element is the parent 176 // First element is the parent
190 const char *ptr = static_cast<const char*>(curr); 177 const char *ptr = static_cast<const char*>(curr);
191 cls.parent = get_class_name(class_format_cxx(safe_lower(ptr))); 178 cls.parent = _convert_class_name(class_format_cxx(safe_lower(ptr)));
192 179
193 EINA_ITERATOR_FOREACH(inheritances, curr) 180 EINA_ITERATOR_FOREACH(inheritances, curr)
194 { 181 {
195 std::string extension = safe_lower(static_cast<const char*>(curr)); 182 std::string extension = safe_lower(static_cast<const char*>(curr));
196 cls.extensions.push_back(get_class_name(class_format_cxx(extension))); 183 cls.extensions.push_back(_convert_class_name(class_format_cxx(extension)));
197 } 184 }
198 } 185 }
199 eina_iterator_free(inheritances); 186 eina_iterator_free(inheritances);
200} 187}
201 188
202void 189void
203convert_eolian_implements(efl::eolian::eo_class& cls, Eolian_Class const& klass)
204{
205 std::string prefix(class_prefix(klass));
206 Eina_Iterator *itr = ::eolian_class_implements_get(&klass);
207 void *impl_desc_;
208
209 EINA_ITERATOR_FOREACH(itr, impl_desc_)
210 {
211 const Eolian_Implement *impl_desc = static_cast<Eolian_Implement*>(impl_desc_);
212 const Eolian_Class *impl_class = eolian_implement_class_get(impl_desc);
213 Eolian_Function_Type impl_type;
214 const Eolian_Function *impl_func = eolian_implement_function_get(impl_desc, &impl_type);
215 /* fixme */
216 if (eolian_function_is_constructing(impl_func))
217 {
218 efl::eolian::eo_constructor constructor;
219 std::string parent = safe_lower(eolian_class_full_name_get(impl_class));
220 if (parent == "eo_base" || parent == "eo.base") parent = "eo";
221 constructor.name = parent + "_" + function_name(*impl_func);
222 constructor.params = convert_eolian_parameters(*impl_func);
223 constructor.comment = convert_comments_function(*impl_func, eolian_cxx::ctor);
224 cls.constructors.push_back(constructor);
225 }
226 }
227 eina_iterator_free(itr);
228}
229
230void
231convert_eolian_constructors(efl::eolian::eo_class& cls, Eolian_Class const& klass)
232{
233 void *curr;
234 std::string prefix(class_prefix(klass));
235 Eina_Iterator *constructors =
236 ::eolian_class_functions_get(&klass, EOLIAN_METHOD);
237 EINA_ITERATOR_FOREACH(constructors, curr)
238 {
239 Eolian_Function *eo_constructor = static_cast<Eolian_Function*>(curr);
240 /* fixme */
241 if (!eolian_function_is_constructing(eo_constructor))
242 continue;
243 efl::eolian::eo_constructor constructor;
244 constructor.name = function_impl(*eo_constructor, prefix);
245 constructor.params = convert_eolian_parameters(*eo_constructor);
246 constructor.comment = convert_comments_function(*eo_constructor, eolian_cxx::ctor);
247 cls.constructors.push_back(constructor);
248 }
249 eina_iterator_free(constructors);
250}
251
252void
253convert_eolian_functions(efl::eolian::eo_class& cls, Eolian_Class const& klass)
254{
255 void *curr;
256
257 Eina_Iterator *eolian_functions =
258 ::eolian_class_functions_get(&klass, EOLIAN_METHOD);
259 EINA_ITERATOR_FOREACH(eolian_functions, curr)
260 {
261 efl::eolian::eo_function func_;
262 Eolian_Function *eol_func = static_cast<Eolian_Function*>(curr);
263 /* fixme */
264 if (eolian_function_is_constructing(eol_func))
265 continue;
266 // XXX Eolian only provides regular methods so far
267 func_.type = efl::eolian::eo_function::regular_;
268 func_.name = function_name(*eol_func);
269 func_.impl = function_impl(*eol_func, class_prefix(klass));
270 func_.ret = function_return_type(*eol_func);
271 func_.params = convert_eolian_parameters(*eol_func);
272 func_.comment = convert_comments_function(*eol_func, eolian_cxx::method);
273 cls.functions.push_back(func_);
274 }
275 eina_iterator_free(eolian_functions);
276}
277
278void
279convert_eolian_properties(efl::eolian::eo_class& cls, Eolian_Class const& klass)
280{
281 efl::eolian::functions_container_type properties
282 = convert_eolian_property_to_functions(klass);
283 cls.functions.insert
284 (cls.functions.end(), properties.begin(), properties.end());
285}
286
287void
288convert_eolian_events(efl::eolian::eo_class& cls, Eolian_Class const& klass) 190convert_eolian_events(efl::eolian::eo_class& cls, Eolian_Class const& klass)
289{ 191{
290 efl::eolian::events_container_type events = event_list(klass); 192 efl::eolian::events_container_type events = event_list(klass);
@@ -297,22 +199,74 @@ convert_eolian_class_new(Eolian_Class const& klass)
297{ 199{
298 efl::eolian::eo_class cls; 200 efl::eolian::eo_class cls;
299 cls.type = class_type(klass); 201 cls.type = class_type(klass);
300 cls.name = safe_lower(class_name(klass)); 202 cls.name = class_name(klass);
301 cls.name_space = class_namespace_full(klass); 203 cls.name_space = class_namespace_full(klass);
302 cls.eo_name = class_eo_name(klass); 204 cls.eo_name = class_eo_name(klass);
303 cls.comment = convert_comments_class(klass); 205 cls.comment = convert_comments_class(klass);
304 return cls; 206 return cls;
305} 207}
306 208
209void
210convert_eolian_implements(efl::eolian::eo_class& cls, Eolian_Class const& klass)
211{
212 std::string prefix(class_prefix(klass));
213 efl::eina::iterator<const Eolian_Implement> itr = implements_get(klass);
214 efl::eina::iterator<const Eolian_Implement> end;
215
216 while (itr != end)
217 {
218 const Eolian_Implement impl = *itr;
219 assert(!!implement_function(impl));
220 assert(!!implement_class(impl));
221 Eolian_Function const& func = *implement_function(impl);
222 Eolian_Class const& icls = *implement_class(impl);
223
224 if (implement_is_property_get(impl))
225 {
226 cls.functions.push_back
227 (_convert_property_get_to_function(icls, func));
228 }
229 else if (implement_is_property_set(impl))
230 {
231 cls.functions.push_back
232 (_convert_property_set_to_function(icls, func));
233 }
234 else if (function_op_type(func) == eolian_cxx::property.value)
235 {
236 cls.functions.push_back
237 (_convert_property_get_to_function(icls, func));
238 cls.functions.push_back
239 (_convert_property_set_to_function(icls, func));
240 }
241 else if (function_is_constructor(klass, func))
242 {
243 cls.constructors.push_back({
244 function_impl(func, class_prefix(icls)),
245 _convert_eolian_parameters(func),
246 convert_comments_function(icls, func)
247 });
248 }
249 else if (implement_is_visible(impl))
250 {
251 cls.functions.push_back({
252 function_type(func),
253 function_name(func),
254 function_impl(func, class_prefix(icls)),
255 function_return_type(func),
256 _convert_eolian_parameters(func),
257 convert_comments_function(icls, func, eolian_cxx::method)
258 });
259 }
260 ++itr;
261 }
262}
263
307efl::eolian::eo_class 264efl::eolian::eo_class
308convert_eolian_class(const Eolian_Class& klass) 265convert_eolian_class(const Eolian_Class& klass)
309{ 266{
310 efl::eolian::eo_class cls(eolian_cxx::convert_eolian_class_new(klass)); 267 efl::eolian::eo_class cls(eolian_cxx::convert_eolian_class_new(klass));
311 eolian_cxx::convert_eolian_inheritances(cls, klass); 268 eolian_cxx::convert_eolian_inheritances(cls, klass);
312 eolian_cxx::convert_eolian_implements(cls, klass); 269 eolian_cxx::convert_eolian_implements(cls, klass);
313 eolian_cxx::convert_eolian_constructors(cls, klass);
314 eolian_cxx::convert_eolian_functions(cls, klass);
315 eolian_cxx::convert_eolian_properties(cls, klass);
316 eolian_cxx::convert_eolian_events(cls, klass); 270 eolian_cxx::convert_eolian_events(cls, klass);
317 efl::eolian::eo_class_validate(cls); 271 efl::eolian::eo_class_validate(cls);
318 return cls; 272 return cls;
diff --git a/src/bin/eolian_cxx/convert_comments.cc b/src/bin/eolian_cxx/convert_comments.cc
index 43aadcdc9f..381786e8a1 100644
--- a/src/bin/eolian_cxx/convert_comments.cc
+++ b/src/bin/eolian_cxx/convert_comments.cc
@@ -38,7 +38,7 @@ _comment_parameters_list(Eina_Iterator *params)
38} 38}
39 39
40static std::string 40static std::string
41_comment_brief_and_params(Eolian_Function const& function, Eolian_Function_Type ftype = EOLIAN_METHOD) 41_comment_brief_and_params(Eolian_Function const& function, Eolian_Function_Type ftype)
42{ 42{
43 std::string doc = ""; 43 std::string doc = "";
44 std::string func = safe_str(::eolian_function_description_get(&function, ftype)); 44 std::string func = safe_str(::eolian_function_description_get(&function, ftype));
@@ -79,11 +79,12 @@ convert_comments_class(Eolian_Class const& klass)
79} 79}
80 80
81std::string 81std::string
82convert_comments_function(Eolian_Function const& function, 82convert_comments_function(Eolian_Class const& klass,
83 Eolian_Function const& function,
83 Eolian_Function_Type func_type) 84 Eolian_Function_Type func_type)
84{ 85{
85 std::string doc = _comment_brief_and_params(function); 86 std::string doc = _comment_brief_and_params(function, func_type);
86 if (func_type != eolian_cxx::ctor.value) 87 if (!function_is_constructor(klass, function))
87 doc += _comment_return(function, func_type); 88 doc += _comment_return(function, func_type);
88 return doc; 89 return doc;
89} 90}
diff --git a/src/bin/eolian_cxx/convert_comments.hh b/src/bin/eolian_cxx/convert_comments.hh
index 75d420af58..788362e4be 100644
--- a/src/bin/eolian_cxx/convert_comments.hh
+++ b/src/bin/eolian_cxx/convert_comments.hh
@@ -11,33 +11,34 @@
11 11
12namespace eolian_cxx { 12namespace eolian_cxx {
13 13
14std::string convert_comments_class(Eolian_Class const& kls); 14std::string convert_comments_class(Eolian_Class const& klass);
15 15
16std::string convert_comments_function(Eolian_Function const& function, 16std::string convert_comments_function(Eolian_Class const& klass,
17 Eolian_Function const& function,
17 Eolian_Function_Type func_type); 18 Eolian_Function_Type func_type);
18 19
19inline std::string 20inline std::string
20convert_comments_function(Eolian_Function const& constructor_, ctor_t func_type_) 21convert_comments_function(Eolian_Class const& klass, Eolian_Function const& function_, method_t func_type_)
21{ 22{
22 return convert_comments_function(constructor_, func_type_.value); 23 return convert_comments_function(klass, function_, func_type_.value);
23} 24}
24 25
25inline std::string 26inline std::string
26convert_comments_function(Eolian_Function const& function_, method_t func_type_) 27convert_comments_function(Eolian_Class const& klass, Eolian_Function const& property_, getter_t func_type_)
27{ 28{
28 return convert_comments_function(function_, func_type_.value); 29 return convert_comments_function(klass, property_, func_type_.value);
29} 30}
30 31
31inline std::string 32inline std::string
32convert_comments_function(Eolian_Function const& property_, getter_t func_type_) 33convert_comments_function(Eolian_Class const& klass, Eolian_Function const& property_, setter_t func_type_)
33{ 34{
34 return convert_comments_function(property_, func_type_.value); 35 return convert_comments_function(klass, property_, func_type_.value);
35} 36}
36 37
37inline std::string 38inline std::string
38convert_comments_function(Eolian_Function const& property_, setter_t func_type_) 39convert_comments_function(Eolian_Class const& klass, Eolian_Function const& function_)
39{ 40{
40 return convert_comments_function(property_, func_type_.value); 41 return convert_comments_function(klass, function_, eolian_cxx::method);
41} 42}
42 43
43} 44}
diff --git a/src/bin/eolian_cxx/eolian_cxx.cc b/src/bin/eolian_cxx/eolian_cxx.cc
index 4a689c50fb..5aa477edf0 100644
--- a/src/bin/eolian_cxx/eolian_cxx.cc
+++ b/src/bin/eolian_cxx/eolian_cxx.cc
@@ -169,14 +169,17 @@ run(options_type const& opts)
169 } 169 }
170 else 170 else
171 { 171 {
172 auto classes = class_list_all(); 172 efl::eina::iterator<const Eolian_Class> it(class_list_all());
173 for (const Eolian_Class& c : classes) 173 efl::eina::iterator<const Eolian_Class> end;
174 while (it != end)
174 { 175 {
176 Eolian_Class c = (*it);
175 if (!generate(c, opts)) 177 if (!generate(c, opts))
176 { 178 {
177 klass = &c; 179 klass = &c;
178 goto err; 180 goto err;
179 } 181 }
182 ++it;
180 } 183 }
181 } 184 }
182 return; 185 return;