summaryrefslogtreecommitdiff
path: root/src/bin/eolian_mono
diff options
context:
space:
mode:
authorLauro Moura <lauromoura@expertisesolutions.com.br>2018-03-19 20:35:36 -0300
committerFelipe Magno de Almeida <felipe@expertisesolutions.com.br>2018-03-20 16:50:30 -0300
commitf9586a831b8ba13542f59c9e1143c3d7b276bd51 (patch)
treebf1c81ace60441c4cf4007709ae32580db8ee58d /src/bin/eolian_mono
parent9a6dd32cb1e8f5b1bcd23d32fc4b2d5fa425abbd (diff)
csharp: Add support for efl parts as Properties
Instead of var bg = efl.ui.Background.static_cast(myobj.Part("background")); Now do var bg = myobj.Background; Also a couple helper functions were added.
Diffstat (limited to 'src/bin/eolian_mono')
-rw-r--r--src/bin/eolian_mono/eolian/mono/helpers.hh23
-rw-r--r--src/bin/eolian_mono/eolian/mono/klass.hh13
-rw-r--r--src/bin/eolian_mono/eolian/mono/part_definition.hh52
-rw-r--r--src/bin/eolian_mono/eolian/mono/utils.hh13
4 files changed, 96 insertions, 5 deletions
diff --git a/src/bin/eolian_mono/eolian/mono/helpers.hh b/src/bin/eolian_mono/eolian/mono/helpers.hh
index d1bebeee14..bdfdbb182c 100644
--- a/src/bin/eolian_mono/eolian/mono/helpers.hh
+++ b/src/bin/eolian_mono/eolian/mono/helpers.hh
@@ -2,6 +2,13 @@
2#define EOLIAN_MONO_HELPERS_HH 2#define EOLIAN_MONO_HELPERS_HH
3 3
4#include "grammar/klass_def.hpp" 4#include "grammar/klass_def.hpp"
5#include "utils.hh"
6
7/* General helper functions for the main generators.
8 *
9 * These range from blacklisting structures to 'nano-generators' (functions that receive
10 * a binding-specifict structure and returns a string).
11 */
5 12
6namespace eolian_mono { 13namespace eolian_mono {
7 14
@@ -102,9 +109,19 @@ inline bool need_pointer_conversion(attributes::regular_type_def const* regular)
102 109
103inline std::string to_field_name(std::string const& in) 110inline std::string to_field_name(std::string const& in)
104{ 111{
105 std::string field_name = in; 112 return utils::capitalize(in);
106 field_name[0] = std::toupper(field_name[0]); // Hack to allow 'static' as a field name 113}
107 return field_name; 114
115inline std::string klass_name_to_csharp(attributes::klass_name const& clsname)
116{
117 std::ostringstream output;
118
119 for (auto namesp : clsname.namespaces)
120 output << utils::to_lowercase(namesp) << ".";
121
122 output << clsname.eolian_name;
123
124 return output.str();
108} 125}
109 126
110} 127}
diff --git a/src/bin/eolian_mono/eolian/mono/klass.hh b/src/bin/eolian_mono/eolian/mono/klass.hh
index f0c73b3aaf..7de2f2b47b 100644
--- a/src/bin/eolian_mono/eolian/mono/klass.hh
+++ b/src/bin/eolian_mono/eolian/mono/klass.hh
@@ -15,6 +15,7 @@
15#include "function_registration.hh" 15#include "function_registration.hh"
16#include "function_declaration.hh" 16#include "function_declaration.hh"
17#include "documentation.hh" 17#include "documentation.hh"
18#include "part_definition.hh"
18#include "grammar/string.hpp" 19#include "grammar/string.hpp"
19#include "grammar/attribute_replace.hpp" 20#include "grammar/attribute_replace.hpp"
20#include "grammar/integral.hpp" 21#include "grammar/integral.hpp"
@@ -239,6 +240,10 @@ struct klass
239 return false; 240 return false;
240 } 241 }
241 242
243 for (auto &&p : cls.parts)
244 if (!as_generator( klass_name_to_csharp(p.klass) << " " << utils::capitalize(p.name) << "{ get;}\n").generate(sink, attributes::unused, iface_cxt))
245 return false;
246
242 // End of interface declaration 247 // End of interface declaration
243 if(!as_generator("}\n").generate(sink, attributes::unused, iface_cxt)) return false; 248 if(!as_generator("}\n").generate(sink, attributes::unused, iface_cxt)) return false;
244 } 249 }
@@ -331,6 +336,10 @@ struct klass
331 if (!generate_events_registration(sink, cls, concrete_cxt)) 336 if (!generate_events_registration(sink, cls, concrete_cxt))
332 return false; 337 return false;
333 338
339 // Parts
340 if(!as_generator(*(part_definition))
341 .generate(sink, cls.get_all_parts(), concrete_cxt)) return false;
342
334 // Concrete function definitions 343 // Concrete function definitions
335 if(!as_generator(*(function_definition)) 344 if(!as_generator(*(function_definition))
336 .generate(sink, methods, concrete_cxt)) return false; 345 .generate(sink, methods, concrete_cxt)) return false;
@@ -431,6 +440,10 @@ struct klass
431 if (!generate_events_registration(sink, cls, inherit_cxt)) 440 if (!generate_events_registration(sink, cls, inherit_cxt))
432 return false; 441 return false;
433 442
443 // Parts
444 if(!as_generator(*(part_definition))
445 .generate(sink, cls.get_all_parts(), inherit_cxt)) return false;
446
434 // Inherit function definitions 447 // Inherit function definitions
435 if(!as_generator(*(function_definition(true))) 448 if(!as_generator(*(function_definition(true)))
436 .generate(sink, methods, inherit_cxt)) return false; 449 .generate(sink, methods, inherit_cxt)) return false;
diff --git a/src/bin/eolian_mono/eolian/mono/part_definition.hh b/src/bin/eolian_mono/eolian/mono/part_definition.hh
new file mode 100644
index 0000000000..83222c9ed4
--- /dev/null
+++ b/src/bin/eolian_mono/eolian/mono/part_definition.hh
@@ -0,0 +1,52 @@
1#ifndef EOLIAN_MONO_PART_DEFINITION_HH
2#define EOLIAN_MONO_PART_DEFINITION_HH
3
4#include <Eina.hh>
5
6#include "grammar/generator.hpp"
7#include "grammar/klass_def.hpp"
8#include "grammar/indentation.hpp"
9
10#include "utils.hh"
11#include "documentation.hh"
12
13namespace eolian_mono {
14
15struct part_definition_generator
16{
17 template <typename OutputIterator, typename Context>
18 bool generate(OutputIterator sink, attributes::part_def const& part, Context const& context) const
19 {
20 std::string part_klass_name = klass_name_to_csharp(part.klass);
21 return as_generator(scope_tab << documentation
22 << scope_tab << "public " << part_klass_name << " " << utils::capitalize(part.name) << "\n"
23 << scope_tab << "{\n"
24 << scope_tab << scope_tab << "get\n"
25 << scope_tab << scope_tab << "{\n"
26 << scope_tab << scope_tab << scope_tab << "efl.Object obj = efl_part(raw_handle, \"" << part.name << "\");\n"
27 << scope_tab << scope_tab << scope_tab << "return " << part_klass_name << "Concrete.static_cast(obj);\n"
28 << scope_tab << scope_tab << "}\n"
29 << scope_tab << "}\n"
30 ).generate(sink, part.documentation, context);
31 }
32
33} const part_definition {};
34
35}
36
37namespace efl { namespace eolian { namespace grammar {
38
39template <>
40struct is_eager_generator< ::eolian_mono::part_definition_generator> : std::true_type {};
41template <>
42struct is_generator< ::eolian_mono::part_definition_generator> : std::true_type {};
43
44namespace type_traits {
45template <>
46struct attributes_needed< ::eolian_mono::part_definition_generator> : std::integral_constant<int, 1> {};
47
48}
49} } }
50
51#endif
52
diff --git a/src/bin/eolian_mono/eolian/mono/utils.hh b/src/bin/eolian_mono/eolian/mono/utils.hh
index 3e48e518b5..6be2076caa 100644
--- a/src/bin/eolian_mono/eolian/mono/utils.hh
+++ b/src/bin/eolian_mono/eolian/mono/utils.hh
@@ -4,19 +4,28 @@
4#include <string> 4#include <string>
5#include <algorithm> 5#include <algorithm>
6 6
7/* Compared to the helpers.hh header, these functions are lower level, not dealing with
8 * binding-specific structures or knowledge */
9
7namespace eolian_mono { namespace utils { 10namespace eolian_mono { namespace utils {
8 11
9 // Helper method to avoid multiple as_generator calls when mixing case strings 12 // Helper method to avoid multiple as_generator calls when mixing case strings
10 std::string to_uppercase(std::string s) 13 inline std::string to_uppercase(std::string s)
11 { 14 {
12 std::transform(s.begin(), s.end(), s.begin(), ::toupper); 15 std::transform(s.begin(), s.end(), s.begin(), ::toupper);
13 return s; 16 return s;
14 } 17 }
15 std::string to_lowercase(std::string s) 18 inline std::string to_lowercase(std::string s)
16 { 19 {
17 std::transform(s.begin(), s.end(), s.begin(), ::tolower); 20 std::transform(s.begin(), s.end(), s.begin(), ::tolower);
18 return s; 21 return s;
19 } 22 }
23 inline std::string capitalize(std::string const &s)
24 {
25 std::string ret = s;
26 ret[0] = std::toupper(ret[0]);
27 return ret;
28 }
20} } 29} }
21 30
22#endif 31#endif