summaryrefslogtreecommitdiff
path: root/src/bin/eolian_mono/eolian/mono/marshall_annotation.hh
diff options
context:
space:
mode:
Diffstat (limited to 'src/bin/eolian_mono/eolian/mono/marshall_annotation.hh')
-rw-r--r--src/bin/eolian_mono/eolian/mono/marshall_annotation.hh158
1 files changed, 83 insertions, 75 deletions
diff --git a/src/bin/eolian_mono/eolian/mono/marshall_annotation.hh b/src/bin/eolian_mono/eolian/mono/marshall_annotation.hh
index 82bbd13..a9fc45d 100644
--- a/src/bin/eolian_mono/eolian/mono/marshall_annotation.hh
+++ b/src/bin/eolian_mono/eolian/mono/marshall_annotation.hh
@@ -1,3 +1,18 @@
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 */
1#ifndef EOLIAN_MONO_MARSHALL_ANNOTATION_IMPL_HH 16#ifndef EOLIAN_MONO_MARSHALL_ANNOTATION_IMPL_HH
2#define EOLIAN_MONO_MARSHALL_ANNOTATION_IMPL_HH 17#define EOLIAN_MONO_MARSHALL_ANNOTATION_IMPL_HH
3 18
@@ -6,25 +21,13 @@
6#include "grammar/case.hpp" 21#include "grammar/case.hpp"
7#include "name_helpers.hh" 22#include "name_helpers.hh"
8#include "type_impl.hh" 23#include "type_impl.hh"
24#include "type_match.hh"
9 25
10namespace eolian_mono { 26namespace eolian_mono {
11 27
12namespace eina = efl::eina; 28namespace eina = efl::eina;
13 29
14namespace detail { 30namespace detail {
15
16template <typename Array, typename F, int N, typename A>
17eina::optional<bool> call_annotation_match(Array const (&array)[N], F f, A a)
18{
19 typedef Array const* iterator_type;
20 iterator_type match_iterator = &array[0], match_last = match_iterator + N;
21 match_iterator = std::find_if(match_iterator, match_last, f);
22 if(match_iterator != match_last)
23 {
24 return a(match_iterator->function());
25 }
26 return {nullptr};
27}
28 31
29template <typename OutputIterator, typename Context> 32template <typename OutputIterator, typename Context>
30struct marshall_annotation_visitor_generate 33struct marshall_annotation_visitor_generate
@@ -48,103 +51,108 @@ struct marshall_annotation_visitor_generate
48 eina::optional<bool> has_own; 51 eina::optional<bool> has_own;
49 std::function<std::string()> function; 52 std::function<std::string()> function;
50 }; 53 };
54 // These two tables are currently the same but will hold different marshallers
55 // for @in and @out/return semantics in a future commit.
51 match const parameter_match_table[] = 56 match const parameter_match_table[] =
52 { 57 {
53 // signed primitives 58 // signed primitives
54 {"bool", nullptr, [&] { return "[MarshalAs(UnmanagedType.U1)]"; }}, 59 {"bool", nullptr, [] { return "MarshalAs(UnmanagedType.U1)"; }},
55 {"string", true, [&] { 60 {"string", true, [] {
56 return "[MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Efl.Eo.StringPassOwnershipMarshaler))]"; 61 return "MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Efl.Eo.StringPassOwnershipMarshaler))";
57 }}, 62 }},
58 {"string", false, [&] { 63 {"string", false, [] {
59 return "[MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Efl.Eo.StringKeepOwnershipMarshaler))]"; 64 return "MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Efl.Eo.StringKeepOwnershipMarshaler))";
60 }}, 65 }},
61 {"mstring", true, [&] { 66 {"mstring", true, [] {
62 return "[MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Efl.Eo.StringPassOwnershipMarshaler))]"; 67 return "MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Efl.Eo.StringPassOwnershipMarshaler))";
63 }}, 68 }},
64 {"mstring", false, [&] { 69 {"mstring", false, [] {
65 return "[MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Efl.Eo.StringKeepOwnershipMarshaler))]"; 70 return "MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Efl.Eo.StringKeepOwnershipMarshaler))";
66 }}, 71 }},
67 {"stringshare", true, [&] { 72 {"stringshare", true, [] {
68 return "[MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Efl.Eo.StringsharePassOwnershipMarshaler))]"; 73 return "MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Efl.Eo.StringsharePassOwnershipMarshaler))";
69 }}, 74 }},
70 {"stringshare", false, [&] { 75 {"stringshare", false, [] {
71 return "[MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Efl.Eo.StringshareKeepOwnershipMarshaler))]"; 76 return "MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Efl.Eo.StringshareKeepOwnershipMarshaler))";
72 }}, 77 }},
73 {"any_value_ref", true, [&] { 78 {"any_value_ref", true, [] {
74 return "[MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Eina.ValueMarshalerOwn))]"; 79 return "MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Eina.ValueMarshalerOwn))";
75 }}, 80 }},
76 {"any_value_ref", false, [&] { 81 {"any_value_ref", false, [] {
77 return "[MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Eina.ValueMarshaler))]"; 82 return "MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Eina.ValueMarshaler))";
78 }}, 83 }},
79 {"strbuf", true, [&] { 84 {"strbuf", true, [] {
80 return "[MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Efl.Eo.StrbufPassOwnershipMarshaler))]"; 85 return "MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Efl.Eo.StrbufPassOwnershipMarshaler))";
81 }}, 86 }},
82 {"strbuf", false, [&] { 87 {"strbuf", false, [] {
83 return "[MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Efl.Eo.StrbufKeepOwnershipMarshaler))]"; 88 return "MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Efl.Eo.StrbufKeepOwnershipMarshaler))";
84 }}, 89 }},
85 {"Value_Type", false, [&] { 90 {"Value_Type", false, [] {
86 return "[MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Eina.ValueTypeMarshaler))]"; 91 return "MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Eina.ValueTypeMarshaler))";
87 }}, 92 }},
88 }; 93 };
89 match const return_match_table[] = 94 match const return_match_table[] =
90 { 95 {
91 // signed primitives 96 // signed primitives
92 {"bool", nullptr, [&] { return "[return: MarshalAs(UnmanagedType.U1)]"; }}, 97 {"bool", nullptr, [] { return "MarshalAs(UnmanagedType.U1)"; }},
93 {"string", true, [&] { 98 {"string", true, [] {
94 return "[return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Efl.Eo.StringPassOwnershipMarshaler))]"; 99 return "MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Efl.Eo.StringPassOwnershipMarshaler))";
95 }}, 100 }},
96 {"string", nullptr, [&] { 101 {"string", false, [] {
97 return "[return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Efl.Eo.StringKeepOwnershipMarshaler))]"; 102 return "MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Efl.Eo.StringKeepOwnershipMarshaler))";
98 }}, 103 }},
99 {"mstring", true, [&] { 104 {"mstring", true, [] {
100 return "[return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Efl.Eo.StringPassOwnershipMarshaler))]"; 105 return "MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Efl.Eo.StringPassOwnershipMarshaler))";
101 }}, 106 }},
102 {"mstring", false, [&] { 107 {"mstring", false, [] {
103 return "[return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Efl.Eo.StringKeepOwnershipMarshaler))]"; 108 return "MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Efl.Eo.StringKeepOwnershipMarshaler))";
104 }}, 109 }},
105 {"stringshare", true, [&] { 110 {"stringshare", true, [] {
106 return "[return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Efl.Eo.StringsharePassOwnershipMarshaler))]"; 111 return "MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Efl.Eo.StringsharePassOwnershipMarshaler))";
107 }}, 112 }},
108 {"stringshare", false, [&] { 113 {"stringshare", false, [] {
109 return "[return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Efl.Eo.StringshareKeepOwnershipMarshaler))]"; 114 return "MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Efl.Eo.StringshareKeepOwnershipMarshaler))";
110 }}, 115 }},
111 {"any_value_ref", true, [&] { 116 {"any_value_ref", true, [] {
112 return "[return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Eina.ValueMarshalerOwn))]"; 117 return "MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Eina.ValueMarshalerOwn))";
113 }}, 118 }},
114 {"any_value_ref", false, [&] { 119 {"any_value_ref", false, [] {
115 return "[return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Eina.ValueMarshaler))]"; 120 return "MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Eina.ValueMarshaler))";
116 }}, 121 }},
117 {"strbuf", true, [&] { 122 {"strbuf", true, [] {
118 return "[return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Efl.Eo.StrbufPassOwnershipMarshaler))]"; 123 return "MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Efl.Eo.StrbufPassOwnershipMarshaler))";
119 }}, 124 }},
120 {"strbuf", false, [&] { 125 {"strbuf", false, [] {
121 return "[return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Efl.Eo.StrbufKeepOwnershipMarshaler))]"; 126 return "MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Efl.Eo.StrbufKeepOwnershipMarshaler))";
122 }}, 127 }},
123 {"Value_Type", false, [&] { 128 {"Value_Type", false, [] {
124 return "[return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Eina.ValueTypeMarshaler))]"; 129 return "MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Eina.ValueTypeMarshaler))";
125 }}, 130 }},
126 }; 131 };
127 132
128 if(eina::optional<bool> b = call_annotation_match 133 auto predicate = [&regular] (match const& m)
129 ((is_return ? return_match_table : parameter_match_table)
130 , [&] (match const& m)
131 { 134 {
132 return (!m.name || *m.name == regular.base_type) 135 return (!m.name || *m.name == regular.base_type)
133 && (!m.has_own || *m.has_own == (bool)(regular.base_qualifier & qualifier_info::is_own)) 136 && (!m.has_own || *m.has_own == (bool)(regular.base_qualifier & qualifier_info::is_own))
134 ; 137 ;
138 };
139
140 auto acceptCb = [this] (std::string const& marshalTag)
141 {
142 std::string prefix = is_return ? "return: " : "";
143 return as_generator("[" << prefix << marshalTag << "]").generate(sink, nullptr, *context);
144 };
145
146 const auto& match_table = is_return ? return_match_table : parameter_match_table;
147
148 if(eina::optional<bool> b = type_match::get_match(match_table, predicate, acceptCb))
149 {
150 return *b;
135 } 151 }
136 , [&] (std::string const& string) 152 else
137 { 153 {
138 std::copy(string.begin(), string.end(), sink); 154 return true;
139 return true; 155 }
140 }))
141 {
142 return *b;
143 }
144 else
145 {
146 return true;
147 }
148 } 156 }
149 bool operator()(attributes::klass_name const& klass_name) const 157 bool operator()(attributes::klass_name const& klass_name) const
150 { 158 {
@@ -157,8 +165,8 @@ struct marshall_annotation_visitor_generate
157 name = "Efl.Eo.MarshalEflClass"; 165 name = "Efl.Eo.MarshalEflClass";
158 else 166 else
159 { 167 {
160 std::string own = klass_name.base_qualifier & qualifier_info::is_own ? "OwnTag" : "NonOwnTag"; 168 std::string own = klass_name.base_qualifier & qualifier_info::is_own ? "Move" : "NoMove";
161 name = "Efl.Eo.MarshalEo<Efl.Eo." + own + ">"; 169 name = "Efl.Eo.MarshalEo" + own;
162 } 170 }
163 171
164 return as_generator( 172 return as_generator(