summaryrefslogtreecommitdiff
path: root/src/bin/eolian_mono/eolian/mono/klass.hh
diff options
context:
space:
mode:
authorLauro Moura <lauromoura@expertisesolutions.com.br>2019-04-22 18:07:11 -0300
committerVitor Sousa <vitorsousa@expertisesolutions.com.br>2019-04-22 18:12:19 -0300
commit863c0b3272d6185f028afb83f2643ad75bcafbe5 (patch)
tree2125c742b5ea3c6906ee5fa6c64077092077c88d /src/bin/eolian_mono/eolian/mono/klass.hh
parent7681d187daf80254cadd8debb0da2d37c92cb37d (diff)
csharp: klass style changes
Summary: Warnings down to 120k Depends on D8612 Reviewers: vitor.sousa, felipealmeida, segfaultxavi Reviewed By: vitor.sousa, segfaultxavi Subscribers: cedric, #reviewers, #committers Tags: #efl_language_bindings Differential Revision: https://phab.enlightenment.org/D8614
Diffstat (limited to 'src/bin/eolian_mono/eolian/mono/klass.hh')
-rw-r--r--src/bin/eolian_mono/eolian/mono/klass.hh108
1 files changed, 69 insertions, 39 deletions
diff --git a/src/bin/eolian_mono/eolian/mono/klass.hh b/src/bin/eolian_mono/eolian/mono/klass.hh
index fd4c629..b4af094 100644
--- a/src/bin/eolian_mono/eolian/mono/klass.hh
+++ b/src/bin/eolian_mono/eolian/mono/klass.hh
@@ -35,24 +35,30 @@ template <typename OutputIterator, typename Context>
35static bool generate_equals_method(OutputIterator sink, Context const &context) 35static bool generate_equals_method(OutputIterator sink, Context const &context)
36{ 36{
37 return as_generator( 37 return as_generator(
38 scope_tab << "///<summary>Verifies if the given object is equal to this one.</summary>\n" 38 scope_tab << "/// <summary>Verifies if the given object is equal to this one.</summary>\n"
39 << scope_tab << "public override bool Equals(object obj)\n" 39 << scope_tab << "/// <param name=\"instance\">The object to compare to.</param>\n"
40 << scope_tab << "/// <returns>True if both objects point to the same native object.</returns>\n"
41 << scope_tab << "public override bool Equals(object instance)\n"
40 << scope_tab << "{\n" 42 << scope_tab << "{\n"
41 << scope_tab << scope_tab << "var other = obj as Efl.Object;\n" 43 << scope_tab << scope_tab << "var other = instance as Efl.Object;\n"
42 << scope_tab << scope_tab << "if (other == null)\n" 44 << scope_tab << scope_tab << "if (other == null)\n"
45 << scope_tab << scope_tab << "{\n"
43 << scope_tab << scope_tab << scope_tab << "return false;\n" 46 << scope_tab << scope_tab << scope_tab << "return false;\n"
47 << scope_tab << scope_tab << "}\n"
44 << scope_tab << scope_tab << "return this.NativeHandle == other.NativeHandle;\n" 48 << scope_tab << scope_tab << "return this.NativeHandle == other.NativeHandle;\n"
45 << scope_tab << "}\n" 49 << scope_tab << "}\n\n"
46 << scope_tab << "///<summary>Gets the hash code for this object based on the native pointer it points to.</summary>\n" 50 << scope_tab << "/// <summary>Gets the hash code for this object based on the native pointer it points to.</summary>\n"
51 << scope_tab << "/// <returns>The value of the pointer, to be used as the hash code of this object.</returns>\n"
47 << scope_tab << "public override int GetHashCode()\n" 52 << scope_tab << "public override int GetHashCode()\n"
48 << scope_tab << "{\n" 53 << scope_tab << "{\n"
49 << scope_tab << scope_tab << "return this.NativeHandle.ToInt32();\n" 54 << scope_tab << scope_tab << "return this.NativeHandle.ToInt32();\n"
50 << scope_tab << "}\n" 55 << scope_tab << "}\n\n"
51 << scope_tab << "///<summary>Turns the native pointer into a string representation.</summary>\n" 56 << scope_tab << "/// <summary>Turns the native pointer into a string representation.</summary>\n"
57 << scope_tab << "/// <returns>A string with the type and the native pointer for this object.</returns>\n"
52 << scope_tab << "public override String ToString()\n" 58 << scope_tab << "public override String ToString()\n"
53 << scope_tab << "{\n" 59 << scope_tab << "{\n"
54 << scope_tab << scope_tab << "return $\"{this.GetType().Name}@[{this.NativeHandle.ToInt32():x}]\";\n" 60 << scope_tab << scope_tab << "return $\"{this.GetType().Name}@[{this.NativeHandle.ToInt32():x}]\";\n"
55 << scope_tab << "}\n" 61 << scope_tab << "}\n\n"
56 ).generate(sink, nullptr, context); 62 ).generate(sink, nullptr, context);
57} 63}
58 64
@@ -223,7 +229,8 @@ struct klass
223 scope_tab << "[System.Runtime.InteropServices.DllImport(" << context_find_tag<library_context>(concrete_cxt).actual_library_name(cls.filename) 229 scope_tab << "[System.Runtime.InteropServices.DllImport(" << context_find_tag<library_context>(concrete_cxt).actual_library_name(cls.filename)
224 << ")] internal static extern System.IntPtr\n" 230 << ")] internal static extern System.IntPtr\n"
225 << scope_tab << scope_tab << name_helpers::klass_get_name(cls) << "();\n" 231 << scope_tab << scope_tab << name_helpers::klass_get_name(cls) << "();\n"
226 << scope_tab << "///<summary>Internal usage: Constructs an instance from a native pointer. This is used when interacting with C code and should not be used directly.</summary>\n" 232 << scope_tab << "/// <summary>Initializes a new instance of the <see cref=\"" << interface_name << "\"/> class.\n"
233 << scope_tab << "/// Internal usage: This is used when interacting with C code and should not be used directly.</summary>\n"
227 << scope_tab << "private " << concrete_name << "(System.IntPtr raw)" << (root ? "" : " : base(raw)") << "\n" 234 << scope_tab << "private " << concrete_name << "(System.IntPtr raw)" << (root ? "" : " : base(raw)") << "\n"
228 << scope_tab << "{\n" 235 << scope_tab << "{\n"
229 << scope_tab << scope_tab << (root ? "handle = raw;\n" : "") 236 << scope_tab << scope_tab << (root ? "handle = raw;\n" : "")
@@ -397,7 +404,6 @@ struct klass
397 ).generate(sink, attributes::unused, inative_cxt)) 404 ).generate(sink, attributes::unused, inative_cxt))
398 return false; 405 return false;
399 406
400
401 if(!root) 407 if(!root)
402 if(!as_generator(scope_tab << scope_tab << "descs.AddRange(base.GetEoOps(type));\n").generate(sink, attributes::unused, inative_cxt)) 408 if(!as_generator(scope_tab << scope_tab << "descs.AddRange(base.GetEoOps(type));\n").generate(sink, attributes::unused, inative_cxt))
403 return false; 409 return false;
@@ -413,7 +419,7 @@ struct klass
413 scope_tab << "public override IntPtr GetEflClass()\n" 419 scope_tab << "public override IntPtr GetEflClass()\n"
414 << scope_tab << "{\n" 420 << scope_tab << "{\n"
415 << scope_tab << scope_tab << "return " << name_helpers::klass_get_full_name(cls) << "();\n" 421 << scope_tab << scope_tab << "return " << name_helpers::klass_get_full_name(cls) << "();\n"
416 << scope_tab << "}\n" 422 << scope_tab << "}\n\n"
417 ).generate(sink, attributes::unused, inative_cxt)) 423 ).generate(sink, attributes::unused, inative_cxt))
418 return false; 424 return false;
419 425
@@ -421,7 +427,7 @@ struct klass
421 scope_tab << "public static " << (root ? "" : "new ") << " IntPtr GetEflClassStatic()\n" 427 scope_tab << "public static " << (root ? "" : "new ") << " IntPtr GetEflClassStatic()\n"
422 << scope_tab << "{\n" 428 << scope_tab << "{\n"
423 << scope_tab << scope_tab << "return " << name_helpers::klass_get_full_name(cls) << "();\n" 429 << scope_tab << scope_tab << "return " << name_helpers::klass_get_full_name(cls) << "();\n"
424 << scope_tab << "}\n" 430 << scope_tab << "}\n\n"
425 ).generate(sink, attributes::unused, inative_cxt)) 431 ).generate(sink, attributes::unused, inative_cxt))
426 return false; 432 return false;
427 433
@@ -457,14 +463,20 @@ struct klass
457 463
458 if(!as_generator( 464 if(!as_generator(
459 scope_tab << "///<summary>Pointer to the native class description.</summary>\n" 465 scope_tab << "///<summary>Pointer to the native class description.</summary>\n"
460 << scope_tab << "public " << raw_klass_modifier << "System.IntPtr NativeClass {\n" 466 << scope_tab << "public " << raw_klass_modifier << "System.IntPtr NativeClass\n"
461 << scope_tab << scope_tab << "get {\n" 467 << scope_tab << "{\n"
462 << scope_tab << scope_tab << scope_tab << "if (((object)this).GetType() == typeof (" << inherit_name << "))\n" 468 << scope_tab << scope_tab << "get\n"
469 << scope_tab << scope_tab << "{\n"
470 << scope_tab << scope_tab << scope_tab << "if (((object)this).GetType() == typeof(" << inherit_name << "))\n"
471 << scope_tab << scope_tab << scope_tab << "{\n"
463 << scope_tab << scope_tab << scope_tab << scope_tab << "return " << native_inherit_full_name << ".GetEflClassStatic();\n" 472 << scope_tab << scope_tab << scope_tab << scope_tab << "return " << native_inherit_full_name << ".GetEflClassStatic();\n"
473 << scope_tab << scope_tab << scope_tab << "}\n"
464 << scope_tab << scope_tab << scope_tab << "else\n" 474 << scope_tab << scope_tab << scope_tab << "else\n"
475 << scope_tab << scope_tab << scope_tab << "{\n"
465 << scope_tab << scope_tab << scope_tab << scope_tab << "return Efl.Eo.ClassRegister.klassFromType[((object)this).GetType()];\n" 476 << scope_tab << scope_tab << scope_tab << scope_tab << "return Efl.Eo.ClassRegister.klassFromType[((object)this).GetType()];\n"
477 << scope_tab << scope_tab << scope_tab << "}\n"
466 << scope_tab << scope_tab << "}\n" 478 << scope_tab << scope_tab << "}\n"
467 << scope_tab << "}\n" 479 << scope_tab << "}\n\n"
468 ).generate(sink, attributes::unused, context)) 480 ).generate(sink, attributes::unused, context))
469 return false; 481 return false;
470 482
@@ -489,9 +501,10 @@ struct klass
489 return as_generator( 501 return as_generator(
490 scope_tab << visibility << " System.IntPtr handle;\n" 502 scope_tab << visibility << " System.IntPtr handle;\n"
491 << scope_tab << "///<summary>Pointer to the native instance.</summary>\n" 503 << scope_tab << "///<summary>Pointer to the native instance.</summary>\n"
492 << scope_tab << "public System.IntPtr NativeHandle {\n" 504 << scope_tab << "public System.IntPtr NativeHandle\n"
505 << scope_tab << "{\n"
493 << scope_tab << scope_tab << "get { return handle; }\n" 506 << scope_tab << scope_tab << "get { return handle; }\n"
494 << scope_tab << "}\n" 507 << scope_tab << "}\n\n"
495 ).generate(sink, attributes::unused, context); 508 ).generate(sink, attributes::unused, context);
496 } 509 }
497 510
@@ -518,22 +531,24 @@ struct klass
518 531
519 // Public (API) constructors 532 // Public (API) constructors
520 if (!as_generator( 533 if (!as_generator(
521 scope_tab << "///<summary>Creates a new instance.</summary>\n" 534 scope_tab << "/// <summary>Initializes a new instance of the <see cref=\"" << inherit_name << "\"/> class.</summary>\n"
522 << scope_tab << "///<param name=\"parent\">Parent instance.</param>\n" 535 << scope_tab << "/// <param name=\"parent\">Parent instance.</param>\n"
523 << *(documentation) 536 << *(documentation)
524 // For constructors with arguments, the parent is also required, as optional parameters can't come before non-optional paramenters. 537 // For constructors with arguments, the parent is also required, as optional parameters can't come before non-optional paramenters.
525 << scope_tab << "public " << inherit_name << "(Efl.Object parent" << ((constructors.size() > 0) ? "" : "= null") << "\n" 538 << scope_tab << "public " << inherit_name << "(Efl.Object parent" << ((constructors.size() > 0) ? "" : "= null") << "\n"
526 << scope_tab << scope_tab << scope_tab << *(", " << constructor_param ) << ") :\n" 539 << scope_tab << scope_tab << scope_tab << *(", " << constructor_param ) << ") : "
527 << scope_tab << scope_tab << (root ? "this" : "base") << "(" << name_helpers::klass_get_name(cls) << "(), typeof(" << inherit_name << "), parent)\n" 540 << (root ? "this" : "base") << "(" << name_helpers::klass_get_name(cls) << "(), typeof(" << inherit_name << "), parent)\n"
528 << scope_tab << "{\n" 541 << scope_tab << "{\n"
529 << *(scope_tab << scope_tab << constructor_invocation << "\n" ) 542 << (*(scope_tab << scope_tab << constructor_invocation << "\n"))
530 << scope_tab << scope_tab << "FinishInstantiation();\n" 543 << scope_tab << scope_tab << "FinishInstantiation();\n"
531 << scope_tab << "}\n" 544 << scope_tab << "}\n\n"
532 << scope_tab << "///<summary>Internal usage: Constructs an instance from a native pointer. This is used when interacting with C code and should not be used directly.</summary>\n" 545 << scope_tab << "/// <summary>Initializes a new instance of the <see cref=\"" << inherit_name << "\"/> class.\n"
546 << scope_tab << "/// Internal usage: Constructs an instance from a native pointer. This is used when interacting with C code and should not be used directly.</summary>\n"
547 << scope_tab << "/// <param name=\"raw\">The native pointer to be wrapped.</param>\n"
533 << scope_tab << "protected " << inherit_name << "(System.IntPtr raw)" << (root ? "" : " : base(raw)") << "\n" 548 << scope_tab << "protected " << inherit_name << "(System.IntPtr raw)" << (root ? "" : " : base(raw)") << "\n"
534 << scope_tab << "{\n" 549 << scope_tab << "{\n"
535 << scope_tab << scope_tab << (root ? "handle = raw;\n" : "") 550 << scope_tab << scope_tab << (root ? "handle = raw;\n" : "")
536 << scope_tab << "}\n" 551 << scope_tab << "}\n\n"
537 ).generate(sink, std::make_tuple(constructors, constructors, constructors), context)) 552 ).generate(sink, std::make_tuple(constructors, constructors, constructors), context))
538 return false; 553 return false;
539 554
@@ -558,8 +573,14 @@ struct klass
558 if (!root) 573 if (!root)
559 { 574 {
560 return as_generator( 575 return as_generator(
561 scope_tab << "///<summary>Internal usage: Constructor to forward the wrapper initialization to the root class that interfaces with native code. Should not be used directly.</summary>\n" 576 scope_tab << "/// <summary>Initializes a new instance of the <see cref=\"" << inherit_name << "\"/> class.\n"
562 << scope_tab << "protected " << inherit_name << "(IntPtr base_klass, System.Type managed_type, Efl.Object parent) : base(base_klass, managed_type, parent) {}\n" 577 << scope_tab << "/// Internal usage: Constructor to forward the wrapper initialization to the root class that interfaces with native code. Should not be used directly.</summary>\n"
578 << scope_tab << "/// <param name=\"baseKlass\">The pointer to the base native Eo class.</param>\n"
579 << scope_tab << "/// <param name=\"managedType\">The managed type of the public constructor that originated this call.</param>\n"
580 << scope_tab << "/// <param name=\"parent\">The Efl.Object parent of this instance.</param>\n"
581 << scope_tab << "protected " << inherit_name << "(IntPtr baseKlass, System.Type managedType, Efl.Object parent) : base(baseKlass, managedType, parent)\n"
582 << scope_tab << "{\n"
583 << scope_tab << "}\n\n"
563 ).generate(sink, attributes::unused, context); 584 ).generate(sink, attributes::unused, context);
564 585
565 } 586 }
@@ -567,25 +588,34 @@ struct klass
567 // Detailed constructors go only in root classes. 588 // Detailed constructors go only in root classes.
568 return as_generator( 589 return as_generator(
569 /// Actual root costructor that creates class and instantiates 590 /// Actual root costructor that creates class and instantiates
570 scope_tab << "protected " << inherit_name << "(IntPtr base_klass, System.Type managed_type, Efl.Object parent)\n" 591 scope_tab << "/// <summary>Initializes a new instance of the <see cref=\"" << inherit_name << "\"/> class.\n"
592 << scope_tab << "/// Internal usage: Constructor to actually call the native library constructors. C# subclasses\n"
593 << scope_tab << "/// must use the public constructor only.</summary>\n"
594 << scope_tab << "/// <param name=\"baseKlass\">The pointer to the base native Eo class.</param>\n"
595 << scope_tab << "/// <param name=\"managedType\">The managed type of the public constructor that originated this call.</param>\n"
596 << scope_tab << "/// <param name=\"parent\">The Efl.Object parent of this instance.</param>\n"
597 << scope_tab << "protected " << inherit_name << "(IntPtr baseKlass, System.Type managedType, Efl.Object parent)\n"
571 << scope_tab << "{\n" 598 << scope_tab << "{\n"
572 << scope_tab << scope_tab << "inherited = ((object)this).GetType() != managed_type;\n" 599 << scope_tab << scope_tab << "inherited = ((object)this).GetType() != managedType;\n"
573 << scope_tab << scope_tab << "IntPtr actual_klass = base_klass;\n" 600 << scope_tab << scope_tab << "IntPtr actual_klass = baseKlass;\n"
574 << scope_tab << scope_tab << "if (inherited) {\n" 601 << scope_tab << scope_tab << "if (inherited)\n"
575 << scope_tab << scope_tab << scope_tab << "actual_klass = Efl.Eo.ClassRegister.GetInheritKlassOrRegister(base_klass, ((object)this).GetType());\n" 602 << scope_tab << scope_tab << "{\n"
576 << scope_tab << scope_tab << "}\n" 603 << scope_tab << scope_tab << scope_tab << "actual_klass = Efl.Eo.ClassRegister.GetInheritKlassOrRegister(baseKlass, ((object)this).GetType());\n"
604 << scope_tab << scope_tab << "}\n\n"
577 << scope_tab << scope_tab << "handle = Efl.Eo.Globals.instantiate_start(actual_klass, parent);\n" 605 << scope_tab << scope_tab << "handle = Efl.Eo.Globals.instantiate_start(actual_klass, parent);\n"
578 << scope_tab << scope_tab << "if (inherited)\n" 606 << scope_tab << scope_tab << "if (inherited)\n"
579 << scope_tab << scope_tab << "{\n" 607 << scope_tab << scope_tab << "{\n"
580 << scope_tab << scope_tab << scope_tab << "Efl.Eo.Globals.PrivateDataSet(this);\n" 608 << scope_tab << scope_tab << scope_tab << "Efl.Eo.Globals.PrivateDataSet(this);\n"
581 << scope_tab << scope_tab << "}\n" 609 << scope_tab << scope_tab << "}\n"
582 << scope_tab << "}\n" 610 << scope_tab << "}\n\n"
583 611
612 << scope_tab << "/// <summary>Finishes instantiating this object.\n"
613 << scope_tab << "/// Internal usage by generated code.</summary>\n"
584 << scope_tab << "protected void FinishInstantiation()\n" 614 << scope_tab << "protected void FinishInstantiation()\n"
585 << scope_tab << "{\n" 615 << scope_tab << "{\n"
586 << scope_tab << scope_tab << "handle = Efl.Eo.Globals.instantiate_end(handle);\n" 616 << scope_tab << scope_tab << "handle = Efl.Eo.Globals.instantiate_end(handle);\n"
587 << scope_tab << scope_tab << "Eina.Error.RaiseIfUnhandledException();\n" 617 << scope_tab << scope_tab << "Eina.Error.RaiseIfUnhandledException();\n"
588 << scope_tab << "}\n" 618 << scope_tab << "}\n\n"
589 619
590 ).generate(sink, attributes::unused, context); 620 ).generate(sink, attributes::unused, context);
591 } 621 }
@@ -597,7 +627,7 @@ struct klass
597 if (helpers::has_regular_ancestor(cls)) 627 if (helpers::has_regular_ancestor(cls))
598 return true; 628 return true;
599 629
600 std::string visibility = is_inherit_context(context) ? "protected virtual " : ""; 630 std::string visibility = is_inherit_context(context) ? "protected virtual " : "private ";
601 631
602 auto inherit_name = name_helpers::klass_concrete_name(cls); 632 auto inherit_name = name_helpers::klass_concrete_name(cls);
603 633
@@ -647,7 +677,7 @@ struct klass
647 << scope_tab << scope_tab << scope_tab << scope_tab << "}\n\n" 677 << scope_tab << scope_tab << scope_tab << scope_tab << "}\n\n"
648 << scope_tab << scope_tab << scope_tab << scope_tab << "Monitor.Exit(Efl.All.InitLock);\n" 678 << scope_tab << scope_tab << scope_tab << scope_tab << "Monitor.Exit(Efl.All.InitLock);\n"
649 << scope_tab << scope_tab << scope_tab << "}\n" 679 << scope_tab << scope_tab << scope_tab << "}\n"
650 << scope_tab << scope_tab << "}\n" 680 << scope_tab << scope_tab << "}\n\n"
651 << scope_tab << "}\n\n" 681 << scope_tab << "}\n\n"
652 682
653 << scope_tab << "///<summary>Releases the underlying native instance.</summary>\n" 683 << scope_tab << "///<summary>Releases the underlying native instance.</summary>\n"
@@ -734,7 +764,7 @@ struct klass
734 << scope_tab << scope_tab << "{\n" 764 << scope_tab << scope_tab << "{\n"
735 << scope_tab << scope_tab << scope_tab << "Eina.Log.Error($\"Trying to remove proxy for event {key} when it is nothing registered.\");\n" 765 << scope_tab << scope_tab << scope_tab << "Eina.Log.Error($\"Trying to remove proxy for event {key} when it is nothing registered.\");\n"
736 << scope_tab << scope_tab << "}\n" 766 << scope_tab << scope_tab << "}\n"
737 << scope_tab << "}\n" 767 << scope_tab << "}\n\n"
738 ) 768 )
739 .generate(sink, NULL, context)) 769 .generate(sink, NULL, context))
740 return false; 770 return false;