forked from enlightenment/efl
eolian-cxx: Add constructor_def
Summary: To be used generating argument-aware constructors in C#. Reviewers: felipealmeida, vitor.sousa Reviewed By: felipealmeida Subscribers: cedric, #reviewers, #committers Tags: #efl Differential Revision: https://phab.enlightenment.org/D7794
This commit is contained in:
parent
95e31dbc4a
commit
c03f272bec
|
@ -988,6 +988,42 @@ struct part_def
|
|||
, documentation(::eolian_part_documentation_get(part)) {}
|
||||
};
|
||||
|
||||
struct constructor_def
|
||||
{
|
||||
std::string name;
|
||||
klass_name klass;
|
||||
function_def function;
|
||||
bool is_optional;
|
||||
bool is_ctor_param;
|
||||
|
||||
friend inline bool operator==(constructor_def const& lhs, constructor_def const& rhs)
|
||||
{
|
||||
return lhs.name == rhs.name
|
||||
&& lhs.klass == rhs.klass
|
||||
&& lhs.function == rhs.function
|
||||
&& lhs.is_optional == rhs.is_optional
|
||||
&& lhs.is_ctor_param == rhs.is_ctor_param;
|
||||
}
|
||||
|
||||
friend inline bool operator!=(constructor_def const& lhs, constructor_def const& rhs)
|
||||
{
|
||||
return !(lhs == rhs);
|
||||
}
|
||||
|
||||
constructor_def(Eolian_Constructor const* constructor, Eolian_Unit const* unit)
|
||||
: name(::eolian_constructor_name_get(constructor))
|
||||
, klass(::eolian_constructor_class_get(constructor), {})
|
||||
, is_optional(::eolian_constructor_is_optional(constructor))
|
||||
, is_ctor_param(::eolian_constructor_is_ctor_param(constructor))
|
||||
{
|
||||
Eolian_Function const* eo_function = ::eolian_constructor_function_get(constructor);
|
||||
Eolian_Function_Type eo_func_type = ::eolian_function_type_get(eo_function);
|
||||
if (eo_func_type == ::EOLIAN_PROPERTY)
|
||||
eo_func_type = ::EOLIAN_PROP_SET;
|
||||
function = function_def(eo_function, eo_func_type, NULL, unit);
|
||||
}
|
||||
};
|
||||
|
||||
inline Eolian_Class const* get_klass(klass_name const& klass_name_, Eolian_Unit const* unit);
|
||||
|
||||
struct klass_def
|
||||
|
@ -999,6 +1035,7 @@ struct klass_def
|
|||
std::vector<std::string> namespaces;
|
||||
std::vector<function_def> functions;
|
||||
std::vector<property_def> properties;
|
||||
std::vector<constructor_def> constructors;
|
||||
std::set<klass_name, compare_klass_name_by_name> inherits;
|
||||
class_type type;
|
||||
std::vector<event_def> events;
|
||||
|
@ -1197,6 +1234,10 @@ struct klass_def
|
|||
} catch(std::exception const&) {}
|
||||
}
|
||||
|
||||
for(efl::eina::iterator<Eolian_Constructor const> constructor_iterator(::eolian_class_constructors_get(klass))
|
||||
, constructor_last; constructor_iterator != constructor_last; ++constructor_iterator)
|
||||
constructors.push_back({&*constructor_iterator, unit});
|
||||
|
||||
documentation = eolian_class_documentation_get(klass);
|
||||
}
|
||||
|
||||
|
@ -1248,6 +1289,22 @@ struct klass_def
|
|||
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::vector<constructor_def> get_all_constructors() const
|
||||
{
|
||||
std::vector<constructor_def> ret;
|
||||
|
||||
std::copy(constructors.cbegin(), constructors.cend(), std::back_inserter(ret));
|
||||
|
||||
for (auto inherit : inherits)
|
||||
{
|
||||
klass_def klass(get_klass(inherit, unit), unit);
|
||||
std::copy(klass.constructors.cbegin(), klass.constructors.cend(),
|
||||
std::back_inserter(ret));
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
};
|
||||
|
||||
struct value_def
|
||||
|
|
|
@ -258,7 +258,6 @@ EFL_START_TEST(eolian_cxx_test_properties)
|
|||
|
||||
klass_def cls = init_test_data("property_holder.eo", "Property_Holder", eolian_state);
|
||||
|
||||
// FIXME Currently parsing only properties with both get/set values.
|
||||
auto props = cls.properties;
|
||||
ck_assert_int_eq(4, cls.properties.size());
|
||||
|
||||
|
@ -322,6 +321,35 @@ EFL_START_TEST(eolian_cxx_test_cls_get)
|
|||
}
|
||||
EFL_END_TEST
|
||||
|
||||
EFL_START_TEST(eolian_cxx_test_constructors)
|
||||
{
|
||||
efl::eolian::eolian_init eolian_init;
|
||||
efl::eolian::eolian_state eolian_state;
|
||||
|
||||
klass_def cls = init_test_data("generic.eo", "Generic", eolian_state);
|
||||
|
||||
auto constructors = cls.constructors;
|
||||
|
||||
ck_assert_int_eq(constructors.size(), 4);
|
||||
|
||||
auto ctor = constructors[0];
|
||||
ck_assert_str_eq("Generic.required_ctor_a", ctor.name.c_str());
|
||||
ck_assert(!ctor.is_optional);
|
||||
ck_assert(!ctor.is_ctor_param);
|
||||
|
||||
auto function = ctor.function;
|
||||
ck_assert_str_eq("required_ctor_a", function.name.c_str());
|
||||
|
||||
ctor = constructors[2];
|
||||
ck_assert_str_eq("Generic.optional_ctor_a", ctor.name.c_str());
|
||||
ck_assert(ctor.is_optional);
|
||||
ck_assert(!ctor.is_ctor_param);
|
||||
|
||||
function = ctor.function;
|
||||
ck_assert_str_eq("optional_ctor_a", function.name.c_str());
|
||||
}
|
||||
EFL_END_TEST
|
||||
|
||||
void
|
||||
eolian_cxx_test_binding(TCase* tc)
|
||||
{
|
||||
|
@ -335,4 +363,5 @@ eolian_cxx_test_binding(TCase* tc)
|
|||
tcase_add_test(tc, eolian_cxx_test_properties);
|
||||
tcase_add_test(tc, eolian_cxx_test_parent_extensions);
|
||||
tcase_add_test(tc, eolian_cxx_test_cls_get);
|
||||
tcase_add_test(tc, eolian_cxx_test_constructors);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue