2017-11-23 16:50:16 -08:00
|
|
|
#ifndef EOLIAN_MONO_FUNCTION_DEFINITION_HH
|
|
|
|
#define EOLIAN_MONO_FUNCTION_DEFINITION_HH
|
|
|
|
|
|
|
|
#include <Eina.hh>
|
|
|
|
|
|
|
|
#include "grammar/generator.hpp"
|
|
|
|
#include "grammar/klass_def.hpp"
|
|
|
|
|
|
|
|
#include "grammar/indentation.hpp"
|
|
|
|
#include "grammar/list.hpp"
|
|
|
|
#include "grammar/alternative.hpp"
|
|
|
|
#include "grammar/attribute_reorder.hpp"
|
2018-04-27 14:08:25 -07:00
|
|
|
#include "logging.hh"
|
2017-11-23 16:50:16 -08:00
|
|
|
#include "type.hh"
|
2018-04-16 12:26:13 -07:00
|
|
|
#include "name_helpers.hh"
|
2018-04-10 18:30:40 -07:00
|
|
|
#include "helpers.hh"
|
2017-11-23 16:50:16 -08:00
|
|
|
#include "function_helpers.hh"
|
|
|
|
#include "marshall_type.hh"
|
|
|
|
#include "parameter.hh"
|
2017-12-06 16:03:55 -08:00
|
|
|
#include "documentation.hh"
|
2017-11-23 16:50:16 -08:00
|
|
|
#include "using_decl.hh"
|
|
|
|
#include "generation_contexts.hh"
|
2018-04-16 12:26:13 -07:00
|
|
|
#include "blacklist.hh"
|
2017-11-23 16:50:16 -08:00
|
|
|
|
|
|
|
namespace eolian_mono {
|
|
|
|
|
|
|
|
struct native_function_definition_generator
|
|
|
|
{
|
|
|
|
attributes::klass_def const* klass;
|
|
|
|
|
|
|
|
template <typename OutputIterator, typename Context>
|
|
|
|
bool generate(OutputIterator sink, attributes::function_def const& f, Context const& context) const
|
|
|
|
{
|
2018-04-27 14:08:25 -07:00
|
|
|
EINA_CXX_DOM_LOG_DBG(eolian_mono::domain) << "native_function_definition_generator: " << f.c_name << std::endl;
|
2019-01-15 23:29:56 -08:00
|
|
|
if(blacklist::is_function_blacklisted(f, context))
|
2017-11-23 16:50:16 -08:00
|
|
|
return true;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if(!as_generator
|
|
|
|
("\n\n" << scope_tab
|
2019-01-15 23:29:56 -08:00
|
|
|
<< eolian_mono::marshall_annotation(true)
|
2017-12-06 16:03:55 -08:00
|
|
|
<< " private delegate "
|
2017-11-23 16:50:16 -08:00
|
|
|
<< eolian_mono::marshall_type(true)
|
|
|
|
<< " "
|
|
|
|
<< string
|
2019-01-15 23:29:56 -08:00
|
|
|
<< "_delegate(" << (f.is_static ? "" : "System.IntPtr obj, System.IntPtr pd")
|
|
|
|
<< ((!f.is_static && f.parameters.size() > 0) ? ", " : "")
|
|
|
|
<< (grammar::attribute_reorder<-1, -1>
|
2017-11-23 16:50:16 -08:00
|
|
|
(
|
2019-01-15 23:29:56 -08:00
|
|
|
(marshall_annotation << " " << marshall_parameter)
|
|
|
|
) % ", ")
|
2017-11-23 16:50:16 -08:00
|
|
|
<< ");\n")
|
|
|
|
.generate(sink, std::make_tuple(f.return_type, f.return_type, f.c_name, f.parameters), context))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if(!as_generator
|
2019-01-15 23:29:56 -08:00
|
|
|
("\n\n" << scope_tab
|
|
|
|
<< eolian_mono::marshall_annotation(true)
|
|
|
|
<< " public delegate "
|
2017-11-23 16:50:16 -08:00
|
|
|
<< eolian_mono::marshall_type(true)
|
2019-01-15 23:29:56 -08:00
|
|
|
<< " "
|
|
|
|
<< string << "_api_delegate(" << (f.is_static ? "" : "System.IntPtr obj")
|
|
|
|
<< ((!f.is_static && f.parameters.size() > 0) ? ", " : "")
|
|
|
|
<< (grammar::attribute_reorder<-1, -1>
|
2017-11-23 16:50:16 -08:00
|
|
|
(
|
2019-01-15 23:29:56 -08:00
|
|
|
(marshall_annotation << " " << marshall_parameter)
|
|
|
|
) % ", ")
|
2017-11-23 16:50:16 -08:00
|
|
|
<< ");\n")
|
|
|
|
.generate(sink, std::make_tuple(f.return_type, f.return_type, f.c_name, f.parameters), context))
|
|
|
|
return false;
|
|
|
|
|
2019-01-15 23:29:56 -08:00
|
|
|
if(!as_generator
|
|
|
|
(scope_tab
|
|
|
|
<< " public static Efl.Eo.FunctionWrapper<" << string << "_api_delegate> " << string << "_ptr = new Efl.Eo.FunctionWrapper<"
|
|
|
|
<< string << "_api_delegate>(_Module, \"" << string << "\");\n")
|
|
|
|
.generate(sink, std::make_tuple(f.c_name, f.c_name, f.c_name, f.c_name), context))
|
|
|
|
return false;
|
|
|
|
|
2017-11-23 16:50:16 -08:00
|
|
|
std::string return_type;
|
|
|
|
if(!as_generator(eolian_mono::type(true)).generate(std::back_inserter(return_type), f.return_type, context))
|
|
|
|
return false;
|
|
|
|
|
2019-01-17 04:33:09 -08:00
|
|
|
std::string klass_cast_name;
|
|
|
|
if (klass->type != attributes::class_type::interface_)
|
|
|
|
klass_cast_name = name_helpers::klass_inherit_name(*klass);
|
|
|
|
else
|
|
|
|
klass_cast_name = name_helpers::klass_interface_name(*klass);
|
2018-04-27 14:08:25 -07:00
|
|
|
|
2019-01-15 23:29:56 -08:00
|
|
|
std::string self = "Efl.Eo.Globals.efl_super(obj, Efl.Eo.Globals.efl_class_get(obj))";
|
|
|
|
|
|
|
|
if (f.is_static)
|
|
|
|
self = "";
|
|
|
|
|
2017-11-23 16:50:16 -08:00
|
|
|
if(!as_generator
|
|
|
|
(scope_tab
|
2019-01-18 01:37:26 -08:00
|
|
|
<< " private static "
|
2017-11-23 16:50:16 -08:00
|
|
|
<< eolian_mono::marshall_type(true) << " "
|
|
|
|
<< string
|
|
|
|
<< "(System.IntPtr obj, System.IntPtr pd"
|
|
|
|
<< *(", " << marshall_parameter)
|
|
|
|
<< ")\n"
|
|
|
|
<< scope_tab << "{\n"
|
|
|
|
/****/
|
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
|
|
|
<< scope_tab << scope_tab << "Eina.Log.Debug(\"function " << string << " was called\");\n"
|
2017-11-23 16:50:16 -08:00
|
|
|
/****/
|
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
|
|
|
<< scope_tab << scope_tab << "Efl.Eo.IWrapper wrapper = Efl.Eo.Globals.PrivateDataGet(pd);\n"
|
2017-11-23 16:50:16 -08:00
|
|
|
<< scope_tab << scope_tab << "if(wrapper != null) {\n"
|
|
|
|
<< scope_tab << scope_tab << scope_tab << eolian_mono::native_function_definition_preamble()
|
|
|
|
<< scope_tab << scope_tab << scope_tab << "try {\n"
|
2019-03-26 10:45:18 -07:00
|
|
|
<< scope_tab << scope_tab << scope_tab << scope_tab << (return_type != "void" ? "_ret_var = " : "")
|
2019-01-15 23:29:56 -08:00
|
|
|
<< (f.is_static ? "" : "((") << klass_cast_name << (f.is_static ? "." : ")wrapper).") << string
|
2017-11-23 16:50:16 -08:00
|
|
|
<< "(" << (native_argument_invocation % ", ") << ");\n"
|
|
|
|
<< scope_tab << scope_tab << scope_tab << "} catch (Exception e) {\n"
|
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
|
|
|
<< scope_tab << scope_tab << scope_tab << scope_tab << "Eina.Log.Warning($\"Callback error: {e.ToString()}\");\n"
|
2019-01-15 00:51:20 -08:00
|
|
|
<< scope_tab << scope_tab << scope_tab << scope_tab << "Eina.Error.Set(Eina.Error.UNHANDLED_EXCEPTION);\n"
|
2017-11-23 16:50:16 -08:00
|
|
|
<< scope_tab << scope_tab << scope_tab << "}\n"
|
|
|
|
<< eolian_mono::native_function_definition_epilogue(*klass)
|
|
|
|
<< scope_tab << scope_tab << "} else {\n"
|
2019-03-26 10:45:18 -07:00
|
|
|
<< scope_tab << scope_tab << scope_tab << (return_type != "void" ? "return " : "") << string
|
2019-01-15 23:29:56 -08:00
|
|
|
<< "_ptr.Value.Delegate(" << self << ((!f.is_static && f.parameters.size() > 0) ? ", " : "") << (argument % ", ") << ");\n"
|
2017-11-23 16:50:16 -08:00
|
|
|
<< scope_tab << scope_tab << "}\n"
|
|
|
|
<< scope_tab << "}\n"
|
|
|
|
)
|
|
|
|
.generate(sink, std::make_tuple(f.return_type, escape_keyword(f.name), f.parameters
|
|
|
|
, /***/f.c_name/***/
|
|
|
|
, f
|
2018-05-02 15:49:37 -07:00
|
|
|
, name_helpers::managed_method_name(f)
|
2017-11-23 16:50:16 -08:00
|
|
|
, f.parameters
|
|
|
|
, f
|
|
|
|
, f.c_name
|
2018-04-27 14:08:25 -07:00
|
|
|
, f.parameters
|
2017-11-23 16:50:16 -08:00
|
|
|
)
|
|
|
|
, context))
|
|
|
|
return false;
|
|
|
|
|
2019-01-15 23:29:56 -08:00
|
|
|
// Static functions do not need to be called from C
|
|
|
|
if (f.is_static)
|
|
|
|
return true;
|
|
|
|
|
2018-12-14 14:39:09 -08:00
|
|
|
// This is the delegate that will be passed to Eo to be called from C.
|
|
|
|
if(!as_generator(
|
2019-01-15 23:29:56 -08:00
|
|
|
scope_tab << "private static " << f.c_name << "_delegate " << f.c_name << "_static_delegate;\n"
|
2018-12-14 14:39:09 -08:00
|
|
|
).generate(sink, attributes::unused, context))
|
2017-11-23 16:50:16 -08:00
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct function_definition_generator
|
|
|
|
{
|
|
|
|
function_definition_generator(bool do_super = false)
|
|
|
|
: do_super(do_super)
|
|
|
|
{}
|
|
|
|
|
|
|
|
template <typename OutputIterator, typename Context>
|
|
|
|
bool generate(OutputIterator sink, attributes::function_def const& f, Context const& context) const
|
|
|
|
{
|
2018-04-27 14:08:25 -07:00
|
|
|
EINA_CXX_DOM_LOG_DBG(eolian_mono::domain) << "function_definition_generator: " << f.c_name << std::endl;
|
2019-01-17 04:43:57 -08:00
|
|
|
if(blacklist::is_function_blacklisted(f, context))
|
2017-11-23 16:50:16 -08:00
|
|
|
return true;
|
2018-04-10 18:30:40 -07:00
|
|
|
|
2017-11-23 16:50:16 -08:00
|
|
|
std::string return_type;
|
|
|
|
if(!as_generator(eolian_mono::type(true)).generate(std::back_inserter(return_type), f.return_type, context))
|
|
|
|
return false;
|
|
|
|
|
2017-12-06 16:03:55 -08:00
|
|
|
if(!as_generator
|
|
|
|
(documentation(1)).generate(sink, f, context))
|
|
|
|
return false;
|
|
|
|
|
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
|
|
|
std::string self = "this.NativeHandle";
|
|
|
|
|
|
|
|
// inherited is set in the constructor, true if this instance is from a pure C# class (not generated).
|
|
|
|
if (do_super && !f.is_static)
|
|
|
|
self = "(inherited ? Efl.Eo.Globals.efl_super(" + self + ", this.NativeClass) : " + self + ")";
|
2019-02-11 10:53:29 -08:00
|
|
|
else if (f.is_static)
|
2019-02-09 09:45:27 -08:00
|
|
|
self = "";
|
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
|
|
|
|
2017-11-23 16:50:16 -08:00
|
|
|
if(!as_generator
|
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
|
|
|
(scope_tab << ((do_super && !f.is_static) ? "virtual " : "") << "public " << (f.is_static ? "static " : "") << return_type << " " << string << "(" << (parameter % ", ")
|
2017-11-23 16:50:16 -08:00
|
|
|
<< ") {\n "
|
2019-01-15 23:29:56 -08:00
|
|
|
<< eolian_mono::function_definition_preamble()
|
|
|
|
<< klass_full_native_inherit_name(f.klass) << "." << string << "_ptr.Value.Delegate("
|
|
|
|
<< self
|
|
|
|
<< ((!f.is_static && (f.parameters.size() > 0)) ? "," : "")
|
2019-02-09 09:45:27 -08:00
|
|
|
<< (argument_invocation % ", ") << ");\n"
|
2017-11-23 16:50:16 -08:00
|
|
|
<< eolian_mono::function_definition_epilogue()
|
|
|
|
<< " }\n")
|
2018-05-02 15:49:37 -07:00
|
|
|
.generate(sink, std::make_tuple(name_helpers::managed_method_name(f), f.parameters, f, f.c_name, f.parameters, f), context))
|
2017-11-23 16:50:16 -08:00
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool do_super;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct function_definition_parameterized
|
|
|
|
{
|
|
|
|
function_definition_generator operator()(bool do_super) const
|
|
|
|
{
|
|
|
|
return {do_super};
|
|
|
|
}
|
|
|
|
} const function_definition;
|
|
|
|
function_definition_generator as_generator(function_definition_parameterized)
|
|
|
|
{
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
struct native_function_definition_parameterized
|
|
|
|
{
|
|
|
|
native_function_definition_generator operator()(attributes::klass_def const& klass) const
|
|
|
|
{
|
|
|
|
return {&klass};
|
|
|
|
}
|
|
|
|
} const native_function_definition;
|
|
|
|
|
2018-12-14 12:17:23 -08:00
|
|
|
struct property_wrapper_definition_generator
|
|
|
|
{
|
|
|
|
template<typename OutputIterator, typename Context>
|
2019-03-22 14:37:50 -07:00
|
|
|
bool generate(OutputIterator sink, attributes::property_def const& property, Context const& context) const
|
2018-12-14 12:17:23 -08:00
|
|
|
{
|
2019-03-21 10:38:45 -07:00
|
|
|
if (blacklist::is_property_blacklisted(property, *implementing_klass, context))
|
2018-12-14 12:17:23 -08:00
|
|
|
return true;
|
|
|
|
|
|
|
|
bool interface = context_find_tag<class_context>(context).current_wrapper_kind == class_context::interface;
|
2018-12-21 07:04:43 -08:00
|
|
|
bool is_static = (property.getter.is_engaged() && property.getter->is_static)
|
|
|
|
|| (property.setter.is_engaged() && property.setter->is_static);
|
2018-12-14 12:17:23 -08:00
|
|
|
|
|
|
|
|
|
|
|
if (interface && is_static)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
auto get_params = property.getter.is_engaged() ? property.getter->parameters.size() : 0;
|
|
|
|
auto set_params = property.setter.is_engaged() ? property.setter->parameters.size() : 0;
|
|
|
|
|
|
|
|
// C# properties must have a single value.
|
|
|
|
//
|
|
|
|
// Single values in getters are automatically converted to return_type,
|
|
|
|
// meaning they should have 0 parameters.
|
|
|
|
//
|
|
|
|
// For setters, we ignore the return type - usually boolean.
|
|
|
|
if (get_params > 0 || set_params > 1)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
attributes::type_def prop_type;
|
|
|
|
|
|
|
|
if (property.getter.is_engaged())
|
|
|
|
prop_type = property.getter->return_type;
|
|
|
|
else if (property.setter.is_engaged())
|
|
|
|
prop_type = property.setter->parameters[0].type;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
EINA_CXX_DOM_LOG_ERR(eolian_mono::domain) << "Property must have either a getter or a setter." << std::endl;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string dir_mod;
|
|
|
|
if (property.setter.is_engaged())
|
|
|
|
dir_mod = direction_modifier(property.setter->parameters[0]);
|
|
|
|
|
|
|
|
std::string managed_name = name_helpers::property_managed_name(property);
|
|
|
|
|
|
|
|
if (!as_generator(
|
|
|
|
scope_tab << documentation
|
|
|
|
<< scope_tab << (interface ? "" : "public ") << (is_static ? "static " : "") << type(true) << " " << managed_name << " {\n"
|
|
|
|
).generate(sink, std::make_tuple(property, prop_type), context))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (property.getter.is_engaged())
|
|
|
|
if (!as_generator(scope_tab << scope_tab << "get " << (interface ? ";" : "{ return Get" + managed_name + "(); }") << "\n"
|
|
|
|
).generate(sink, attributes::unused, context))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (property.setter.is_engaged())
|
|
|
|
if (!as_generator(scope_tab << scope_tab << "set " << (interface ? ";" : "{ Set" + managed_name + "(" + dir_mod + "value); }") << "\n"
|
|
|
|
).generate(sink, attributes::unused, context))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (!as_generator(scope_tab << "}\n").generate(sink, attributes::unused, context))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2019-03-21 10:38:45 -07:00
|
|
|
attributes::klass_def const* implementing_klass;
|
|
|
|
};
|
|
|
|
struct property_wrapper_definition_parameterized
|
|
|
|
{
|
|
|
|
property_wrapper_definition_generator operator()(attributes::klass_def const& klass) const
|
|
|
|
{
|
|
|
|
return {&klass};
|
|
|
|
}
|
2018-12-14 12:17:23 -08:00
|
|
|
} const property_wrapper_definition;
|
2019-03-21 10:38:45 -07:00
|
|
|
property_wrapper_definition_generator as_generator(property_wrapper_definition_parameterized)
|
|
|
|
{
|
|
|
|
return {};
|
|
|
|
}
|
2018-12-14 12:17:23 -08:00
|
|
|
|
2017-11-23 16:50:16 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
namespace efl { namespace eolian { namespace grammar {
|
|
|
|
|
|
|
|
template <>
|
|
|
|
struct is_eager_generator< ::eolian_mono::function_definition_generator> : std::true_type {};
|
|
|
|
template <>
|
|
|
|
struct is_eager_generator< ::eolian_mono::native_function_definition_generator> : std::true_type {};
|
|
|
|
template <>
|
2018-12-14 12:17:23 -08:00
|
|
|
struct is_eager_generator< ::eolian_mono::property_wrapper_definition_generator> : std::true_type {};
|
|
|
|
template <>
|
2019-03-21 10:38:45 -07:00
|
|
|
struct is_eager_generator< ::eolian_mono::property_wrapper_definition_parameterized> : std::true_type {};
|
|
|
|
template <>
|
2017-11-23 16:50:16 -08:00
|
|
|
struct is_generator< ::eolian_mono::function_definition_generator> : std::true_type {};
|
|
|
|
template <>
|
|
|
|
struct is_generator< ::eolian_mono::native_function_definition_generator> : std::true_type {};
|
|
|
|
template <>
|
|
|
|
struct is_generator< ::eolian_mono::function_definition_parameterized> : std::true_type {};
|
2018-12-14 12:17:23 -08:00
|
|
|
template <>
|
|
|
|
struct is_generator< ::eolian_mono::property_wrapper_definition_generator> : std::true_type {};
|
2019-03-21 10:38:45 -07:00
|
|
|
template <>
|
|
|
|
struct is_generator< ::eolian_mono::property_wrapper_definition_parameterized> : std::true_type {};
|
2017-11-23 16:50:16 -08:00
|
|
|
|
|
|
|
namespace type_traits {
|
|
|
|
template <>
|
|
|
|
struct attributes_needed< ::eolian_mono::function_definition_generator> : std::integral_constant<int, 1> {};
|
|
|
|
|
|
|
|
template <>
|
|
|
|
struct attributes_needed< ::eolian_mono::function_definition_parameterized> : std::integral_constant<int, 1> {};
|
|
|
|
|
|
|
|
template <>
|
|
|
|
struct attributes_needed< ::eolian_mono::native_function_definition_generator> : std::integral_constant<int, 1> {};
|
2018-12-14 12:17:23 -08:00
|
|
|
|
|
|
|
template <>
|
|
|
|
struct attributes_needed< ::eolian_mono::property_wrapper_definition_generator> : std::integral_constant<int, 1> {};
|
2019-03-21 10:38:45 -07:00
|
|
|
template <>
|
|
|
|
struct attributes_needed< ::eolian_mono::property_wrapper_definition_parameterized> : std::integral_constant<int, 1> {};
|
2017-11-23 16:50:16 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
} } }
|
|
|
|
|
|
|
|
#endif
|