summaryrefslogtreecommitdiff
path: root/src/bin/eolian_mono/eolian/mono/function_definition.hh
diff options
context:
space:
mode:
authorLauro Moura <lauromoura@expertisesolutions.com.br>2018-12-14 18:17:23 -0200
committerVitor Sousa <vitorsousa@expertisesolutions.com.br>2018-12-14 18:30:59 -0200
commita83c3cdba446c42d42b22b314ed6f91351e5234d (patch)
tree5e33da910696f07626d0de2fd1977306ed6c42d6 /src/bin/eolian_mono/eolian/mono/function_definition.hh
parent0611dbc1e9bbf81026e7630a65766c325495bf47 (diff)
eolian_mono: Add support for C# style properties
Summary: Syntatic sugar around the Get/Set functions for now. Test Plan: Run efl-mono-suite Reviewers: vitor.sousa, segfaultxavi, felipealmeida, Jaehyun_Cho Reviewed By: vitor.sousa Subscribers: cedric Tags: #efl_language_bindings Differential Revision: https://phab.enlightenment.org/D7394
Diffstat (limited to 'src/bin/eolian_mono/eolian/mono/function_definition.hh')
-rw-r--r--src/bin/eolian_mono/eolian/mono/function_definition.hh78
1 files changed, 76 insertions, 2 deletions
diff --git a/src/bin/eolian_mono/eolian/mono/function_definition.hh b/src/bin/eolian_mono/eolian/mono/function_definition.hh
index 93765065b8..2821360a04 100644
--- a/src/bin/eolian_mono/eolian/mono/function_definition.hh
+++ b/src/bin/eolian_mono/eolian/mono/function_definition.hh
@@ -137,8 +137,6 @@ struct function_definition_generator
137 bool generate(OutputIterator sink, attributes::function_def const& f, Context const& context) const 137 bool generate(OutputIterator sink, attributes::function_def const& f, Context const& context) const
138 { 138 {
139 EINA_CXX_DOM_LOG_DBG(eolian_mono::domain) << "function_definition_generator: " << f.c_name << std::endl; 139 EINA_CXX_DOM_LOG_DBG(eolian_mono::domain) << "function_definition_generator: " << f.c_name << std::endl;
140 if(!do_super && f.is_static) // Static methods goes only on Concrete classes.
141 return true;
142 if(blacklist::is_function_blacklisted(f.c_name)) 140 if(blacklist::is_function_blacklisted(f.c_name))
143 return true; 141 return true;
144 142
@@ -209,6 +207,75 @@ struct native_function_definition_parameterized
209 } 207 }
210} const native_function_definition; 208} const native_function_definition;
211 209
210struct property_wrapper_definition_generator
211{
212 template<typename OutputIterator, typename Context>
213 bool generate(OutputIterator sink, attributes::property_def const& property, Context context) const
214 {
215 if (blacklist::is_property_blacklisted(property))
216 return true;
217
218 bool interface = context_find_tag<class_context>(context).current_wrapper_kind == class_context::interface;
219 bool is_static = (property.getter.is_engaged() && property.getter->is_static
220 || property.setter.is_engaged() && property.setter->is_static);
221
222
223 if (interface && is_static)
224 return true;
225
226 auto get_params = property.getter.is_engaged() ? property.getter->parameters.size() : 0;
227 auto set_params = property.setter.is_engaged() ? property.setter->parameters.size() : 0;
228
229 // C# properties must have a single value.
230 //
231 // Single values in getters are automatically converted to return_type,
232 // meaning they should have 0 parameters.
233 //
234 // For setters, we ignore the return type - usually boolean.
235 if (get_params > 0 || set_params > 1)
236 return true;
237
238 attributes::type_def prop_type;
239
240 if (property.getter.is_engaged())
241 prop_type = property.getter->return_type;
242 else if (property.setter.is_engaged())
243 prop_type = property.setter->parameters[0].type;
244 else
245 {
246 EINA_CXX_DOM_LOG_ERR(eolian_mono::domain) << "Property must have either a getter or a setter." << std::endl;
247 return false;
248 }
249
250 std::string dir_mod;
251 if (property.setter.is_engaged())
252 dir_mod = direction_modifier(property.setter->parameters[0]);
253
254 std::string managed_name = name_helpers::property_managed_name(property);
255
256 if (!as_generator(
257 scope_tab << documentation
258 << scope_tab << (interface ? "" : "public ") << (is_static ? "static " : "") << type(true) << " " << managed_name << " {\n"
259 ).generate(sink, std::make_tuple(property, prop_type), context))
260 return false;
261
262 if (property.getter.is_engaged())
263 if (!as_generator(scope_tab << scope_tab << "get " << (interface ? ";" : "{ return Get" + managed_name + "(); }") << "\n"
264 ).generate(sink, attributes::unused, context))
265 return false;
266
267 if (property.setter.is_engaged())
268 if (!as_generator(scope_tab << scope_tab << "set " << (interface ? ";" : "{ Set" + managed_name + "(" + dir_mod + "value); }") << "\n"
269 ).generate(sink, attributes::unused, context))
270 return false;
271
272 if (!as_generator(scope_tab << "}\n").generate(sink, attributes::unused, context))
273 return false;
274
275 return true;
276 }
277} const property_wrapper_definition;
278
212} 279}
213 280
214namespace efl { namespace eolian { namespace grammar { 281namespace efl { namespace eolian { namespace grammar {
@@ -218,11 +285,15 @@ struct is_eager_generator< ::eolian_mono::function_definition_generator> : std::
218template <> 285template <>
219struct is_eager_generator< ::eolian_mono::native_function_definition_generator> : std::true_type {}; 286struct is_eager_generator< ::eolian_mono::native_function_definition_generator> : std::true_type {};
220template <> 287template <>
288struct is_eager_generator< ::eolian_mono::property_wrapper_definition_generator> : std::true_type {};
289template <>
221struct is_generator< ::eolian_mono::function_definition_generator> : std::true_type {}; 290struct is_generator< ::eolian_mono::function_definition_generator> : std::true_type {};
222template <> 291template <>
223struct is_generator< ::eolian_mono::native_function_definition_generator> : std::true_type {}; 292struct is_generator< ::eolian_mono::native_function_definition_generator> : std::true_type {};
224template <> 293template <>
225struct is_generator< ::eolian_mono::function_definition_parameterized> : std::true_type {}; 294struct is_generator< ::eolian_mono::function_definition_parameterized> : std::true_type {};
295template <>
296struct is_generator< ::eolian_mono::property_wrapper_definition_generator> : std::true_type {};
226 297
227namespace type_traits { 298namespace type_traits {
228template <> 299template <>
@@ -233,6 +304,9 @@ struct attributes_needed< ::eolian_mono::function_definition_parameterized> : st
233 304
234template <> 305template <>
235struct attributes_needed< ::eolian_mono::native_function_definition_generator> : std::integral_constant<int, 1> {}; 306struct attributes_needed< ::eolian_mono::native_function_definition_generator> : std::integral_constant<int, 1> {};
307
308template <>
309struct attributes_needed< ::eolian_mono::property_wrapper_definition_generator> : std::integral_constant<int, 1> {};
236} 310}
237 311
238} } } 312} } }