summaryrefslogtreecommitdiff
path: root/src/bin/eolian_cxx
diff options
context:
space:
mode:
authorSavio Sena <savio.sena@acm.org>2014-07-01 10:55:45 +0100
committerDaniel Kolesa <d.kolesa@samsung.com>2014-07-01 10:55:45 +0100
commitce63b16f400ae041d66a79f7d6d8c09838a7af12 (patch)
tree001befeaa20be58fb61ace4dee1d19cf09adb03e /src/bin/eolian_cxx
parent86aa034379113b92cb8cdbc7904c42ea87466c6f (diff)
eolian-cxx: Make proper handling of namespaces.
Summary: The generation of class prefixes was not taking into account the full classname -- the namespace was not being prepended to it. Fixed that and also re-organized the code a bit, removed some Wshadow warnings also. This commit fixes 'make examples' and 'make check'. Reviewers: tasn, cedric, q66 CC: felipealmeida, smohanty, cedric Differential Revision: https://phab.enlightenment.org/D1100
Diffstat (limited to 'src/bin/eolian_cxx')
-rw-r--r--src/bin/eolian_cxx/convert.cc53
-rw-r--r--src/bin/eolian_cxx/eolian_wrappers.hh55
-rw-r--r--src/bin/eolian_cxx/safe_strings.hh19
3 files changed, 71 insertions, 56 deletions
diff --git a/src/bin/eolian_cxx/convert.cc b/src/bin/eolian_cxx/convert.cc
index 0b7b8366da..e50dd4626d 100644
--- a/src/bin/eolian_cxx/convert.cc
+++ b/src/bin/eolian_cxx/convert.cc
@@ -22,15 +22,6 @@ namespace eolian_cxx {
22 22
23extern efl::eina::log_domain domain; 23extern efl::eina::log_domain domain;
24 24
25static std::string
26_dedup_func_name(Eolian_Function func, const std::string &classn)
27{
28 const char *s = eolian_function_full_c_name_get(func, classn.c_str());
29 std::string ret(s);
30 eina_stringshare_del(s);
31 return ret;
32}
33
34static efl::eolian::parameters_container_type 25static efl::eolian::parameters_container_type
35convert_eolian_parameters(Eina_List const* parameters, 26convert_eolian_parameters(Eina_List const* parameters,
36 Eolian_Function_Type func_type) 27 Eolian_Function_Type func_type)
@@ -55,33 +46,30 @@ convert_eolian_parameters(Eina_List const* parameters,
55} 46}
56 47
57static efl::eolian::parameters_container_type 48static efl::eolian::parameters_container_type
58convert_eolian_parameters(Eolian_Function const& function, 49convert_eolian_parameters(Eolian_Function const& func, getter_t func_type)
59 getter_t func_type)
60{ 50{
61 return convert_eolian_parameters 51 return convert_eolian_parameters
62 (::eolian_parameters_list_get(function), func_type.value); 52 (::eolian_parameters_list_get(func), func_type.value);
63} 53}
64 54
65static efl::eolian::parameters_container_type 55static efl::eolian::parameters_container_type
66convert_eolian_parameters(Eina_List const* parameters, 56convert_eolian_parameters(Eina_List const* parameters, getter_t func_type)
67 getter_t func_type)
68{ 57{
69 return convert_eolian_parameters(parameters, func_type.value); 58 return convert_eolian_parameters(parameters, func_type.value);
70} 59}
71 60
72static efl::eolian::parameters_container_type 61static efl::eolian::parameters_container_type
73convert_eolian_parameters(Eina_List const* parameters, 62convert_eolian_parameters(Eina_List const* parameters, setter_t func_type)
74 setter_t func_type)
75{ 63{
76 return convert_eolian_parameters(parameters, func_type.value); 64 return convert_eolian_parameters(parameters, func_type.value);
77} 65}
78 66
79static efl::eolian::parameters_container_type 67static efl::eolian::parameters_container_type
80convert_eolian_parameters(Eolian_Function const& function) 68convert_eolian_parameters(Eolian_Function const& func)
81{ 69{
82 assert(function_type(function) != EOLIAN_PROPERTY); 70 assert(function_type(func) != EOLIAN_PROPERTY);
83 return convert_eolian_parameters 71 return convert_eolian_parameters
84 (::eolian_parameters_list_get(function), function_type(function)); 72 (::eolian_parameters_list_get(func), function_type(func));
85} 73}
86 74
87static efl::eolian::functions_container_type 75static efl::eolian::functions_container_type
@@ -105,7 +93,7 @@ convert_eolian_property_to_functions(Eolian_Class const& klass)
105 efl::eolian::eo_function get_; 93 efl::eolian::eo_function get_;
106 get_.type = efl::eolian::eo_function::regular_; 94 get_.type = efl::eolian::eo_function::regular_;
107 get_.name = function_name(prop_) + "_get"; 95 get_.name = function_name(prop_) + "_get";
108 get_.impl = _dedup_func_name(prop_, prefix) + "_get"; 96 get_.impl = function_impl(prop_, prefix) + "_get";
109 97
110 efl::eolian::eolian_type_instance ret = 98 efl::eolian::eolian_type_instance ret =
111 function_return_type(prop_, eolian_cxx::getter); 99 function_return_type(prop_, eolian_cxx::getter);
@@ -157,7 +145,7 @@ convert_eolian_property_to_functions(Eolian_Class const& klass)
157 efl::eolian::eo_function set_; 145 efl::eolian::eo_function set_;
158 set_.type = efl::eolian::eo_function::regular_; 146 set_.type = efl::eolian::eo_function::regular_;
159 set_.name = function_name(prop_) + "_set"; 147 set_.name = function_name(prop_) + "_set";
160 set_.impl = _dedup_func_name(prop_, prefix) + "_set"; 148 set_.impl = function_impl(prop_, prefix) + "_set";
161 set_.params = params; 149 set_.params = params;
162 set_.ret = function_return_type(prop_, eolian_cxx::setter); 150 set_.ret = function_return_type(prop_, eolian_cxx::setter);
163 set_.comment = convert_comments_function(prop_, eolian_cxx::setter); 151 set_.comment = convert_comments_function(prop_, eolian_cxx::setter);
@@ -241,7 +229,7 @@ convert_eolian_constructors(efl::eolian::eo_class& cls, Eolian_Class const& klas
241 { 229 {
242 Eolian_Function eo_constructor = static_cast<Eolian_Function>(curr); 230 Eolian_Function eo_constructor = static_cast<Eolian_Function>(curr);
243 efl::eolian::eo_constructor constructor; 231 efl::eolian::eo_constructor constructor;
244 constructor.name = _dedup_func_name(eo_constructor, prefix); 232 constructor.name = function_impl(eo_constructor, prefix);
245 constructor.params = convert_eolian_parameters(eo_constructor); 233 constructor.params = convert_eolian_parameters(eo_constructor);
246 constructor.comment = convert_comments_function(eo_constructor, eolian_cxx::ctor); 234 constructor.comment = convert_comments_function(eo_constructor, eolian_cxx::ctor);
247 cls.constructors.push_back(constructor); 235 cls.constructors.push_back(constructor);
@@ -258,17 +246,16 @@ convert_eolian_functions(efl::eolian::eo_class& cls, Eolian_Class const& klass)
258 eolian_class_functions_list_get(klass, EOLIAN_METHOD); 246 eolian_class_functions_list_get(klass, EOLIAN_METHOD);
259 EINA_LIST_FOREACH (eolian_functions, it, curr) 247 EINA_LIST_FOREACH (eolian_functions, it, curr)
260 { 248 {
261 efl::eolian::eo_function function; 249 efl::eolian::eo_function func_;
262 Eolian_Function eolian_function = static_cast<Eolian_Function>(curr); 250 Eolian_Function eol_func = static_cast<Eolian_Function>(curr);
263 std::string prefix(class_prefix(klass));
264 // XXX Eolian only provides regular methods so far 251 // XXX Eolian only provides regular methods so far
265 function.type = efl::eolian::eo_function::regular_; 252 func_.type = efl::eolian::eo_function::regular_;
266 function.name = function_name(eolian_function); 253 func_.name = function_name(eol_func);
267 function.impl = _dedup_func_name(eolian_function, prefix); 254 func_.impl = function_impl(eol_func, class_prefix(klass));
268 function.ret = function_return_type(eolian_function); 255 func_.ret = function_return_type(eol_func);
269 function.params = convert_eolian_parameters(eolian_function); 256 func_.params = convert_eolian_parameters(eol_func);
270 function.comment = convert_comments_function(eolian_function, eolian_cxx::method); 257 func_.comment = convert_comments_function(eol_func, eolian_cxx::method);
271 cls.functions.push_back(function); 258 cls.functions.push_back(func_);
272 } 259 }
273} 260}
274 261
@@ -295,7 +282,7 @@ convert_eolian_class_new(Eolian_Class const& klass)
295 efl::eolian::eo_class cls; 282 efl::eolian::eo_class cls;
296 cls.type = class_type(klass); 283 cls.type = class_type(klass);
297 cls.name = safe_lower(class_name(klass)); 284 cls.name = safe_lower(class_name(klass));
298 cls.name_space = safe_lower(class_namespace_full(klass)); 285 cls.name_space = class_namespace_full(klass);
299 cls.eo_name = class_eo_name(klass); 286 cls.eo_name = class_eo_name(klass);
300 cls.comment = convert_comments_class(klass); 287 cls.comment = convert_comments_class(klass);
301 return cls; 288 return cls;
diff --git a/src/bin/eolian_cxx/eolian_wrappers.hh b/src/bin/eolian_cxx/eolian_wrappers.hh
index 2472e4a42d..e357c25ab4 100644
--- a/src/bin/eolian_cxx/eolian_wrappers.hh
+++ b/src/bin/eolian_cxx/eolian_wrappers.hh
@@ -109,7 +109,7 @@ class_prefix(Eolian_Class const& klass)
109{ 109{
110 std::string prefix = safe_lower(::eolian_class_eo_prefix_get(klass)); 110 std::string prefix = safe_lower(::eolian_class_eo_prefix_get(klass));
111 if (prefix.empty()) 111 if (prefix.empty())
112 prefix = safe_lower(class_name(klass)); 112 prefix = safe_lower(find_replace(class_full_name(klass), ".", "_"));
113 assert(!prefix.empty()); 113 assert(!prefix.empty());
114 return prefix; 114 return prefix;
115} 115}
@@ -148,7 +148,7 @@ class_namespace_full(Eolian_Class const& klass)
148 } 148 }
149 if (s.size() >= 2) 149 if (s.size() >= 2)
150 s = s.substr(0, s.size()-2); 150 s = s.substr(0, s.size()-2);
151 return s; 151 return safe_lower(s);
152} 152}
153 153
154inline efl::eina::range_ptr_list<const Eolian_Class> 154inline efl::eina::range_ptr_list<const Eolian_Class>
@@ -158,46 +158,55 @@ class_list_all()
158} 158}
159 159
160inline std::string 160inline std::string
161function_name(Eolian_Function const& function) 161function_name(Eolian_Function const& func)
162{
163 return safe_str(::eolian_function_name_get(func));
164}
165
166inline std::string
167function_impl(Eolian_Function const& func, std::string const& prefix)
162{ 168{
163 return safe_str(::eolian_function_name_get(function)); 169 const char *s = ::eolian_function_full_c_name_get(func, prefix.c_str());
170 std::string ret(s);
171 ::eina_stringshare_del(s);
172 return ret;
164} 173}
165 174
166inline Eolian_Function_Type 175inline Eolian_Function_Type
167function_type(Eolian_Function const& function) 176function_type(Eolian_Function const& func)
168{ 177{
169 return ::eolian_function_type_get(function); 178 return ::eolian_function_type_get(func);
170} 179}
171 180
172inline efl::eolian::eolian_type_instance 181inline efl::eolian::eolian_type_instance
173function_return_type(Eolian_Function const& function, Eolian_Function_Type func_type = method_t::value) 182function_return_type(Eolian_Function const& func, Eolian_Function_Type func_type = method_t::value)
174{ 183{
175 return type_lookup 184 return type_lookup
176 (::eolian_function_return_type_get(function, func_type)); 185 (::eolian_function_return_type_get(func, func_type));
177} 186}
178 187
179inline efl::eolian::eolian_type_instance 188inline efl::eolian::eolian_type_instance
180function_return_type(Eolian_Function const& function, setter_t func_type) 189function_return_type(Eolian_Function const& func, setter_t func_type)
181{ 190{
182 return function_return_type(function, func_type.value); 191 return function_return_type(func, func_type.value);
183} 192}
184 193
185inline efl::eolian::eolian_type_instance 194inline efl::eolian::eolian_type_instance
186function_return_type(Eolian_Function const& function, getter_t func_type) 195function_return_type(Eolian_Function const& func, getter_t func_type)
187{ 196{
188 return function_return_type(function, func_type.value); 197 return function_return_type(func, func_type.value);
189} 198}
190 199
191inline efl::eolian::eolian_type_instance 200inline efl::eolian::eolian_type_instance
192function_return_type(Eolian_Function const& function, method_t func_type) 201function_return_type(Eolian_Function const& func, method_t func_type)
193{ 202{
194 return function_return_type(function, func_type.value); 203 return function_return_type(func, func_type.value);
195} 204}
196 205
197inline efl::eolian::eolian_type_instance 206inline efl::eolian::eolian_type_instance
198function_return_type(Eolian_Function const& function, ctor_t func_type) 207function_return_type(Eolian_Function const& func, ctor_t func_type)
199{ 208{
200 return function_return_type(function, func_type.value); 209 return function_return_type(func, func_type.value);
201} 210}
202 211
203inline bool 212inline bool
@@ -207,9 +216,9 @@ property_is_getter(Eolian_Function_Type func_type)
207} 216}
208 217
209inline bool 218inline bool
210property_is_getter(Eolian_Function const& function) 219property_is_getter(Eolian_Function const& func)
211{ 220{
212 return property_is_getter(function_type(function)); 221 return property_is_getter(function_type(func));
213} 222}
214 223
215inline bool 224inline bool
@@ -219,9 +228,9 @@ property_is_setter(Eolian_Function_Type func_type)
219} 228}
220 229
221inline bool 230inline bool
222property_is_setter(Eolian_Function const& function) 231property_is_setter(Eolian_Function const& func)
223{ 232{
224 return property_is_setter(function_type(function)); 233 return property_is_setter(function_type(func));
225} 234}
226 235
227inline std::string 236inline std::string
@@ -264,11 +273,11 @@ parameter_is_const(Eolian_Function_Parameter const& parameter,
264 273
265inline bool 274inline bool
266parameter_is_const(Eolian_Function_Parameter const& parameter, 275parameter_is_const(Eolian_Function_Parameter const& parameter,
267 Eolian_Function const& function) 276 Eolian_Function const& func)
268{ 277{
269 assert(function_type(function) != EOLIAN_PROPERTY); 278 assert(function_type(func) != EOLIAN_PROPERTY);
270 return ::eolian_parameter_const_attribute_get 279 return ::eolian_parameter_const_attribute_get
271 (parameter, property_is_getter(function)); 280 (parameter, property_is_getter(func));
272} 281}
273 282
274inline efl::eolian::eolian_type_instance 283inline efl::eolian::eolian_type_instance
diff --git a/src/bin/eolian_cxx/safe_strings.hh b/src/bin/eolian_cxx/safe_strings.hh
index b45a4ff32d..d9a906984e 100644
--- a/src/bin/eolian_cxx/safe_strings.hh
+++ b/src/bin/eolian_cxx/safe_strings.hh
@@ -94,6 +94,8 @@ normalize_spaces(std::string const& s)
94 return r; 94 return r;
95} 95}
96 96
97/// @brief Return the basename of a path.
98///
97inline std::string 99inline std::string
98path_base(std::string path) 100path_base(std::string path)
99{ 101{
@@ -102,5 +104,22 @@ path_base(std::string path)
102 return std::string(slash.base(), path.end()); 104 return std::string(slash.base(), path.end());
103} 105}
104 106
107/// @brief Find-and-replace patterns in a string.
108///
109inline std::string
110find_replace(std::string const& s_,
111 std::string const& old,
112 std::string const& new_)
113{
114 std::string s = s_;
115 std::string::size_type found = s.find(old);
116 std::string::size_type len = new_.length();
117 while (found != std::string::npos)
118 {
119 s.replace(found, len, new_);
120 found = s.find(old);
121 }
122 return s;
123}
105 124
106#endif // EOLIAN_CXX_BIN_SAFE_STRINGS_HH 125#endif // EOLIAN_CXX_BIN_SAFE_STRINGS_HH