summaryrefslogtreecommitdiff
path: root/src/bin
diff options
context:
space:
mode:
authorYeongjong Lee <yj34.lee@samsung.com>2020-01-23 07:30:13 +0900
committerWooHyun Jung <wh0705.jung@samsung.com>2020-01-23 07:30:14 +0900
commit97098dcc50b62e51dad3469619ed55242ca01a80 (patch)
tree33d372fef1f883a12f4172ceb9ab07223ca28805 /src/bin
parent5137f6d143c681fcf4f53e4e45df8af1a538ae75 (diff)
csharp: cleanup concrete class
Summary: Concrete class is only used to call static member of NativeMethod. they don't need any inheritance and implementation of c functions. Depends on D9893 Test Plan: ninja test Reviewers: lauromoura, felipealmeida Subscribers: Jaehyun_Cho, woohyun, segfaultxavi, cedric, #reviewers, #committers Tags: #efl Differential Revision: https://phab.enlightenment.org/D9894
Diffstat (limited to 'src/bin')
-rw-r--r--src/bin/eolian_mono/eolian/mono/events.hh2
-rw-r--r--src/bin/eolian_mono/eolian/mono/klass.hh108
-rw-r--r--src/bin/eolian_mono/eolian/mono/name_helpers.hh17
-rw-r--r--src/bin/eolian_mono/eolian/mono/struct_definition.hh3
4 files changed, 30 insertions, 100 deletions
diff --git a/src/bin/eolian_mono/eolian/mono/events.hh b/src/bin/eolian_mono/eolian/mono/events.hh
index 7405f8c..b6cb4aa 100644
--- a/src/bin/eolian_mono/eolian/mono/events.hh
+++ b/src/bin/eolian_mono/eolian/mono/events.hh
@@ -131,7 +131,7 @@ struct unpack_event_args_visitor
131 } 131 }
132 bool operator()(grammar::attributes::klass_name const& cls) const 132 bool operator()(grammar::attributes::klass_name const& cls) const
133 { 133 {
134 return as_generator("(Efl.Eo.Globals.CreateWrapperFor(info) as " + name_helpers::klass_full_concrete_name(cls) + ")").generate(sink, attributes::unused, *context); 134 return as_generator("(Efl.Eo.Globals.CreateWrapperFor(info) as " + name_helpers::klass_full_interface_name(cls) + ")").generate(sink, attributes::unused, *context);
135 } 135 }
136 bool operator()(attributes::complex_type_def const& types) const 136 bool operator()(attributes::complex_type_def const& types) const
137 { 137 {
diff --git a/src/bin/eolian_mono/eolian/mono/klass.hh b/src/bin/eolian_mono/eolian/mono/klass.hh
index 072ea6c..da6fd6d 100644
--- a/src/bin/eolian_mono/eolian/mono/klass.hh
+++ b/src/bin/eolian_mono/eolian/mono/klass.hh
@@ -193,98 +193,9 @@ struct klass
193 auto concrete_cxt = context_add_tag(class_context{class_context::concrete, 193 auto concrete_cxt = context_add_tag(class_context{class_context::concrete,
194 name_helpers::klass_full_concrete_or_interface_name(cls)}, 194 name_helpers::klass_full_concrete_or_interface_name(cls)},
195 context); 195 context);
196 auto concrete_name = name_helpers::klass_concrete_name(cls);
197 auto interface_name = name_helpers::klass_interface_name(cls);
198 196
199 // We can't make these internal yet as they have methods that are used by 197 if(!generate_native_inherit_class(sink, cls, change_indentation(indent, concrete_cxt)))
200 // other classes that implement the interface.
201 if(!as_generator
202 (
203 documentation(1)
204 << scope_tab << "public sealed " << (is_partial ? "partial ":"") << "class " << concrete_name << " :\n"
205 << scope_tab(2) << (root ? "Efl.Eo.EoWrapper" : "") << (klass_full_concrete_or_interface_name % "")
206 << ",\n" << scope_tab(2) << interface_name
207 << *(",\n" << scope_tab(2) << name_helpers::klass_full_concrete_or_interface_name) << "\n"
208 << scope_tab << "{\n"
209 ).generate(sink, std::make_tuple(cls, inherit_classes, inherit_interfaces), concrete_cxt))
210 return false;
211
212 if (!generate_fields(sink, cls, concrete_cxt))
213 return false;
214
215 if (!as_generator
216 (
217 scope_tab(2) << "/// <summary>Subclasses should override this constructor if they are expected to be instantiated from native code.\n"
218 << scope_tab(2) << "/// Do not call this constructor directly.</summary>\n"
219 << scope_tab(2) << "/// <param name=\"ch\">Tag struct storing the native handle of the object being constructed.</param>\n"
220 << scope_tab(2) << "private " << concrete_name << "(ConstructingHandle ch) : base(ch)\n"
221 << scope_tab(2) << "{\n"
222 << scope_tab(2) << "}\n\n"
223 )
224 .generate(sink, attributes::unused, concrete_cxt))
225 return false;
226
227 if (!as_generator
228 (
229 scope_tab(2) << "[System.Runtime.InteropServices.DllImport(" << context_find_tag<library_context>(concrete_cxt).actual_library_name(cls.filename)
230 << ")] internal static extern System.IntPtr\n"
231 << scope_tab(2) << scope_tab << name_helpers::klass_get_name(cls) << "();\n\n"
232 << scope_tab(2) << "/// <summary>Initializes a new instance of the <see cref=\"" << interface_name << "\"/> class.\n"
233 << scope_tab(2) << "/// Internal usage: This is used when interacting with C code and should not be used directly.</summary>\n"
234 << scope_tab(2) << "/// <param name=\"wh\">The native pointer to be wrapped.</param>\n"
235 << scope_tab(2) << "private " << concrete_name << "(Efl.Eo.WrappingHandle wh) : base(wh)\n"
236 << scope_tab(2) << "{\n"
237 << scope_tab(2) << "}\n\n"
238 )
239 .generate(sink, attributes::unused, concrete_cxt))
240 return false;
241
242 if (!generate_events(sink, cls, concrete_cxt))
243 return false;
244
245 if (!as_generator(lit("#pragma warning disable CS0628\n")).generate(sink, attributes::unused, concrete_cxt))
246 return false;
247
248 // Parts
249 if(!as_generator(*(part_definition))
250 .generate(sink, cls.parts, concrete_cxt)) return false;
251
252 // Concrete function definitions
253 auto implemented_methods = helpers::get_all_implementable_methods(cls, concrete_cxt);
254 if(!as_generator(*(function_definition))
255 .generate(sink, implemented_methods, concrete_cxt)) return false;
256
257 // Async wrappers
258 if(!as_generator(*(async_function_definition)).generate(sink, implemented_methods, concrete_cxt))
259 return false;
260
261 // Property wrappers
262 if (!as_generator(*(property_wrapper_definition(cls))).generate(sink, cls.properties, concrete_cxt))
263 return false;
264
265 for (auto&& klass : helpers::non_implemented_interfaces(cls, concrete_cxt))
266 {
267 attributes::klass_def c(get_klass(klass, cls.unit), cls.unit);
268 if (!as_generator(*(property_wrapper_definition(cls))).generate(sink, c.properties, concrete_cxt))
269 return false;
270 }
271
272 if (!as_generator(lit("#pragma warning restore CS0628\n")).generate(sink, attributes::unused, concrete_cxt))
273 return false;
274
275 // Copied from nativeinherit class, used when setting up providers.
276 if(!as_generator(
277 scope_tab(2) << "private static IntPtr GetEflClassStatic()\n"
278 << scope_tab(2) << "{\n"
279 << scope_tab(2) << scope_tab << "return " << name_helpers::klass_get_full_name(cls) << "();\n"
280 << scope_tab(2) << "}\n\n"
281 ).generate(sink, attributes::unused, concrete_cxt))
282 return false;
283
284 if(!generate_native_inherit_class(sink, cls, change_indentation(indent.inc(), concrete_cxt)))
285 return true; 198 return true;
286
287 if(!as_generator(scope_tab << "}\n").generate(sink, attributes::unused, concrete_cxt)) return false;
288 } 199 }
289 200
290 // Inheritable class 201 // Inheritable class
@@ -427,6 +338,7 @@ struct klass
427 auto inherit_name = name_helpers::klass_inherit_name(cls); 338 auto inherit_name = name_helpers::klass_inherit_name(cls);
428 auto implementable_methods = helpers::get_all_registerable_methods(cls, context); 339 auto implementable_methods = helpers::get_all_registerable_methods(cls, context);
429 bool root = !helpers::has_regular_ancestor(cls); 340 bool root = !helpers::has_regular_ancestor(cls);
341 bool is_concrete = context_find_tag<class_context>(context).current_wrapper_kind == class_context::concrete;
430 auto const& indent = current_indentation(inative_cxt).inc(); 342 auto const& indent = current_indentation(inative_cxt).inc();
431 std::string klass_since; 343 std::string klass_since;
432 344
@@ -447,11 +359,23 @@ struct klass
447 << klass_since 359 << klass_since
448 << indent << "/// </summary>\n" 360 << indent << "/// </summary>\n"
449 << indent << "[EditorBrowsable(EditorBrowsableState.Never)]\n" 361 << indent << "[EditorBrowsable(EditorBrowsableState.Never)]\n"
450 << indent << "internal new class " << native_inherit_name << " : " << (root ? "Efl.Eo.EoWrapper.NativeMethods" : base_name) << "\n" 362 << indent << "internal " << (is_concrete ? "" : "new ") << "class " << native_inherit_name << " : " << (root ? "Efl.Eo.EoWrapper.NativeMethods" : base_name) << "\n"
451 << indent << "{\n" 363 << indent << "{\n"
452 ).generate(sink, attributes::unused, inative_cxt)) 364 ).generate(sink, attributes::unused, inative_cxt))
453 return false; 365 return false;
454 366
367 if(is_concrete)
368 {
369 if (!as_generator
370 (
371 scope_tab(2) << "[System.Runtime.InteropServices.DllImport(" << context_find_tag<library_context>(context).actual_library_name(cls.filename)
372 << ")] internal static extern System.IntPtr\n"
373 << scope_tab(2) << scope_tab << name_helpers::klass_get_name(cls) << "();\n"
374 )
375 .generate(sink, attributes::unused, inative_cxt))
376 return false;
377 }
378
455 if(implementable_methods.size() >= 1) 379 if(implementable_methods.size() >= 1)
456 { 380 {
457 if(!as_generator( 381 if(!as_generator(
@@ -502,7 +426,7 @@ struct klass
502 ).generate(sink, attributes::unused, inative_cxt)) 426 ).generate(sink, attributes::unused, inative_cxt))
503 return false; 427 return false;
504 428
505 if (!root || context_find_tag<class_context>(context).current_wrapper_kind != class_context::concrete) 429 if (!root || !is_concrete)
506 if(!as_generator(indent << scope_tab << scope_tab << "descs.AddRange(base.GetEoOps(type, false));\n").generate(sink, attributes::unused, inative_cxt)) 430 if(!as_generator(indent << scope_tab << scope_tab << "descs.AddRange(base.GetEoOps(type, false));\n").generate(sink, attributes::unused, inative_cxt))
507 return false; 431 return false;
508 432
diff --git a/src/bin/eolian_mono/eolian/mono/name_helpers.hh b/src/bin/eolian_mono/eolian/mono/name_helpers.hh
index 7f71d92..ae958ba 100644
--- a/src/bin/eolian_mono/eolian/mono/name_helpers.hh
+++ b/src/bin/eolian_mono/eolian/mono/name_helpers.hh
@@ -399,9 +399,7 @@ struct klass_full_interface_name_generator
399template<typename T> 399template<typename T>
400inline std::string klass_concrete_name(T const& klass) 400inline std::string klass_concrete_name(T const& klass)
401{ 401{
402 return utils::remove_all(klass.eolian_name, '_') + ((klass.type == attributes::class_type::mixin 402 return utils::remove_all(klass.eolian_name, '_');
403 || klass.type == attributes::class_type::interface_)
404 ? "Concrete" : "");
405} 403}
406 404
407template<typename T> 405template<typename T>
@@ -467,14 +465,19 @@ inline std::string klass_inherit_name(T const& klass)
467} 465}
468 466
469template<typename T> 467template<typename T>
470inline std::string klass_native_inherit_name(EINA_UNUSED T const& klass) 468inline std::string klass_native_inherit_name(T const& klass)
471{ 469{
472 return "NativeMethods"; 470 return ((klass.type == attributes::class_type::mixin
471 || klass.type == attributes::class_type::interface_) ? klass_interface_name(klass) : "") + "NativeMethods";
473} 472}
474 473
475template<typename T> 474template<typename T>
476inline std::string klass_full_native_inherit_name(T const& klass) 475inline std::string klass_full_native_inherit_name(T const& klass)
477{ 476{
477 if(klass.type == attributes::class_type::mixin
478 || klass.type == attributes::class_type::interface_)
479 return join_namespaces(klass.namespaces, '.', managed_namespace) + klass_native_inherit_name(klass);
480
478 return klass_full_concrete_name(klass) + "." + klass_native_inherit_name(klass); 481 return klass_full_concrete_name(klass) + "." + klass_native_inherit_name(klass);
479} 482}
480 483
@@ -487,6 +490,10 @@ inline std::string klass_get_name(T const& clsname)
487template<typename T> 490template<typename T>
488inline std::string klass_get_full_name(T const& clsname) 491inline std::string klass_get_full_name(T const& clsname)
489{ 492{
493 if(clsname.type == attributes::class_type::mixin
494 || clsname.type == attributes::class_type::interface_)
495 return klass_get_name(clsname);
496
490 return klass_full_concrete_name(clsname) + "." + klass_get_name(clsname); 497 return klass_full_concrete_name(clsname) + "." + klass_get_name(clsname);
491} 498}
492 499
diff --git a/src/bin/eolian_mono/eolian/mono/struct_definition.hh b/src/bin/eolian_mono/eolian/mono/struct_definition.hh
index 176b551..1f4152a 100644
--- a/src/bin/eolian_mono/eolian/mono/struct_definition.hh
+++ b/src/bin/eolian_mono/eolian/mono/struct_definition.hh
@@ -190,11 +190,10 @@ struct to_external_field_convert_generator
190 if (klass) 190 if (klass)
191 { 191 {
192 auto interface_name = name_helpers::klass_full_interface_name(*klass); 192 auto interface_name = name_helpers::klass_full_interface_name(*klass);
193 auto concrete_name = name_helpers::klass_full_concrete_name(*klass);
194 if (!as_generator( 193 if (!as_generator(
195 "\n" 194 "\n"
196 << indent << scope_tab << scope_tab << "_external_struct." << string 195 << indent << scope_tab << scope_tab << "_external_struct." << string
197 << " = (" << concrete_name << ") Efl.Eo.Globals.CreateWrapperFor(_internal_struct." << string << ");\n" 196 << " = (" << interface_name << ") Efl.Eo.Globals.CreateWrapperFor(_internal_struct." << string << ");\n"
198 ).generate(sink, std::make_tuple(field_name, field_name), context)) 197 ).generate(sink, std::make_tuple(field_name, field_name), context))
199 return false; 198 return false;
200 } 199 }