summaryrefslogtreecommitdiff
path: root/src/bin/eolian_mono
diff options
context:
space:
mode:
authorLauro Moura <lauromoura@expertisesolutions.com.br>2018-04-16 12:36:51 -0300
committerLauro Moura <lauromoura@expertisesolutions.com.br>2018-04-26 10:55:18 -0300
commit628e5ab95029c222e5f2eca3fa9a3702015fb8c1 (patch)
treef819d6e41a6c0981751003a81058affbb4ad986e /src/bin/eolian_mono
parente59e8f0a15a6e1a699c1395e12b9431ea430c2b8 (diff)
efl_mono: Use PascalCase in events
Summary: To deal with events with the same name as some methods (Del, Invalidate, etc), the suffix Evt was added. Thus, now we use obj.ButtonClickedEvt += callback; Instead of obj.BUTTON_CLICKED += cal The argument classes use the same scheme, being called <Evt name>_Args. Depends on D5991 Reviewers: felipealmeida Reviewed By: felipealmeida Subscribers: cedric Differential Revision: https://phab.enlightenment.org/D5992
Diffstat (limited to 'src/bin/eolian_mono')
-rw-r--r--src/bin/eolian_mono/eolian/mono/keyword.hh4
-rw-r--r--src/bin/eolian_mono/eolian/mono/klass.hh15
-rw-r--r--src/bin/eolian_mono/eolian/mono/name_helpers.hh33
-rw-r--r--src/bin/eolian_mono/eolian/mono/utils.hh41
4 files changed, 53 insertions, 40 deletions
diff --git a/src/bin/eolian_mono/eolian/mono/keyword.hh b/src/bin/eolian_mono/eolian/mono/keyword.hh
index 71771b2c5c..e73db31ec8 100644
--- a/src/bin/eolian_mono/eolian/mono/keyword.hh
+++ b/src/bin/eolian_mono/eolian/mono/keyword.hh
@@ -39,11 +39,11 @@ inline std::string escape_keyword(std::string const& name)
39 39
40std::string managed_method_name(std::string const& underscore_name) 40std::string managed_method_name(std::string const& underscore_name)
41{ 41{
42 std::vector<std::string> names = name_helpers::split(underscore_name, '_'); 42 std::vector<std::string> names = utils::split(underscore_name, '_');
43 43
44 name_helpers::reorder_verb(names); 44 name_helpers::reorder_verb(names);
45 45
46 return escape_keyword(name_helpers::pascal_case(names)); 46 return escape_keyword(utils::to_pascal_case(names));
47} 47}
48 48
49} 49}
diff --git a/src/bin/eolian_mono/eolian/mono/klass.hh b/src/bin/eolian_mono/eolian/mono/klass.hh
index a5f380932c..fa55828df6 100644
--- a/src/bin/eolian_mono/eolian/mono/klass.hh
+++ b/src/bin/eolian_mono/eolian/mono/klass.hh
@@ -173,8 +173,7 @@ struct klass
173 if (!etype.is_engaged()) 173 if (!etype.is_engaged())
174 continue; 174 continue;
175 175
176 std::string evt_name = utils::to_uppercase(e.name); 176 std::string evt_name = name_helpers::managed_event_name(e.name);
177 std::replace(evt_name.begin(), evt_name.end(), ',', '_');
178 std::string arg_type = (*etype).original_type.visit(get_csharp_type_visitor{}); 177 std::string arg_type = (*etype).original_type.visit(get_csharp_type_visitor{});
179 178
180 if (!as_generator("///<summary>Event argument wrapper for event " << string << ".</summary>\n" 179 if (!as_generator("///<summary>Event argument wrapper for event " << string << ".</summary>\n"
@@ -221,7 +220,7 @@ struct klass
221 for (auto &&e : cls.events) 220 for (auto &&e : cls.events)
222 { 221 {
223 std::string wrapper_args_type; 222 std::string wrapper_args_type;
224 std::string evt_name = utils::to_uppercase(e.name); 223 std::string evt_name = name_helpers::managed_event_name(e.name);
225 std::replace(evt_name.begin(), evt_name.end(), ',', '_'); 224 std::replace(evt_name.begin(), evt_name.end(), ',', '_');
226 225
227 efl::eina::optional<grammar::attributes::type_def> etype = e.type; 226 efl::eina::optional<grammar::attributes::type_def> etype = e.type;
@@ -569,9 +568,7 @@ struct klass
569 s << n; 568 s << n;
570 s << '_'; 569 s << '_';
571 } 570 }
572 std::string evt_name = utils::to_uppercase(evt.name); 571 s << klass.cxx_name << '_' << name_helpers::managed_event_name(evt.name);
573 std::replace(evt_name.begin(), evt_name.end(), ',', '_');
574 s << klass.cxx_name << '_' << evt_name;
575 return s.str(); 572 return s.str();
576 } 573 }
577 574
@@ -633,8 +630,7 @@ struct klass
633 // Self events 630 // Self events
634 for (auto&& e : cls.events) 631 for (auto&& e : cls.events)
635 { 632 {
636 std::string upper_name = utils::to_uppercase(e.name); 633 std::string upper_name = name_helpers::managed_event_name(e.name);
637 std::replace(upper_name.begin(), upper_name.end(), ',', '_');
638 std::string upper_c_name = utils::to_uppercase(e.c_name); 634 std::string upper_c_name = utils::to_uppercase(e.c_name);
639 std::string event_name = e.name; 635 std::string event_name = e.name;
640 std::replace(event_name.begin(), event_name.end(), ',', '_'); 636 std::replace(event_name.begin(), event_name.end(), ',', '_');
@@ -720,8 +716,7 @@ struct klass
720 { 716 {
721 717
722 std::string wrapper_evt_name = translate_inherited_event_name(e, klass); 718 std::string wrapper_evt_name = translate_inherited_event_name(e, klass);
723 std::string upper_name = utils::to_uppercase(e.name); 719 std::string upper_name = name_helpers::managed_event_name(e.name);
724 std::replace(upper_name.begin(), upper_name.end(), ',', '_');
725 std::string upper_c_name = utils::to_uppercase(e.c_name); 720 std::string upper_c_name = utils::to_uppercase(e.c_name);
726 721
727 std::stringstream wrapper_args_type; 722 std::stringstream wrapper_args_type;
diff --git a/src/bin/eolian_mono/eolian/mono/name_helpers.hh b/src/bin/eolian_mono/eolian/mono/name_helpers.hh
index 6b40829b20..4ae988cf5f 100644
--- a/src/bin/eolian_mono/eolian/mono/name_helpers.hh
+++ b/src/bin/eolian_mono/eolian/mono/name_helpers.hh
@@ -7,9 +7,14 @@
7#include <sstream> 7#include <sstream>
8#include <string> 8#include <string>
9#include <vector> 9#include <vector>
10#include "utils.hh"
10 11
11namespace eolian_mono { 12namespace eolian_mono {
12 13
14/* Utility functions for naming things. Compared to the utils.hh, this header has higher level
15 * functions, dealing with the knowledge of how to convert the items to the C# style we are using, for
16 * example, while being too short to be implemented as full-fledged generators.
17 */
13namespace name_helpers { 18namespace name_helpers {
14 19
15static const std::vector<std::string> verbs = 20static const std::vector<std::string> verbs =
@@ -103,33 +108,9 @@ void reorder_verb(std::vector<std::string> &names)
103 } 108 }
104} 109}
105 110
106std::vector<std::string> split(std::string const &input, char delim) 111std::string managed_event_name(std::string const& name)
107{ 112{
108 std::stringstream ss(input); 113 return utils::to_pascal_case(utils::split(name, ','), "") + "Evt";
109 std::string name;
110 std::vector<std::string> names;
111
112 while (std::getline(ss, name, delim)) {
113 if (!name.empty())
114 names.push_back(name);
115 }
116 return names;
117}
118
119std::string pascal_case(const std::vector<std::string> &names)
120{
121 std::vector<std::string> outv(names.size());
122 std::stringstream osstream;
123
124 std::transform(names.begin(), names.end(), outv.begin(),
125 [](std::string name) {
126 name[0] = std::toupper(name[0]);
127 return name;
128 });
129
130 std::copy(outv.begin(), outv.end(), std::ostream_iterator<std::string>(osstream, ""));
131
132 return osstream.str();
133} 114}
134 115
135} // namespace name_helpers 116} // namespace name_helpers
diff --git a/src/bin/eolian_mono/eolian/mono/utils.hh b/src/bin/eolian_mono/eolian/mono/utils.hh
index 6be2076caa..0e1c2efc29 100644
--- a/src/bin/eolian_mono/eolian/mono/utils.hh
+++ b/src/bin/eolian_mono/eolian/mono/utils.hh
@@ -2,10 +2,12 @@
2#define EOLIAN_MONO_UTILS_HPP 2#define EOLIAN_MONO_UTILS_HPP
3 3
4#include <string> 4#include <string>
5#include <sstream>
6#include <iterator>
5#include <algorithm> 7#include <algorithm>
6 8
7/* Compared to the helpers.hh header, these functions are lower level, not dealing with 9/* Compared to the helpers.hh and name_helpers headers, these functions are
8 * binding-specific structures or knowledge */ 10 * lower level, not dealing with binding-specific structures or knowledge */
9 11
10namespace eolian_mono { namespace utils { 12namespace eolian_mono { namespace utils {
11 13
@@ -26,6 +28,41 @@ namespace eolian_mono { namespace utils {
26 ret[0] = std::toupper(ret[0]); 28 ret[0] = std::toupper(ret[0]);
27 return ret; 29 return ret;
28 } 30 }
31
32 std::vector<std::string> split(std::string const &input, char delim)
33 {
34 std::stringstream ss(input);
35 std::string name;
36 std::vector<std::string> names;
37
38 while (std::getline(ss, name, delim))
39 {
40 if (!name.empty())
41 names.push_back(name);
42 }
43 return names;
44 }
45
46 std::string to_pascal_case(const std::vector<std::string> &names, std::string const& delim="")
47 {
48 std::vector<std::string> outv(names.size());
49 std::stringstream osstream;
50
51 std::transform(names.begin(), names.end(), outv.begin(),
52 [](std::string name) {
53 name[0] = std::toupper(name[0]);
54 return name;
55 });
56
57 std::copy(outv.begin(), outv.end(), std::ostream_iterator<std::string>(osstream, delim.c_str()));
58
59 std::string ret = osstream.str();
60
61 if (delim != "")
62 ret.pop_back(); // We could implement an infix_iterator but this pop is enough for now.
63
64 return ret;
65 }
29} } 66} }
30 67
31#endif 68#endif