summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/bin/eolian_mono/eolian/mono/events.hh12
-rw-r--r--src/bin/eolian_mono/eolian/mono/marshall_annotation.hh16
-rw-r--r--src/bin/eolian_mono/eolian/mono/marshall_type_impl.hh5
-rw-r--r--src/bin/eolian_mono/eolian/mono/type_impl.hh20
-rw-r--r--src/bin/eolian_mono/eolian/mono/type_match.hh46
5 files changed, 63 insertions, 36 deletions
diff --git a/src/bin/eolian_mono/eolian/mono/events.hh b/src/bin/eolian_mono/eolian/mono/events.hh
index a4289af559..f0367c31dc 100644
--- a/src/bin/eolian_mono/eolian/mono/events.hh
+++ b/src/bin/eolian_mono/eolian/mono/events.hh
@@ -18,14 +18,18 @@
18 18
19#include <iterator> 19#include <iterator>
20 20
21#include <Eina.hh>
22
21#include "grammar/generator.hpp" 23#include "grammar/generator.hpp"
22#include "grammar/klass_def.hpp" 24#include "grammar/klass_def.hpp"
23#include "type_impl.hh" // For call_match 25#include "type_match.hh"
24#include "name_helpers.hh" 26#include "name_helpers.hh"
25#include "using_decl.hh" 27#include "using_decl.hh"
26 28
27namespace eolian_mono { 29namespace eolian_mono {
28 30
31namespace eina = efl::eina;
32
29template<typename OutputIterator, typename Context> 33template<typename OutputIterator, typename Context>
30struct unpack_event_args_visitor 34struct unpack_event_args_visitor
31{ 35{
@@ -114,7 +118,7 @@ struct unpack_event_args_visitor
114 return as_generator(conversion).generate(sink, attributes::unused, *context); 118 return as_generator(conversion).generate(sink, attributes::unused, *context);
115 }; 119 };
116 120
117 if (eina::optional<bool> b = call_match(match_table, filter_func, accept_func)) 121 if (eina::optional<bool> b = type_match::get_match(match_table, filter_func, accept_func))
118 return *b; 122 return *b;
119 else 123 else
120 { 124 {
@@ -188,7 +192,7 @@ struct pack_event_info_and_call_visitor
188 ).generate(sink, attributes::unused, *context); 192 ).generate(sink, attributes::unused, *context);
189 }; 193 };
190 194
191 if (eina::optional<bool> b = call_match(str_table, filter_func, str_accept_func)) 195 if (eina::optional<bool> b = type_match::get_match(str_table, filter_func, str_accept_func))
192 return *b; 196 return *b;
193 197
194 match const value_table [] = 198 match const value_table [] =
@@ -206,7 +210,7 @@ struct pack_event_info_and_call_visitor
206 ).generate(sink, attributes::unused, *context); 210 ).generate(sink, attributes::unused, *context);
207 }; 211 };
208 212
209 if (eina::optional<bool> b = call_match(value_table, filter_func, value_accept_func)) 213 if (eina::optional<bool> b = type_match::get_match(value_table, filter_func, value_accept_func))
210 return *b; 214 return *b;
211 215
212 return value_accept_func("e.args"); 216 return value_accept_func("e.args");
diff --git a/src/bin/eolian_mono/eolian/mono/marshall_annotation.hh b/src/bin/eolian_mono/eolian/mono/marshall_annotation.hh
index 90da376a73..a9fc45d7da 100644
--- a/src/bin/eolian_mono/eolian/mono/marshall_annotation.hh
+++ b/src/bin/eolian_mono/eolian/mono/marshall_annotation.hh
@@ -21,25 +21,13 @@
21#include "grammar/case.hpp" 21#include "grammar/case.hpp"
22#include "name_helpers.hh" 22#include "name_helpers.hh"
23#include "type_impl.hh" 23#include "type_impl.hh"
24#include "type_match.hh"
24 25
25namespace eolian_mono { 26namespace eolian_mono {
26 27
27namespace eina = efl::eina; 28namespace eina = efl::eina;
28 29
29namespace detail { 30namespace detail {
30
31template <typename Array, typename SelectionPredicate, int N, typename AcceptFunc>
32eina::optional<bool> call_annotation_match(Array const (&array)[N], SelectionPredicate predicate, AcceptFunc acceptFunc)
33{
34 typedef Array const* iterator_type;
35 iterator_type match_iterator = &array[0], match_last = match_iterator + N;
36 match_iterator = std::find_if(match_iterator, match_last, predicate);
37 if(match_iterator != match_last)
38 {
39 return acceptFunc(match_iterator->function());
40 }
41 return {nullptr};
42}
43 31
44template <typename OutputIterator, typename Context> 32template <typename OutputIterator, typename Context>
45struct marshall_annotation_visitor_generate 33struct marshall_annotation_visitor_generate
@@ -157,7 +145,7 @@ struct marshall_annotation_visitor_generate
157 145
158 const auto& match_table = is_return ? return_match_table : parameter_match_table; 146 const auto& match_table = is_return ? return_match_table : parameter_match_table;
159 147
160 if(eina::optional<bool> b = call_annotation_match(match_table, predicate, acceptCb)) 148 if(eina::optional<bool> b = type_match::get_match(match_table, predicate, acceptCb))
161 { 149 {
162 return *b; 150 return *b;
163 } 151 }
diff --git a/src/bin/eolian_mono/eolian/mono/marshall_type_impl.hh b/src/bin/eolian_mono/eolian/mono/marshall_type_impl.hh
index 69b4a9afc1..4d1e188997 100644
--- a/src/bin/eolian_mono/eolian/mono/marshall_type_impl.hh
+++ b/src/bin/eolian_mono/eolian/mono/marshall_type_impl.hh
@@ -21,6 +21,7 @@
21#include "grammar/case.hpp" 21#include "grammar/case.hpp"
22#include "helpers.hh" 22#include "helpers.hh"
23#include "name_helpers.hh" 23#include "name_helpers.hh"
24#include "type_match.hh"
24#include "type_impl.hh" 25#include "type_impl.hh"
25#include "generation_contexts.hh" 26#include "generation_contexts.hh"
26#include "blacklist.hh" 27#include "blacklist.hh"
@@ -192,7 +193,7 @@ struct marshall_type_visitor_generate
192 return as_generator(string << ".NativeStruct") 193 return as_generator(string << ".NativeStruct")
193 .generate(sink, name_helpers::type_full_managed_name(regular), *context); 194 .generate(sink, name_helpers::type_full_managed_name(regular), *context);
194 } 195 }
195 else if (eina::optional<bool> b = call_match 196 else if (eina::optional<bool> b = type_match::get_match
196 (match_table 197 (match_table
197 , [&] (match const& m) 198 , [&] (match const& m)
198 { 199 {
@@ -296,7 +297,7 @@ struct marshall_type_visitor_generate
296 && as_generator("<" << (type(false, false, true) % ", ") << ">").generate(sink, complex.subtypes, *context); 297 && as_generator("<" << (type(false, false, true) % ", ") << ">").generate(sink, complex.subtypes, *context);
297 }; 298 };
298 299
299 if(eina::optional<bool> b = call_match 300 if(eina::optional<bool> b = type_match::get_match
300 (matches 301 (matches
301 , [&] (match const& m) 302 , [&] (match const& m)
302 { 303 {
diff --git a/src/bin/eolian_mono/eolian/mono/type_impl.hh b/src/bin/eolian_mono/eolian/mono/type_impl.hh
index 2dd2c34ae9..fb521f273e 100644
--- a/src/bin/eolian_mono/eolian/mono/type_impl.hh
+++ b/src/bin/eolian_mono/eolian/mono/type_impl.hh
@@ -20,6 +20,7 @@
20#include "grammar/klass_def.hpp" 20#include "grammar/klass_def.hpp"
21#include "grammar/case.hpp" 21#include "grammar/case.hpp"
22#include "name_helpers.hh" 22#include "name_helpers.hh"
23#include "type_match.hh"
23 24
24namespace eolian_mono { 25namespace eolian_mono {
25 26
@@ -69,19 +70,6 @@ attributes::complex_type_def replace_outer(attributes::complex_type_def v, attri
69 v.outer = regular; 70 v.outer = regular;
70 return v; 71 return v;
71} 72}
72
73template <typename Array, typename F, int N, typename A>
74eina::optional<bool> call_match(Array const (&array)[N], F f, A a)
75{
76 typedef Array const* iterator_type;
77 iterator_type match_iterator = &array[0], match_last = match_iterator + N;
78 match_iterator = std::find_if(match_iterator, match_last, f);
79 if(match_iterator != match_last)
80 {
81 return a(match_iterator->function());
82 }
83 return {nullptr};
84}
85 73
86template <typename OutputIterator, typename Context> 74template <typename OutputIterator, typename Context>
87struct visitor_regular_type_def_printer 75struct visitor_regular_type_def_printer
@@ -248,7 +236,7 @@ struct visitor_generate
248 }} // FIXME add proper support for any_value_ref 236 }} // FIXME add proper support for any_value_ref
249 }; 237 };
250 std::string full_type_name = name_helpers::type_full_eolian_name(regular); 238 std::string full_type_name = name_helpers::type_full_eolian_name(regular);
251 if(eina::optional<bool> b = call_match 239 if(eina::optional<bool> b = type_match::get_match
252 (optional_match_table 240 (optional_match_table
253 , [&] (match const& m) 241 , [&] (match const& m)
254 { 242 {
@@ -271,7 +259,7 @@ struct visitor_generate
271 is_optional = false; 259 is_optional = false;
272 return (*this)(r); 260 return (*this)(r);
273 } 261 }
274 else if(eina::optional<bool> b = call_match 262 else if(eina::optional<bool> b = type_match::get_match
275 (match_table 263 (match_table
276 , [&] (match const& m) 264 , [&] (match const& m)
277 { 265 {
@@ -441,7 +429,7 @@ struct visitor_generate
441 // && detail::generate_pointers(sink, pointers, *context, false); 429 // && detail::generate_pointers(sink, pointers, *context, false);
442 }; 430 };
443 431
444 if(eina::optional<bool> b = call_match 432 if(eina::optional<bool> b = type_match::get_match
445 (matches 433 (matches
446 , [&] (match const& m) 434 , [&] (match const& m)
447 { 435 {
diff --git a/src/bin/eolian_mono/eolian/mono/type_match.hh b/src/bin/eolian_mono/eolian/mono/type_match.hh
new file mode 100644
index 0000000000..b42fb43190
--- /dev/null
+++ b/src/bin/eolian_mono/eolian/mono/type_match.hh
@@ -0,0 +1,46 @@
1/*
2 * Copyright 2019 by its authors. See AUTHORS.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16#ifndef EOLIAN_MONO_TYPE_MATCH_HH
17#define EOLIAN_MONO_TYPE_MATCH_HH
18
19#include <Eina.hh>
20
21namespace eolian_mono {
22
23namespace type_match {
24
25namespace eina = efl::eina;
26
27/**
28 * Apply the given AcceptFunction to the first element that matches the SelectionPredicate.
29 */
30template <typename Array, typename SelectionPredicate, int N, typename AcceptFunc>
31eina::optional<bool> get_match(Array const (&array)[N], SelectionPredicate predicate, AcceptFunc acceptFunc)
32{
33 typedef Array const* iterator_type;
34 iterator_type match_iterator = &array[0], match_last = match_iterator + N;
35 match_iterator = std::find_if(match_iterator, match_last, predicate);
36 if(match_iterator != match_last)
37 {
38 return acceptFunc(match_iterator->function());
39 }
40 return {nullptr};
41}
42
43} // type_match
44
45} // eolian_mono
46#endif