forked from enlightenment/efl
eolian_cxx: Use C++ wrappers instead of native types as parameters
Summary: Using C++ wrapper types in the signature of methods of the generated classes. Now, when the type is an Eo type defined in Eolian, eolian_cxx will detect it and use the equivalent C++ wrapper. Types defined in Eolian no longer need to be specified in the lookup table, so removed them from there. Disable wrapping of non-const char*. The current wrapper (unique_ptr) is not suited for some required operations like ownership acquisition from C code. Fix constructing properties that only have the "set" method. Fix translation of non-const parameters. Modified Makefiles to allow proper inclusion of evas_cxx headers required by some tests and examples. Move one auxiliary function to another reader to make it more accessible. @feature Reviewers: felipealmeida, q66, cedric Subscribers: cedric Differential Revision: https://phab.enlightenment.org/D2752
This commit is contained in:
parent
eff0e37947
commit
dae35333fd
|
@ -35,12 +35,13 @@ tests_ecore_audio_cxx_cxx_compile_test_CPPFLAGS = \
|
|||
-I$(top_srcdir)/src/lib/efl \
|
||||
-I$(builddir)/src/lib/efl \
|
||||
-I$(srcdir)/src/lib/efl \
|
||||
-I$(top_builddir)/src/lib/evas/canvas/ \
|
||||
-DTESTS_WD=\"`pwd`\" \
|
||||
-DTESTS_SRC_DIR=\"$(top_srcdir)/src/tests/ecore_audio_cxx\" \
|
||||
-DPACKAGE_BUILD_DIR=\"$(abs_top_builddir)/src/tests/ecore_audio_cxx\" \
|
||||
-DTESTS_BUILD_DIR=\"$(top_builddir)/src/tests/ecore_audio_cxx\" \
|
||||
@CHECK_CFLAGS@ @ECORE_CFLAGS@ @EINA_CFLAGS@ @EO_CFLAGS@ @ECORE_AUDIO_CFLAGS@ \
|
||||
@ECORE_CXX_CFLAGS@ @EINA_CXX_CFLAGS@ @EO_CXX_CFLAGS@ @ECORE_AUDIO_CXX_CFLAGS@
|
||||
@CHECK_CFLAGS@ @ECORE_CFLAGS@ @EINA_CFLAGS@ @EVAS_CFLAGS@ @EO_CFLAGS@ @ECORE_AUDIO_CFLAGS@ \
|
||||
@ECORE_CXX_CFLAGS@ @EINA_CXX_CFLAGS@ @EVAS_CXX_CFLAGS@ @EO_CXX_CFLAGS@ @ECORE_AUDIO_CXX_CFLAGS@
|
||||
|
||||
tests_ecore_audio_cxx_cxx_compile_test_LDADD = @CHECK_LIBS@ @USE_ECORE_LIBS@
|
||||
tests_ecore_audio_cxx_cxx_compile_test_DEPENDENCIES = @USE_ECORE_INTERNAL_LIBS@
|
||||
|
|
|
@ -42,8 +42,8 @@ tests_ecore_cxx_ecore_cxx_suite_CPPFLAGS = \
|
|||
-I$(top_builddir)/src/lib/ecore \
|
||||
-DTESTS_SRC_DIR=\"$(top_srcdir)/src/tests/ecore_cxx\" \
|
||||
-DTESTS_BUILD_DIR=\"$(top_builddir)/src/tests/ecore_cxx\" \
|
||||
@CHECK_CFLAGS@ @ECORE_CXX_CFLAGS@ @EINA_CXX_CFLAGS@ @EINA_CFLAGS@ \
|
||||
@ECORE_CFLAGS@ @EO_CFLAGS@ @EO_CXX_CFLAGS@
|
||||
@CHECK_CFLAGS@ @ECORE_CXX_CFLAGS@ @EINA_CXX_CFLAGS@ @EVAS_CXX_CFLAGS@ @EINA_CFLAGS@ \
|
||||
@ECORE_CFLAGS@ @EVAS_CFLAGS@ @EO_CFLAGS@ @EO_CXX_CFLAGS@
|
||||
|
||||
tests_ecore_cxx_ecore_cxx_suite_LDADD = @CHECK_LIBS@ @USE_ECORE_LIBS@
|
||||
tests_ecore_cxx_ecore_cxx_suite_DEPENDENCIES = @USE_ECORE_INTERNAL_LIBS@
|
||||
|
@ -52,6 +52,7 @@ tests_ecore_cxx_cxx_compile_test_SOURCES = tests/ecore_cxx/cxx_compile_test.cc
|
|||
tests_ecore_cxx_cxx_compile_test_CPPFLAGS = -I$(top_builddir)/src/lib/efl \
|
||||
-I$(top_builddir)/src/lib/ecore \
|
||||
-I$(top_builddir)/src/lib/efl/interfaces/ \
|
||||
-I$(top_builddir)/src/lib/evas/canvas/ \
|
||||
-DTESTS_SRC_DIR=\"$(top_srcdir)/src/tests/ecore_cxx\" \
|
||||
-DTESTS_BUILD_DIR=\"$(top_builddir)/src/tests/ecore_cxx\" \
|
||||
@CHECK_CFLAGS@ @ECORE_CXX_CFLAGS@ @EINA_CXX_CFLAGS@ @EINA_CFLAGS@ \
|
||||
|
|
|
@ -34,7 +34,7 @@ tests_edje_cxx_cxx_compile_test_CPPFLAGS = -I$(top_builddir)/src/lib/efl \
|
|||
-I$(top_builddir)/src/lib/efl/interfaces/ \
|
||||
-DTESTS_SRC_DIR=\"$(top_srcdir)/src/tests/edje_cxx\" \
|
||||
-DTESTS_BUILD_DIR=\"$(top_builddir)/src/tests/edje_cxx\" \
|
||||
@CHECK_CFLAGS@ @ECORE_CXX_CFLAGS@ @EINA_CXX_CFLAGS@ @EDJE_CXX_CFLAGS@ @EO_CXX_CFLAGS@ \
|
||||
@CHECK_CFLAGS@ @ECORE_CXX_CFLAGS@ @EINA_CXX_CFLAGS@ @EVAS_CXX_CFLAGS@ @EDJE_CXX_CFLAGS@ @EO_CXX_CFLAGS@ \
|
||||
@ECORE_CFLAGS@ @EINA_CFLAGS@ @EVAS_CFLAGS@ @EDJE_CFLAGS@ @EO_CFLAGS@
|
||||
tests_edje_cxx_cxx_compile_test_LDADD = @CHECK_LIBS@ @USE_EDJE_LIBS@
|
||||
tests_edje_cxx_cxx_compile_test_DEPENDENCIES = @USE_EDJE_INTERNAL_LIBS@
|
||||
|
|
|
@ -35,6 +35,7 @@ TESTS += tests/evas_cxx/cxx_compile_test
|
|||
tests_evas_cxx_cxx_compile_test_SOURCES = tests/evas_cxx/cxx_compile_test.cc
|
||||
tests_evas_cxx_cxx_compile_test_CPPFLAGS = -I$(top_builddir)/src/lib/efl \
|
||||
-I$(top_builddir)/src/lib/efl/interfaces/ \
|
||||
-I$(top_builddir)/src/lib/evas/canvas/ \
|
||||
-DTESTS_SRC_DIR=\"$(top_srcdir)/src/tests/evas_cxx\" \
|
||||
-DTESTS_BUILD_DIR=\"$(top_builddir)/src/tests/evas_cxx\" \
|
||||
@CHECK_CFLAGS@ @ECORE_CXX_CFLAGS@ @EINA_CXX_CFLAGS@ @EVAS_CXX_CFLAGS@ @EO_CXX_CFLAGS@ \
|
||||
|
|
|
@ -302,7 +302,7 @@ convert_eolian_functions(efl::eolian::eo_class& cls, Eolian_Class const& klass)
|
|||
Eolian_Function const& func = *(::eolian_constructor_function_get(&ctor));
|
||||
|
||||
efl::eolian::eo_function f;
|
||||
if (::eolian_function_type_get(&func) != EOLIAN_PROPERTY)
|
||||
if (function_op_type(func) == EOLIAN_METHOD)
|
||||
f = _convert_function(klass, func);
|
||||
else
|
||||
f = _convert_property_set_to_function(klass, func);
|
||||
|
|
|
@ -97,19 +97,6 @@ class_eo_name(Eolian_Class const& klass)
|
|||
(find_replace(class_full_name(klass) + "_" + suffix, ".", "_"));
|
||||
}
|
||||
|
||||
inline std::string
|
||||
class_format_cxx(std::string const& fullname)
|
||||
{
|
||||
std::string s = fullname;
|
||||
auto found = s.find(".");
|
||||
while (found != std::string::npos)
|
||||
{
|
||||
s.replace(found, 1, "::");
|
||||
found = s.find(".");
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
inline efl::eolian::eo_class::eo_class_type
|
||||
class_type(Eolian_Class const& klass)
|
||||
{
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#include <vector>
|
||||
#include <cctype>
|
||||
#include <iterator>
|
||||
#include <stdexcept>
|
||||
#include <cassert>
|
||||
#include <cstddef>
|
||||
|
||||
|
@ -23,6 +24,19 @@ namespace eolian_cxx {
|
|||
typedef std::vector<efl::eolian::eolian_type> lookup_table_type;
|
||||
extern const lookup_table_type type_lookup_table;
|
||||
|
||||
inline std::string
|
||||
class_format_cxx(std::string const& fullname)
|
||||
{
|
||||
std::string s = fullname;
|
||||
auto found = s.find(".");
|
||||
while (found != std::string::npos)
|
||||
{
|
||||
s.replace(found, 1, "::");
|
||||
found = s.find(".");
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
inline bool
|
||||
type_is_complex(Eolian_Type const& type)
|
||||
{
|
||||
|
@ -33,6 +47,28 @@ inline efl::eolian::eolian_type
|
|||
type_from_eolian(Eolian_Type const& type)
|
||||
{
|
||||
efl::eolian::eolian_type x;
|
||||
|
||||
Eolian_Type_Type tpt = ::eolian_type_type_get(&type);
|
||||
if (tpt == EOLIAN_TYPE_POINTER || tpt == EOLIAN_TYPE_ALIAS || tpt == EOLIAN_TYPE_REGULAR)
|
||||
{
|
||||
Eolian_Type const* base_type = ::eolian_type_base_type_get(&type);
|
||||
if (base_type && ::eolian_type_type_get(base_type) == EOLIAN_TYPE_CLASS)
|
||||
{
|
||||
Eolian_Class const* klass = ::eolian_type_class_get(base_type);
|
||||
if (klass)
|
||||
{
|
||||
x.category = efl::eolian::eolian_type::simple_;
|
||||
x.is_class = true;
|
||||
x.binding_requires_optional = false;
|
||||
x.binding = "::" + class_format_cxx(safe_lower(safe_str(::eolian_class_full_name_get(klass))));
|
||||
|
||||
Eina_Stringshare* klass_file = ::eolian_class_file_get(klass);
|
||||
if (klass_file)
|
||||
x.includes = {safe_str(klass_file) + ".hh"};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
x.native = normalize_spaces(safe_str(::eolian_type_c_type_get(&type)));
|
||||
x.is_own = ::eolian_type_is_own(&type);
|
||||
x.is_const = ::eolian_type_is_const(&type);
|
||||
|
|
|
@ -23,12 +23,10 @@ type_lookup_table
|
|||
{"Eina_List *", eolian_type::complex_, false, true, true, true, "::efl::eina::list", {"eina-cxx/eina_list.hh"}},
|
||||
{"const Eina_List *", eolian_type::complex_, true, false, true, true, "::efl::eina::crange_list", {"eina-cxx/eina_list.hh"}},
|
||||
{"Eio_Filter_Direct_Cb", eolian_type::callback_, {"Eio.h"}},
|
||||
{"Emodel *", eolian_type::simple_, false, false, true, false, "::emodel", {"Emodel.hh"}},
|
||||
{"Eo *", eolian_type::simple_, false, true, true, false, "::efl::eo::concrete", {"eo_concrete.hh"}},
|
||||
{"Eo *", eolian_type::simple_, false, false, true, false, "::efl::eo::concrete", {"eo_concrete.hh"}},
|
||||
//{"Evas_Object_Box_Layout", eolian_type::callback_, {"Evas.h"}},
|
||||
{"Evas_Object *", eolian_type::simple_, false, false, true, false, "::evas::object", {"canvas/evas_object.eo.hh"}},
|
||||
{"char *", eolian_type::simple_, false, true, true, false, "std::unique_ptr<char*>", {"memory"}},
|
||||
//{"char *", eolian_type::simple_, false, true, true, false, "std::unique_ptr<char*>", {"memory"}},
|
||||
{"const Eina_Inlist *", eolian_type::complex_, false, false, true, true, "::efl::eina::range_inlist", {"eina-cxx/eina_inlist.hh"}},
|
||||
{"const Eina_List *", eolian_type::complex_, false, false, true, true, "::efl::eina::range_list", {"eina-cxx/eina_ptrlist.hh"}},
|
||||
{"const char *", eolian_type::simple_, false, false, true, true, "::efl::eina::string_view", {"string"}},
|
||||
|
|
|
@ -100,14 +100,14 @@ Eo** to_c(T* v, typename std::enable_if<std::is_convertible<T*, ::efl::eo::concr
|
|||
}
|
||||
|
||||
template <typename R, typename T>
|
||||
R to_native(T const& v)
|
||||
R to_native(T& v)
|
||||
{
|
||||
static_assert(sizeof(T) == sizeof(R), "");
|
||||
return v.native_handle();
|
||||
}
|
||||
|
||||
template <typename R, typename T>
|
||||
R to_native(eina::optional<T> const& v)
|
||||
R to_native(eina::optional<T>& v)
|
||||
{
|
||||
static_assert(sizeof(T) == sizeof(R), "");
|
||||
if (!v)
|
||||
|
|
|
@ -314,6 +314,7 @@ EXTRA_PROGRAMS += evas_cxx_rectangle
|
|||
evas_cxx_rectangle_SOURCES = evas_cxx_rectangle.cc
|
||||
evas_cxx_rectangle_LDADD = $(ECORE_EVAS_COMMON_LDADD)
|
||||
evas_cxx_rectangle_CPPFLAGS = $(ECORE_EVAS_COMMON_CPPFLAGS) @EINA_CXX_CFLAGS@ @EO_CXX_CFLAGS@ @EVAS_CXX_CFLAGS@ \
|
||||
-I$(top_builddir)/src/lib/evas/canvas/ \
|
||||
$(AM_CPPFLAGS) @EVAS_CFLAGS@
|
||||
|
||||
endif
|
||||
|
|
|
@ -41,8 +41,10 @@ namespace efl { namespace eolian { namespace grammar {
|
|||
struct include_dependencies
|
||||
{
|
||||
eo_class const& _cls;
|
||||
include_dependencies(eo_class const& cls)
|
||||
eo_generator_options const& _opts;
|
||||
include_dependencies(eo_class const& cls, eo_generator_options const& opts)
|
||||
: _cls(cls)
|
||||
, _opts(opts)
|
||||
{}
|
||||
};
|
||||
|
||||
|
@ -58,7 +60,8 @@ operator<<(std::ostream& out, include_dependencies const& x)
|
|||
it_p != last_p; ++it_p)
|
||||
for (eolian_type const& subtype : (*it_p).type.parts)
|
||||
for (std::string header : subtype.includes)
|
||||
headers.insert(header);
|
||||
if (header != x._opts.header_decl_file_name)
|
||||
headers.insert(header);
|
||||
|
||||
for (auto it = cls.functions.begin(), last = cls.functions.end();
|
||||
it != last; ++it)
|
||||
|
@ -66,7 +69,8 @@ operator<<(std::ostream& out, include_dependencies const& x)
|
|||
it_p != last_p; ++it_p)
|
||||
for (eolian_type const& subtype : (*it_p).type.parts)
|
||||
for (std::string header : subtype.includes)
|
||||
headers.insert(header);
|
||||
if (header != x._opts.header_decl_file_name)
|
||||
headers.insert(header);
|
||||
|
||||
for (std::string header : headers)
|
||||
out << "#include <" << header << ">" << endl;
|
||||
|
@ -111,7 +115,7 @@ include_headers(std::ostream& out,
|
|||
{
|
||||
out << "#include \"" << cxx_header << "\"" << endl;
|
||||
}
|
||||
out << include_dependencies(cls) << endl;
|
||||
out << include_dependencies(cls, opts) << endl;
|
||||
}
|
||||
|
||||
inline void
|
||||
|
|
Loading…
Reference in New Issue