summaryrefslogtreecommitdiff
path: root/src/bin/eolian_mono
diff options
context:
space:
mode:
authorLauro Moura <lauromoura@expertisesolutions.com.br>2018-04-10 22:30:40 -0300
committerFelipe Magno de Almeida <felipe@expertisesolutions.com.br>2018-04-12 21:23:42 -0300
commit65f868786a59533a1cbf9d58b886cdc4f49ceb94 (patch)
treea0d2478b2f8504cb14d2e06ea78cb3c5b655764a /src/bin/eolian_mono
parenta252c3445d2cf45aba332b6fcd634e54ee7239dc (diff)
efl_mono: Proper support for @class methods.
Previously, class methods were implemented as regular instance methods. This commits generates C# static methods for @class methods on the *Concrete classes (and their childs).
Diffstat (limited to 'src/bin/eolian_mono')
-rw-r--r--src/bin/eolian_mono/eolian/mono/function_declaration.hh2
-rw-r--r--src/bin/eolian_mono/eolian/mono/function_definition.hh13
-rw-r--r--src/bin/eolian_mono/eolian/mono/function_registration.hh2
-rw-r--r--src/bin/eolian_mono/eolian/mono/helpers.hh15
-rw-r--r--src/bin/eolian_mono/eolian/mono/klass.hh9
5 files changed, 29 insertions, 12 deletions
diff --git a/src/bin/eolian_mono/eolian/mono/function_declaration.hh b/src/bin/eolian_mono/eolian/mono/function_declaration.hh
index 76bbd6103b..fe35c5341d 100644
--- a/src/bin/eolian_mono/eolian/mono/function_declaration.hh
+++ b/src/bin/eolian_mono/eolian/mono/function_declaration.hh
@@ -19,7 +19,7 @@ struct function_declaration_generator
19 template <typename OutputIterator, typename Context> 19 template <typename OutputIterator, typename Context>
20 bool generate(OutputIterator sink, attributes::function_def const& f, Context const& context) const 20 bool generate(OutputIterator sink, attributes::function_def const& f, Context const& context) const
21 { 21 {
22 if(is_function_blacklisted(f.c_name)) 22 if(is_function_blacklisted(f.c_name) || f.is_static)
23 return true; 23 return true;
24 24
25 if(!as_generator(documentation).generate(sink, f, context)) 25 if(!as_generator(documentation).generate(sink, f, context))
diff --git a/src/bin/eolian_mono/eolian/mono/function_definition.hh b/src/bin/eolian_mono/eolian/mono/function_definition.hh
index 04e8921fad..e030434687 100644
--- a/src/bin/eolian_mono/eolian/mono/function_definition.hh
+++ b/src/bin/eolian_mono/eolian/mono/function_definition.hh
@@ -11,6 +11,7 @@
11#include "grammar/alternative.hpp" 11#include "grammar/alternative.hpp"
12#include "grammar/attribute_reorder.hpp" 12#include "grammar/attribute_reorder.hpp"
13#include "type.hh" 13#include "type.hh"
14#include "helpers.hh"
14#include "function_helpers.hh" 15#include "function_helpers.hh"
15#include "marshall_type.hh" 16#include "marshall_type.hh"
16#include "parameter.hh" 17#include "parameter.hh"
@@ -28,7 +29,7 @@ struct native_function_definition_generator
28 template <typename OutputIterator, typename Context> 29 template <typename OutputIterator, typename Context>
29 bool generate(OutputIterator sink, attributes::function_def const& f, Context const& context) const 30 bool generate(OutputIterator sink, attributes::function_def const& f, Context const& context) const
30 { 31 {
31 if(is_function_blacklisted(f.c_name)) 32 if(is_function_blacklisted(f.c_name) || f.is_static) // Only Concrete classes implement static methods.
32 return true; 33 return true;
33 else 34 else
34 { 35 {
@@ -131,10 +132,11 @@ struct function_definition_generator
131 template <typename OutputIterator, typename Context> 132 template <typename OutputIterator, typename Context>
132 bool generate(OutputIterator sink, attributes::function_def const& f, Context const& context) const 133 bool generate(OutputIterator sink, attributes::function_def const& f, Context const& context) const
133 { 134 {
135 if(do_super && f.is_static) // Static methods goes only on Concrete classes.
136 return true;
134 if(is_function_blacklisted(f.c_name)) 137 if(is_function_blacklisted(f.c_name))
135 return true; 138 return true;
136 else 139
137 {
138 if(!as_generator 140 if(!as_generator
139 ("\n\n" << scope_tab << "[System.Runtime.InteropServices.DllImport(" << context_find_tag<library_context>(context).actual_library_name(f.filename) << ")]\n" 141 ("\n\n" << scope_tab << "[System.Runtime.InteropServices.DllImport(" << context_find_tag<library_context>(context).actual_library_name(f.filename) << ")]\n"
140 << scope_tab << eolian_mono::marshall_annotation(true) 142 << scope_tab << eolian_mono::marshall_annotation(true)
@@ -159,11 +161,11 @@ struct function_definition_generator
159 return false; 161 return false;
160 162
161 if(!as_generator 163 if(!as_generator
162 (scope_tab << (do_super ? "virtual " : "") << "public " << return_type << " " << string << "(" << (parameter % ", ") 164 (scope_tab << (do_super ? "virtual " : "") << "public " << (f.is_static ? "static " : "") << return_type << " " << string << "(" << (parameter % ", ")
163 << ") {\n " 165 << ") {\n "
164 << eolian_mono::function_definition_preamble() << string << "(" 166 << eolian_mono::function_definition_preamble() << string << "("
165 << (do_super ? "efl.eo.Globals.efl_super(" : "") 167 << (do_super ? "efl.eo.Globals.efl_super(" : "")
166 << "this.raw_handle" 168 << (f.is_static ? klass_get_name(f.klass) + "()": "this.raw_handle")
167 << (do_super ? ", this.raw_klass)" : "") 169 << (do_super ? ", this.raw_klass)" : "")
168 << *(", " << argument_invocation ) << ");\n" 170 << *(", " << argument_invocation ) << ");\n"
169 << eolian_mono::function_definition_epilogue() 171 << eolian_mono::function_definition_epilogue()
@@ -172,7 +174,6 @@ struct function_definition_generator
172 return false; 174 return false;
173 175
174 return true; 176 return true;
175 }
176 } 177 }
177 178
178 bool do_super; 179 bool do_super;
diff --git a/src/bin/eolian_mono/eolian/mono/function_registration.hh b/src/bin/eolian_mono/eolian/mono/function_registration.hh
index a88c938924..aaae5511af 100644
--- a/src/bin/eolian_mono/eolian/mono/function_registration.hh
+++ b/src/bin/eolian_mono/eolian/mono/function_registration.hh
@@ -28,7 +28,7 @@ struct function_registration_generator
28 template <typename OutputIterator, typename Context> 28 template <typename OutputIterator, typename Context>
29 bool generate(OutputIterator sink, attributes::function_def const& f, Context const& context) const 29 bool generate(OutputIterator sink, attributes::function_def const& f, Context const& context) const
30 { 30 {
31 if(is_function_blacklisted(f.c_name)) 31 if(is_function_blacklisted(f.c_name) || f.is_static) // Static methods aren't overrideable
32 return true; 32 return true;
33 else 33 else
34 { 34 {
diff --git a/src/bin/eolian_mono/eolian/mono/helpers.hh b/src/bin/eolian_mono/eolian/mono/helpers.hh
index a281f524d5..420efc6984 100644
--- a/src/bin/eolian_mono/eolian/mono/helpers.hh
+++ b/src/bin/eolian_mono/eolian/mono/helpers.hh
@@ -125,6 +125,21 @@ inline std::string klass_name_to_csharp(attributes::klass_name const& clsname)
125 return output.str(); 125 return output.str();
126} 126}
127 127
128inline std::string klass_get_name(attributes::klass_name const &clsname)
129{
130 std::ostringstream output;
131
132 output << klass_name_to_csharp(clsname);
133 output << "Concrete.";
134
135 for (auto namesp : clsname.namespaces)
136 output << utils::to_lowercase(namesp) << "_";
137 output << utils::to_lowercase(clsname.eolian_name);
138 output << "_class_get";
139
140 return output.str();
141}
142
128} 143}
129 144
130#endif 145#endif
diff --git a/src/bin/eolian_mono/eolian/mono/klass.hh b/src/bin/eolian_mono/eolian/mono/klass.hh
index 2bfdbea3d7..bf3f27cdd5 100644
--- a/src/bin/eolian_mono/eolian/mono/klass.hh
+++ b/src/bin/eolian_mono/eolian/mono/klass.hh
@@ -69,12 +69,12 @@ static bool generate_equals_method(OutputIterator sink, Context const &context)
69 69
70/* Get the actual number of functions of a class, checking for blacklisted ones */ 70/* Get the actual number of functions of a class, checking for blacklisted ones */
71static std::size_t 71static std::size_t
72get_function_count(grammar::attributes::klass_def const& cls) 72get_inheritable_function_count(grammar::attributes::klass_def const& cls)
73{ 73{
74 auto methods = cls.get_all_methods(); 74 auto methods = cls.get_all_methods();
75 return std::count_if(methods.cbegin(), methods.cend(), [](grammar::attributes::function_def const& func) 75 return std::count_if(methods.cbegin(), methods.cend(), [](grammar::attributes::function_def const& func)
76 { 76 {
77 return !is_function_blacklisted(func.c_name); 77 return !is_function_blacklisted(func.c_name) && !func.is_static;
78 }); 78 });
79} 79}
80 80
@@ -268,8 +268,9 @@ struct klass
268 << scope_tab << "}\n" 268 << scope_tab << "}\n"
269 << scope_tab << "///<summary>Delegate for function to be called from inside the native constructor.</summary>\n" 269 << scope_tab << "///<summary>Delegate for function to be called from inside the native constructor.</summary>\n"
270 << scope_tab << "public delegate void ConstructingMethod(" << string << " obj);\n" 270 << scope_tab << "public delegate void ConstructingMethod(" << string << " obj);\n"
271 << scope_tab << "///<summary>Returns the pointer the unerlying Eo class object. Used internally on class methods.</summary>\n"
271 << scope_tab << "[System.Runtime.InteropServices.DllImport(" << context_find_tag<library_context>(concrete_cxt).actual_library_name(cls.filename) 272 << scope_tab << "[System.Runtime.InteropServices.DllImport(" << context_find_tag<library_context>(concrete_cxt).actual_library_name(cls.filename)
272 << ")] private static extern System.IntPtr\n" 273 << ")] public static extern System.IntPtr\n"
273 << scope_tab << scope_tab << class_get_name << "();\n" 274 << scope_tab << scope_tab << class_get_name << "();\n"
274 << (class_type == "class" ? "" : "/*") 275 << (class_type == "class" ? "" : "/*")
275 << scope_tab << "///<summary>Creates a new instance.</summary>\n" 276 << scope_tab << "///<summary>Creates a new instance.</summary>\n"
@@ -451,7 +452,7 @@ struct klass
451 if(!as_generator("}\n").generate(sink, attributes::unused, inherit_cxt)) return false; 452 if(!as_generator("}\n").generate(sink, attributes::unused, inherit_cxt)) return false;
452 } 453 }
453 454
454 std::size_t function_count = get_function_count(cls); 455 std::size_t function_count = get_inheritable_function_count(cls);
455 456
456 int function_registration_index = 0; 457 int function_registration_index = 0;
457 auto index_generator = [&function_registration_index] 458 auto index_generator = [&function_registration_index]