summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLauro Moura <lauromoura@expertisesolutions.com.br>2019-12-09 16:40:13 -0300
committerLauro Moura <lauromoura@expertisesolutions.com.br>2019-12-09 16:40:13 -0300
commitf793939315b37a6a8332af0ec870a0af1b6ad434 (patch)
tree6f447695b30582fb5d66103b0b385c07fd4d4c27
parent06c2bbf798ca318efe23baec8e6454f8c5b177f4 (diff)
csharp: Refactor annotation selection function
Summary: Better names to convey their intent and formatting. Removing the hardcoded `return` from them will also free the return list to be used for `@out` parameters as they have similar semantics to `return`, different from regular `@in` parameters. This change in behavior will come in a future commit, and explains why are are keeping both lists for now despite being essentially the same. Ref T8515 Test Plan: Run existing tests Reviewers: felipealmeida, brunobelo, jptiz, YOhoho Reviewed By: jptiz Subscribers: cedric, #reviewers, #committers Tags: #efl Maniphest Tasks: T8515 Differential Revision: https://phab.enlightenment.org/D10827
-rw-r--r--src/bin/eolian_mono/eolian/mono/marshall_annotation.hh133
1 files changed, 69 insertions, 64 deletions
diff --git a/src/bin/eolian_mono/eolian/mono/marshall_annotation.hh b/src/bin/eolian_mono/eolian/mono/marshall_annotation.hh
index 081145144c..90da376a73 100644
--- a/src/bin/eolian_mono/eolian/mono/marshall_annotation.hh
+++ b/src/bin/eolian_mono/eolian/mono/marshall_annotation.hh
@@ -28,15 +28,15 @@ namespace eina = efl::eina;
28 28
29namespace detail { 29namespace detail {
30 30
31template <typename Array, typename F, int N, typename A> 31template <typename Array, typename SelectionPredicate, int N, typename AcceptFunc>
32eina::optional<bool> call_annotation_match(Array const (&array)[N], F f, A a) 32eina::optional<bool> call_annotation_match(Array const (&array)[N], SelectionPredicate predicate, AcceptFunc acceptFunc)
33{ 33{
34 typedef Array const* iterator_type; 34 typedef Array const* iterator_type;
35 iterator_type match_iterator = &array[0], match_last = match_iterator + N; 35 iterator_type match_iterator = &array[0], match_last = match_iterator + N;
36 match_iterator = std::find_if(match_iterator, match_last, f); 36 match_iterator = std::find_if(match_iterator, match_last, predicate);
37 if(match_iterator != match_last) 37 if(match_iterator != match_last)
38 { 38 {
39 return a(match_iterator->function()); 39 return acceptFunc(match_iterator->function());
40 } 40 }
41 return {nullptr}; 41 return {nullptr};
42} 42}
@@ -63,103 +63,108 @@ struct marshall_annotation_visitor_generate
63 eina::optional<bool> has_own; 63 eina::optional<bool> has_own;
64 std::function<std::string()> function; 64 std::function<std::string()> function;
65 }; 65 };
66 // These two tables are currently the same but will hold different marshallers
67 // for @in and @out/return semantics in a future commit.
66 match const parameter_match_table[] = 68 match const parameter_match_table[] =
67 { 69 {
68 // signed primitives 70 // signed primitives
69 {"bool", nullptr, [&] { return "[MarshalAs(UnmanagedType.U1)]"; }}, 71 {"bool", nullptr, [] { return "MarshalAs(UnmanagedType.U1)"; }},
70 {"string", true, [&] { 72 {"string", true, [] {
71 return "[MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Efl.Eo.StringPassOwnershipMarshaler))]"; 73 return "MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Efl.Eo.StringPassOwnershipMarshaler))";
72 }}, 74 }},
73 {"string", false, [&] { 75 {"string", false, [] {
74 return "[MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Efl.Eo.StringKeepOwnershipMarshaler))]"; 76 return "MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Efl.Eo.StringKeepOwnershipMarshaler))";
75 }}, 77 }},
76 {"mstring", true, [&] { 78 {"mstring", true, [] {
77 return "[MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Efl.Eo.StringPassOwnershipMarshaler))]"; 79 return "MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Efl.Eo.StringPassOwnershipMarshaler))";
78 }}, 80 }},
79 {"mstring", false, [&] { 81 {"mstring", false, [] {
80 return "[MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Efl.Eo.StringKeepOwnershipMarshaler))]"; 82 return "MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Efl.Eo.StringKeepOwnershipMarshaler))";
81 }}, 83 }},
82 {"stringshare", true, [&] { 84 {"stringshare", true, [] {
83 return "[MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Efl.Eo.StringsharePassOwnershipMarshaler))]"; 85 return "MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Efl.Eo.StringsharePassOwnershipMarshaler))";
84 }}, 86 }},
85 {"stringshare", false, [&] { 87 {"stringshare", false, [] {
86 return "[MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Efl.Eo.StringshareKeepOwnershipMarshaler))]"; 88 return "MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Efl.Eo.StringshareKeepOwnershipMarshaler))";
87 }}, 89 }},
88 {"any_value_ref", true, [&] { 90 {"any_value_ref", true, [] {
89 return "[MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Eina.ValueMarshalerOwn))]"; 91 return "MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Eina.ValueMarshalerOwn))";
90 }}, 92 }},
91 {"any_value_ref", false, [&] { 93 {"any_value_ref", false, [] {
92 return "[MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Eina.ValueMarshaler))]"; 94 return "MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Eina.ValueMarshaler))";
93 }}, 95 }},
94 {"strbuf", true, [&] { 96 {"strbuf", true, [] {
95 return "[MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Efl.Eo.StrbufPassOwnershipMarshaler))]"; 97 return "MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Efl.Eo.StrbufPassOwnershipMarshaler))";
96 }}, 98 }},
97 {"strbuf", false, [&] { 99 {"strbuf", false, [] {
98 return "[MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Efl.Eo.StrbufKeepOwnershipMarshaler))]"; 100 return "MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Efl.Eo.StrbufKeepOwnershipMarshaler))";
99 }}, 101 }},
100 {"Value_Type", false, [&] { 102 {"Value_Type", false, [] {
101 return "[MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Eina.ValueTypeMarshaler))]"; 103 return "MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Eina.ValueTypeMarshaler))";
102 }}, 104 }},
103 }; 105 };
104 match const return_match_table[] = 106 match const return_match_table[] =
105 { 107 {
106 // signed primitives 108 // signed primitives
107 {"bool", nullptr, [&] { return "[return: MarshalAs(UnmanagedType.U1)]"; }}, 109 {"bool", nullptr, [] { return "MarshalAs(UnmanagedType.U1)"; }},
108 {"string", true, [&] { 110 {"string", true, [] {
109 return "[return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Efl.Eo.StringPassOwnershipMarshaler))]"; 111 return "MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Efl.Eo.StringPassOwnershipMarshaler))";
110 }}, 112 }},
111 {"string", nullptr, [&] { 113 {"string", false, [] {
112 return "[return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Efl.Eo.StringKeepOwnershipMarshaler))]"; 114 return "MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Efl.Eo.StringKeepOwnershipMarshaler))";
113 }}, 115 }},
114 {"mstring", true, [&] { 116 {"mstring", true, [] {
115 return "[return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Efl.Eo.StringPassOwnershipMarshaler))]"; 117 return "MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Efl.Eo.StringPassOwnershipMarshaler))";
116 }}, 118 }},
117 {"mstring", false, [&] { 119 {"mstring", false, [] {
118 return "[return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Efl.Eo.StringKeepOwnershipMarshaler))]"; 120 return "MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Efl.Eo.StringKeepOwnershipMarshaler))";
119 }}, 121 }},
120 {"stringshare", true, [&] { 122 {"stringshare", true, [] {
121 return "[return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Efl.Eo.StringsharePassOwnershipMarshaler))]"; 123 return "MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Efl.Eo.StringsharePassOwnershipMarshaler))";
122 }}, 124 }},
123 {"stringshare", false, [&] { 125 {"stringshare", false, [] {
124 return "[return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Efl.Eo.StringshareKeepOwnershipMarshaler))]"; 126 return "MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Efl.Eo.StringshareKeepOwnershipMarshaler))";
125 }}, 127 }},
126 {"any_value_ref", true, [&] { 128 {"any_value_ref", true, [] {
127 return "[return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Eina.ValueMarshalerOwn))]"; 129 return "MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Eina.ValueMarshalerOwn))";
128 }}, 130 }},
129 {"any_value_ref", false, [&] { 131 {"any_value_ref", false, [] {
130 return "[return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Eina.ValueMarshaler))]"; 132 return "MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Eina.ValueMarshaler))";
131 }}, 133 }},
132 {"strbuf", true, [&] { 134 {"strbuf", true, [] {
133 return "[return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Efl.Eo.StrbufPassOwnershipMarshaler))]"; 135 return "MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Efl.Eo.StrbufPassOwnershipMarshaler))";
134 }}, 136 }},
135 {"strbuf", false, [&] { 137 {"strbuf", false, [] {
136 return "[return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Efl.Eo.StrbufKeepOwnershipMarshaler))]"; 138 return "MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Efl.Eo.StrbufKeepOwnershipMarshaler))";
137 }}, 139 }},
138 {"Value_Type", false, [&] { 140 {"Value_Type", false, [] {
139 return "[return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Eina.ValueTypeMarshaler))]"; 141 return "MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Eina.ValueTypeMarshaler))";
140 }}, 142 }},
141 }; 143 };
142 144
143 if(eina::optional<bool> b = call_annotation_match 145 auto predicate = [&regular] (match const& m)
144 ((is_return ? return_match_table : parameter_match_table)
145 , [&] (match const& m)
146 { 146 {
147 return (!m.name || *m.name == regular.base_type) 147 return (!m.name || *m.name == regular.base_type)
148 && (!m.has_own || *m.has_own == (bool)(regular.base_qualifier & qualifier_info::is_own)) 148 && (!m.has_own || *m.has_own == (bool)(regular.base_qualifier & qualifier_info::is_own))
149 ; 149 ;
150 };
151
152 auto acceptCb = [this] (std::string const& marshalTag)
153 {
154 std::string prefix = is_return ? "return: " : "";
155 return as_generator("[" << prefix << marshalTag << "]").generate(sink, nullptr, *context);
156 };
157
158 const auto& match_table = is_return ? return_match_table : parameter_match_table;
159
160 if(eina::optional<bool> b = call_annotation_match(match_table, predicate, acceptCb))
161 {
162 return *b;
150 } 163 }
151 , [&] (std::string const& string) 164 else
152 { 165 {
153 std::copy(string.begin(), string.end(), sink); 166 return true;
154 return true; 167 }
155 }))
156 {
157 return *b;
158 }
159 else
160 {
161 return true;
162 }
163 } 168 }
164 bool operator()(attributes::klass_name const& klass_name) const 169 bool operator()(attributes::klass_name const& klass_name) const
165 { 170 {