summaryrefslogtreecommitdiff
path: root/src/bin/eolian_mono/eolian/mono/struct_definition.hh
diff options
context:
space:
mode:
authorVitor Sousa <vitorsousa@expertisesolutions.com.br>2019-03-22 18:47:27 -0300
committerVitor Sousa <vitorsousa@expertisesolutions.com.br>2019-03-26 16:43:15 -0300
commit762ae45f056e8358e06d4c1843ae83c97691c774 (patch)
treebbbcbe3c13895da78f42ec20585e9596562e812c /src/bin/eolian_mono/eolian/mono/struct_definition.hh
parent378ba8ebd1c2e3a049cff0bad9b23b2000d7c939 (diff)
eolian_csharp: make struct generator use indentation level from context
Summary: Make the struct generator (the first one to) extract indentation information from the context, an effort for a future overall consistency in white space generation. Depends on D8468 Reviewers: lauromoura, segfaultxavi, felipealmeida Reviewed By: lauromoura Subscribers: cedric, #reviewers, #committers Tags: #efl Differential Revision: https://phab.enlightenment.org/D8469
Diffstat (limited to 'src/bin/eolian_mono/eolian/mono/struct_definition.hh')
-rw-r--r--src/bin/eolian_mono/eolian/mono/struct_definition.hh176
1 files changed, 92 insertions, 84 deletions
diff --git a/src/bin/eolian_mono/eolian/mono/struct_definition.hh b/src/bin/eolian_mono/eolian/mono/struct_definition.hh
index ba058d0817..ea379c67ff 100644
--- a/src/bin/eolian_mono/eolian/mono/struct_definition.hh
+++ b/src/bin/eolian_mono/eolian/mono/struct_definition.hh
@@ -32,12 +32,14 @@ struct struct_definition_generator
32 bool generate(OutputIterator sink, attributes::struct_def const& struct_, Context const& context) const 32 bool generate(OutputIterator sink, attributes::struct_def const& struct_, Context const& context) const
33 { 33 {
34 EINA_CXX_DOM_LOG_DBG(eolian_mono::domain) << "struct_definition_generator: " << struct_.cxx_name << std::endl; 34 EINA_CXX_DOM_LOG_DBG(eolian_mono::domain) << "struct_definition_generator: " << struct_.cxx_name << std::endl;
35 auto const& indent = current_indentation(context);
35 if(!as_generator(documentation).generate(sink, struct_, context)) 36 if(!as_generator(documentation).generate(sink, struct_, context))
36 return false; 37 return false;
37 if(!as_generator 38 if(!as_generator
38 ( 39 (
39 "[StructLayout(LayoutKind.Sequential)]\n" 40 indent << "[StructLayout(LayoutKind.Sequential)]\n"
40 "public struct " << string << "\n{\n" 41 << indent << "public struct " << string << "\n"
42 << indent << "{\n"
41 ) 43 )
42 .generate(sink, binding_struct_name(struct_), context)) 44 .generate(sink, binding_struct_name(struct_), context))
43 return false; 45 return false;
@@ -49,8 +51,8 @@ struct struct_definition_generator
49 field_name[0] = std::toupper(field_name[0]); // Hack to allow 'static' as a field name 51 field_name[0] = std::toupper(field_name[0]); // Hack to allow 'static' as a field name
50 if (!as_generator 52 if (!as_generator
51 ( 53 (
52 documentation(1) 54 indent << scope_tab << documentation
53 << scope_tab(1) << "public " << type << " " << string << ";\n" 55 << indent << scope_tab << "public " << type << " " << string << ";\n"
54 ) 56 )
55 .generate(sink, std::make_tuple(field, field.type, name_helpers::to_field_name(field.name)), context)) 57 .generate(sink, std::make_tuple(field, field.type, name_helpers::to_field_name(field.name)), context))
56 return false; 58 return false;
@@ -64,35 +66,36 @@ struct struct_definition_generator
64 // those 'mini-amd64.c condition fields not met' crashes. 66 // those 'mini-amd64.c condition fields not met' crashes.
65 if (struct_.fields.size() == 0) 67 if (struct_.fields.size() == 0)
66 { 68 {
67 if (!as_generator("///<summary>Placeholder field</summary>\npublic IntPtr field;\n").generate(sink, nullptr, context)) 69 if (!as_generator(indent << scope_tab << "///<summary>Placeholder field</summary>\n"
70 << indent << scope_tab << "public IntPtr field;\n").generate(sink, nullptr, context))
68 return false; 71 return false;
69 } 72 }
70 else 73 else
71 { 74 {
72 // Constructor with default parameters for easy struct initialization 75 // Constructor with default parameters for easy struct initialization
73 if(!as_generator( 76 if(!as_generator(
74 scope_tab << "///<summary>Constructor for " << string << ".</summary>\n" 77 indent << scope_tab << "///<summary>Constructor for " << string << ".</summary>\n"
75 << scope_tab << "public " << string << "(\n" 78 << indent << scope_tab << "public " << string << "(\n"
76 << ((scope_tab << scope_tab << field_argument_default) % ",\n") 79 << ((indent << scope_tab << scope_tab << field_argument_default) % ",\n")
77 << scope_tab << ")\n" 80 << indent << scope_tab << ")\n"
78 << scope_tab << "{\n" 81 << indent << scope_tab << "{\n"
79 << *(scope_tab << scope_tab << field_argument_assignment << ";\n") 82 << *(indent << scope_tab << scope_tab << field_argument_assignment << ";\n")
80 << scope_tab << "}\n") 83 << indent << scope_tab << "}\n\n")
81 .generate(sink, std::make_tuple(struct_name, struct_name, struct_.fields, struct_.fields), context)) 84 .generate(sink, std::make_tuple(struct_name, struct_name, struct_.fields, struct_.fields), context))
82 return false; 85 return false;
83 } 86 }
84 87
85 if(!as_generator( 88 if(!as_generator(
86 "public static implicit operator " << struct_name << "(IntPtr ptr)\n" 89 indent << scope_tab << "public static implicit operator " << struct_name << "(IntPtr ptr)\n"
87 << scope_tab << "{\n" 90 << indent << scope_tab << "{\n"
88 << scope_tab << scope_tab << "var tmp = (" << struct_name << "_StructInternal)Marshal.PtrToStructure(ptr, typeof(" << struct_name << "_StructInternal));\n" 91 << indent << scope_tab << scope_tab << "var tmp = (" << struct_name << "_StructInternal)Marshal.PtrToStructure(ptr, typeof(" << struct_name << "_StructInternal));\n"
89 << scope_tab << scope_tab << "return " << struct_name << "_StructConversion.ToManaged(tmp);\n" 92 << indent << scope_tab << scope_tab << "return " << struct_name << "_StructConversion.ToManaged(tmp);\n"
90 << scope_tab << "}\n" 93 << indent << scope_tab << "}\n\n"
91 ).generate(sink, attributes::unused, context)) 94 ).generate(sink, attributes::unused, context))
92 return false; 95 return false;
93 96
94 97
95 if(!as_generator("}\n").generate(sink, attributes::unused, context)) return false; 98 if(!as_generator(indent << "}\n\n").generate(sink, attributes::unused, context)) return false;
96 99
97 return true; 100 return true;
98 } 101 }
@@ -104,11 +107,13 @@ struct struct_internal_definition_generator
104 template <typename OutputIterator, typename Context> 107 template <typename OutputIterator, typename Context>
105 bool generate(OutputIterator sink, attributes::struct_def const& struct_, Context const& context) const 108 bool generate(OutputIterator sink, attributes::struct_def const& struct_, Context const& context) const
106 { 109 {
110 auto const& indent = current_indentation(context);
107 if (!as_generator 111 if (!as_generator
108 ( 112 (
109 "///<summary>Internal wrapper for struct " << string << ".</summary>\n" 113 indent << "///<summary>Internal wrapper for struct " << string << ".</summary>\n"
110 "[StructLayout(LayoutKind.Sequential)]\n" 114 << indent << "[StructLayout(LayoutKind.Sequential)]\n"
111 "public struct " << string << "\n{\n" 115 << indent << "public struct " << string << "\n"
116 << indent << "{\n"
112 ) 117 )
113 .generate(sink, std::make_tuple<>(binding_struct_name(struct_), binding_struct_internal_name(struct_)), context)) 118 .generate(sink, std::make_tuple<>(binding_struct_name(struct_), binding_struct_internal_name(struct_)), context))
114 return false; 119 return false;
@@ -126,29 +131,29 @@ struct struct_internal_definition_generator
126 || regular->base_type == "stringshare" 131 || regular->base_type == "stringshare"
127 || regular->base_type == "any_value_ptr"))) 132 || regular->base_type == "any_value_ptr")))
128 { 133 {
129 if (!as_generator("///<summary>Internal wrapper for field " << field_name << "</summary>\n" 134 if (!as_generator(indent << scope_tab << "///<summary>Internal wrapper for field " << field_name << "</summary>\n"
130 << "public System.IntPtr " << field_name << ";\n") 135 << indent << scope_tab << "public System.IntPtr " << field_name << ";\n")
131 .generate(sink, nullptr, context)) 136 .generate(sink, nullptr, context))
132 return false; 137 return false;
133 } 138 }
134 else if (regular && !(regular->base_qualifier & efl::eolian::grammar::attributes::qualifier_info::is_ref) 139 else if (regular && !(regular->base_qualifier & efl::eolian::grammar::attributes::qualifier_info::is_ref)
135 && regular->base_type == "bool") 140 && regular->base_type == "bool")
136 { 141 {
137 if (!as_generator("///<summary>Internal wrapper for field " << field_name << "</summary>\n" 142 if (!as_generator(indent << scope_tab << "///<summary>Internal wrapper for field " << field_name << "</summary>\n"
138 "public System.Byte " << field_name << ";\n") 143 << indent << scope_tab << "public System.Byte " << field_name << ";\n")
139 .generate(sink, nullptr, context)) 144 .generate(sink, nullptr, context))
140 return false; 145 return false;
141 } 146 }
142 else if (regular && !(regular->base_qualifier & efl::eolian::grammar::attributes::qualifier_info::is_ref) 147 else if (regular && !(regular->base_qualifier & efl::eolian::grammar::attributes::qualifier_info::is_ref)
143 && regular->base_type == "char") 148 && regular->base_type == "char")
144 { 149 {
145 if (!as_generator("///<summary>Internal wrapper for field " << field_name << "</summary>\n" 150 if (!as_generator(indent << scope_tab << "///<summary>Internal wrapper for field " << field_name << "</summary>\n"
146 "public System.Byte " << field_name << ";\n") 151 << indent << scope_tab << "public System.Byte " << field_name << ";\n")
147 .generate(sink, nullptr, context)) 152 .generate(sink, nullptr, context))
148 return false; 153 return false;
149 } 154 }
150 else if (!as_generator(scope_tab << eolian_mono::marshall_annotation(false) << "\n" 155 else if (!as_generator(indent << scope_tab << eolian_mono::marshall_annotation(false) << "\n"
151 << scope_tab << "public " << eolian_mono::marshall_type(false) << " " << string << ";\n") 156 << indent << scope_tab << "public " << eolian_mono::marshall_type(false) << " " << string << ";\n")
152 .generate(sink, std::make_tuple(field.type, field.type, field_name), context)) 157 .generate(sink, std::make_tuple(field.type, field.type, field_name), context))
153 return false; 158 return false;
154 } 159 }
@@ -159,7 +164,7 @@ struct struct_internal_definition_generator
159 // those 'mini-amd64.c condition fields not met' crashes. 164 // those 'mini-amd64.c condition fields not met' crashes.
160 if (struct_.fields.size() == 0) 165 if (struct_.fields.size() == 0)
161 { 166 {
162 if (!as_generator("internal IntPtr field;\n").generate(sink, nullptr, context)) 167 if (!as_generator(indent << scope_tab << "internal IntPtr field;\n").generate(sink, nullptr, context))
163 return false; 168 return false;
164 } 169 }
165 170
@@ -167,21 +172,21 @@ struct struct_internal_definition_generator
167 auto internal_name = binding_struct_internal_name(struct_); 172 auto internal_name = binding_struct_internal_name(struct_);
168 173
169 if(!as_generator( 174 if(!as_generator(
170 scope_tab << "///<summary>Implicit conversion to the internal/marshalling representation.</summary>\n" 175 indent << scope_tab << "///<summary>Implicit conversion to the internal/marshalling representation.</summary>\n"
171 << scope_tab << "public static implicit operator " << string << "(" << string << " struct_)\n" 176 << indent << scope_tab << "public static implicit operator " << string << "(" << string << " struct_)\n"
172 << scope_tab << "{\n" 177 << indent << scope_tab << "{\n"
173 << scope_tab << scope_tab << "return " << string << "_StructConversion.ToManaged(struct_);\n" 178 << indent << scope_tab << scope_tab << "return " << string << "_StructConversion.ToManaged(struct_);\n"
174 << scope_tab << "}\n" 179 << indent << scope_tab << "}\n\n"
175 << scope_tab << "///<summary>Implicit conversion to the managed representation.</summary>\n" 180 << indent << scope_tab << "///<summary>Implicit conversion to the managed representation.</summary>\n"
176 << scope_tab << "public static implicit operator " << string << "(" << string << " struct_)\n" 181 << indent << scope_tab << "public static implicit operator " << string << "(" << string << " struct_)\n"
177 << scope_tab << "{\n" 182 << indent << scope_tab << "{\n"
178 << scope_tab << scope_tab << "return " << string << "_StructConversion.ToInternal(struct_);\n" 183 << indent << scope_tab << scope_tab << "return " << string << "_StructConversion.ToInternal(struct_);\n"
179 << scope_tab << "}\n" 184 << indent << scope_tab << "}\n\n"
180 ).generate(sink, std::make_tuple(external_name, internal_name, external_name, 185 ).generate(sink, std::make_tuple(external_name, internal_name, external_name,
181 internal_name, external_name, external_name), context)) 186 internal_name, external_name, external_name), context))
182 return false; 187 return false;
183 188
184 if(!as_generator("}\n").generate(sink, attributes::unused, context)) return false; 189 if(!as_generator(indent << "}\n\n").generate(sink, attributes::unused, context)) return false;
185 190
186 return true; 191 return true;
187 } 192 }
@@ -195,6 +200,7 @@ struct to_internal_field_convert_generator
195 template <typename OutputIterator, typename Context> 200 template <typename OutputIterator, typename Context>
196 bool generate(OutputIterator sink, attributes::struct_field_def const& field, Context const& context) const 201 bool generate(OutputIterator sink, attributes::struct_field_def const& field, Context const& context) const
197 { 202 {
203 auto const& indent = current_indentation(context);
198 auto field_name = name_helpers::to_field_name(field.name); 204 auto field_name = name_helpers::to_field_name(field.name);
199 // FIXME Replace need_struct_conversion(regular) with need_struct_conversion(type) 205 // FIXME Replace need_struct_conversion(regular) with need_struct_conversion(type)
200 auto regular = efl::eina::get<attributes::regular_type_def>(&field.type.original_type); 206 auto regular = efl::eina::get<attributes::regular_type_def>(&field.type.original_type);
@@ -204,7 +210,7 @@ struct to_internal_field_convert_generator
204 if (klass) 210 if (klass)
205 { 211 {
206 if (!as_generator( 212 if (!as_generator(
207 scope_tab << scope_tab << "_internal_struct." << string << " = _external_struct." << string << ".NativeHandle;\n") 213 indent << scope_tab << scope_tab << "_internal_struct." << string << " = _external_struct." << string << ".NativeHandle;\n")
208 .generate(sink, std::make_tuple(field_name, field_name), context)) 214 .generate(sink, std::make_tuple(field_name, field_name), context))
209 return false; 215 return false;
210 } 216 }
@@ -216,35 +222,35 @@ struct to_internal_field_convert_generator
216 { 222 {
217 // Always assumes pointer 223 // Always assumes pointer
218 if (!as_generator( 224 if (!as_generator(
219 scope_tab << scope_tab << "_internal_struct." << string << " = _external_struct." << string << ".Handle;\n") 225 indent << scope_tab << scope_tab << "_internal_struct." << string << " = _external_struct." << string << ".Handle;\n")
220 .generate(sink, std::make_tuple(field_name, field_name), context)) 226 .generate(sink, std::make_tuple(field_name, field_name), context))
221 return false; 227 return false;
222 } 228 }
223 else if (field.type.is_ptr && helpers::need_pointer_conversion(regular) && !helpers::need_struct_conversion(regular)) 229 else if (field.type.is_ptr && helpers::need_pointer_conversion(regular) && !helpers::need_struct_conversion(regular))
224 { 230 {
225 if (!as_generator( 231 if (!as_generator(
226 scope_tab << scope_tab << "_internal_struct." << string << " = Eina.PrimitiveConversion.ManagedToPointerAlloc(_external_struct." << string << ");\n") 232 indent << scope_tab << scope_tab << "_internal_struct." << string << " = Eina.PrimitiveConversion.ManagedToPointerAlloc(_external_struct." << string << ");\n")
227 .generate(sink, std::make_tuple(field_name, field_name), context)) 233 .generate(sink, std::make_tuple(field_name, field_name), context))
228 return false; 234 return false;
229 } 235 }
230 else if (helpers::need_struct_conversion(regular)) 236 else if (helpers::need_struct_conversion(regular))
231 { 237 {
232 if (!as_generator( 238 if (!as_generator(
233 scope_tab << scope_tab << "_internal_struct." << string << " = " << type << "_StructConversion.ToInternal(_external_struct." << string << ");\n") 239 indent << scope_tab << scope_tab << "_internal_struct." << string << " = " << type << "_StructConversion.ToInternal(_external_struct." << string << ");\n")
234 .generate(sink, std::make_tuple(field_name, field.type, field_name), context)) 240 .generate(sink, std::make_tuple(field_name, field.type, field_name), context))
235 return false; 241 return false;
236 } 242 }
237 else if (regular && (regular->base_type == "string" || regular->base_type == "mstring")) 243 else if (regular && (regular->base_type == "string" || regular->base_type == "mstring"))
238 { 244 {
239 if (!as_generator( 245 if (!as_generator(
240 scope_tab << scope_tab << "_internal_struct." << string << " = Eina.MemoryNative.StrDup(_external_struct." << string << ");\n") 246 indent << scope_tab << scope_tab << "_internal_struct." << string << " = Eina.MemoryNative.StrDup(_external_struct." << string << ");\n")
241 .generate(sink, std::make_tuple(field_name, field_name), context)) 247 .generate(sink, std::make_tuple(field_name, field_name), context))
242 return false; 248 return false;
243 } 249 }
244 else if (regular && regular->base_type == "stringshare") 250 else if (regular && regular->base_type == "stringshare")
245 { 251 {
246 if (!as_generator( 252 if (!as_generator(
247 scope_tab << scope_tab << "_internal_struct." << string << " = Eina.Stringshare.eina_stringshare_add(_external_struct." << string << ");\n") 253 indent << scope_tab << scope_tab << "_internal_struct." << string << " = Eina.Stringshare.eina_stringshare_add(_external_struct." << string << ");\n")
248 .generate(sink, std::make_tuple(field_name, field_name), context)) 254 .generate(sink, std::make_tuple(field_name, field_name), context))
249 return false; 255 return false;
250 } 256 }
@@ -253,43 +259,43 @@ struct to_internal_field_convert_generator
253 { 259 {
254 if (!as_generator( 260 if (!as_generator(
255 "\n" << 261 "\n" <<
256 scope_tab << scope_tab << "_internal_struct." << field_name << ".Len = _external_struct." << field_name << ".Len;\n" << 262 indent << scope_tab << scope_tab << "_internal_struct." << field_name << ".Len = _external_struct." << field_name << ".Len;\n" <<
257 scope_tab << scope_tab << "_internal_struct." << field_name << ".Mem = _external_struct." << field_name << ".Mem;\n\n") 263 indent << scope_tab << scope_tab << "_internal_struct." << field_name << ".Mem = _external_struct." << field_name << ".Mem;\n")
258 .generate(sink, attributes::unused, context)) 264 .generate(sink, attributes::unused, context))
259 return false; 265 return false;
260 } 266 }
261 else if (field.type.c_type == "Eina_Value" || field.type.c_type == "const Eina_Value") 267 else if (field.type.c_type == "Eina_Value" || field.type.c_type == "const Eina_Value")
262 { 268 {
263 if (!as_generator( 269 if (!as_generator(
264 scope_tab << scope_tab << "_internal_struct." << string << " = _external_struct." << string << ".GetNative();\n" 270 indent << scope_tab << scope_tab << "_internal_struct." << string << " = _external_struct." << string << ".GetNative();\n"
265 ).generate(sink, std::make_tuple(field_name, field_name), context)) 271 ).generate(sink, std::make_tuple(field_name, field_name), context))
266 return false; 272 return false;
267 } 273 }
268 else if (field.type.c_type == "Eina_Value *" || field.type.c_type == "const Eina_Value *") 274 else if (field.type.c_type == "Eina_Value *" || field.type.c_type == "const Eina_Value *")
269 { 275 {
270 if (!as_generator( 276 if (!as_generator(
271 scope_tab << scope_tab << "_internal_struct." << string << " = _external_struct." << string << ".NativeHandle;\n" 277 indent << scope_tab << scope_tab << "_internal_struct." << string << " = _external_struct." << string << ".NativeHandle;\n"
272 ).generate(sink, std::make_tuple(field_name, field_name), context)) 278 ).generate(sink, std::make_tuple(field_name, field_name), context))
273 return false; 279 return false;
274 } 280 }
275 else if (!field.type.is_ptr && regular && regular->base_type == "bool") 281 else if (!field.type.is_ptr && regular && regular->base_type == "bool")
276 { 282 {
277 if (!as_generator( 283 if (!as_generator(
278 scope_tab << scope_tab << "_internal_struct." << string << " = _external_struct." << string << " ? (byte)1 : (byte)0;\n") 284 indent << scope_tab << scope_tab << "_internal_struct." << string << " = _external_struct." << string << " ? (byte)1 : (byte)0;\n")
279 .generate(sink, std::make_tuple(field_name, field_name), context)) 285 .generate(sink, std::make_tuple(field_name, field_name), context))
280 return false; 286 return false;
281 } 287 }
282 else if (!field.type.is_ptr && regular && regular->base_type == "char") 288 else if (!field.type.is_ptr && regular && regular->base_type == "char")
283 { 289 {
284 if (!as_generator( 290 if (!as_generator(
285 scope_tab << scope_tab << "_internal_struct." << string << " = (byte)_external_struct." << string << ";\n") 291 indent << scope_tab << scope_tab << "_internal_struct." << string << " = (byte)_external_struct." << string << ";\n")
286 .generate(sink, std::make_tuple(field_name, field_name), context)) 292 .generate(sink, std::make_tuple(field_name, field_name), context))
287 return false; 293 return false;
288 } 294 }
289 else // primitives and enums 295 else // primitives and enums
290 { 296 {
291 if (!as_generator( 297 if (!as_generator(
292 scope_tab << scope_tab << "_internal_struct." << string << " = _external_struct." << string << ";\n") 298 indent << scope_tab << scope_tab << "_internal_struct." << string << " = _external_struct." << string << ";\n")
293 .generate(sink, std::make_tuple(field_name, field_name), context)) 299 .generate(sink, std::make_tuple(field_name, field_name), context))
294 return false; 300 return false;
295 } 301 }
@@ -302,6 +308,7 @@ struct to_external_field_convert_generator
302 template <typename OutputIterator, typename Context> 308 template <typename OutputIterator, typename Context>
303 bool generate(OutputIterator sink, attributes::struct_field_def const& field, Context const& context) const 309 bool generate(OutputIterator sink, attributes::struct_field_def const& field, Context const& context) const
304 { 310 {
311 auto const& indent = current_indentation(context);
305 auto field_name = name_helpers::to_field_name(field.name); 312 auto field_name = name_helpers::to_field_name(field.name);
306 auto regular = efl::eina::get<attributes::regular_type_def>(&field.type.original_type); 313 auto regular = efl::eina::get<attributes::regular_type_def>(&field.type.original_type);
307 auto klass = efl::eina::get<attributes::klass_name>(&field.type.original_type); 314 auto klass = efl::eina::get<attributes::klass_name>(&field.type.original_type);
@@ -313,17 +320,17 @@ struct to_external_field_convert_generator
313 auto concrete_name = name_helpers::klass_full_concrete_name(*klass); 320 auto concrete_name = name_helpers::klass_full_concrete_name(*klass);
314 if (!as_generator( 321 if (!as_generator(
315 "\n" 322 "\n"
316 << scope_tab << scope_tab << "_external_struct." << string 323 << indent << scope_tab << scope_tab << "_external_struct." << string
317 << " = (" << concrete_name << ") System.Activator.CreateInstance(typeof(" 324 << " = (" << concrete_name << ") System.Activator.CreateInstance(typeof("
318 << concrete_name << "), new System.Object[] {_internal_struct." << string << "});\n" 325 << concrete_name << "), new System.Object[] {_internal_struct." << string << "});\n"
319 << scope_tab << scope_tab << "Efl.Eo.Globals.efl_ref(_internal_struct." << string << ");\n\n") 326 << indent << scope_tab << scope_tab << "Efl.Eo.Globals.efl_ref(_internal_struct." << string << ");\n")
320 .generate(sink, std::make_tuple(field_name, field_name, field_name), context)) 327 .generate(sink, std::make_tuple(field_name, field_name, field_name), context))
321 return false; 328 return false;
322 } 329 }
323 else if (field.type.c_type == "Eina_Binbuf *" || field.type.c_type == "const Eina_Binbuf *") 330 else if (field.type.c_type == "Eina_Binbuf *" || field.type.c_type == "const Eina_Binbuf *")
324 { 331 {
325 if (!as_generator( 332 if (!as_generator(
326 scope_tab << scope_tab << "_external_struct." << string << " = new " << type << "(_internal_struct." << string << ", false);\n") 333 indent << scope_tab << scope_tab << "_external_struct." << string << " = new " << type << "(_internal_struct." << string << ", false);\n")
327 .generate(sink, std::make_tuple(field_name, field.type, field_name), context)) 334 .generate(sink, std::make_tuple(field_name, field.type, field_name), context))
328 return false; 335 return false;
329 } 336 }
@@ -333,35 +340,35 @@ struct to_external_field_convert_generator
333 { 340 {
334 // Always assumes pointer 341 // Always assumes pointer
335 if (!as_generator( 342 if (!as_generator(
336 scope_tab << scope_tab << "_external_struct." << string << " = new " << type << "(_internal_struct." << string << ", false, false);\n") 343 indent << scope_tab << scope_tab << "_external_struct." << string << " = new " << type << "(_internal_struct." << string << ", false, false);\n")
337 .generate(sink, std::make_tuple(field_name, field.type, field_name), context)) 344 .generate(sink, std::make_tuple(field_name, field.type, field_name), context))
338 return false; 345 return false;
339 } 346 }
340 else if (complex && complex->outer.base_type == "hash") 347 else if (complex && complex->outer.base_type == "hash")
341 { 348 {
342 if (!as_generator( 349 if (!as_generator(
343 scope_tab << scope_tab << "_external_struct." << string << " = new " << type << "(_internal_struct." << string << ", false, false, false);\n") 350 indent << scope_tab << scope_tab << "_external_struct." << string << " = new " << type << "(_internal_struct." << string << ", false, false, false);\n")
344 .generate(sink, std::make_tuple(field_name, field.type, field_name), context)) 351 .generate(sink, std::make_tuple(field_name, field.type, field_name), context))
345 return false; 352 return false;
346 } 353 }
347 else if (field.type.is_ptr && helpers::need_pointer_conversion(regular) && !helpers::need_struct_conversion(regular)) 354 else if (field.type.is_ptr && helpers::need_pointer_conversion(regular) && !helpers::need_struct_conversion(regular))
348 { 355 {
349 if (!as_generator( 356 if (!as_generator(
350 scope_tab << scope_tab << "_external_struct." << string << " = Eina.PrimitiveConversion.PointerToManaged<" << type << ">(_internal_struct." << string << ");\n") 357 indent << scope_tab << scope_tab << "_external_struct." << string << " = Eina.PrimitiveConversion.PointerToManaged<" << type << ">(_internal_struct." << string << ");\n")
351 .generate(sink, std::make_tuple(field_name, field.type, field_name), context)) 358 .generate(sink, std::make_tuple(field_name, field.type, field_name), context))
352 return false; 359 return false;
353 } 360 }
354 else if (helpers::need_struct_conversion(regular)) 361 else if (helpers::need_struct_conversion(regular))
355 { 362 {
356 if (!as_generator( 363 if (!as_generator(
357 scope_tab << scope_tab << "_external_struct." << string << " = " << type << "_StructConversion.ToManaged(_internal_struct." << string << ");\n") 364 indent << scope_tab << scope_tab << "_external_struct." << string << " = " << type << "_StructConversion.ToManaged(_internal_struct." << string << ");\n")
358 .generate(sink, std::make_tuple(field_name, field.type, field_name), context)) 365 .generate(sink, std::make_tuple(field_name, field.type, field_name), context))
359 return false; 366 return false;
360 } 367 }
361 else if (regular && (regular->base_type == "string" || regular->base_type == "mstring" || regular->base_type == "stringshare")) 368 else if (regular && (regular->base_type == "string" || regular->base_type == "mstring" || regular->base_type == "stringshare"))
362 { 369 {
363 if (!as_generator( 370 if (!as_generator(
364 scope_tab << scope_tab << "_external_struct." << string << " = Eina.StringConversion.NativeUtf8ToManagedString(_internal_struct." << string << ");\n") 371 indent << scope_tab << scope_tab << "_external_struct." << string << " = Eina.StringConversion.NativeUtf8ToManagedString(_internal_struct." << string << ");\n")
365 .generate(sink, std::make_tuple(field_name, field_name), context)) 372 .generate(sink, std::make_tuple(field_name, field_name), context))
366 return false; 373 return false;
367 } 374 }
@@ -370,43 +377,43 @@ struct to_external_field_convert_generator
370 { 377 {
371 if (!as_generator( 378 if (!as_generator(
372 "\n" << 379 "\n" <<
373 scope_tab << scope_tab << "_external_struct." << field_name << ".Len = _internal_struct." << field_name << ".Len;\n" << 380 indent << scope_tab << scope_tab << "_external_struct." << field_name << ".Len = _internal_struct." << field_name << ".Len;\n" <<
374 scope_tab << scope_tab << "_external_struct." << field_name << ".Mem = _internal_struct." << field_name << ".Mem;\n\n") 381 indent << scope_tab << scope_tab << "_external_struct." << field_name << ".Mem = _internal_struct." << field_name << ".Mem;\n")
375 .generate(sink, attributes::unused, context)) 382 .generate(sink, attributes::unused, context))
376 return false; 383 return false;
377 } 384 }
378 else if (field.type.c_type == "Eina_Value" || field.type.c_type == "const Eina_Value") 385 else if (field.type.c_type == "Eina_Value" || field.type.c_type == "const Eina_Value")
379 { 386 {
380 if (!as_generator( 387 if (!as_generator(
381 scope_tab << scope_tab << "_external_struct." << string << " = new Eina.Value(_internal_struct." << string << ");\n" 388 indent << scope_tab << scope_tab << "_external_struct." << string << " = new Eina.Value(_internal_struct." << string << ");\n"
382 ).generate(sink, std::make_tuple(field_name, field_name), context)) 389 ).generate(sink, std::make_tuple(field_name, field_name), context))
383 return false; 390 return false;
384 } 391 }
385 else if (field.type.c_type == "Eina_Value *" || field.type.c_type == "const Eina_Value *") 392 else if (field.type.c_type == "Eina_Value *" || field.type.c_type == "const Eina_Value *")
386 { 393 {
387 if (!as_generator( 394 if (!as_generator(
388 scope_tab << scope_tab << "_external_struct." << string << " = new Eina.Value(_internal_struct." << string << ", Eina.Ownership.Unmanaged);\n" 395 indent << scope_tab << scope_tab << "_external_struct." << string << " = new Eina.Value(_internal_struct." << string << ", Eina.Ownership.Unmanaged);\n"
389 ).generate(sink, std::make_tuple(field_name, field_name), context)) 396 ).generate(sink, std::make_tuple(field_name, field_name), context))
390 return false; 397 return false;
391 } 398 }
392 else if (!field.type.is_ptr && regular && regular->base_type == "bool") 399 else if (!field.type.is_ptr && regular && regular->base_type == "bool")
393 { 400 {
394 if (!as_generator( 401 if (!as_generator(
395 scope_tab << scope_tab << "_external_struct." << string << " = _internal_struct." << string << " != 0;\n" 402 indent << scope_tab << scope_tab << "_external_struct." << string << " = _internal_struct." << string << " != 0;\n"
396 ).generate(sink, std::make_tuple(field_name, field_name), context)) 403 ).generate(sink, std::make_tuple(field_name, field_name), context))
397 return false; 404 return false;
398 } 405 }
399 else if (!field.type.is_ptr && regular && regular->base_type == "char") 406 else if (!field.type.is_ptr && regular && regular->base_type == "char")
400 { 407 {
401 if (!as_generator( 408 if (!as_generator(
402 scope_tab << scope_tab << "_external_struct." << string << " = (char)_internal_struct." << string << ";\n" 409 indent << scope_tab << scope_tab << "_external_struct." << string << " = (char)_internal_struct." << string << ";\n"
403 ).generate(sink, std::make_tuple(field_name, field_name), context)) 410 ).generate(sink, std::make_tuple(field_name, field_name), context))
404 return false; 411 return false;
405 } 412 }
406 else // primitives and enums 413 else // primitives and enums
407 { 414 {
408 if (!as_generator( 415 if (!as_generator(
409 scope_tab << scope_tab << "_external_struct." << string << " = _internal_struct." << string << ";\n") 416 indent << scope_tab << scope_tab << "_external_struct." << string << " = _internal_struct." << string << ";\n")
410 .generate(sink, std::make_tuple(field_name, field_name), context)) 417 .generate(sink, std::make_tuple(field_name, field_name), context))
411 return false; 418 return false;
412 } 419 }
@@ -419,11 +426,14 @@ struct struct_binding_conversion_functions_generator
419 template <typename OutputIterator, typename Context> 426 template <typename OutputIterator, typename Context>
420 bool generate(OutputIterator sink, attributes::struct_def const& struct_, Context const& context) const 427 bool generate(OutputIterator sink, attributes::struct_def const& struct_, Context const& context) const
421 { 428 {
429 auto const& indent = current_indentation(context);
430
422 // Open conversion class 431 // Open conversion class
423 if (!as_generator 432 if (!as_generator
424 ( 433 (
425 "/// <summary>Conversion class for struct " << name_helpers::typedecl_managed_name(struct_) << "</summary>\n" 434 indent << "/// <summary>Conversion class for struct " << name_helpers::typedecl_managed_name(struct_) << "</summary>\n"
426 "public static class " << name_helpers::typedecl_managed_name(struct_) << "_StructConversion\n{\n" 435 << indent << "public static class " << name_helpers::typedecl_managed_name(struct_) << "_StructConversion\n"
436 << indent << "{\n"
427 ) 437 )
428 .generate(sink, nullptr, context)) 438 .generate(sink, nullptr, context))
429 return false; 439 return false;
@@ -431,9 +441,9 @@ struct struct_binding_conversion_functions_generator
431 // to internal 441 // to internal
432 if (!as_generator 442 if (!as_generator
433 ( 443 (
434 scope_tab << "internal static " << string << " ToInternal(" << string << " _external_struct)\n" 444 indent << scope_tab << "internal static " << string << " ToInternal(" << string << " _external_struct)\n"
435 << scope_tab << "{\n" 445 << indent << scope_tab << "{\n"
436 << scope_tab << scope_tab << "var _internal_struct = new " << string << "();\n\n" 446 << indent << scope_tab << scope_tab << "var _internal_struct = new " << string << "();\n"
437 ) 447 )
438 .generate(sink, std::make_tuple(binding_struct_internal_name(struct_) 448 .generate(sink, std::make_tuple(binding_struct_internal_name(struct_)
439 , binding_struct_name(struct_) 449 , binding_struct_name(struct_)
@@ -449,9 +459,8 @@ struct struct_binding_conversion_functions_generator
449 459
450 if (!as_generator 460 if (!as_generator
451 ( 461 (
452 "\n" 462 indent << scope_tab << scope_tab << "return _internal_struct;\n"
453 << scope_tab << scope_tab << "return _internal_struct;\n" 463 << indent << scope_tab << "}\n\n"
454 << scope_tab << "}\n\n"
455 ) 464 )
456 .generate(sink, attributes::unused, context)) 465 .generate(sink, attributes::unused, context))
457 return false; 466 return false;
@@ -459,9 +468,9 @@ struct struct_binding_conversion_functions_generator
459 // to external 468 // to external
460 if (!as_generator 469 if (!as_generator
461 ( 470 (
462 scope_tab << "internal static " << string << " ToManaged(" << string << " _internal_struct)\n" 471 indent << scope_tab << "internal static " << string << " ToManaged(" << string << " _internal_struct)\n"
463 << scope_tab << "{\n" 472 << indent << scope_tab << "{\n"
464 << scope_tab << scope_tab << "var _external_struct = new " << string << "();\n\n" 473 << indent << scope_tab << scope_tab << "var _external_struct = new " << string << "();\n"
465 ) 474 )
466 .generate(sink, std::make_tuple(binding_struct_name(struct_) 475 .generate(sink, std::make_tuple(binding_struct_name(struct_)
467 , binding_struct_internal_name(struct_) 476 , binding_struct_internal_name(struct_)
@@ -477,15 +486,14 @@ struct struct_binding_conversion_functions_generator
477 486
478 if (!as_generator 487 if (!as_generator
479 ( 488 (
480 "\n" 489 indent << scope_tab << scope_tab << "return _external_struct;\n"
481 << scope_tab << scope_tab << "return _external_struct;\n" 490 << indent << scope_tab << "}\n\n"
482 << scope_tab << "}\n\n"
483 ) 491 )
484 .generate(sink, attributes::unused, context)) 492 .generate(sink, attributes::unused, context))
485 return false; 493 return false;
486 494
487 // Close conversion class 495 // Close conversion class
488 if (!as_generator("}\n").generate(sink, attributes::unused, context)) 496 if (!as_generator(indent << "}\n\n").generate(sink, attributes::unused, context))
489 return false; 497 return false;
490 498
491 return true; 499 return true;