summaryrefslogtreecommitdiff
path: root/src/bin/eolian_mono/eolian/mono/klass.hh
diff options
context:
space:
mode:
authorLauro Moura <lauromoura@expertisesolutions.com.br>2019-04-23 11:48:03 +0200
committerXavi Artigas <xavierartigas@yahoo.es>2019-04-23 11:57:51 +0200
commit766e837a861e401d574d225ac8473367218788b3 (patch)
tree5e3bf56ad67583d448851a70dc73f81a1f09af89 /src/bin/eolian_mono/eolian/mono/klass.hh
parent6547d45b817fbb20333878d189c4def26cdfa819 (diff)
csharp: refactor native_inherit into a nested class.
Summary: Efl.Ui.Button_NativeInherit -> Efl.Ui.Button.NativeMethods Will help using EFL# with completion tools. * Added pragmas around the native function definitions to avoid warnings related to the name of native functions * Updated some style fixes for native function wrappers. Their preamble and epilogue styling will be dealt with in future diffs. As a side effect, concrete classes had to be made public again as they hold the function pointers to the native methods of their interfaces. Thus a third party library class that implements IFoo should be able to access these methods. Fixes T7743 Depends on D8622 Reviewers: vitor.sousa, felipealmeida, segfaultxavi Reviewed By: vitor.sousa, segfaultxavi Subscribers: cedric, #reviewers, #committers Tags: #efl Maniphest Tasks: T7743 Differential Revision: https://phab.enlightenment.org/D8645
Diffstat (limited to 'src/bin/eolian_mono/eolian/mono/klass.hh')
-rw-r--r--src/bin/eolian_mono/eolian/mono/klass.hh102
1 files changed, 66 insertions, 36 deletions
diff --git a/src/bin/eolian_mono/eolian/mono/klass.hh b/src/bin/eolian_mono/eolian/mono/klass.hh
index b4af094..c81a23f 100644
--- a/src/bin/eolian_mono/eolian/mono/klass.hh
+++ b/src/bin/eolian_mono/eolian/mono/klass.hh
@@ -88,6 +88,8 @@ struct klass
88 { 88 {
89 EINA_CXX_DOM_LOG_DBG(eolian_mono::domain) << "klass_generator: " << cls.eolian_name << std::endl; 89 EINA_CXX_DOM_LOG_DBG(eolian_mono::domain) << "klass_generator: " << cls.eolian_name << std::endl;
90 90
91 auto const& indent = current_indentation(context);
92
91 if (blacklist::is_class_blacklisted(cls, context)) 93 if (blacklist::is_class_blacklisted(cls, context))
92 { 94 {
93 EINA_CXX_DOM_LOG_DBG(eolian_mono::domain) << "class " << cls.eolian_name << " is blacklisted. Skipping." << std::endl; 95 EINA_CXX_DOM_LOG_DBG(eolian_mono::domain) << "class " << cls.eolian_name << " is blacklisted. Skipping." << std::endl;
@@ -131,7 +133,7 @@ struct klass
131 return false; 133 return false;
132 134
133 // Mark the interface with the proper native Efl_Class* getter 135 // Mark the interface with the proper native Efl_Class* getter
134 if(!as_generator(lit("[") << name_helpers::klass_native_inherit_name(cls) << "]\n") 136 if(!as_generator(lit("[") << name_helpers::klass_full_native_inherit_name(cls) << "]\n")
135 .generate(sink, attributes::unused, iface_cxt)) 137 .generate(sink, attributes::unused, iface_cxt))
136 return false; 138 return false;
137 139
@@ -209,10 +211,12 @@ struct klass
209 auto concrete_name = name_helpers::klass_concrete_name(cls); 211 auto concrete_name = name_helpers::klass_concrete_name(cls);
210 auto interface_name = name_helpers::klass_interface_name(cls); 212 auto interface_name = name_helpers::klass_interface_name(cls);
211 213
214 // We can't make these internal yet as they have methods that are used by
215 // other classes that implement the interface.
212 if(!as_generator 216 if(!as_generator
213 ( 217 (
214 documentation 218 documentation
215 << "sealed internal class " << concrete_name << " : " << "\n" 219 << "sealed public class " << concrete_name << " : " << "\n"
216 << (klass_full_concrete_or_interface_name % ",") << "\n" 220 << (klass_full_concrete_or_interface_name % ",") << "\n"
217 << (inherit_classes.size() > 0 ? ", " : "" ) << interface_name << "\n" 221 << (inherit_classes.size() > 0 ? ", " : "" ) << interface_name << "\n"
218 << scope_tab << *(", " << name_helpers::klass_full_concrete_or_interface_name) << "\n" 222 << scope_tab << *(", " << name_helpers::klass_full_concrete_or_interface_name) << "\n"
@@ -281,6 +285,8 @@ struct klass
281 ).generate(sink, attributes::unused, concrete_cxt)) 285 ).generate(sink, attributes::unused, concrete_cxt))
282 return false; 286 return false;
283 287
288 if(!generate_native_inherit_class(sink, cls, change_indentation(indent.inc(), context)))
289 return true;
284 290
285 if(!as_generator("}\n").generate(sink, attributes::unused, concrete_cxt)) return false; 291 if(!as_generator("}\n").generate(sink, attributes::unused, concrete_cxt)) return false;
286 } 292 }
@@ -296,7 +302,7 @@ struct klass
296 if(!as_generator 302 if(!as_generator
297 ( 303 (
298 documentation 304 documentation
299 << "[" << name_helpers::klass_native_inherit_name(cls) << "]\n" 305 << "[" << name_helpers::klass_full_native_inherit_name(cls) << "]\n"
300 << "public " << class_type << " " << name_helpers::klass_concrete_name(cls) << " : " 306 << "public " << class_type << " " << name_helpers::klass_concrete_name(cls) << " : "
301 << (klass_full_concrete_or_interface_name % ",") // classes 307 << (klass_full_concrete_or_interface_name % ",") // classes
302 << (inherit_classes.empty() ? "" : ",") 308 << (inherit_classes.empty() ? "" : ",")
@@ -358,11 +364,24 @@ struct klass
358 ).generate(sink, attributes::unused, inherit_cxt)) 364 ).generate(sink, attributes::unused, inherit_cxt))
359 return false; 365 return false;
360 366
367 if(!generate_native_inherit_class(sink, cls, change_indentation(indent.inc(), context)))
368 return true;
369
361 if(!as_generator("}\n").generate(sink, attributes::unused, inherit_cxt)) return false; 370 if(!as_generator("}\n").generate(sink, attributes::unused, inherit_cxt)) return false;
362 } 371 }
363 372
364 // Native Inherit class 373
365 //if(class_type == "class") 374 if(!name_helpers::close_namespaces(sink, cls.namespaces, context))
375 return false;
376
377 return true;
378 }
379
380 // NativeInherit class. Contains function pointers for the native Eo methods and delegates that are registered in Eo as virtual method implementations
381 // These delegates are called from C to C#, checking whether the C# subclass reimplemented it.
382 template <typename OutputIterator, typename Context>
383 bool generate_native_inherit_class(OutputIterator sink, attributes::klass_def const& cls, Context const& context) const
384 {
366 { 385 {
367 auto inative_cxt = context_add_tag(class_context{class_context::inherit_native, 386 auto inative_cxt = context_add_tag(class_context{class_context::inherit_native,
368 name_helpers::klass_full_concrete_or_interface_name(cls)}, 387 name_helpers::klass_full_concrete_or_interface_name(cls)},
@@ -370,6 +389,9 @@ struct klass
370 auto native_inherit_name = name_helpers::klass_native_inherit_name(cls); 389 auto native_inherit_name = name_helpers::klass_native_inherit_name(cls);
371 auto inherit_name = name_helpers::klass_inherit_name(cls); 390 auto inherit_name = name_helpers::klass_inherit_name(cls);
372 auto implementable_methods = helpers::get_all_implementable_methods(cls); 391 auto implementable_methods = helpers::get_all_implementable_methods(cls);
392 bool root = !helpers::has_regular_ancestor(cls);
393 auto const& indent = current_indentation(inative_cxt);
394
373 std::string base_name; 395 std::string base_name;
374 if(!root) 396 if(!root)
375 { 397 {
@@ -379,12 +401,28 @@ struct klass
379 401
380 if(!as_generator 402 if(!as_generator
381 ( 403 (
382 "public class " << native_inherit_name << " " << (root ? " : Efl.Eo.NativeClass" : (": " + base_name)) <<"{\n" 404 indent << lit("/// <summary>Wrapper for native methods and virtual method delegates.\n")
383 << scope_tab << "public " << (root ? "" : "new ") << " static Efl.Eo.NativeModule _Module = new Efl.Eo.NativeModule(" 405 << indent << "/// For internal use by generated code only.</summary>\n"
384 << context_find_tag<library_context>(context).actual_library_name(cls.filename) << ");\n" 406 << indent << "public " << (root ? "" : "new " ) << "class " << native_inherit_name << " " << (root ? " : Efl.Eo.NativeClass" : (": " + base_name)) <<"\n"
385 << scope_tab << "public override System.Collections.Generic.List<Efl_Op_Description> GetEoOps(System.Type type)\n" 407 << indent << "{\n"
386 << scope_tab << "{\n" 408 ).generate(sink, attributes::unused, inative_cxt))
387 << scope_tab << scope_tab << "var descs = new System.Collections.Generic.List<Efl_Op_Description>();\n" 409 return false;
410
411 if(implementable_methods.size() >= 1)
412 {
413 if(!as_generator(
414 indent << scope_tab << "private static Efl.Eo.NativeModule Module = new Efl.Eo.NativeModule("
415 << indent << context_find_tag<library_context>(context).actual_library_name(cls.filename) << ");\n"
416 ).generate(sink, attributes::unused, inative_cxt))
417 return false;
418 }
419
420 if(!as_generator(
421 indent << scope_tab << "/// <summary>Gets the list of Eo operations to override.</summary>\n"
422 << indent << scope_tab << "/// <returns>The list of Eo operations to be overload.</returns>\n"
423 << indent << scope_tab << "public override System.Collections.Generic.List<Efl_Op_Description> GetEoOps(System.Type type)\n"
424 << indent << scope_tab << "{\n"
425 << indent << scope_tab << scope_tab << "var descs = new System.Collections.Generic.List<Efl_Op_Description>();\n"
388 ) 426 )
389 .generate(sink, attributes::unused, inative_cxt)) 427 .generate(sink, attributes::unused, inative_cxt))
390 return false; 428 return false;
@@ -394,53 +432,46 @@ struct klass
394 // only non-registrable methods like class functions, leading to unused `methods` variable. 432 // only non-registrable methods like class functions, leading to unused `methods` variable.
395 std::string tmp_registration; 433 std::string tmp_registration;
396 if(!as_generator(*(function_registration(cls))) 434 if(!as_generator(*(function_registration(cls)))
397 .generate(std::back_inserter(tmp_registration), implementable_methods, inative_cxt)) 435 .generate(std::back_inserter(tmp_registration), implementable_methods, change_indentation(indent.inc(2), inative_cxt)))
398 return false; 436 return false;
399 437
400 if (tmp_registration.find("methods") != std::string::npos) 438 if (tmp_registration.find("methods") != std::string::npos)
401 if (!as_generator( 439 if (!as_generator(
402 scope_tab << scope_tab << "var methods = Efl.Eo.Globals.GetUserMethods(type);\n" 440 indent << scope_tab << scope_tab << "var methods = Efl.Eo.Globals.GetUserMethods(type);\n\n"
403 << tmp_registration 441 << tmp_registration
404 ).generate(sink, attributes::unused, inative_cxt)) 442 ).generate(sink, attributes::unused, inative_cxt))
405 return false; 443 return false;
406 444
407 if(!root) 445 if(!root)
408 if(!as_generator(scope_tab << scope_tab << "descs.AddRange(base.GetEoOps(type));\n").generate(sink, attributes::unused, inative_cxt)) 446 if(!as_generator(indent << scope_tab << scope_tab << "descs.AddRange(base.GetEoOps(type));\n").generate(sink, attributes::unused, inative_cxt))
409 return false; 447 return false;
410 448
411 if(!as_generator( 449 if(!as_generator(
412 scope_tab << scope_tab << "return descs;\n" 450 indent << scope_tab << scope_tab << "return descs;\n"
413 << scope_tab << "}\n" 451 << indent << scope_tab << "}\n"
414 ).generate(sink, attributes::unused, inative_cxt)) 452 ).generate(sink, attributes::unused, inative_cxt))
415 return false; 453 return false;
416 454
417 // Attribute getter of the native 'Efl_Class *' handle (for proper inheritance from additional explicit interfaces) 455 // Attribute getter of the native 'Efl_Class *' handle (for proper inheritance from additional explicit interfaces)
418 if(!as_generator( 456 if(!as_generator(
419 scope_tab << "public override IntPtr GetEflClass()\n" 457 indent << scope_tab << "/// <summary>Returns the Eo class for the native methods of this class.</summary>\n"
420 << scope_tab << "{\n" 458 << indent << scope_tab << "/// <returns>The native class pointer.</returns>\n"
421 << scope_tab << scope_tab << "return " << name_helpers::klass_get_full_name(cls) << "();\n" 459 << indent << scope_tab << "public override IntPtr GetEflClass()\n"
422 << scope_tab << "}\n\n" 460 << indent << scope_tab << "{\n"
423 ).generate(sink, attributes::unused, inative_cxt)) 461 << indent << scope_tab << scope_tab << "return " << name_helpers::klass_get_full_name(cls) << "();\n"
424 return false; 462 << indent << scope_tab << "}\n\n"
425
426 if(!as_generator(
427 scope_tab << "public static " << (root ? "" : "new ") << " IntPtr GetEflClassStatic()\n"
428 << scope_tab << "{\n"
429 << scope_tab << scope_tab << "return " << name_helpers::klass_get_full_name(cls) << "();\n"
430 << scope_tab << "}\n\n"
431 ).generate(sink, attributes::unused, inative_cxt)) 463 ).generate(sink, attributes::unused, inative_cxt))
432 return false; 464 return false;
433 465
434 // Native method definitions 466 // Native method definitions
435 if(!as_generator(*(native_function_definition(cls))) 467 if(!as_generator(
436 .generate(sink, implementable_methods, inative_cxt)) return false; 468 indent << scope_tab << "#pragma warning disable CA1707, SA1300, SA1600\n\n"
469 << *(native_function_definition(cls))
470 << indent << scope_tab << "#pragma warning restore CA1707, SA1300, SA1600\n\n")
471 .generate(sink, implementable_methods, change_indentation(indent.inc(), inative_cxt))) return false;
437 472
438 if(!as_generator("}\n").generate(sink, attributes::unused, inative_cxt)) return false; 473 if(!as_generator("}\n").generate(sink, attributes::unused, inative_cxt)) return false;
439 } 474 }
440
441 if(!name_helpers::close_namespaces(sink, cls.namespaces, context))
442 return false;
443
444 return true; 475 return true;
445 } 476 }
446 477
@@ -469,7 +500,7 @@ struct klass
469 << scope_tab << scope_tab << "{\n" 500 << scope_tab << scope_tab << "{\n"
470 << scope_tab << scope_tab << scope_tab << "if (((object)this).GetType() == typeof(" << inherit_name << "))\n" 501 << scope_tab << scope_tab << scope_tab << "if (((object)this).GetType() == typeof(" << inherit_name << "))\n"
471 << scope_tab << scope_tab << scope_tab << "{\n" 502 << scope_tab << scope_tab << scope_tab << "{\n"
472 << scope_tab << scope_tab << scope_tab << scope_tab << "return " << native_inherit_full_name << ".GetEflClassStatic();\n" 503 << scope_tab << scope_tab << scope_tab << scope_tab << "return GetEflClassStatic();\n"
473 << scope_tab << scope_tab << scope_tab << "}\n" 504 << scope_tab << scope_tab << scope_tab << "}\n"
474 << scope_tab << scope_tab << scope_tab << "else\n" 505 << scope_tab << scope_tab << scope_tab << "else\n"
475 << scope_tab << scope_tab << scope_tab << "{\n" 506 << scope_tab << scope_tab << scope_tab << "{\n"
@@ -513,7 +544,6 @@ struct klass
513 { 544 {
514 bool root = !helpers::has_regular_ancestor(cls); 545 bool root = !helpers::has_regular_ancestor(cls);
515 auto inherit_name = name_helpers::klass_concrete_name(cls); 546 auto inherit_name = name_helpers::klass_concrete_name(cls);
516 auto native_inherit_name = name_helpers::klass_native_inherit_name(cls);
517 547
518 if(!as_generator( 548 if(!as_generator(
519 scope_tab << "[System.Runtime.InteropServices.DllImport(" << context_find_tag<library_context>(context).actual_library_name(cls.filename) 549 scope_tab << "[System.Runtime.InteropServices.DllImport(" << context_find_tag<library_context>(context).actual_library_name(cls.filename)