diff options
author | Lauro Moura <lauromoura@expertisesolutions.com.br> | 2019-09-09 18:10:02 +0200 |
---|---|---|
committer | Daniel Kolesa <d.kolesa@samsung.com> | 2019-09-09 18:10:02 +0200 |
commit | 165921ec040f427875fc0b32b1f03d4a45efd25e (patch) | |
tree | 64c719b432dcc55d4fec60d8c88cda2dbf9d1913 | |
parent | 1148ab3393080b9ed616b0efa1e979a9ed1266cf (diff) |
eolian_cxx: Add support for @by_ref
Summary:
It will coexist with `eolian_type_is_ptr` while we phase out the latter.
Fixes: T8211
Depends on D9866
Reviewers: q66, felipealmeida
Reviewed By: q66
Subscribers: cedric, #reviewers, #committers
Tags: #efl
Differential Revision: https://phab.enlightenment.org/D9867
-rw-r--r-- | src/lib/eolian_cxx/grammar/klass_def.hpp | 72 | ||||
-rw-r--r-- | src/lib/eolian_cxx/grammar/qualifier_def.hpp | 4 |
2 files changed, 56 insertions, 20 deletions
diff --git a/src/lib/eolian_cxx/grammar/klass_def.hpp b/src/lib/eolian_cxx/grammar/klass_def.hpp index fbd8779e0f..4de294e836 100644 --- a/src/lib/eolian_cxx/grammar/klass_def.hpp +++ b/src/lib/eolian_cxx/grammar/klass_def.hpp | |||
@@ -372,6 +372,12 @@ namespace value_ownership | |||
372 | const bool unmoved = false; | 372 | const bool unmoved = false; |
373 | }; | 373 | }; |
374 | 374 | ||
375 | namespace is_by | ||
376 | { | ||
377 | const bool reference = true; | ||
378 | const bool value = false; | ||
379 | }; | ||
380 | |||
375 | // type_def represents a type where it is used, like a method parameter or a struc field, in contrast to more | 381 | // type_def represents a type where it is used, like a method parameter or a struc field, in contrast to more |
376 | // specifict types like struct_def, class_def, function_def, which represents a declaration of a type. | 382 | // specifict types like struct_def, class_def, function_def, which represents a declaration of a type. |
377 | struct type_def | 383 | struct type_def |
@@ -389,11 +395,11 @@ struct type_def | |||
389 | type_def(variant_type original_type, std::string c_type, bool has_own, bool is_ptr, bool is_beta, std::string doc_summary) | 395 | type_def(variant_type original_type, std::string c_type, bool has_own, bool is_ptr, bool is_beta, std::string doc_summary) |
390 | : original_type(original_type), c_type(c_type), has_own(has_own), is_ptr(is_ptr), is_beta(is_beta), doc_summary(doc_summary) {} | 396 | : original_type(original_type), c_type(c_type), has_own(has_own), is_ptr(is_ptr), is_beta(is_beta), doc_summary(doc_summary) {} |
391 | 397 | ||
392 | type_def(Eolian_Type const* eolian_type, Eolian_Unit const* unit, Eolian_C_Type_Type ctype, bool is_moved) | 398 | type_def(Eolian_Type const* eolian_type, Eolian_Unit const* unit, std::string const& ctype, bool is_moved, bool is_reference) |
393 | { | 399 | { |
394 | set(eolian_type, unit, ctype, is_moved); | 400 | set(eolian_type, unit, ctype, is_moved, is_reference); |
395 | } | 401 | } |
396 | void set(Eolian_Type const* eolian_type, Eolian_Unit const* unit, Eolian_C_Type_Type ctype, bool is_moved); | 402 | void set(Eolian_Type const* eolian_type, Eolian_Unit const* unit, std::string const & ctype, bool is_moved, bool is_reference); |
397 | void set(Eolian_Expression_Type eolian_exp_type); | 403 | void set(Eolian_Expression_Type eolian_exp_type); |
398 | 404 | ||
399 | friend inline bool operator<(type_def const& lhs, type_def const& rhs) | 405 | friend inline bool operator<(type_def const& lhs, type_def const& rhs) |
@@ -433,14 +439,15 @@ inline bool operator!=(type_def const& lhs, type_def const& rhs) | |||
433 | 439 | ||
434 | type_def const void_ {attributes::regular_type_def{"void", {qualifier_info::is_none, {}}, {}}, "void", false, false, false, ""}; | 440 | type_def const void_ {attributes::regular_type_def{"void", {qualifier_info::is_none, {}}, {}}, "void", false, false, false, ""}; |
435 | 441 | ||
436 | inline void type_def::set(Eolian_Type const* eolian_type, Eolian_Unit const* unit, Eolian_C_Type_Type ctype, bool is_moved) | 442 | inline void type_def::set(Eolian_Type const* eolian_type, Eolian_Unit const* unit, std::string const& ctype, bool is_moved, bool is_reference) |
437 | { | 443 | { |
438 | c_type = ::eolian_type_c_type_get(eolian_type, ctype); | 444 | c_type = ctype; |
439 | is_value_type = ('*' != c_type.back()); | 445 | is_value_type = ('*' != c_type.back()); |
440 | // ::eina_stringshare_del(stringshare); // this crashes | 446 | // ::eina_stringshare_del(stringshare); // this crashes |
441 | Eolian_Type const* stp = eolian_type_base_type_get(eolian_type); | 447 | Eolian_Type const* stp = eolian_type_base_type_get(eolian_type); |
442 | has_own = is_moved; | 448 | has_own = is_moved; |
443 | is_ptr = !!::eolian_type_is_ptr(eolian_type); | 449 | |
450 | is_ptr = is_reference || eolian_type_is_ptr(eolian_type); | ||
444 | 451 | ||
445 | Eolian_Typedecl const* decl = eolian_type_typedecl_get(eolian_type); | 452 | Eolian_Typedecl const* decl = eolian_type_typedecl_get(eolian_type); |
446 | is_beta = decl && eolian_object_is_beta(EOLIAN_OBJECT(decl)); | 453 | is_beta = decl && eolian_object_is_beta(EOLIAN_OBJECT(decl)); |
@@ -452,7 +459,7 @@ inline void type_def::set(Eolian_Type const* eolian_type, Eolian_Unit const* uni | |||
452 | switch( ::eolian_type_type_get(eolian_type)) | 459 | switch( ::eolian_type_type_get(eolian_type)) |
453 | { | 460 | { |
454 | case EOLIAN_TYPE_VOID: | 461 | case EOLIAN_TYPE_VOID: |
455 | original_type = attributes::regular_type_def{"void", {qualifiers(eolian_type, is_moved), {}}, {}}; | 462 | original_type = attributes::regular_type_def{"void", {qualifiers(eolian_type, is_moved, is_ptr), {}}, {}}; |
456 | break; | 463 | break; |
457 | case EOLIAN_TYPE_REGULAR: | 464 | case EOLIAN_TYPE_REGULAR: |
458 | if (!stp) | 465 | if (!stp) |
@@ -474,15 +481,19 @@ inline void type_def::set(Eolian_Type const* eolian_type, Eolian_Unit const* uni | |||
474 | for(efl::eina::iterator<const char> namespace_iterator( ::eolian_type_namespaces_get(eolian_type)) | 481 | for(efl::eina::iterator<const char> namespace_iterator( ::eolian_type_namespaces_get(eolian_type)) |
475 | , namespace_last; namespace_iterator != namespace_last; ++namespace_iterator) | 482 | , namespace_last; namespace_iterator != namespace_last; ++namespace_iterator) |
476 | namespaces.push_back(&*namespace_iterator); | 483 | namespaces.push_back(&*namespace_iterator); |
477 | original_type = {regular_type_def{ ::eolian_type_short_name_get(eolian_type), {qualifiers(eolian_type, is_moved), {}}, namespaces, type_type, is_undefined}}; | 484 | original_type = {regular_type_def{ ::eolian_type_short_name_get(eolian_type), {qualifiers(eolian_type, is_moved, is_ptr), {}}, namespaces, type_type, is_undefined}}; |
478 | } | 485 | } |
479 | else | 486 | else |
480 | { | 487 | { |
481 | complex_type_def complex | 488 | complex_type_def complex |
482 | {{::eolian_type_short_name_get(eolian_type), {qualifiers(eolian_type, is_moved), {}}, {}}, {}}; | 489 | {{::eolian_type_short_name_get(eolian_type), {qualifiers(eolian_type, is_moved, is_ptr), {}}, {}}, {}}; |
483 | while (stp) | 490 | while (stp) |
484 | { | 491 | { |
485 | complex.subtypes.push_back({stp, unit, EOLIAN_C_TYPE_DEFAULT, eolian_type_is_move(stp)}); | 492 | complex.subtypes.push_back({stp |
493 | , unit | ||
494 | , ::eolian_type_c_type_get(stp, EOLIAN_C_TYPE_DEFAULT) | ||
495 | , eolian_type_is_move(stp) | ||
496 | , is_by::value}); | ||
486 | stp = eolian_type_next_type_get(stp); | 497 | stp = eolian_type_next_type_get(stp); |
487 | } | 498 | } |
488 | original_type = complex; | 499 | original_type = complex; |
@@ -491,7 +502,7 @@ inline void type_def::set(Eolian_Type const* eolian_type, Eolian_Unit const* uni | |||
491 | case EOLIAN_TYPE_CLASS: | 502 | case EOLIAN_TYPE_CLASS: |
492 | { | 503 | { |
493 | Eolian_Class const* klass = eolian_type_class_get(eolian_type); | 504 | Eolian_Class const* klass = eolian_type_class_get(eolian_type); |
494 | original_type = klass_name(klass, {qualifiers(eolian_type, is_moved), {}}); | 505 | original_type = klass_name(klass, {qualifiers(eolian_type, is_moved, is_ptr), {}}); |
495 | } | 506 | } |
496 | break; | 507 | break; |
497 | default: | 508 | default: |
@@ -540,7 +551,12 @@ struct alias_def | |||
540 | is_undefined = true; | 551 | is_undefined = true; |
541 | else | 552 | else |
542 | { | 553 | { |
543 | base_type = type_def(::eolian_typedecl_base_type_get(alias_obj), unit, EOLIAN_C_TYPE_DEFAULT, value_ownership::unmoved); | 554 | auto eolian_type = ::eolian_typedecl_base_type_get(alias_obj); |
555 | base_type = type_def(eolian_type | ||
556 | , unit | ||
557 | , ::eolian_type_c_type_get(eolian_type, EOLIAN_C_TYPE_DEFAULT) | ||
558 | , value_ownership::unmoved | ||
559 | , is_by::value); | ||
544 | is_undefined = false; | 560 | is_undefined = false; |
545 | } | 561 | } |
546 | 562 | ||
@@ -593,7 +609,11 @@ struct parameter_def | |||
593 | documentation_def documentation, Eolian_Unit const* unit) | 609 | documentation_def documentation, Eolian_Unit const* unit) |
594 | : direction(std::move(direction)), type(std::move(type)), param_name(std::move(param_name)), documentation(documentation), unit(unit) {} | 610 | : direction(std::move(direction)), type(std::move(type)), param_name(std::move(param_name)), documentation(documentation), unit(unit) {} |
595 | parameter_def(Eolian_Function_Parameter const* param, Eolian_Unit const* unit) | 611 | parameter_def(Eolian_Function_Parameter const* param, Eolian_Unit const* unit) |
596 | : type( ::eolian_parameter_type_get(param), unit, EOLIAN_C_TYPE_PARAM, eolian_parameter_is_move(param)) | 612 | : type( ::eolian_parameter_type_get(param) |
613 | , unit | ||
614 | , eolian_parameter_c_type_get(param, EINA_FALSE) | ||
615 | , eolian_parameter_is_move(param) | ||
616 | , eolian_parameter_is_by_ref(param)) | ||
597 | , param_name( ::eolian_parameter_name_get(param)), unit(unit) | 617 | , param_name( ::eolian_parameter_name_get(param)), unit(unit) |
598 | { | 618 | { |
599 | Eolian_Parameter_Dir direction = ::eolian_parameter_direction_get(param); | 619 | Eolian_Parameter_Dir direction = ::eolian_parameter_direction_get(param); |
@@ -747,7 +767,11 @@ struct function_def | |||
747 | return_documentation = eolian_function_return_documentation_get(function, type); | 767 | return_documentation = eolian_function_return_documentation_get(function, type); |
748 | scope = static_cast<member_scope>(eolian_function_scope_get(function, type)); | 768 | scope = static_cast<member_scope>(eolian_function_scope_get(function, type)); |
749 | if(r_type) | 769 | if(r_type) |
750 | return_type.set(r_type, unit, EOLIAN_C_TYPE_RETURN, eolian_function_return_is_move(function, type)); | 770 | return_type.set(r_type |
771 | , unit | ||
772 | , eolian_function_return_c_type_get(function, type) | ||
773 | , eolian_function_return_is_move(function, type) | ||
774 | , eolian_function_return_is_by_ref(function, type)); | ||
751 | if(type == EOLIAN_METHOD || type == EOLIAN_FUNCTION_POINTER) | 775 | if(type == EOLIAN_METHOD || type == EOLIAN_FUNCTION_POINTER) |
752 | { | 776 | { |
753 | for(efl::eina::iterator<Eolian_Function_Parameter> param_iterator ( ::eolian_function_parameters_get(function)) | 777 | for(efl::eina::iterator<Eolian_Function_Parameter> param_iterator ( ::eolian_function_parameters_get(function)) |
@@ -1003,7 +1027,11 @@ struct variable_def | |||
1003 | variable_def(Eolian_Variable const* variable, Eolian_Unit const* unit) | 1027 | variable_def(Eolian_Variable const* variable, Eolian_Unit const* unit) |
1004 | : name(::eolian_variable_short_name_get(variable)) | 1028 | : name(::eolian_variable_short_name_get(variable)) |
1005 | , full_name(::eolian_variable_name_get(variable)) | 1029 | , full_name(::eolian_variable_name_get(variable)) |
1006 | , base_type(::eolian_variable_base_type_get(variable), unit, ::EOLIAN_C_TYPE_DEFAULT, value_ownership::unmoved) | 1030 | , base_type(::eolian_variable_base_type_get(variable) |
1031 | , unit | ||
1032 | , ::eolian_type_c_type_get(eolian_variable_base_type_get(variable), ::EOLIAN_C_TYPE_DEFAULT) | ||
1033 | , value_ownership::unmoved | ||
1034 | , is_by::value) | ||
1007 | , documentation(::eolian_variable_documentation_get(variable)) | 1035 | , documentation(::eolian_variable_documentation_get(variable)) |
1008 | , type(static_cast<variable_type>(::eolian_variable_type_get(variable))) | 1036 | , type(static_cast<variable_type>(::eolian_variable_type_get(variable))) |
1009 | , expression_value() | 1037 | , expression_value() |
@@ -1087,7 +1115,12 @@ struct event_def | |||
1087 | 1115 | ||
1088 | event_def(Eolian_Event const* event, Eolian_Class const* cls, Eolian_Unit const* unit) | 1116 | event_def(Eolian_Event const* event, Eolian_Class const* cls, Eolian_Unit const* unit) |
1089 | : klass(cls, {attributes::qualifier_info::is_none, std::string()}) | 1117 | : klass(cls, {attributes::qualifier_info::is_none, std::string()}) |
1090 | , type( ::eolian_event_type_get(event) ? eina::optional<type_def>{{::eolian_event_type_get(event), unit, EOLIAN_C_TYPE_DEFAULT, value_ownership::unmoved}} : eina::optional<type_def>{}) | 1118 | , type( ::eolian_event_type_get(event) ? eina::optional<type_def>{{::eolian_event_type_get(event) |
1119 | , unit | ||
1120 | , ::eolian_type_c_type_get(::eolian_event_type_get(event), EOLIAN_C_TYPE_DEFAULT) | ||
1121 | , value_ownership::unmoved | ||
1122 | , is_by::value} | ||
1123 | } : eina::optional<type_def>{}) | ||
1091 | , name( ::eolian_event_name_get(event)) | 1124 | , name( ::eolian_event_name_get(event)) |
1092 | , c_name( ::eolian_event_c_macro_get(event)) | 1125 | , c_name( ::eolian_event_c_macro_get(event)) |
1093 | , beta( ::eolian_event_is_beta(event)) | 1126 | , beta( ::eolian_event_is_beta(event)) |
@@ -1552,8 +1585,11 @@ struct struct_field_def | |||
1552 | { | 1585 | { |
1553 | name = eolian_typedecl_struct_field_name_get(struct_field); | 1586 | name = eolian_typedecl_struct_field_name_get(struct_field); |
1554 | try { | 1587 | try { |
1555 | type.set(eolian_typedecl_struct_field_type_get(struct_field), unit, EOLIAN_C_TYPE_DEFAULT | 1588 | type.set(eolian_typedecl_struct_field_type_get(struct_field) |
1556 | , eolian_typedecl_struct_field_is_move(struct_field)); | 1589 | , unit |
1590 | , eolian_typedecl_struct_field_c_type_get(struct_field) | ||
1591 | , eolian_typedecl_struct_field_is_move(struct_field) | ||
1592 | , eolian_typedecl_struct_field_is_by_ref(struct_field)); | ||
1557 | } catch(std::runtime_error const&) { /* Silently skip pointer fields*/ } | 1593 | } catch(std::runtime_error const&) { /* Silently skip pointer fields*/ } |
1558 | documentation = ::eolian_typedecl_struct_field_documentation_get(struct_field); | 1594 | documentation = ::eolian_typedecl_struct_field_documentation_get(struct_field); |
1559 | } | 1595 | } |
diff --git a/src/lib/eolian_cxx/grammar/qualifier_def.hpp b/src/lib/eolian_cxx/grammar/qualifier_def.hpp index cab3ca8667..0823010437 100644 --- a/src/lib/eolian_cxx/grammar/qualifier_def.hpp +++ b/src/lib/eolian_cxx/grammar/qualifier_def.hpp | |||
@@ -72,11 +72,11 @@ inline qualifier_bool operator^(qualifier_bool lhs, qualifier_info rhs) | |||
72 | return lhs; | 72 | return lhs; |
73 | } | 73 | } |
74 | 74 | ||
75 | inline qualifier_info qualifiers(Eolian_Type const* type, bool is_moved) | 75 | inline qualifier_info qualifiers(Eolian_Type const* type, bool is_moved, bool is_by_ref) |
76 | { | 76 | { |
77 | qualifier_info is_own = is_moved ? qualifier_info::is_own : qualifier_info::is_none; | 77 | qualifier_info is_own = is_moved ? qualifier_info::is_own : qualifier_info::is_none; |
78 | qualifier_info is_const = ::eolian_type_is_const(type) ? qualifier_info::is_const : qualifier_info::is_none; | 78 | qualifier_info is_const = ::eolian_type_is_const(type) ? qualifier_info::is_const : qualifier_info::is_none; |
79 | qualifier_info is_ref = ::eolian_type_is_ptr(type) ? qualifier_info::is_ref : qualifier_info::is_none; | 79 | qualifier_info is_ref = is_by_ref ? qualifier_info::is_ref : qualifier_info::is_none; |
80 | return is_own | is_const | is_ref; | 80 | return is_own | is_const | is_ref; |
81 | } | 81 | } |
82 | 82 | ||