summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLauro Moura <lauromoura@expertisesolutions.com.br>2019-09-19 20:46:15 -0300
committerLauro Moura <lauromoura@expertisesolutions.com.br>2019-09-19 20:46:15 -0300
commiteaf447d391facf569075c2d937954bf6baf6b3bb (patch)
tree3264e8756482d59798823767b9dc35f875a69268
parente973b87bf845bc6375b7608be40ba9a0851cd4e6 (diff)
csharp: WIP Add support for default param referencesdevs/lauromoura/default_params
-rw-r--r--src/bin/eolian_mono/eolian/mono/documentation.hh11
-rw-r--r--src/bin/eolian_mono/eolian/mono/name_helpers.hh24
-rw-r--r--src/lib/eolian_cxx/grammar/klass_def.hpp102
3 files changed, 113 insertions, 24 deletions
diff --git a/src/bin/eolian_mono/eolian/mono/documentation.hh b/src/bin/eolian_mono/eolian/mono/documentation.hh
index 6cf57fd342..bad574ea80 100644
--- a/src/bin/eolian_mono/eolian/mono/documentation.hh
+++ b/src/bin/eolian_mono/eolian/mono/documentation.hh
@@ -526,7 +526,16 @@ struct documentation_generator
526 template<typename OutputIterator, typename Context> 526 template<typename OutputIterator, typename Context>
527 bool generate_parameter(OutputIterator sink, attributes::parameter_def const& param, Context const& context) const 527 bool generate_parameter(OutputIterator sink, attributes::parameter_def const& param, Context const& context) const
528 { 528 {
529 return generate_tag_param(sink, name_helpers::escape_keyword(param.param_name), param.documentation.full_text, context); 529 auto text = param.documentation.full_text;
530 if (param.default_value.is_engaged())
531 {
532 auto value = param.default_value->serialized;
533
534 if (param.default_value->is_name_ref)
535 value = name_helpers::full_managed_name(value);
536 text += "\nThis parameter has a default value of \\<c\\>" + value + "\\</c\\>";
537 }
538 return generate_tag_param(sink, name_helpers::escape_keyword(param.param_name), text, context);
530 } 539 }
531 540
532 template<typename OutputIterator, typename Context> 541 template<typename OutputIterator, typename Context>
diff --git a/src/bin/eolian_mono/eolian/mono/name_helpers.hh b/src/bin/eolian_mono/eolian/mono/name_helpers.hh
index a1fd8cd6d0..b2063116e0 100644
--- a/src/bin/eolian_mono/eolian/mono/name_helpers.hh
+++ b/src/bin/eolian_mono/eolian/mono/name_helpers.hh
@@ -204,6 +204,30 @@ inline std::string managed_name(std::string const& name, char separator='_')
204 return utils::to_pascal_case(tokens); 204 return utils::to_pascal_case(tokens);
205} 205}
206 206
207inline std::string full_managed_name(std::string const& name)
208{
209 std::stringstream ss;
210
211 auto words = utils::split(name, '.');
212 std::transform(words.begin(), words.end(), words.begin(), [](std::string const& word) {
213 return managed_name(word);
214 });
215
216 auto b = std::begin(words), e = std::end(words);
217
218 if (b != e)
219 {
220 std::copy(b, std::prev(e), std::ostream_iterator<std::string>(ss, "."));
221 b = std::prev(e);
222 }
223
224 // Avoid trailing separator
225 if (b != e)
226 ss << *b;
227
228 return ss.str();
229}
230
207inline std::string alias_full_eolian_name(attributes::alias_def const& alias) 231inline std::string alias_full_eolian_name(attributes::alias_def const& alias)
208{ 232{
209 233
diff --git a/src/lib/eolian_cxx/grammar/klass_def.hpp b/src/lib/eolian_cxx/grammar/klass_def.hpp
index 683bb000a4..7b8bd35a2e 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,36 @@ 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");
521 break; 537 break;
522 default: 538 default:
523 // FIXME implement the remaining types 539 // FIXME implement the remaining types
524 EINA_LOG_ERR("Unsupported expression type"); 540 EINA_LOG_ERR("Unsupported expression type : %d", eolian_exp_type);
525 std::abort(); 541 std::abort();
526 break; 542 break;
527 } 543 }
528} 544}
529 545
546inline void type_def::set(const char* regular_name, const char* c_type)
547{
548 original_type = attributes::regular_type_def{regular_name, {{}, {}}, {}};
549 this->c_type = c_type;
550}
551
530struct alias_def 552struct alias_def
531{ 553{
532 std::string eolian_name; 554 std::string eolian_name;
@@ -585,12 +607,57 @@ struct add_optional_qualifier_visitor
585}; 607};
586} 608}
587 609
610struct value_def
611{
612 typedef eina::variant<int> variant_type; // FIXME support other types
613 variant_type value;
614 std::string literal;
615 type_def type;
616
617 value_def() = default;
618 value_def(Eolian_Value value_obj)
619 {
620 type.set(value_obj.type);
621 value = value_obj.value.i;
622 literal = eolian_expression_value_to_literal(&value_obj);
623 }
624};
625
626
627struct expression_def
628{
629 value_def value;
630 std::string serialized;
631 // We store this explicitly as evaluating the value reduces a name reference
632 // to a plain string value.
633 bool is_name_ref;
634
635 friend inline bool operator==(expression_def const& lhs, expression_def const& rhs)
636 {
637 return lhs.serialized == rhs.serialized;
638 }
639 friend inline bool operator!=(expression_def const& lhs, expression_def const& rhs)
640 {
641 return lhs != rhs;
642 }
643
644 expression_def(Eolian_Expression const* expression) : value(::eolian_expression_eval(expression, EOLIAN_MASK_ALL))
645 , serialized()
646 , is_name_ref(::eolian_expression_type_get(expression) == EOLIAN_EXPR_NAME)
647 {
648 auto serialized_s = ::eolian_expression_serialize(expression);
649 serialized = serialized_s;
650 ::eina_stringshare_del(serialized_s);
651 }
652};
653
588struct parameter_def 654struct parameter_def
589{ 655{
590 parameter_direction direction; 656 parameter_direction direction;
591 type_def type; 657 type_def type;
592 std::string param_name; 658 std::string param_name;
593 documentation_def documentation; 659 documentation_def documentation;
660 eina::optional<expression_def> default_value;
594 Eolian_Unit const* unit; 661 Eolian_Unit const* unit;
595 662
596 friend inline bool operator==(parameter_def const& lhs, parameter_def const& rhs) 663 friend inline bool operator==(parameter_def const& lhs, parameter_def const& rhs)
@@ -598,7 +665,8 @@ struct parameter_def
598 return lhs.direction == rhs.direction 665 return lhs.direction == rhs.direction
599 && lhs.type == rhs.type 666 && lhs.type == rhs.type
600 && lhs.param_name == rhs.param_name 667 && lhs.param_name == rhs.param_name
601 && lhs.documentation == rhs.documentation; 668 && lhs.documentation == rhs.documentation
669 && lhs.default_value == rhs.default_value;
602 } 670 }
603 friend inline bool operator!=(parameter_def const& lhs, parameter_def const& rhs) 671 friend inline bool operator!=(parameter_def const& lhs, parameter_def const& rhs)
604 { 672 {
@@ -608,13 +676,17 @@ struct parameter_def
608 parameter_def(parameter_direction direction, type_def type, std::string param_name, 676 parameter_def(parameter_direction direction, type_def type, std::string param_name,
609 documentation_def documentation, Eolian_Unit const* unit) 677 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) {} 678 : 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) 679 parameter_def(Eolian_Function_Parameter const* param, Eolian_Unit const* _unit)
612 : type( ::eolian_parameter_type_get(param) 680 : type( ::eolian_parameter_type_get(param)
613 , unit 681 , _unit
614 , eolian_parameter_c_type_get(param, EINA_FALSE) 682 , eolian_parameter_c_type_get(param, EINA_FALSE)
615 , eolian_parameter_is_move(param) 683 , eolian_parameter_is_move(param)
616 , eolian_parameter_is_by_ref(param)) 684 , eolian_parameter_is_by_ref(param))
617 , param_name( ::eolian_parameter_name_get(param)), unit(unit) 685 , param_name( ::eolian_parameter_name_get(param))
686 , default_value(::eolian_parameter_default_value_get(param) ?
687 ::eolian_parameter_default_value_get(param) :
688 eina::optional<expression_def>{})
689 , unit(_unit)
618 { 690 {
619 Eolian_Parameter_Dir direction = ::eolian_parameter_direction_get(param); 691 Eolian_Parameter_Dir direction = ::eolian_parameter_direction_get(param);
620 switch(direction) 692 switch(direction)
@@ -1533,22 +1605,6 @@ struct klass_def
1533 } 1605 }
1534}; 1606};
1535 1607
1536struct value_def
1537{
1538 typedef eina::variant<int> variant_type; // FIXME support other types
1539 variant_type value;
1540 std::string literal;
1541 type_def type;
1542
1543 value_def() = default;
1544 value_def(Eolian_Value value_obj)
1545 {
1546 type.set(value_obj.type);
1547 value = value_obj.value.i;
1548 literal = eolian_expression_value_to_literal(&value_obj);
1549 }
1550};
1551
1552struct enum_value_def 1608struct enum_value_def
1553{ 1609{
1554 value_def value; 1610 value_def value;