summaryrefslogtreecommitdiff
path: root/src/bin/eolian_mono/eolian/mono/function_definition.hh
diff options
context:
space:
mode:
authorLauro Moura <lauromoura@expertisesolutions.com.br>2018-11-29 21:04:37 -0200
committerVitor Sousa <vitorsousa@expertisesolutions.com.br>2018-11-29 21:29:48 -0200
commit3623753c1d6b893955a1c31e8559a2312f674192 (patch)
treee862682ff92d34ce4ebf44c95efa24ba3a57fe7a /src/bin/eolian_mono/eolian/mono/function_definition.hh
parenteec7bc458eee333fd7237a3bd43e8c2c884f21ca (diff)
csharp: Change to new class API.
Summary: As discussed in T7204: - Eo Interfaces/mixins -> C# Interfaces with concrete class implementations - Eo Regular/Abstracts -> Proper C# classes - Added some new generators and helper methods. - Refactored the class generator, splitting into helper methods Eo handles now are stored only in the "root" class in any given inheritance tree (generally, Efl.Object), and accessible to each child. Methods also are defined in a single place instead of repeatedly generated in everyfile, reducing the size of the generated .dll from 30MB to around 4.5MB. Mixins are generated as C# interfaces but any regular class it inherits from is lost, as we can't have interfaces inheriting from regular classes. This will be dealt with in a later commit. Summary of API Changes: - Merged Inherit/Concrete classes. (These suffixes disappear from regular classes). - Interface still have implementations with 'Concrete' suffix for when they are returned from methods. - Removed 'I' from interface names. - Removed interfaces for regular/abstract Eo classes. - Concrete classes for interfaces/mixins hold the event argument struct. - Removed '_' from classes, enums, structs, etc, as indicated in C# naming conventions. - Namespaces are now Camel.Cased. - Renamed IWrapper's raw_handle/raw_klass to NativeHandle/NativeClass Also renamed the test classes as after the namespace change, the test namespace Test can conflict with the helper Test namespace. (And use more meaningful names than Test.Testing...) Also Fixes T7336 by removing a deprecated example and adding efl_loop_timer_example to build system. Fixes T7451 by hiding the class_get DllImports and renaming the IWrapper fields. The native handlers are used in the manual binding. Still need to work: - As there are still some events names clashing (e.g. Efl.Ui.Bg with "resize" from Efl.Gfx.Entity and Efl.Gfx.Image), Events are currently declared on the interface and implemented "namespaced" in the classes, requiring the cast to the interface to access the event. - The Mixin Conundrum. Mixin inheritance will be dealt in a future commit. Depends on D7260 Reviewers: segfaultxavi, vitor.sousa, felipealmeida, Jaehyun_Cho Reviewed By: vitor.sousa Subscribers: cedric, #reviewers, #committers Tags: #efl Maniphest Tasks: T7451, T7336 Differential Revision: https://phab.enlightenment.org/D7262
Diffstat (limited to 'src/bin/eolian_mono/eolian/mono/function_definition.hh')
-rw-r--r--src/bin/eolian_mono/eolian/mono/function_definition.hh28
1 files changed, 17 insertions, 11 deletions
diff --git a/src/bin/eolian_mono/eolian/mono/function_definition.hh b/src/bin/eolian_mono/eolian/mono/function_definition.hh
index 7e44b29..9376506 100644
--- a/src/bin/eolian_mono/eolian/mono/function_definition.hh
+++ b/src/bin/eolian_mono/eolian/mono/function_definition.hh
@@ -83,22 +83,22 @@ struct native_function_definition_generator
83 << ")\n" 83 << ")\n"
84 << scope_tab << "{\n" 84 << scope_tab << "{\n"
85 /****/ 85 /****/
86 << scope_tab << scope_tab << "eina.Log.Debug(\"function " << string << " was called\");\n" 86 << scope_tab << scope_tab << "Eina.Log.Debug(\"function " << string << " was called\");\n"
87 /****/ 87 /****/
88 << scope_tab << scope_tab << "efl.eo.IWrapper wrapper = efl.eo.Globals.data_get(pd);\n" 88 << scope_tab << scope_tab << "Efl.Eo.IWrapper wrapper = Efl.Eo.Globals.data_get(pd);\n"
89 << scope_tab << scope_tab << "if(wrapper != null) {\n" 89 << scope_tab << scope_tab << "if(wrapper != null) {\n"
90 << scope_tab << scope_tab << scope_tab << eolian_mono::native_function_definition_preamble() 90 << scope_tab << scope_tab << scope_tab << eolian_mono::native_function_definition_preamble()
91 << scope_tab << scope_tab << scope_tab << "try {\n" 91 << scope_tab << scope_tab << scope_tab << "try {\n"
92 << scope_tab << scope_tab << scope_tab << scope_tab << (return_type != " void" ? "_ret_var = " : "") << "((" << klass_inherit_name << ")wrapper)." << string 92 << scope_tab << scope_tab << scope_tab << scope_tab << (return_type != " void" ? "_ret_var = " : "") << "((" << klass_inherit_name << ")wrapper)." << string
93 << "(" << (native_argument_invocation % ", ") << ");\n" 93 << "(" << (native_argument_invocation % ", ") << ");\n"
94 << scope_tab << scope_tab << scope_tab << "} catch (Exception e) {\n" 94 << scope_tab << scope_tab << scope_tab << "} catch (Exception e) {\n"
95 << scope_tab << scope_tab << scope_tab << scope_tab << "eina.Log.Warning($\"Callback error: {e.ToString()}\");\n" 95 << scope_tab << scope_tab << scope_tab << scope_tab << "Eina.Log.Warning($\"Callback error: {e.ToString()}\");\n"
96 << scope_tab << scope_tab << scope_tab << scope_tab << "eina.Error.Set(eina.Error.EFL_ERROR);\n" 96 << scope_tab << scope_tab << scope_tab << scope_tab << "Eina.Error.Set(Eina.Error.EFL_ERROR);\n"
97 << scope_tab << scope_tab << scope_tab << "}\n" 97 << scope_tab << scope_tab << scope_tab << "}\n"
98 << eolian_mono::native_function_definition_epilogue(*klass) 98 << eolian_mono::native_function_definition_epilogue(*klass)
99 << scope_tab << scope_tab << "} else {\n" 99 << scope_tab << scope_tab << "} else {\n"
100 << scope_tab << scope_tab << scope_tab << (return_type != " void" ? "return " : "") << string 100 << scope_tab << scope_tab << scope_tab << (return_type != " void" ? "return " : "") << string
101 << "(efl.eo.Globals.efl_super(obj, " << klass_inherit_name << ".klass)" << *(", " << argument) << ");\n" 101 << "(Efl.Eo.Globals.efl_super(obj, " << klass_inherit_name << ".klass)" << *(", " << argument) << ");\n"
102 << scope_tab << scope_tab << "}\n" 102 << scope_tab << scope_tab << "}\n"
103 << scope_tab << "}\n" 103 << scope_tab << "}\n"
104 ) 104 )
@@ -137,7 +137,7 @@ struct function_definition_generator
137 bool generate(OutputIterator sink, attributes::function_def const& f, Context const& context) const 137 bool generate(OutputIterator sink, attributes::function_def const& f, Context const& context) const
138 { 138 {
139 EINA_CXX_DOM_LOG_DBG(eolian_mono::domain) << "function_definition_generator: " << f.c_name << std::endl; 139 EINA_CXX_DOM_LOG_DBG(eolian_mono::domain) << "function_definition_generator: " << f.c_name << std::endl;
140 if(do_super && f.is_static) // Static methods goes only on Concrete classes. 140 if(!do_super && f.is_static) // Static methods goes only on Concrete classes.
141 return true; 141 return true;
142 if(blacklist::is_function_blacklisted(f.c_name)) 142 if(blacklist::is_function_blacklisted(f.c_name))
143 return true; 143 return true;
@@ -145,7 +145,7 @@ struct function_definition_generator
145 if(!as_generator 145 if(!as_generator
146 ("\n\n" << scope_tab << "[System.Runtime.InteropServices.DllImport(" << context_find_tag<library_context>(context).actual_library_name(f.filename) << ")]\n" 146 ("\n\n" << scope_tab << "[System.Runtime.InteropServices.DllImport(" << context_find_tag<library_context>(context).actual_library_name(f.filename) << ")]\n"
147 << scope_tab << eolian_mono::marshall_annotation(true) 147 << scope_tab << eolian_mono::marshall_annotation(true)
148 << " private static extern " 148 << (do_super ? " protected " : " private ") << "static extern "
149 << eolian_mono::marshall_type(true) 149 << eolian_mono::marshall_type(true)
150 << " " << string 150 << " " << string
151 << "(System.IntPtr obj" 151 << "(System.IntPtr obj"
@@ -165,13 +165,19 @@ struct function_definition_generator
165 (documentation(1)).generate(sink, f, context)) 165 (documentation(1)).generate(sink, f, context))
166 return false; 166 return false;
167 167
168 std::string self = "this.NativeHandle";
169
170 // inherited is set in the constructor, true if this instance is from a pure C# class (not generated).
171 if (do_super && !f.is_static)
172 self = "(inherited ? Efl.Eo.Globals.efl_super(" + self + ", this.NativeClass) : " + self + ")";
173 else
174 self = name_helpers::klass_get_full_name(f.klass) + "()";
175
168 if(!as_generator 176 if(!as_generator
169 (scope_tab << (do_super ? "virtual " : "") << "public " << (f.is_static ? "static " : "") << return_type << " " << string << "(" << (parameter % ", ") 177 (scope_tab << ((do_super && !f.is_static) ? "virtual " : "") << "public " << (f.is_static ? "static " : "") << return_type << " " << string << "(" << (parameter % ", ")
170 << ") {\n " 178 << ") {\n "
171 << eolian_mono::function_definition_preamble() << string << "(" 179 << eolian_mono::function_definition_preamble() << string << "("
172 << (do_super ? "efl.eo.Globals.efl_super(" : "") 180 << self
173 << (f.is_static ? name_helpers::klass_get_full_name(f.klass) + "()": "this.raw_handle")
174 << (do_super ? ", this.raw_klass)" : "")
175 << *(", " << argument_invocation ) << ");\n" 181 << *(", " << argument_invocation ) << ");\n"
176 << eolian_mono::function_definition_epilogue() 182 << eolian_mono::function_definition_epilogue()
177 << " }\n") 183 << " }\n")