summaryrefslogtreecommitdiff
path: root/src/bin/eolian_mono/eolian/mono/struct_definition.hh
diff options
context:
space:
mode:
authorLauro Moura <lauromoura@expertisesolutions.com.br>2018-03-08 15:43:14 -0800
committerCedric BAIL <cedric@osg.samsung.com>2018-03-08 15:46:45 -0800
commit067a8baffa692668acc0f19c91e2198195f480e2 (patch)
treea77e8608e2e3fce0f7ea3c0f745b3739844c3995 /src/bin/eolian_mono/eolian/mono/struct_definition.hh
parent34673ab983f2ebab038016b6a0aff4e160c43225 (diff)
csharp: generate helper constructors for structs.
Summary: C# does not have a literal form for structs (like C++'s {} aggregate initialization). Before this commit the user would need to explicitly instantiate a struct and assign the required values to it, like: eina.Size2D size; size.W = width; size.H = height; widget.SetSize(size); As a workaround, this commit generates helper constructor with parameters corresponding to the struct fields in the order they are declared. These parameters have default values if one does not want to explicitly initialize all fields directly. With these constructs, the above code could be translated to: widget.SetSize(new eina.Size2D(width, height)); It should be noted that the constructed struct will live on the managed memory (GC) instead of the stack. Test Plan: run "make check" Reviewers: felipealmeida Subscribers: cedric Differential Revision: https://phab.enlightenment.org/D5838 Signed-off-by: Cedric BAIL <cedric@osg.samsung.com>
Diffstat (limited to 'src/bin/eolian_mono/eolian/mono/struct_definition.hh')
-rw-r--r--src/bin/eolian_mono/eolian/mono/struct_definition.hh23
1 files changed, 16 insertions, 7 deletions
diff --git a/src/bin/eolian_mono/eolian/mono/struct_definition.hh b/src/bin/eolian_mono/eolian/mono/struct_definition.hh
index 324e787748..a0ff03315e 100644
--- a/src/bin/eolian_mono/eolian/mono/struct_definition.hh
+++ b/src/bin/eolian_mono/eolian/mono/struct_definition.hh
@@ -11,6 +11,7 @@
11#include "keyword.hh" 11#include "keyword.hh"
12#include "using_decl.hh" 12#include "using_decl.hh"
13#include "documentation.hh" 13#include "documentation.hh"
14#include "struct_fields.hh"
14 15
15namespace eolian_mono { 16namespace eolian_mono {
16 17
@@ -24,13 +25,6 @@ inline std::string binding_struct_internal_name(attributes::struct_def const& st
24 return struct_.cxx_name + "_StructInternal"; 25 return struct_.cxx_name + "_StructInternal";
25} 26}
26 27
27inline std::string to_field_name(std::string const& in)
28{
29 std::string field_name = in;
30 field_name[0] = std::toupper(field_name[0]); // Hack to allow 'static' as a field name
31 return field_name;
32}
33
34struct struct_definition_generator 28struct struct_definition_generator
35{ 29{
36 template <typename OutputIterator, typename Context> 30 template <typename OutputIterator, typename Context>
@@ -70,6 +64,21 @@ struct struct_definition_generator
70 if (!as_generator("///<summary>Placeholder field</summary>\npublic IntPtr field;\n").generate(sink, nullptr, context)) 64 if (!as_generator("///<summary>Placeholder field</summary>\npublic IntPtr field;\n").generate(sink, nullptr, context))
71 return false; 65 return false;
72 } 66 }
67 else
68 {
69 // Constructor with default parameters for easy struct initialization
70 auto struct_name = binding_struct_name(struct_);
71 if(!as_generator(
72 scope_tab << "///<summary>Constructor for " << string << ".</summary>\n"
73 << scope_tab << "public " << string << "(\n"
74 << ((scope_tab << scope_tab << field_argument_default) % ",\n")
75 << scope_tab << ")\n"
76 << scope_tab << "{\n"
77 << *(scope_tab << scope_tab << field_argument_assignment << ";\n")
78 << scope_tab << "}\n")
79 .generate(sink, std::make_tuple(struct_name, struct_name, struct_.fields, struct_.fields), context))
80 return false;
81 }
73 82
74 if(!as_generator("}\n").generate(sink, attributes::unused, context)) return false; 83 if(!as_generator("}\n").generate(sink, attributes::unused, context)) return false;
75 84