summaryrefslogtreecommitdiff
path: root/src/lib/eolian_cxx/grammar/klass_def.hpp
diff options
context:
space:
mode:
authorLauro Moura <lauromoura@expertisesolutions.com.br>2019-09-20 16:05:01 +0200
committerXavi Artigas <xavierartigas@yahoo.es>2019-09-20 16:23:54 +0200
commit32f92d3d869f889d729314574bf4e3b5c14a3e29 (patch)
tree4b624c371253ca8ee3cac4a864e2cf52e716d344 /src/lib/eolian_cxx/grammar/klass_def.hpp
parent4672598b032d27c1b63e4c6271de12f21f41e380 (diff)
csharp: Add support for default param references in documentation
Summary: This also adds the information of default values in `parameter_def`. This will help adding actual default parameter support in the C# bindings. Thanks to @segfaultxavi for improved formatting and escaping. Fixes T8224 Reviewers: segfaultxavi, felipealmeida, brunobelo Reviewed By: segfaultxavi Subscribers: cedric, #reviewers, segfaultxavi, #committers Tags: #efl Maniphest Tasks: T8224 Differential Revision: https://phab.enlightenment.org/D10050
Diffstat (limited to '')
-rw-r--r--src/lib/eolian_cxx/grammar/klass_def.hpp105
1 files changed, 82 insertions, 23 deletions
diff --git a/src/lib/eolian_cxx/grammar/klass_def.hpp b/src/lib/eolian_cxx/grammar/klass_def.hpp
index a3f3f3d7df..b1f6c383a3 100644
--- a/src/lib/eolian_cxx/grammar/klass_def.hpp
+++ b/src/lib/eolian_cxx/grammar/klass_def.hpp
@@ -412,6 +412,9 @@ struct type_def
412 << rhs.c_type << " has_own " << rhs.has_own << " is_ptr " 412 << rhs.c_type << " has_own " << rhs.has_own << " is_ptr "
413 << rhs.is_ptr << "]"; 413 << rhs.is_ptr << "]";
414 } 414 }
415
416private:
417 void set(const char* regular_name, const char* c_type);
415}; 418};
416 419
417struct get_qualifier_visitor 420struct get_qualifier_visitor
@@ -516,17 +519,39 @@ inline void type_def::set(Eolian_Expression_Type eolian_exp_type)
516 switch(eolian_exp_type) 519 switch(eolian_exp_type)
517 { 520 {
518 case EOLIAN_EXPR_INT: 521 case EOLIAN_EXPR_INT:
519 original_type = attributes::regular_type_def{"int", {{}, {}}, {}}; 522 set("int", "int");
520 c_type = "int"; 523 break;
524 case EOLIAN_EXPR_UINT:
525 set("uint", "unsigned int");
526 break;
527 case EOLIAN_EXPR_FLOAT:
528 set("float", "float");
529 break;
530 case EOLIAN_EXPR_DOUBLE:
531 set("double", "double");
532 break;
533 case EOLIAN_EXPR_STRING:
534 set("string", "const char *");
535 case EOLIAN_EXPR_BOOL:
536 set("bool", "Eina_Bool");
537 break;
538 case EOLIAN_EXPR_NULL:
539 set("null", "void *");
521 break; 540 break;
522 default: 541 default:
523 // FIXME implement the remaining types 542 // FIXME implement the remaining types
524 EINA_LOG_ERR("Unsupported expression type"); 543 EINA_LOG_ERR("Unsupported expression type : %d", eolian_exp_type);
525 std::abort(); 544 std::abort();
526 break; 545 break;
527 } 546 }
528} 547}
529 548
549inline void type_def::set(const char* regular_name, const char* c_type)
550{
551 original_type = attributes::regular_type_def{regular_name, {{}, {}}, {}};
552 this->c_type = c_type;
553}
554
530struct alias_def 555struct alias_def
531{ 556{
532 std::string eolian_name; 557 std::string eolian_name;
@@ -585,12 +610,57 @@ struct add_optional_qualifier_visitor
585}; 610};
586} 611}
587 612
613struct value_def
614{
615 typedef eina::variant<int> variant_type; // FIXME support other types
616 variant_type value;
617 std::string literal;
618 type_def type;
619
620 value_def() = default;
621 value_def(Eolian_Value value_obj)
622 {
623 type.set(value_obj.type);
624 value = value_obj.value.i;
625 literal = eolian_expression_value_to_literal(&value_obj);
626 }
627};
628
629
630struct expression_def
631{
632 value_def value;
633 std::string serialized;
634 // We store this explicitly as evaluating the value reduces a name reference
635 // to a plain string value.
636 bool is_name_ref;
637
638 friend inline bool operator==(expression_def const& lhs, expression_def const& rhs)
639 {
640 return lhs.serialized == rhs.serialized;
641 }
642 friend inline bool operator!=(expression_def const& lhs, expression_def const& rhs)
643 {
644 return lhs != rhs;
645 }
646
647 expression_def(Eolian_Expression const* expression) : value(::eolian_expression_eval(expression, EOLIAN_MASK_ALL))
648 , serialized()
649 , is_name_ref(::eolian_expression_type_get(expression) == EOLIAN_EXPR_NAME)
650 {
651 auto serialized_s = ::eolian_expression_serialize(expression);
652 serialized = serialized_s;
653 ::eina_stringshare_del(serialized_s);
654 }
655};
656
588struct parameter_def 657struct parameter_def
589{ 658{
590 parameter_direction direction; 659 parameter_direction direction;
591 type_def type; 660 type_def type;
592 std::string param_name; 661 std::string param_name;
593 documentation_def documentation; 662 documentation_def documentation;
663 eina::optional<expression_def> default_value;
594 Eolian_Unit const* unit; 664 Eolian_Unit const* unit;
595 665
596 friend inline bool operator==(parameter_def const& lhs, parameter_def const& rhs) 666 friend inline bool operator==(parameter_def const& lhs, parameter_def const& rhs)
@@ -598,7 +668,8 @@ struct parameter_def
598 return lhs.direction == rhs.direction 668 return lhs.direction == rhs.direction
599 && lhs.type == rhs.type 669 && lhs.type == rhs.type
600 && lhs.param_name == rhs.param_name 670 && lhs.param_name == rhs.param_name
601 && lhs.documentation == rhs.documentation; 671 && lhs.documentation == rhs.documentation
672 && lhs.default_value == rhs.default_value;
602 } 673 }
603 friend inline bool operator!=(parameter_def const& lhs, parameter_def const& rhs) 674 friend inline bool operator!=(parameter_def const& lhs, parameter_def const& rhs)
604 { 675 {
@@ -608,13 +679,17 @@ struct parameter_def
608 parameter_def(parameter_direction direction, type_def type, std::string param_name, 679 parameter_def(parameter_direction direction, type_def type, std::string param_name,
609 documentation_def documentation, Eolian_Unit const* unit) 680 documentation_def documentation, Eolian_Unit const* unit)
610 : direction(std::move(direction)), type(std::move(type)), param_name(std::move(param_name)), documentation(documentation), unit(unit) {} 681 : direction(std::move(direction)), type(std::move(type)), param_name(std::move(param_name)), documentation(documentation), unit(unit) {}
611 parameter_def(Eolian_Function_Parameter const* param, Eolian_Unit const* unit) 682 parameter_def(Eolian_Function_Parameter const* param, Eolian_Unit const* _unit)
612 : type( ::eolian_parameter_type_get(param) 683 : type( ::eolian_parameter_type_get(param)
613 , unit 684 , _unit
614 , eolian_parameter_c_type_get(param, EINA_FALSE) 685 , eolian_parameter_c_type_get(param, EINA_FALSE)
615 , eolian_parameter_is_move(param) 686 , eolian_parameter_is_move(param)
616 , eolian_parameter_is_by_ref(param)) 687 , eolian_parameter_is_by_ref(param))
617 , param_name( ::eolian_parameter_name_get(param)), unit(unit) 688 , param_name( ::eolian_parameter_name_get(param))
689 , default_value(::eolian_parameter_default_value_get(param) ?
690 ::eolian_parameter_default_value_get(param) :
691 eina::optional<expression_def>{})
692 , unit(_unit)
618 { 693 {
619 Eolian_Parameter_Dir direction = ::eolian_parameter_direction_get(param); 694 Eolian_Parameter_Dir direction = ::eolian_parameter_direction_get(param);
620 switch(direction) 695 switch(direction)
@@ -1530,22 +1605,6 @@ struct klass_def
1530 } 1605 }
1531}; 1606};
1532 1607
1533struct value_def
1534{
1535 typedef eina::variant<int> variant_type; // FIXME support other types
1536 variant_type value;
1537 std::string literal;
1538 type_def type;
1539
1540 value_def() = default;
1541 value_def(Eolian_Value value_obj)
1542 {
1543 type.set(value_obj.type);
1544 value = value_obj.value.i;
1545 literal = eolian_expression_value_to_literal(&value_obj);
1546 }
1547};
1548
1549struct enum_value_def 1608struct enum_value_def
1550{ 1609{
1551 value_def value; 1610 value_def value;