2017-11-23 16:50:16 -08:00
|
|
|
#ifndef EOLIAN_MONO_STRUCT_DEFINITION_HH
|
|
|
|
#define EOLIAN_MONO_STRUCT_DEFINITION_HH
|
|
|
|
|
|
|
|
#include "grammar/generator.hpp"
|
|
|
|
#include "grammar/klass_def.hpp"
|
|
|
|
#include "grammar/indentation.hpp"
|
|
|
|
#include "grammar/list.hpp"
|
|
|
|
#include "grammar/alternative.hpp"
|
2018-04-16 12:26:13 -07:00
|
|
|
#include "name_helpers.hh"
|
2017-12-12 06:06:46 -08:00
|
|
|
#include "helpers.hh"
|
2017-11-23 16:50:16 -08:00
|
|
|
#include "type.hh"
|
|
|
|
#include "using_decl.hh"
|
2017-12-06 16:03:55 -08:00
|
|
|
#include "documentation.hh"
|
2018-03-08 15:43:14 -08:00
|
|
|
#include "struct_fields.hh"
|
2018-04-16 12:26:13 -07:00
|
|
|
#include "blacklist.hh"
|
2017-11-23 16:50:16 -08:00
|
|
|
|
|
|
|
namespace eolian_mono {
|
|
|
|
|
2017-12-12 06:06:46 -08:00
|
|
|
inline std::string binding_struct_name(attributes::struct_def const& struct_)
|
2017-11-23 16:50:16 -08:00
|
|
|
{
|
csharp: Change to new class API.
Summary:
As discussed in T7204:
- Eo Interfaces/mixins -> C# Interfaces with concrete class
implementations
- Eo Regular/Abstracts -> Proper C# classes
- Added some new generators and helper methods.
- Refactored the class generator, splitting into helper methods
Eo handles now are stored only in the "root" class in any given
inheritance tree (generally, Efl.Object), and accessible to each child.
Methods also are defined in a single place instead of repeatedly
generated in everyfile, reducing the size of the generated .dll from
30MB to around 4.5MB.
Mixins are generated as C# interfaces but any regular class it inherits
from is lost, as we can't have interfaces inheriting from regular
classes. This will be dealt with in a later commit.
Summary of API Changes:
- Merged Inherit/Concrete classes. (These suffixes disappear from
regular classes).
- Interface still have implementations with 'Concrete' suffix for when
they are returned from methods.
- Removed 'I' from interface names.
- Removed interfaces for regular/abstract Eo classes.
- Concrete classes for interfaces/mixins hold the event argument struct.
- Removed '_' from classes, enums, structs, etc, as indicated in C#
naming conventions.
- Namespaces are now Camel.Cased.
- Renamed IWrapper's raw_handle/raw_klass to NativeHandle/NativeClass
Also renamed the test classes as after the namespace change, the
test namespace Test can conflict with the helper Test namespace.
(And use more meaningful names than Test.Testing...)
Also Fixes T7336 by removing a deprecated example and adding
efl_loop_timer_example to build system.
Fixes T7451 by hiding the class_get DllImports and renaming the IWrapper
fields. The native handlers are used in the manual binding.
Still need to work:
- As there are still some events names clashing (e.g. Efl.Ui.Bg with "resize"
from Efl.Gfx.Entity and Efl.Gfx.Image), Events are currently declared on
the interface and implemented "namespaced" in the classes,
requiring the cast to the interface to access the event.
- The Mixin Conundrum. Mixin inheritance will be dealt in a future
commit.
Depends on D7260
Reviewers: segfaultxavi, vitor.sousa, felipealmeida, Jaehyun_Cho
Reviewed By: vitor.sousa
Subscribers: cedric, #reviewers, #committers
Tags: #efl
Maniphest Tasks: T7451, T7336
Differential Revision: https://phab.enlightenment.org/D7262
2018-11-29 15:04:37 -08:00
|
|
|
return name_helpers::typedecl_managed_name(struct_);
|
2017-12-12 06:06:46 -08:00
|
|
|
}
|
|
|
|
|
2019-03-25 13:14:32 -07:00
|
|
|
inline std::string struct_internal_decl_name()
|
2017-12-12 06:06:46 -08:00
|
|
|
{
|
2019-03-25 13:14:32 -07:00
|
|
|
return "NativeStruct";
|
2017-12-12 06:06:46 -08:00
|
|
|
}
|
|
|
|
|
2019-03-25 13:14:32 -07:00
|
|
|
inline std::string binding_struct_internal_name(attributes::struct_def const& struct_)
|
2017-12-12 06:06:46 -08:00
|
|
|
{
|
2019-03-25 13:14:32 -07:00
|
|
|
return binding_struct_name(struct_) + "." + struct_internal_decl_name();
|
|
|
|
}
|
2017-12-12 06:06:46 -08:00
|
|
|
|
|
|
|
// Conversors generation //
|
|
|
|
|
|
|
|
struct to_internal_field_convert_generator
|
|
|
|
{
|
|
|
|
template <typename OutputIterator, typename Context>
|
|
|
|
bool generate(OutputIterator sink, attributes::struct_field_def const& field, Context const& context) const
|
|
|
|
{
|
2019-03-22 14:47:27 -07:00
|
|
|
auto const& indent = current_indentation(context);
|
2018-04-16 12:26:13 -07:00
|
|
|
auto field_name = name_helpers::to_field_name(field.name);
|
efl-csharp: Respect beta for classes and other stuff.
Summary:
In order to work around an issue with Efl.App, which is stable but
inherits from Efl.Core.Command_Line, @beta interfaces/mixins in the
inheritance chain are simply skipped.
Also changed the class used int test for inheritance from C#
Efl.Loop is stable but internally it uses a @beta class as argument to
its Register() method in the constructor. When instantiating a
user-defined C# subclass, the binding calls the C# override in the
NativeInherit class and the marshalling fails as no code is generated
for the beta class.
Also moved Efl.Part test to a beta class. Efl.Part is still beta.
Regarding parts, they are skipped if its class is @beta too.
Also rejected all elm_* files in elm public eo files. They should get
back in as they are converted to Efl.Ui.* api. An exception is
elm_interface_scrollable.eo, as efl_ui_panel depends on it.
Fixes T7730
Test Plan: Run tests
Reviewers: vitor.sousa, segfaultxavi, felipealmeida, cedric, bu5hm4n, zmike
Reviewed By: vitor.sousa
Subscribers: #reviewers, #committers
Tags: #efl
Maniphest Tasks: T7730
Differential Revision: https://phab.enlightenment.org/D8268
2019-03-11 11:46:12 -07:00
|
|
|
// FIXME Replace need_struct_conversion(regular) with need_struct_conversion(type)
|
2017-12-12 06:06:46 -08:00
|
|
|
auto regular = efl::eina::get<attributes::regular_type_def>(&field.type.original_type);
|
|
|
|
auto klass = efl::eina::get<attributes::klass_name>(&field.type.original_type);
|
|
|
|
auto complex = efl::eina::get<attributes::complex_type_def>(&field.type.original_type);
|
|
|
|
|
|
|
|
if (klass)
|
|
|
|
{
|
|
|
|
if (!as_generator(
|
2019-04-09 12:23:03 -07:00
|
|
|
indent << scope_tab << scope_tab << "_internal_struct." << string << " = _external_struct." << string << "?.NativeHandle ?? System.IntPtr.Zero;\n")
|
2017-12-12 06:06:46 -08:00
|
|
|
.generate(sink, std::make_tuple(field_name, field_name), context))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else if ((complex && (complex->outer.base_type == "array"
|
|
|
|
|| complex->outer.base_type == "list"
|
|
|
|
|| complex->outer.base_type == "iterator"
|
|
|
|
|| complex->outer.base_type == "hash"))
|
|
|
|
|| field.type.c_type == "Eina_Binbuf *" || field.type.c_type == "const Eina_Binbuf *")
|
|
|
|
{
|
|
|
|
// Always assumes pointer
|
|
|
|
if (!as_generator(
|
2019-03-22 14:47:27 -07:00
|
|
|
indent << scope_tab << scope_tab << "_internal_struct." << string << " = _external_struct." << string << ".Handle;\n")
|
2017-12-12 06:06:46 -08:00
|
|
|
.generate(sink, std::make_tuple(field_name, field_name), context))
|
|
|
|
return false;
|
|
|
|
}
|
2018-04-10 18:50:05 -07:00
|
|
|
else if (field.type.is_ptr && helpers::need_pointer_conversion(regular) && !helpers::need_struct_conversion(regular))
|
2017-12-15 16:15:00 -08:00
|
|
|
{
|
|
|
|
if (!as_generator(
|
2019-03-22 14:47:27 -07:00
|
|
|
indent << scope_tab << scope_tab << "_internal_struct." << string << " = Eina.PrimitiveConversion.ManagedToPointerAlloc(_external_struct." << string << ");\n")
|
2017-12-15 16:15:00 -08:00
|
|
|
.generate(sink, std::make_tuple(field_name, field_name), context))
|
|
|
|
return false;
|
|
|
|
}
|
2018-04-10 18:50:05 -07:00
|
|
|
else if (helpers::need_struct_conversion(regular))
|
2017-12-12 06:06:46 -08:00
|
|
|
{
|
|
|
|
if (!as_generator(
|
2019-03-25 13:14:32 -07:00
|
|
|
indent << scope_tab << scope_tab << "_internal_struct." << string << " = _external_struct." << string << ";\n")
|
|
|
|
.generate(sink, std::make_tuple(field_name, field_name), context))
|
2017-12-12 06:06:46 -08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else if (regular && (regular->base_type == "string" || regular->base_type == "mstring"))
|
|
|
|
{
|
|
|
|
if (!as_generator(
|
2019-03-22 14:47:27 -07:00
|
|
|
indent << scope_tab << scope_tab << "_internal_struct." << string << " = Eina.MemoryNative.StrDup(_external_struct." << string << ");\n")
|
2017-12-12 06:06:46 -08:00
|
|
|
.generate(sink, std::make_tuple(field_name, field_name), context))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else if (regular && regular->base_type == "stringshare")
|
|
|
|
{
|
|
|
|
if (!as_generator(
|
2019-06-28 06:40:52 -07:00
|
|
|
indent << scope_tab << scope_tab << "_internal_struct." << string << " = Eina.MemoryNative.AddStringshare(_external_struct." << string << ");\n")
|
2017-12-12 06:06:46 -08:00
|
|
|
.generate(sink, std::make_tuple(field_name, field_name), context))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else if (field.type.c_type == "Eina_Slice" || field.type.c_type == "const Eina_Slice"
|
|
|
|
|| field.type.c_type == "Eina_Rw_Slice" || field.type.c_type == "const Eina_Rw_Slice")
|
|
|
|
{
|
|
|
|
if (!as_generator(
|
|
|
|
"\n" <<
|
2019-03-22 14:47:27 -07:00
|
|
|
indent << scope_tab << scope_tab << "_internal_struct." << field_name << ".Len = _external_struct." << field_name << ".Len;\n" <<
|
|
|
|
indent << scope_tab << scope_tab << "_internal_struct." << field_name << ".Mem = _external_struct." << field_name << ".Mem;\n")
|
2017-12-12 06:06:46 -08:00
|
|
|
.generate(sink, attributes::unused, context))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else if (field.type.c_type == "Eina_Value" || field.type.c_type == "const Eina_Value")
|
|
|
|
{
|
|
|
|
if (!as_generator(
|
2019-03-22 14:47:27 -07:00
|
|
|
indent << scope_tab << scope_tab << "_internal_struct." << string << " = _external_struct." << string << ".GetNative();\n"
|
2017-12-12 06:06:46 -08:00
|
|
|
).generate(sink, std::make_tuple(field_name, field_name), context))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else if (field.type.c_type == "Eina_Value *" || field.type.c_type == "const Eina_Value *")
|
|
|
|
{
|
|
|
|
if (!as_generator(
|
2019-04-09 12:23:03 -07:00
|
|
|
indent << scope_tab << scope_tab << "_internal_struct." << string << " = _external_struct." << string << "?.NativeHandle ?? System.IntPtr.Zero;\n"
|
2017-12-12 06:06:46 -08:00
|
|
|
).generate(sink, std::make_tuple(field_name, field_name), context))
|
|
|
|
return false;
|
|
|
|
}
|
2019-01-15 23:29:56 -08:00
|
|
|
else if (!field.type.is_ptr && regular && regular->base_type == "bool")
|
|
|
|
{
|
|
|
|
if (!as_generator(
|
2019-03-22 14:47:27 -07:00
|
|
|
indent << scope_tab << scope_tab << "_internal_struct." << string << " = _external_struct." << string << " ? (byte)1 : (byte)0;\n")
|
2019-01-15 23:29:56 -08:00
|
|
|
.generate(sink, std::make_tuple(field_name, field_name), context))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else if (!field.type.is_ptr && regular && regular->base_type == "char")
|
|
|
|
{
|
|
|
|
if (!as_generator(
|
2019-03-22 14:47:27 -07:00
|
|
|
indent << scope_tab << scope_tab << "_internal_struct." << string << " = (byte)_external_struct." << string << ";\n")
|
2019-01-15 23:29:56 -08:00
|
|
|
.generate(sink, std::make_tuple(field_name, field_name), context))
|
|
|
|
return false;
|
|
|
|
}
|
2017-12-12 06:06:46 -08:00
|
|
|
else // primitives and enums
|
|
|
|
{
|
|
|
|
if (!as_generator(
|
2019-03-22 14:47:27 -07:00
|
|
|
indent << scope_tab << scope_tab << "_internal_struct." << string << " = _external_struct." << string << ";\n")
|
2017-12-12 06:06:46 -08:00
|
|
|
.generate(sink, std::make_tuple(field_name, field_name), context))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
} const to_internal_field_convert {};
|
|
|
|
|
|
|
|
struct to_external_field_convert_generator
|
|
|
|
{
|
|
|
|
template <typename OutputIterator, typename Context>
|
|
|
|
bool generate(OutputIterator sink, attributes::struct_field_def const& field, Context const& context) const
|
|
|
|
{
|
2019-03-22 14:47:27 -07:00
|
|
|
auto const& indent = current_indentation(context);
|
2018-04-16 12:26:13 -07:00
|
|
|
auto field_name = name_helpers::to_field_name(field.name);
|
2017-12-12 06:06:46 -08:00
|
|
|
auto regular = efl::eina::get<attributes::regular_type_def>(&field.type.original_type);
|
|
|
|
auto klass = efl::eina::get<attributes::klass_name>(&field.type.original_type);
|
|
|
|
auto complex = efl::eina::get<attributes::complex_type_def>(&field.type.original_type);
|
|
|
|
|
|
|
|
if (klass)
|
|
|
|
{
|
2018-04-27 14:08:25 -07:00
|
|
|
auto interface_name = name_helpers::klass_full_interface_name(*klass);
|
|
|
|
auto concrete_name = name_helpers::klass_full_concrete_name(*klass);
|
2017-12-12 06:06:46 -08:00
|
|
|
if (!as_generator(
|
|
|
|
"\n"
|
2019-03-22 14:47:27 -07:00
|
|
|
<< indent << scope_tab << scope_tab << "_external_struct." << string
|
csharp: Make classes abstract and rework casting
Summary:
Abstract Eo classes are now proper C# abstract classes.
As a side effect, returning Eo instances from native code was reworked
to return instances of their actual Eo classes instead of previous
behavior of returning a generic Efl.Object and using static_cast.
Instead of `var window = Efl.Ui.Win.static_cast(widget.GetParent());`
Use `var window = widget.GetParent() as Efl.Ui.Win;`
Another side effect was that `efl_constructor` was removed from the list
of supported `Efl.Object` overrides. It is invoked inside
`efl_add_internal_start`, before the bindings makes the association of
the newly created EoId with the C# instance that created it, making the
managed delegate meaningless. C# users then can use regular C#
constructors to initialize fields.
Also changed to set the private data of C#-inherited classes before the
call to constructing methods (aka constructor parameters) so C# classes
can override them correctly.
Fixes T7778
Fixes T7757
Reviewers: vitor.sousa, felipealmeida, segfaultxavi
Reviewed By: vitor.sousa, segfaultxavi
Subscribers: cedric, #reviewers, #committers
Tags: #efl
Maniphest Tasks: T7778, T7757, T7702
Differential Revision: https://phab.enlightenment.org/D8550
2019-04-05 15:53:37 -07:00
|
|
|
<< " = (" << concrete_name << ") Efl.Eo.Globals.CreateWrapperFor(_internal_struct." << string << ");\n"
|
|
|
|
).generate(sink, std::make_tuple(field_name, field_name), context))
|
2017-12-12 06:06:46 -08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else if (field.type.c_type == "Eina_Binbuf *" || field.type.c_type == "const Eina_Binbuf *")
|
|
|
|
{
|
|
|
|
if (!as_generator(
|
2019-03-22 14:47:27 -07:00
|
|
|
indent << scope_tab << scope_tab << "_external_struct." << string << " = new " << type << "(_internal_struct." << string << ", false);\n")
|
2017-12-12 06:06:46 -08:00
|
|
|
.generate(sink, std::make_tuple(field_name, field.type, field_name), context))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else if (complex && (complex->outer.base_type == "array"
|
2019-06-27 09:49:42 -07:00
|
|
|
|| complex->outer.base_type == "list"))
|
2017-12-12 06:06:46 -08:00
|
|
|
{
|
|
|
|
// Always assumes pointer
|
|
|
|
if (!as_generator(
|
2019-03-22 14:47:27 -07:00
|
|
|
indent << scope_tab << scope_tab << "_external_struct." << string << " = new " << type << "(_internal_struct." << string << ", false, false);\n")
|
2017-12-12 06:06:46 -08:00
|
|
|
.generate(sink, std::make_tuple(field_name, field.type, field_name), context))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else if (complex && complex->outer.base_type == "hash")
|
|
|
|
{
|
|
|
|
if (!as_generator(
|
2019-03-22 14:47:27 -07:00
|
|
|
indent << scope_tab << scope_tab << "_external_struct." << string << " = new " << type << "(_internal_struct." << string << ", false, false, false);\n")
|
2017-12-12 06:06:46 -08:00
|
|
|
.generate(sink, std::make_tuple(field_name, field.type, field_name), context))
|
|
|
|
return false;
|
|
|
|
}
|
2019-06-27 09:49:42 -07:00
|
|
|
else if (complex && complex->outer.base_type == "iterator")
|
|
|
|
{
|
|
|
|
if (!as_generator(
|
|
|
|
indent << scope_tab << scope_tab << "_external_struct." << string << " = new " << type << "(_internal_struct." << string << ", false);\n")
|
|
|
|
.generate(sink, std::make_tuple(field_name, field.type, field_name), context))
|
|
|
|
return false;
|
|
|
|
}
|
2018-04-10 18:50:05 -07:00
|
|
|
else if (field.type.is_ptr && helpers::need_pointer_conversion(regular) && !helpers::need_struct_conversion(regular))
|
2017-12-15 16:15:00 -08:00
|
|
|
{
|
|
|
|
if (!as_generator(
|
2019-03-22 14:47:27 -07:00
|
|
|
indent << scope_tab << scope_tab << "_external_struct." << string << " = Eina.PrimitiveConversion.PointerToManaged<" << type << ">(_internal_struct." << string << ");\n")
|
2017-12-15 16:15:00 -08:00
|
|
|
.generate(sink, std::make_tuple(field_name, field.type, field_name), context))
|
|
|
|
return false;
|
|
|
|
}
|
2018-04-10 18:50:05 -07:00
|
|
|
else if (helpers::need_struct_conversion(regular))
|
2017-12-12 06:06:46 -08:00
|
|
|
{
|
|
|
|
if (!as_generator(
|
2019-03-25 13:14:32 -07:00
|
|
|
indent << scope_tab << scope_tab << "_external_struct." << string << " = _internal_struct." << string << ";\n")
|
|
|
|
.generate(sink, std::make_tuple(field_name, field_name), context))
|
2017-12-12 06:06:46 -08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else if (regular && (regular->base_type == "string" || regular->base_type == "mstring" || regular->base_type == "stringshare"))
|
|
|
|
{
|
|
|
|
if (!as_generator(
|
2019-03-22 14:47:27 -07:00
|
|
|
indent << scope_tab << scope_tab << "_external_struct." << string << " = Eina.StringConversion.NativeUtf8ToManagedString(_internal_struct." << string << ");\n")
|
2017-12-12 06:06:46 -08:00
|
|
|
.generate(sink, std::make_tuple(field_name, field_name), context))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else if (field.type.c_type == "Eina_Slice" || field.type.c_type == "const Eina_Slice"
|
|
|
|
|| field.type.c_type == "Eina_Rw_Slice" || field.type.c_type == "const Eina_Rw_Slice")
|
|
|
|
{
|
|
|
|
if (!as_generator(
|
|
|
|
"\n" <<
|
2019-03-22 14:47:27 -07:00
|
|
|
indent << scope_tab << scope_tab << "_external_struct." << field_name << ".Len = _internal_struct." << field_name << ".Len;\n" <<
|
|
|
|
indent << scope_tab << scope_tab << "_external_struct." << field_name << ".Mem = _internal_struct." << field_name << ".Mem;\n")
|
2017-12-12 06:06:46 -08:00
|
|
|
.generate(sink, attributes::unused, context))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else if (field.type.c_type == "Eina_Value" || field.type.c_type == "const Eina_Value")
|
|
|
|
{
|
|
|
|
if (!as_generator(
|
2019-03-22 14:47:27 -07:00
|
|
|
indent << scope_tab << scope_tab << "_external_struct." << string << " = new Eina.Value(_internal_struct." << string << ");\n"
|
2017-12-12 06:06:46 -08:00
|
|
|
).generate(sink, std::make_tuple(field_name, field_name), context))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else if (field.type.c_type == "Eina_Value *" || field.type.c_type == "const Eina_Value *")
|
|
|
|
{
|
|
|
|
if (!as_generator(
|
2019-03-22 14:47:27 -07:00
|
|
|
indent << scope_tab << scope_tab << "_external_struct." << string << " = new Eina.Value(_internal_struct." << string << ", Eina.Ownership.Unmanaged);\n"
|
2017-12-12 06:06:46 -08:00
|
|
|
).generate(sink, std::make_tuple(field_name, field_name), context))
|
|
|
|
return false;
|
|
|
|
}
|
2019-01-15 23:29:56 -08:00
|
|
|
else if (!field.type.is_ptr && regular && regular->base_type == "bool")
|
|
|
|
{
|
|
|
|
if (!as_generator(
|
2019-03-22 14:47:27 -07:00
|
|
|
indent << scope_tab << scope_tab << "_external_struct." << string << " = _internal_struct." << string << " != 0;\n"
|
2019-01-15 23:29:56 -08:00
|
|
|
).generate(sink, std::make_tuple(field_name, field_name), context))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else if (!field.type.is_ptr && regular && regular->base_type == "char")
|
|
|
|
{
|
|
|
|
if (!as_generator(
|
2019-03-22 14:47:27 -07:00
|
|
|
indent << scope_tab << scope_tab << "_external_struct." << string << " = (char)_internal_struct." << string << ";\n"
|
2019-01-15 23:29:56 -08:00
|
|
|
).generate(sink, std::make_tuple(field_name, field_name), context))
|
|
|
|
return false;
|
|
|
|
}
|
2017-12-12 06:06:46 -08:00
|
|
|
else // primitives and enums
|
|
|
|
{
|
|
|
|
if (!as_generator(
|
2019-03-22 14:47:27 -07:00
|
|
|
indent << scope_tab << scope_tab << "_external_struct." << string << " = _internal_struct." << string << ";\n")
|
2017-12-12 06:06:46 -08:00
|
|
|
.generate(sink, std::make_tuple(field_name, field_name), context))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
} const to_external_field_convert {};
|
|
|
|
|
2019-03-25 13:14:32 -07:00
|
|
|
// Internal Struct //
|
|
|
|
|
|
|
|
struct struct_internal_definition_generator
|
2017-12-12 06:06:46 -08:00
|
|
|
{
|
|
|
|
template <typename OutputIterator, typename Context>
|
|
|
|
bool generate(OutputIterator sink, attributes::struct_def const& struct_, Context const& context) const
|
|
|
|
{
|
2019-03-22 14:47:27 -07:00
|
|
|
auto const& indent = current_indentation(context);
|
2017-12-12 06:06:46 -08:00
|
|
|
if (!as_generator
|
|
|
|
(
|
2019-05-03 01:09:58 -07:00
|
|
|
indent << "#pragma warning disable CS1591\n\n"
|
2019-08-01 04:27:51 -07:00
|
|
|
<< indent << "/// <summary>Internal wrapper for struct " << string << ".</summary>\n"
|
2019-03-25 13:14:32 -07:00
|
|
|
<< indent << "[StructLayout(LayoutKind.Sequential)]\n"
|
|
|
|
<< indent << "public struct " << string << "\n"
|
2019-03-22 14:47:27 -07:00
|
|
|
<< indent << "{\n"
|
2017-12-12 06:06:46 -08:00
|
|
|
)
|
2019-03-25 13:14:32 -07:00
|
|
|
.generate(sink, std::make_tuple<>(binding_struct_name(struct_), struct_internal_decl_name()), context))
|
2017-12-12 06:06:46 -08:00
|
|
|
return false;
|
|
|
|
|
2019-03-25 13:14:32 -07:00
|
|
|
// iterate struct fields
|
|
|
|
for (auto const& field : struct_.fields)
|
|
|
|
{
|
|
|
|
auto field_name = name_helpers::to_field_name(field.name);
|
|
|
|
auto klass = efl::eina::get<attributes::klass_name>(&field.type.original_type);
|
|
|
|
auto regular = efl::eina::get<attributes::regular_type_def>(&field.type.original_type);
|
|
|
|
|
|
|
|
if (klass
|
|
|
|
|| (regular && (regular->base_type == "string"
|
|
|
|
|| regular->base_type == "mstring"
|
|
|
|
|| regular->base_type == "stringshare"
|
|
|
|
|| regular->base_type == "any_value_ptr")))
|
|
|
|
{
|
2019-08-01 04:27:51 -07:00
|
|
|
if (!as_generator(indent << scope_tab << "/// <summary>Internal wrapper for field " << field_name << "</summary>\n"
|
2019-03-25 13:14:32 -07:00
|
|
|
<< indent << scope_tab << "public System.IntPtr " << field_name << ";\n")
|
|
|
|
.generate(sink, nullptr, context))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else if (regular && !(regular->base_qualifier & efl::eolian::grammar::attributes::qualifier_info::is_ref)
|
|
|
|
&& regular->base_type == "bool")
|
|
|
|
{
|
2019-08-01 04:27:51 -07:00
|
|
|
if (!as_generator(indent << scope_tab << "/// <summary>Internal wrapper for field " << field_name << "</summary>\n"
|
2019-03-25 13:14:32 -07:00
|
|
|
<< indent << scope_tab << "public System.Byte " << field_name << ";\n")
|
|
|
|
.generate(sink, nullptr, context))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else if (regular && !(regular->base_qualifier & efl::eolian::grammar::attributes::qualifier_info::is_ref)
|
|
|
|
&& regular->base_type == "char")
|
|
|
|
{
|
2019-08-01 04:27:51 -07:00
|
|
|
if (!as_generator(indent << scope_tab << "/// <summary>Internal wrapper for field " << field_name << "</summary>\n"
|
2019-03-25 13:14:32 -07:00
|
|
|
<< indent << scope_tab << "public System.Byte " << field_name << ";\n")
|
|
|
|
.generate(sink, nullptr, context))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else if (!as_generator(indent << scope_tab << eolian_mono::marshall_annotation(false) << "\n"
|
|
|
|
<< indent << scope_tab << "public " << eolian_mono::marshall_type(false) << " " << string << ";\n")
|
|
|
|
.generate(sink, std::make_tuple(field.type, field.type, field_name), context))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check whether this is an extern struct without declared fields in .eo file and generate a
|
|
|
|
// placeholder field if positive.
|
|
|
|
// Mono's JIT is picky when generating function pointer for delegates with empty structs, leading to
|
|
|
|
// those 'mini-amd64.c condition fields not met' crashes.
|
|
|
|
if (struct_.fields.size() == 0)
|
|
|
|
{
|
|
|
|
if (!as_generator(indent << scope_tab << "internal IntPtr field;\n").generate(sink, nullptr, context))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto external_name = binding_struct_name(struct_);
|
|
|
|
auto internal_name = binding_struct_internal_name(struct_);
|
|
|
|
|
2017-12-12 06:06:46 -08:00
|
|
|
// to internal
|
2019-03-25 13:14:32 -07:00
|
|
|
if (!as_generator(
|
2019-08-01 04:27:51 -07:00
|
|
|
indent << scope_tab << "/// <summary>Implicit conversion to the internal/marshalling representation.</summary>\n"
|
2019-03-25 13:14:32 -07:00
|
|
|
<< indent << scope_tab << "public static implicit operator " << string << "(" << string << " _external_struct)\n"
|
|
|
|
<< indent << scope_tab << "{\n"
|
|
|
|
<< indent << scope_tab << scope_tab << "var _internal_struct = new " << string << "();\n"
|
|
|
|
).generate(sink, std::make_tuple(internal_name, external_name, internal_name), context))
|
2017-12-12 06:06:46 -08:00
|
|
|
return false;
|
|
|
|
|
|
|
|
for (auto const& field : struct_.fields)
|
|
|
|
{
|
|
|
|
if (!to_internal_field_convert.generate(sink, field, context))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-03-25 13:14:32 -07:00
|
|
|
if (!as_generator(indent << scope_tab << scope_tab << "return _internal_struct;\n"
|
|
|
|
<< indent << scope_tab << "}\n\n").generate(sink, nullptr, context))
|
2017-12-12 06:06:46 -08:00
|
|
|
return false;
|
|
|
|
|
2019-03-25 13:14:32 -07:00
|
|
|
// to managed
|
|
|
|
if (!as_generator(
|
2019-08-01 04:27:51 -07:00
|
|
|
indent << scope_tab << "/// <summary>Implicit conversion to the managed representation.</summary>\n"
|
2019-03-25 13:14:32 -07:00
|
|
|
<< indent << scope_tab << "public static implicit operator " << string << "(" << string << " _internal_struct)\n"
|
|
|
|
<< indent << scope_tab << "{\n"
|
|
|
|
<< indent << scope_tab << scope_tab << "var _external_struct = new " << string << "();\n"
|
|
|
|
).generate(sink, std::make_tuple(external_name, internal_name, external_name), context))
|
2017-12-12 06:06:46 -08:00
|
|
|
return false;
|
|
|
|
|
|
|
|
for (auto const& field : struct_.fields)
|
|
|
|
{
|
|
|
|
if (!to_external_field_convert.generate(sink, field, context))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-03-25 13:14:32 -07:00
|
|
|
if (!as_generator(indent << scope_tab << scope_tab << "return _external_struct;\n"
|
|
|
|
<< indent << scope_tab << "}\n\n").generate(sink, nullptr, context))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// close internal class
|
2019-05-03 01:09:58 -07:00
|
|
|
if(!as_generator(indent << "}\n\n"
|
|
|
|
<< indent << "#pragma warning restore CS1591\n\n"
|
|
|
|
).generate(sink, attributes::unused, context)) return false;
|
2019-03-25 13:14:32 -07:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
} const struct_internal_definition {};
|
|
|
|
|
|
|
|
// Managed Struct //
|
|
|
|
|
|
|
|
struct struct_definition_generator
|
|
|
|
{
|
|
|
|
template <typename OutputIterator, typename Context>
|
|
|
|
bool generate(OutputIterator sink, attributes::struct_def const& struct_, Context const& context) const
|
|
|
|
{
|
|
|
|
EINA_CXX_DOM_LOG_DBG(eolian_mono::domain) << "struct_definition_generator: " << struct_.cxx_name << std::endl;
|
|
|
|
auto const& indent = current_indentation(context);
|
|
|
|
if(!as_generator(documentation).generate(sink, struct_, context))
|
|
|
|
return false;
|
|
|
|
if(!as_generator
|
|
|
|
(
|
|
|
|
indent << "[StructLayout(LayoutKind.Sequential)]\n"
|
2019-07-11 11:50:33 -07:00
|
|
|
<< indent << "[Efl.Eo.BindingEntity]\n"
|
2019-03-25 13:14:32 -07:00
|
|
|
<< indent << "public struct " << string << "\n"
|
|
|
|
<< indent << "{\n"
|
2017-12-12 06:06:46 -08:00
|
|
|
)
|
2019-03-25 13:14:32 -07:00
|
|
|
.generate(sink, binding_struct_name(struct_), context))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// iterate struct fields
|
|
|
|
for (auto const& field : struct_.fields)
|
|
|
|
{
|
2019-08-01 12:12:10 -07:00
|
|
|
if (!as_generator(documentation(indent.n + 1)).generate(sink, field, context))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (!field.type.doc_summary.empty())
|
|
|
|
{
|
|
|
|
if (!as_generator(indent << scope_tab << "/// <value>" << field.type.doc_summary << "</value>\n").generate(sink, attributes::unused, context))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!as_generator(indent << scope_tab << "public " << type << " " << name_helpers::to_field_name(field.name) << ";\n").generate(sink, field.type, context))
|
2019-03-25 13:14:32 -07:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto struct_name = binding_struct_name(struct_);
|
|
|
|
|
|
|
|
// Check whether this is an extern struct without declared fields in .eo file and generate a
|
|
|
|
// placeholder field if positive.
|
|
|
|
// Mono's JIT is picky when generating function pointer for delegates with empty structs, leading to
|
|
|
|
// those 'mini-amd64.c condition fields not met' crashes.
|
|
|
|
if (struct_.fields.size() == 0)
|
|
|
|
{
|
2019-08-01 04:27:51 -07:00
|
|
|
if (!as_generator(indent << scope_tab << "/// <summary>Placeholder field</summary>\n"
|
2019-03-25 13:14:32 -07:00
|
|
|
<< indent << scope_tab << "public IntPtr field;\n").generate(sink, nullptr, context))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Constructor with default parameters for easy struct initialization
|
|
|
|
if(!as_generator(
|
2019-08-01 04:27:51 -07:00
|
|
|
indent << scope_tab << "/// <summary>Constructor for " << string << ".</summary>\n"
|
2019-08-01 12:12:10 -07:00
|
|
|
<< *(indent << scope_tab << field_argument_docs << ";\n")
|
2019-03-25 13:14:32 -07:00
|
|
|
<< indent << scope_tab << "public " << string << "(\n"
|
|
|
|
<< ((indent << scope_tab << scope_tab << field_argument_default) % ",\n")
|
|
|
|
<< indent << scope_tab << ")\n"
|
|
|
|
<< indent << scope_tab << "{\n"
|
|
|
|
<< *(indent << scope_tab << scope_tab << field_argument_assignment << ";\n")
|
|
|
|
<< indent << scope_tab << "}\n\n")
|
2019-08-01 12:12:10 -07:00
|
|
|
.generate(sink, std::make_tuple(struct_name, struct_.fields, struct_name, struct_.fields, struct_.fields), context))
|
2019-03-25 13:14:32 -07:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!as_generator(
|
2019-08-01 04:27:51 -07:00
|
|
|
indent << scope_tab << "/// <summary>Implicit conversion to the managed representation from a native pointer.</summary>\n"
|
|
|
|
<< indent << scope_tab << "/// <param name=\"ptr\">Native pointer to be converted.</param>\n"
|
2019-05-03 01:09:58 -07:00
|
|
|
<< indent << scope_tab << "public static implicit operator " << struct_name << "(IntPtr ptr)\n"
|
2019-03-25 13:14:32 -07:00
|
|
|
<< indent << scope_tab << "{\n"
|
|
|
|
<< indent << scope_tab << scope_tab << "var tmp = (" << struct_name << ".NativeStruct)Marshal.PtrToStructure(ptr, typeof(" << struct_name << ".NativeStruct));\n"
|
|
|
|
<< indent << scope_tab << scope_tab << "return tmp;\n"
|
|
|
|
<< indent << scope_tab << "}\n\n"
|
|
|
|
).generate(sink, attributes::unused, context))
|
2017-12-12 06:06:46 -08:00
|
|
|
return false;
|
|
|
|
|
2019-03-25 13:14:32 -07:00
|
|
|
if (!struct_internal_definition.generate(sink, struct_, change_indentation(indent.inc(), context)))
|
2017-12-12 06:06:46 -08:00
|
|
|
return false;
|
|
|
|
|
2019-03-25 13:14:32 -07:00
|
|
|
if(!as_generator(indent << "}\n\n").generate(sink, attributes::unused, context)) return false;
|
|
|
|
|
2017-12-12 06:06:46 -08:00
|
|
|
return true;
|
|
|
|
}
|
2019-03-25 13:14:32 -07:00
|
|
|
} const struct_definition {};
|
2017-12-12 06:06:46 -08:00
|
|
|
|
|
|
|
struct struct_entities_generator
|
|
|
|
{
|
|
|
|
template <typename OutputIterator, typename Context>
|
|
|
|
bool generate(OutputIterator sink, attributes::struct_def const& struct_, Context const& context) const
|
|
|
|
{
|
efl-csharp: Respect beta for classes and other stuff.
Summary:
In order to work around an issue with Efl.App, which is stable but
inherits from Efl.Core.Command_Line, @beta interfaces/mixins in the
inheritance chain are simply skipped.
Also changed the class used int test for inheritance from C#
Efl.Loop is stable but internally it uses a @beta class as argument to
its Register() method in the constructor. When instantiating a
user-defined C# subclass, the binding calls the C# override in the
NativeInherit class and the marshalling fails as no code is generated
for the beta class.
Also moved Efl.Part test to a beta class. Efl.Part is still beta.
Regarding parts, they are skipped if its class is @beta too.
Also rejected all elm_* files in elm public eo files. They should get
back in as they are converted to Efl.Ui.* api. An exception is
elm_interface_scrollable.eo, as efl_ui_panel depends on it.
Fixes T7730
Test Plan: Run tests
Reviewers: vitor.sousa, segfaultxavi, felipealmeida, cedric, bu5hm4n, zmike
Reviewed By: vitor.sousa
Subscribers: #reviewers, #committers
Tags: #efl
Maniphest Tasks: T7730
Differential Revision: https://phab.enlightenment.org/D8268
2019-03-11 11:46:12 -07:00
|
|
|
if (blacklist::is_struct_blacklisted(struct_, context))
|
2017-12-12 06:06:46 -08:00
|
|
|
return true;
|
|
|
|
|
2018-04-27 14:08:25 -07:00
|
|
|
if (!name_helpers::open_namespaces(sink, struct_.namespaces, context))
|
2017-12-12 06:06:46 -08:00
|
|
|
return false;
|
|
|
|
|
|
|
|
if (!struct_definition.generate(sink, struct_, context))
|
|
|
|
return false;
|
|
|
|
|
2018-04-27 14:08:25 -07:00
|
|
|
return name_helpers::close_namespaces(sink, struct_.namespaces, context);
|
2017-11-23 16:50:16 -08:00
|
|
|
|
|
|
|
}
|
2017-12-12 06:06:46 -08:00
|
|
|
} const struct_entities {};
|
2017-11-23 16:50:16 -08:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace efl { namespace eolian { namespace grammar {
|
|
|
|
|
|
|
|
template <>
|
|
|
|
struct is_eager_generator< ::eolian_mono::struct_definition_generator> : std::true_type {};
|
|
|
|
template <>
|
|
|
|
struct is_generator< ::eolian_mono::struct_definition_generator> : std::true_type {};
|
|
|
|
|
2017-12-12 06:06:46 -08:00
|
|
|
template <>
|
|
|
|
struct is_eager_generator< ::eolian_mono::struct_internal_definition_generator> : std::true_type {};
|
|
|
|
template <>
|
|
|
|
struct is_generator< ::eolian_mono::struct_internal_definition_generator> : std::true_type {};
|
|
|
|
|
|
|
|
template <>
|
|
|
|
struct is_eager_generator< ::eolian_mono::to_internal_field_convert_generator> : std::true_type {};
|
|
|
|
template <>
|
|
|
|
struct is_generator< ::eolian_mono::to_internal_field_convert_generator> : std::true_type {};
|
|
|
|
|
|
|
|
template <>
|
|
|
|
struct is_eager_generator< ::eolian_mono::to_external_field_convert_generator> : std::true_type {};
|
|
|
|
template <>
|
|
|
|
struct is_generator< ::eolian_mono::to_external_field_convert_generator> : std::true_type {};
|
|
|
|
|
|
|
|
template <>
|
|
|
|
struct is_eager_generator< ::eolian_mono::struct_entities_generator> : std::true_type {};
|
|
|
|
template <>
|
|
|
|
struct is_generator< ::eolian_mono::struct_entities_generator> : std::true_type {};
|
|
|
|
|
2017-11-23 16:50:16 -08:00
|
|
|
namespace type_traits {
|
|
|
|
template <>
|
|
|
|
struct attributes_needed< ::eolian_mono::struct_definition_generator> : std::integral_constant<int, 1> {};
|
2017-12-12 06:06:46 -08:00
|
|
|
|
|
|
|
template <>
|
|
|
|
struct attributes_needed< ::eolian_mono::struct_internal_definition_generator> : std::integral_constant<int, 1> {};
|
|
|
|
|
|
|
|
template <>
|
|
|
|
struct attributes_needed< ::eolian_mono::to_internal_field_convert_generator> : std::integral_constant<int, 1> {};
|
|
|
|
|
|
|
|
template <>
|
|
|
|
struct attributes_needed< ::eolian_mono::to_external_field_convert_generator> : std::integral_constant<int, 1> {};
|
|
|
|
|
|
|
|
template <>
|
|
|
|
struct attributes_needed< ::eolian_mono::struct_entities_generator> : std::integral_constant<int, 1> {};
|
2017-11-23 16:50:16 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
} } }
|
|
|
|
|
|
|
|
#endif
|