summaryrefslogtreecommitdiff
path: root/src/bin/eolian_mono/eolian/mono/klass.hh
diff options
context:
space:
mode:
authorVitor Sousa <vitorsousa@expertisesolutions.com.br>2019-06-28 10:29:01 -0300
committerVitor Sousa <vitorsousa@expertisesolutions.com.br>2019-06-28 10:38:57 -0300
commitb7fa7d48ac9eff4b360e83de4d974a92c84c0291 (patch)
tree91c1ed776686af99a4fb19d816a4f4e5548f84ea /src/bin/eolian_mono/eolian/mono/klass.hh
parent549c417853f8f934a8fe63cd0c0cb2d4e8e9ff01 (diff)
csharp: make inherited C# classes constructible from native C
Summary: With this commit it is now possible for a class that inherits from a C# binding class to be instantiated from native C code. It only has to provide a constructor that receives an `Efl.Eo.EoWrapper.ConstructingHandle` struct, and which calls the base binding constructor passing it. For example: `private Type(ConstructingHandle ch) : base(ch) {}`. Add some test files to validate the proper behavior of this feature. Add some small fixes in generation contexts in order to properly generate base constructors. Depends on D9070 Test Plan: `meson test` and `make check` Reviewers: lauromoura, felipealmeida, segfaultxavi, woohyun, YOhoho Reviewed By: YOhoho Subscribers: YOhoho, cedric, #reviewers, #committers Tags: #efl Differential Revision: https://phab.enlightenment.org/D9071
Diffstat (limited to 'src/bin/eolian_mono/eolian/mono/klass.hh')
-rw-r--r--src/bin/eolian_mono/eolian/mono/klass.hh24
1 files changed, 20 insertions, 4 deletions
diff --git a/src/bin/eolian_mono/eolian/mono/klass.hh b/src/bin/eolian_mono/eolian/mono/klass.hh
index 6ac4aa1..8b018f6 100644
--- a/src/bin/eolian_mono/eolian/mono/klass.hh
+++ b/src/bin/eolian_mono/eolian/mono/klass.hh
@@ -198,6 +198,17 @@ struct klass
198 198
199 if (!as_generator 199 if (!as_generator
200 ( 200 (
201 scope_tab << "/// <summary>Constructor to be used when objects are expected to be constructed from native code.</summary>\n"
202 << scope_tab << "/// <param name=\"ch\">Tag struct storing the native handle of the object being constructed.</param>\n"
203 << scope_tab << "private " << concrete_name << "(ConstructingHandle ch) : base(ch)\n"
204 << scope_tab << "{\n"
205 << scope_tab << "}\n\n"
206 )
207 .generate(sink, attributes::unused, concrete_cxt))
208 return false;
209
210 if (!as_generator
211 (
201 scope_tab << "[System.Runtime.InteropServices.DllImport(" << context_find_tag<library_context>(concrete_cxt).actual_library_name(cls.filename) 212 scope_tab << "[System.Runtime.InteropServices.DllImport(" << context_find_tag<library_context>(concrete_cxt).actual_library_name(cls.filename)
202 << ")] internal static extern System.IntPtr\n" 213 << ")] internal static extern System.IntPtr\n"
203 << scope_tab << scope_tab << name_helpers::klass_get_name(cls) << "();\n" 214 << scope_tab << scope_tab << name_helpers::klass_get_name(cls) << "();\n"
@@ -246,7 +257,7 @@ struct klass
246 ).generate(sink, attributes::unused, concrete_cxt)) 257 ).generate(sink, attributes::unused, concrete_cxt))
247 return false; 258 return false;
248 259
249 if(!generate_native_inherit_class(sink, cls, change_indentation(indent.inc(), context))) 260 if(!generate_native_inherit_class(sink, cls, change_indentation(indent.inc(), concrete_cxt)))
250 return true; 261 return true;
251 262
252 if(!as_generator("}\n").generate(sink, attributes::unused, concrete_cxt)) return false; 263 if(!as_generator("}\n").generate(sink, attributes::unused, concrete_cxt)) return false;
@@ -318,7 +329,7 @@ struct klass
318 ).generate(sink, attributes::unused, inherit_cxt)) 329 ).generate(sink, attributes::unused, inherit_cxt))
319 return false; 330 return false;
320 331
321 if(!generate_native_inherit_class(sink, cls, change_indentation(indent.inc(), context))) 332 if(!generate_native_inherit_class(sink, cls, change_indentation(indent.inc(), inherit_cxt)))
322 return true; 333 return true;
323 334
324 if(!as_generator("}\n").generate(sink, attributes::unused, inherit_cxt)) return false; 335 if(!as_generator("}\n").generate(sink, attributes::unused, inherit_cxt)) return false;
@@ -357,7 +368,7 @@ struct klass
357 ( 368 (
358 indent << lit("/// <summary>Wrapper for native methods and virtual method delegates.\n") 369 indent << lit("/// <summary>Wrapper for native methods and virtual method delegates.\n")
359 << indent << "/// For internal use by generated code only.</summary>\n" 370 << indent << "/// For internal use by generated code only.</summary>\n"
360 << indent << "public " << (root ? "" : "new " ) << "class " << native_inherit_name << " " << (root ? " : Efl.Eo.NativeClass" : (": " + base_name)) <<"\n" 371 << indent << "public new class " << native_inherit_name << " : " << (root ? "Efl.Eo.EoWrapper.NativeMethods" : base_name) << "\n"
361 << indent << "{\n" 372 << indent << "{\n"
362 ).generate(sink, attributes::unused, inative_cxt)) 373 ).generate(sink, attributes::unused, inative_cxt))
363 return false; 374 return false;
@@ -396,7 +407,7 @@ struct klass
396 ).generate(sink, attributes::unused, inative_cxt)) 407 ).generate(sink, attributes::unused, inative_cxt))
397 return false; 408 return false;
398 409
399 if(!root) 410 if (!root || context_find_tag<class_context>(context).current_wrapper_kind != class_context::concrete)
400 if(!as_generator(indent << scope_tab << scope_tab << "descs.AddRange(base.GetEoOps(type));\n").generate(sink, attributes::unused, inative_cxt)) 411 if(!as_generator(indent << scope_tab << scope_tab << "descs.AddRange(base.GetEoOps(type));\n").generate(sink, attributes::unused, inative_cxt))
401 return false; 412 return false;
402 413
@@ -492,6 +503,11 @@ struct klass
492 << (*(scope_tab << scope_tab << constructor_invocation << "\n")) 503 << (*(scope_tab << scope_tab << constructor_invocation << "\n"))
493 << scope_tab << scope_tab << "FinishInstantiation();\n" 504 << scope_tab << scope_tab << "FinishInstantiation();\n"
494 << scope_tab << "}\n\n" 505 << scope_tab << "}\n\n"
506 << scope_tab << "/// <summary>Constructor to be used when objects are expected to be constructed from native code.</summary>\n"
507 << scope_tab << "/// <param name=\"ch\">Tag struct storing the native handle of the object being constructed.</param>\n"
508 << scope_tab << "protected " << inherit_name << "(ConstructingHandle ch) : base(ch)\n"
509 << scope_tab << "{\n"
510 << scope_tab << "}\n\n"
495 << scope_tab << "/// <summary>Initializes a new instance of the <see cref=\"" << inherit_name << "\"/> class.\n" 511 << scope_tab << "/// <summary>Initializes a new instance of the <see cref=\"" << inherit_name << "\"/> class.\n"
496 << 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" 512 << 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"
497 << scope_tab << "/// <param name=\"raw\">The native pointer to be wrapped.</param>\n" 513 << scope_tab << "/// <param name=\"raw\">The native pointer to be wrapped.</param>\n"