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).
efl_mono_test_files = \
tests/efl_mono/test_testing.eo \
+ tests/efl_mono/test_child.eo \
tests/efl_mono/test_numberwrapper.eo \
tests/efl_mono/mono_test_driver.sh
tests_efl_mono_libefl_mono_native_test_la_DEPENDENCIES = @USE_EINA_INTERNAL_LIBS@ @USE_EO_INTERNAL_LIBS@ @USE_ECORE_INTERNAL_LIBS@ @USE_ELDBUS_INTERNAL_LIBS@
tests_efl_mono_libefl_mono_native_test_la_LIBTOOLFLAGS = --tag=disable-static
-tests/efl_mono/libefl_mono_native_test.c: tests/efl_mono/test_testing.eo.h tests/efl_mono/test_testing.eo.c tests/efl_mono/test_numberwrapper.eo.h tests/efl_mono/test_numberwrapper.eo.c
+tests/efl_mono/libefl_mono_native_test.c: tests/efl_mono/test_testing.eo.h tests/efl_mono/test_testing.eo.c tests/efl_mono/test_child.eo.h tests/efl_mono/test_child.eo.c tests/efl_mono/test_numberwrapper.eo.h tests/efl_mono/test_numberwrapper.eo.c
# Intermediate C Sharp test DLL
efl_mono_test_eolian_mono_files = tests/efl_mono/test_testing.eo.cs \
+tests/efl_mono/test_child.eo.cs \
tests/efl_mono/test_numberwrapper.eo.cs
tests/efl_mono/libefl_mono_test.dll: $(efl_mono_test_eolian_mono_files) tests/efl_mono/$(am__dirstamp) lib/efl_mono/libefl_mono.dll tests/efl_mono/libefl_mono_native_test.la tests/efl_mono/libefl_mono_test.dll.config
$(MKDIR_P) $(dir $@); \
$(EOLIAN_MONO) $(EOLIAN_FLAGS) $(EOLIAN_MONO_FLAGS) --dllimport "@DLIB_PREFIX_MONO@efl_mono_native_test@DLIB_SUFFIX_MONO@" -o $@ $(ALL_EO_REFS) $<
-CLEANFILES += tests/efl_mono/libefl_mono_test.dll tests/efl_mono/test_testing.eo.cs tests/efl_mono/test_numberwrapper.eo.cs tests/efl_mono/test_testing.eo.c tests/efl_mono/test_numberwrapper.eo.c tests/efl_mono/test_testing.eo.h tests/efl_mono/test_numberwrapper.eo.h tests/efl_mono/efl_mono.config
+CLEANFILES += tests/efl_mono/libefl_mono_test.dll tests/efl_mono/test_testing.eo.cs tests/efl_mono/test_child.eo.cs tests/efl_mono/test_numberwrapper.eo.cs tests/efl_mono/test_testing.eo.c tests/efl_mono/test_child.eo.c tests/efl_mono/test_numberwrapper.eo.c tests/efl_mono/test_testing.eo.h tests/efl_mono/test_child.eo.h tests/efl_mono/test_numberwrapper.eo.h tests/efl_mono/efl_mono.config
endif
template <typename OutputIterator, typename Context>
bool generate(OutputIterator sink, attributes::function_def const& f, Context const& context) const
{
- if(is_function_blacklisted(f.c_name))
+ if(is_function_blacklisted(f.c_name) || f.is_static)
return true;
if(!as_generator(documentation).generate(sink, f, context))
#include "grammar/alternative.hpp"
#include "grammar/attribute_reorder.hpp"
#include "type.hh"
+#include "helpers.hh"
#include "function_helpers.hh"
#include "marshall_type.hh"
#include "parameter.hh"
template <typename OutputIterator, typename Context>
bool generate(OutputIterator sink, attributes::function_def const& f, Context const& context) const
{
- if(is_function_blacklisted(f.c_name))
+ if(is_function_blacklisted(f.c_name) || f.is_static) // Only Concrete classes implement static methods.
return true;
else
{
template <typename OutputIterator, typename Context>
bool generate(OutputIterator sink, attributes::function_def const& f, Context const& context) const
{
+ if(do_super && f.is_static) // Static methods goes only on Concrete classes.
+ return true;
if(is_function_blacklisted(f.c_name))
return true;
- else
- {
+
if(!as_generator
("\n\n" << scope_tab << "[System.Runtime.InteropServices.DllImport(" << context_find_tag<library_context>(context).actual_library_name(f.filename) << ")]\n"
<< scope_tab << eolian_mono::marshall_annotation(true)
return false;
if(!as_generator
- (scope_tab << (do_super ? "virtual " : "") << "public " << return_type << " " << string << "(" << (parameter % ", ")
+ (scope_tab << (do_super ? "virtual " : "") << "public " << (f.is_static ? "static " : "") << return_type << " " << string << "(" << (parameter % ", ")
<< ") {\n "
<< eolian_mono::function_definition_preamble() << string << "("
<< (do_super ? "efl.eo.Globals.efl_super(" : "")
- << "this.raw_handle"
+ << (f.is_static ? klass_get_name(f.klass) + "()": "this.raw_handle")
<< (do_super ? ", this.raw_klass)" : "")
<< *(", " << argument_invocation ) << ");\n"
<< eolian_mono::function_definition_epilogue()
return false;
return true;
- }
}
bool do_super;
template <typename OutputIterator, typename Context>
bool generate(OutputIterator sink, attributes::function_def const& f, Context const& context) const
{
- if(is_function_blacklisted(f.c_name))
+ if(is_function_blacklisted(f.c_name) || f.is_static) // Static methods aren't overrideable
return true;
else
{
return output.str();
}
+inline std::string klass_get_name(attributes::klass_name const &clsname)
+{
+ std::ostringstream output;
+
+ output << klass_name_to_csharp(clsname);
+ output << "Concrete.";
+
+ for (auto namesp : clsname.namespaces)
+ output << utils::to_lowercase(namesp) << "_";
+ output << utils::to_lowercase(clsname.eolian_name);
+ output << "_class_get";
+
+ return output.str();
+}
+
}
#endif
/* Get the actual number of functions of a class, checking for blacklisted ones */
static std::size_t
-get_function_count(grammar::attributes::klass_def const& cls)
+get_inheritable_function_count(grammar::attributes::klass_def const& cls)
{
auto methods = cls.get_all_methods();
return std::count_if(methods.cbegin(), methods.cend(), [](grammar::attributes::function_def const& func)
{
- return !is_function_blacklisted(func.c_name);
+ return !is_function_blacklisted(func.c_name) && !func.is_static;
});
}
<< scope_tab << "}\n"
<< scope_tab << "///<summary>Delegate for function to be called from inside the native constructor.</summary>\n"
<< scope_tab << "public delegate void ConstructingMethod(" << string << " obj);\n"
+ << scope_tab << "///<summary>Returns the pointer the unerlying Eo class object. Used internally on class methods.</summary>\n"
<< scope_tab << "[System.Runtime.InteropServices.DllImport(" << context_find_tag<library_context>(concrete_cxt).actual_library_name(cls.filename)
- << ")] private static extern System.IntPtr\n"
+ << ")] public static extern System.IntPtr\n"
<< scope_tab << scope_tab << class_get_name << "();\n"
<< (class_type == "class" ? "" : "/*")
<< scope_tab << "///<summary>Creates a new instance.</summary>\n"
if(!as_generator("}\n").generate(sink, attributes::unused, inherit_cxt)) return false;
}
- std::size_t function_count = get_function_count(cls);
+ std::size_t function_count = get_inheritable_function_count(cls);
int function_registration_index = 0;
auto index_generator = [&function_registration_index]
qualifier_def base_qualifier;
class_type type;
+ klass_name() {
+ }
+
klass_name(std::vector<std::string> namespaces
, std::string eolian_name, qualifier_def base_qualifier
, class_type type)
struct function_def
{
+ klass_name klass;
type_def return_type;
std::string name;
std::vector<parameter_def> parameters;
friend inline bool operator==(function_def const& lhs, function_def const& rhs)
{
- return lhs.return_type == rhs.return_type
+ return lhs.klass == rhs.klass
+ && lhs.return_type == rhs.return_type
&& lhs.name == rhs.name
&& lhs.parameters == rhs.parameters
&& lhs.c_name == rhs.c_name
return !(lhs == rhs);
}
function_def() = default;
- function_def(type_def _return_type, std::string const& _name,
+ function_def(klass_name _klass,
+ type_def _return_type, std::string const& _name,
std::vector<parameter_def> const& _parameters,
std::string const& _c_name,
std::string _filename,
bool _is_beta = false,
bool _is_protected = false,
Eolian_Unit const* unit = nullptr)
- : return_type(_return_type), name(_name), parameters(_parameters),
- c_name(_c_name), filename(_filename), documentation(_documentation),
+ : klass(_klass), return_type(_return_type), name(_name),
+ parameters(_parameters), c_name(_c_name), filename(_filename),
+ documentation(_documentation),
return_documentation(_return_documentation),
property_documentation(_property_documentation),
type(_type),
c_name = eolian_function_full_c_name_get(function, type, EINA_FALSE);
if (type != EOLIAN_FUNCTION_POINTER)
{
- const Eolian_Class *klass = eolian_function_class_get(function);
- filename = eolian_object_file_get((const Eolian_Object *)klass);
+ const Eolian_Class *eolian_klass = eolian_function_class_get(function);
+ filename = eolian_object_file_get((const Eolian_Object *)eolian_klass);
+ klass = klass_name(eolian_klass,
+ {attributes::qualifier_info::is_none, std::string()});
}
else
{
}
}
+class TestKlassMethods
+{
+ public static void basic_class_method()
+ {
+ int reference = 0xbeef;
+ test.TestingConcrete.SetKlassProp(reference);
+ Test.AssertEquals(reference, test.TestingConcrete.GetKlassProp());
+ }
+
+ public static void inherited_class_method()
+ {
+ int reference = 0xdead;
+ test.ChildConcrete.SetKlassProp(reference);
+ Test.AssertEquals(reference, test.ChildConcrete.GetKlassProp());
+ }
+}
+
}
func_free_cb(func_data);
}
+/* Class Properties */
+static int _test_testing_klass_prop = 0;
+
+int _test_testing_klass_prop_get(Eo *klass, EINA_UNUSED void *pd)
+{
+ EINA_LOG_ERR("FAIL on GET");
+ if (klass != test_testing_class_get())
+ {
+ eina_error_set(EINVAL);
+ return -1;
+ }
+ return _test_testing_klass_prop;
+}
+
+void _test_testing_klass_prop_set(Eo *klass, EINA_UNUSED void *pd, int value)
+{
+ EINA_LOG_ERR("FAIL on SET");
+ if (klass != test_testing_class_get())
+ {
+ eina_error_set(EINVAL);
+ }
+ _test_testing_klass_prop = value;
+}
+
#include "test_testing.eo.c"
#include "test_numberwrapper.eo.c"
--- /dev/null
+import eina_types;
+
+class Test.Child (Test.Testing) {
+
+ implements {
+ class.constructor;
+ class.destructor;
+ }
+}
@in func: Test.FormatCb;
}
}
+
+ @property klass_prop @class {
+ get {}
+ set {}
+ values {
+ prop: int;
+ }
+ }
}
implements {
class.constructor;