diff options
author | Vitor Sousa <vitorsousasilva@gmail.com> | 2017-12-12 12:06:46 -0200 |
---|---|---|
committer | Vitor Sousa <vitorsousasilva@gmail.com> | 2017-12-15 22:26:29 -0200 |
commit | acd99be98bc6f3218af9322b23acb52ed29fb008 (patch) | |
tree | 3cee18189cc4ab31f4595721ca904bf0cc8d6847 /src/lib/eolian_cxx | |
parent | b20dd869a4a10fb28a9c743910e2f2a1d2e7d1cc (diff) |
efl_mono: tests and better support for structs, plus some other fixes
Fix several integer binding type deduction based in its size on C.
Generation for function pointers no longer use modified argument name
which is different from the parameter name.
New generation context for structs.
bool from UnmanagedType.I1 to UnmanagedType.U1 (correct use
inside structs according to mono documentation).
byte (signed char) and int8 now is correctly represented by
sbyte in C#.
Check parameter direction in some out generators in parameter.hh.
Add efl_libs.csv to gitignore.
Make eina.Value pointer constructor public.
Add missing fields to efl.kw_event.Description struct.
Remove eina.File workaround (let struct gen handle it).
Remove is_function_ptr bool from regular_type_def and
add a typedecl_type enum to it. Also add some helper
methods for easier comparison.
Left some test cases commented for when pointer parameters
are properly working.
Diffstat (limited to 'src/lib/eolian_cxx')
-rw-r--r-- | src/lib/eolian_cxx/grammar/converting_argument.hpp | 2 | ||||
-rw-r--r-- | src/lib/eolian_cxx/grammar/klass_def.hpp | 89 | ||||
-rw-r--r-- | src/lib/eolian_cxx/grammar/parameter.hpp | 2 |
3 files changed, 65 insertions, 28 deletions
diff --git a/src/lib/eolian_cxx/grammar/converting_argument.hpp b/src/lib/eolian_cxx/grammar/converting_argument.hpp index eb7ef57376..c419d36b7c 100644 --- a/src/lib/eolian_cxx/grammar/converting_argument.hpp +++ b/src/lib/eolian_cxx/grammar/converting_argument.hpp | |||
@@ -26,7 +26,7 @@ struct converting_argument_generator | |||
26 | bool operator()(T const&) const { return false;} | 26 | bool operator()(T const&) const { return false;} |
27 | bool operator()(attributes::regular_type_def const& r) const | 27 | bool operator()(attributes::regular_type_def const& r) const |
28 | { | 28 | { |
29 | return r.is_function_ptr; | 29 | return r.is_function_ptr(); |
30 | } | 30 | } |
31 | } static const is_function_ptr; | 31 | } static const is_function_ptr; |
32 | template <typename OutputIterator, typename Context> | 32 | template <typename OutputIterator, typename Context> |
diff --git a/src/lib/eolian_cxx/grammar/klass_def.hpp b/src/lib/eolian_cxx/grammar/klass_def.hpp index d1fce8f6d9..f95b765cee 100644 --- a/src/lib/eolian_cxx/grammar/klass_def.hpp +++ b/src/lib/eolian_cxx/grammar/klass_def.hpp | |||
@@ -24,7 +24,7 @@ namespace efl { namespace eolian { namespace grammar { | |||
24 | namespace attributes { | 24 | namespace attributes { |
25 | 25 | ||
26 | struct complex_type_def; | 26 | struct complex_type_def; |
27 | 27 | ||
28 | } | 28 | } |
29 | 29 | ||
30 | namespace attributes { | 30 | namespace attributes { |
@@ -64,16 +64,44 @@ bool lexicographical_compare(std::tuple<T, U> const& lhs | |||
64 | || (!(std::get<0>(rhs) < std::get<0>(lhs)) | 64 | || (!(std::get<0>(rhs) < std::get<0>(lhs)) |
65 | && std::get<1>(lhs) < std::get<1>(rhs)); | 65 | && std::get<1>(lhs) < std::get<1>(rhs)); |
66 | } | 66 | } |
67 | 67 | ||
68 | enum class typedecl_type | ||
69 | { | ||
70 | unknown, | ||
71 | struct_, | ||
72 | struct_opaque, | ||
73 | enum_, | ||
74 | alias, | ||
75 | function_ptr, | ||
76 | }; | ||
77 | |||
78 | inline typedecl_type typedecl_type_get(Eolian_Typedecl const* decl) | ||
79 | { | ||
80 | if (!decl) | ||
81 | return typedecl_type::unknown; | ||
82 | |||
83 | Eolian_Typedecl_Type t = eolian_typedecl_type_get(decl); | ||
84 | switch (t) | ||
85 | { | ||
86 | case EOLIAN_TYPEDECL_UNKNOWN: return typedecl_type::unknown; | ||
87 | case EOLIAN_TYPEDECL_STRUCT: return typedecl_type::struct_; | ||
88 | case EOLIAN_TYPEDECL_STRUCT_OPAQUE: return typedecl_type::struct_opaque; | ||
89 | case EOLIAN_TYPEDECL_ENUM: return typedecl_type::enum_; | ||
90 | case EOLIAN_TYPEDECL_ALIAS: return typedecl_type::alias; | ||
91 | case EOLIAN_TYPEDECL_FUNCTION_POINTER: return typedecl_type::function_ptr; | ||
92 | default: return typedecl_type::unknown; | ||
93 | } | ||
94 | } | ||
95 | |||
68 | struct type_def; | 96 | struct type_def; |
69 | bool operator==(type_def const& rhs, type_def const& lhs); | 97 | bool operator==(type_def const& rhs, type_def const& lhs); |
70 | bool operator!=(type_def const& rhs, type_def const& lhs); | 98 | bool operator!=(type_def const& rhs, type_def const& lhs); |
71 | 99 | ||
72 | enum class class_type | 100 | enum class class_type |
73 | { | 101 | { |
74 | regular, abstract_, mixin, interface_ | 102 | regular, abstract_, mixin, interface_ |
75 | }; | 103 | }; |
76 | 104 | ||
77 | struct klass_name | 105 | struct klass_name |
78 | { | 106 | { |
79 | std::vector<std::string> namespaces; | 107 | std::vector<std::string> namespaces; |
@@ -168,19 +196,28 @@ get(klass_name const& klass) | |||
168 | { | 196 | { |
169 | return tuple_element<N, klass_name>::get(klass); | 197 | return tuple_element<N, klass_name>::get(klass); |
170 | } | 198 | } |
171 | 199 | ||
172 | struct regular_type_def | 200 | struct regular_type_def |
173 | { | 201 | { |
174 | regular_type_def() : is_undefined(false), is_function_ptr(false) {} | 202 | regular_type_def() : type_type(typedecl_type::unknown), is_undefined(false) {} |
175 | regular_type_def(std::string base_type, qualifier_def qual, std::vector<std::string> namespaces | 203 | regular_type_def(std::string base_type, qualifier_def qual, std::vector<std::string> namespaces |
176 | , bool is_undefined = false, bool is_function_ptr = false) | 204 | , typedecl_type type_type = typedecl_type::unknown, bool is_undefined = false) |
177 | : base_type(std::move(base_type)), base_qualifier(qual), namespaces(std::move(namespaces)) | 205 | : base_type(std::move(base_type)), base_qualifier(qual), namespaces(std::move(namespaces)) |
178 | , is_undefined(is_undefined), is_function_ptr(is_function_ptr) {} | 206 | , type_type(type_type), is_undefined(is_undefined) {} |
179 | 207 | ||
208 | bool is_type(typedecl_type tt) const { return type_type == tt; } | ||
209 | bool is_unknown() const { return is_type(typedecl_type::unknown); } | ||
210 | bool is_struct() const { return is_type(typedecl_type::struct_); } | ||
211 | bool is_struct_opaque() const { return is_type(typedecl_type::struct_opaque); } | ||
212 | bool is_enum() const { return is_type(typedecl_type::enum_); } | ||
213 | bool is_alias() const { return is_type(typedecl_type::alias); } | ||
214 | bool is_function_ptr() const { return is_type(typedecl_type::function_ptr); } | ||
215 | |||
180 | std::string base_type; | 216 | std::string base_type; |
181 | qualifier_def base_qualifier; | 217 | qualifier_def base_qualifier; |
182 | std::vector<std::string> namespaces; | 218 | std::vector<std::string> namespaces; |
183 | bool is_undefined, is_function_ptr; | 219 | typedecl_type type_type; |
220 | bool is_undefined; | ||
184 | }; | 221 | }; |
185 | 222 | ||
186 | inline bool operator==(regular_type_def const& rhs, regular_type_def const& lhs) | 223 | inline bool operator==(regular_type_def const& rhs, regular_type_def const& lhs) |
@@ -245,7 +282,7 @@ struct get_qualifier_visitor | |||
245 | return complex.outer.base_qualifier; | 282 | return complex.outer.base_qualifier; |
246 | } | 283 | } |
247 | }; | 284 | }; |
248 | 285 | ||
249 | inline bool operator==(type_def const& lhs, type_def const& rhs) | 286 | inline bool operator==(type_def const& lhs, type_def const& rhs) |
250 | { | 287 | { |
251 | return lhs.original_type == rhs.original_type && lhs.c_type == rhs.c_type; | 288 | return lhs.original_type == rhs.original_type && lhs.c_type == rhs.c_type; |
@@ -254,9 +291,9 @@ inline bool operator!=(type_def const& lhs, type_def const& rhs) | |||
254 | { | 291 | { |
255 | return !(lhs == rhs); | 292 | return !(lhs == rhs); |
256 | } | 293 | } |
257 | 294 | ||
258 | type_def const void_ {attributes::regular_type_def{"void", {qualifier_info::is_none, {}}, {}, false}, "void", false}; | 295 | type_def const void_ {attributes::regular_type_def{"void", {qualifier_info::is_none, {}}, {}}, "void", false}; |
259 | 296 | ||
260 | inline void type_def::set(Eolian_Type const* eolian_type, Eolian_Unit const* unit, Eolian_C_Type_Type ctype) | 297 | inline void type_def::set(Eolian_Type const* eolian_type, Eolian_Unit const* unit, Eolian_C_Type_Type ctype) |
261 | { | 298 | { |
262 | c_type = ::eolian_type_c_type_get(unit, eolian_type, ctype); | 299 | c_type = ::eolian_type_c_type_get(unit, eolian_type, ctype); |
@@ -267,14 +304,14 @@ inline void type_def::set(Eolian_Type const* eolian_type, Eolian_Unit const* uni | |||
267 | switch( ::eolian_type_type_get(eolian_type)) | 304 | switch( ::eolian_type_type_get(eolian_type)) |
268 | { | 305 | { |
269 | case EOLIAN_TYPE_VOID: | 306 | case EOLIAN_TYPE_VOID: |
270 | original_type = attributes::regular_type_def{"void", {qualifiers(eolian_type), {}}, {}, false}; | 307 | original_type = attributes::regular_type_def{"void", {qualifiers(eolian_type), {}}, {}}; |
271 | break; | 308 | break; |
272 | case EOLIAN_TYPE_REGULAR: | 309 | case EOLIAN_TYPE_REGULAR: |
273 | if (!stp) | 310 | if (!stp) |
274 | { | 311 | { |
275 | bool is_undefined = false; | 312 | bool is_undefined = false; |
276 | Eolian_Typedecl const* decl = eolian_type_typedecl_get(unit, eolian_type); | 313 | Eolian_Typedecl const* decl = eolian_type_typedecl_get(unit, eolian_type); |
277 | bool is_function_ptr = decl && eolian_typedecl_type_get(decl) == EOLIAN_TYPEDECL_FUNCTION_POINTER; | 314 | typedecl_type type_type = (decl ? typedecl_type_get(decl) : typedecl_type::unknown); |
278 | if(decl && eolian_typedecl_type_get(decl) == EOLIAN_TYPEDECL_ALIAS) | 315 | if(decl && eolian_typedecl_type_get(decl) == EOLIAN_TYPEDECL_ALIAS) |
279 | { | 316 | { |
280 | Eolian_Type const* aliased = eolian_typedecl_base_type_get(decl); | 317 | Eolian_Type const* aliased = eolian_typedecl_base_type_get(decl); |
@@ -289,7 +326,7 @@ inline void type_def::set(Eolian_Type const* eolian_type, Eolian_Unit const* uni | |||
289 | for(efl::eina::iterator<const char> namespace_iterator( ::eolian_type_namespaces_get(eolian_type)) | 326 | for(efl::eina::iterator<const char> namespace_iterator( ::eolian_type_namespaces_get(eolian_type)) |
290 | , namespace_last; namespace_iterator != namespace_last; ++namespace_iterator) | 327 | , namespace_last; namespace_iterator != namespace_last; ++namespace_iterator) |
291 | namespaces.push_back(&*namespace_iterator); | 328 | namespaces.push_back(&*namespace_iterator); |
292 | original_type = {regular_type_def{ ::eolian_type_name_get(eolian_type), {qualifiers(eolian_type), {}}, namespaces, is_undefined, is_function_ptr}}; | 329 | original_type = {regular_type_def{ ::eolian_type_name_get(eolian_type), {qualifiers(eolian_type), {}}, namespaces, type_type, is_undefined}}; |
293 | } | 330 | } |
294 | else | 331 | else |
295 | { | 332 | { |
@@ -320,7 +357,7 @@ inline void type_def::set(Eolian_Expression_Type eolian_exp_type) | |||
320 | switch(eolian_exp_type) | 357 | switch(eolian_exp_type) |
321 | { | 358 | { |
322 | case EOLIAN_EXPR_INT: | 359 | case EOLIAN_EXPR_INT: |
323 | original_type = attributes::regular_type_def{"int", {{}, {}}, {}, false}; | 360 | original_type = attributes::regular_type_def{"int", {{}, {}}, {}}; |
324 | c_type = "int"; | 361 | c_type = "int"; |
325 | break; | 362 | break; |
326 | default: | 363 | default: |
@@ -351,7 +388,7 @@ struct add_optional_qualifier_visitor | |||
351 | } | 388 | } |
352 | }; | 389 | }; |
353 | } | 390 | } |
354 | 391 | ||
355 | struct parameter_def | 392 | struct parameter_def |
356 | { | 393 | { |
357 | parameter_direction direction; | 394 | parameter_direction direction; |
@@ -369,7 +406,7 @@ struct parameter_def | |||
369 | { | 406 | { |
370 | return !(lhs == rhs); | 407 | return !(lhs == rhs); |
371 | } | 408 | } |
372 | 409 | ||
373 | parameter_def(parameter_direction direction, type_def type, std::string param_name, Eolian_Unit const* unit) | 410 | parameter_def(parameter_direction direction, type_def type, std::string param_name, Eolian_Unit const* unit) |
374 | : direction(std::move(direction)), type(std::move(type)), param_name(std::move(param_name)), unit(unit) {} | 411 | : direction(std::move(direction)), type(std::move(type)), param_name(std::move(param_name)), unit(unit) {} |
375 | parameter_def(Eolian_Function_Parameter const* param, Eolian_Unit const* unit) | 412 | parameter_def(Eolian_Function_Parameter const* param, Eolian_Unit const* unit) |
@@ -545,7 +582,7 @@ struct function_def | |||
545 | { | 582 | { |
546 | attributes::regular_type_def const* typ = | 583 | attributes::regular_type_def const* typ = |
547 | efl::eina::get<attributes::regular_type_def>(¶m.type.original_type); | 584 | efl::eina::get<attributes::regular_type_def>(¶m.type.original_type); |
548 | if (typ && typ->is_function_ptr) | 585 | if (typ && typ->is_function_ptr()) |
549 | { | 586 | { |
550 | char typenam[2] = { 0, }; | 587 | char typenam[2] = { 0, }; |
551 | typenam[0] = template_typename++; | 588 | typenam[0] = template_typename++; |
@@ -568,7 +605,7 @@ struct function_def | |||
568 | { | 605 | { |
569 | attributes::regular_type_def const* typ = | 606 | attributes::regular_type_def const* typ = |
570 | efl::eina::get<attributes::regular_type_def>(¶m.type.original_type); | 607 | efl::eina::get<attributes::regular_type_def>(¶m.type.original_type); |
571 | if (typ && typ->is_function_ptr) | 608 | if (typ && typ->is_function_ptr()) |
572 | { | 609 | { |
573 | char typenam[2] = { 0, }; | 610 | char typenam[2] = { 0, }; |
574 | typenam[0] = template_typename++; | 611 | typenam[0] = template_typename++; |
@@ -652,8 +689,8 @@ struct event_def | |||
652 | friend inline bool operator!=(event_def const& lhs, event_def const& rhs) | 689 | friend inline bool operator!=(event_def const& lhs, event_def const& rhs) |
653 | { | 690 | { |
654 | return !(lhs == rhs); | 691 | return !(lhs == rhs); |
655 | } | 692 | } |
656 | 693 | ||
657 | event_def(type_def type, std::string name, std::string c_name, bool beta, bool protect) | 694 | event_def(type_def type, std::string name, std::string c_name, bool beta, bool protect) |
658 | : type(type), name(name), c_name(c_name), beta(beta), protect(protect) {} | 695 | : type(type), name(name), c_name(c_name), beta(beta), protect(protect) {} |
659 | event_def(Eolian_Event const* event, Eolian_Unit const* unit) | 696 | event_def(Eolian_Event const* event, Eolian_Unit const* unit) |
@@ -835,7 +872,7 @@ struct klass_def | |||
835 | Eolian_Class const* inherit = &*inherit_iterator; | 872 | Eolian_Class const* inherit = &*inherit_iterator; |
836 | immediate_inherits.insert({inherit, {}}); | 873 | immediate_inherits.insert({inherit, {}}); |
837 | } | 874 | } |
838 | std::function<void(Eolian_Class const*)> inherit_algo = | 875 | std::function<void(Eolian_Class const*)> inherit_algo = |
839 | [&] (Eolian_Class const* inherit_klass) | 876 | [&] (Eolian_Class const* inherit_klass) |
840 | { | 877 | { |
841 | for(efl::eina::iterator<Eolian_Class const> inherit_iterator ( ::eolian_class_inherits_get(inherit_klass)) | 878 | for(efl::eina::iterator<Eolian_Class const> inherit_iterator ( ::eolian_class_inherits_get(inherit_klass)) |
@@ -1100,7 +1137,7 @@ template <> | |||
1100 | struct is_tuple<attributes::parameter_def> : std::true_type {}; | 1137 | struct is_tuple<attributes::parameter_def> : std::true_type {}; |
1101 | template <> | 1138 | template <> |
1102 | struct is_tuple<attributes::event_def> : std::true_type {}; | 1139 | struct is_tuple<attributes::event_def> : std::true_type {}; |
1103 | 1140 | ||
1104 | } | 1141 | } |
1105 | 1142 | ||
1106 | } } } | 1143 | } } } |
diff --git a/src/lib/eolian_cxx/grammar/parameter.hpp b/src/lib/eolian_cxx/grammar/parameter.hpp index 68f5450dd1..e06cfeaaf0 100644 --- a/src/lib/eolian_cxx/grammar/parameter.hpp +++ b/src/lib/eolian_cxx/grammar/parameter.hpp | |||
@@ -28,7 +28,7 @@ struct parameter_type_generator | |||
28 | 28 | ||
29 | attributes::regular_type_def const* typ = | 29 | attributes::regular_type_def const* typ = |
30 | efl::eina::get<attributes::regular_type_def>(¶m.type.original_type); | 30 | efl::eina::get<attributes::regular_type_def>(¶m.type.original_type); |
31 | if (typ && typ->is_function_ptr) | 31 | if (typ && typ->is_function_ptr()) |
32 | return as_generator("F").generate(sink, attributes::unused, context); | 32 | return as_generator("F").generate(sink, attributes::unused, context); |
33 | 33 | ||
34 | return as_generator | 34 | return as_generator |