forked from enlightenment/efl
efl_mono: Change generated classes naming scheme
Summary: Now the generated classes use an approach more familiar to C# developers: Interfaces: efl.Object -> efl.IObject Concrete (implementation) classes: efl.ObjectConcrete -> efl.Object. During this change, some methods that could clash with the implementation class name (CS0542) had the prefix "Do" added (like in efl.Duplicate.Duplicate() and efl.Pack.Pack()). Depends on D6049 Reviewers: felipealmeida, vitor.sousa Reviewed By: vitor.sousa Subscribers: cedric Tags: #efl Differential Revision: https://phab.enlightenment.org/D6050
This commit is contained in:
parent
c9dd86579f
commit
4636d6e0eb
|
@ -27,7 +27,7 @@ struct enum_definition_generator
|
|||
(
|
||||
"public enum " << string << "\n{\n"
|
||||
)
|
||||
.generate(sink, enum_.cxx_name, context))
|
||||
.generate(sink, name_helpers::enum_managed_name(enum_), context))
|
||||
return false;
|
||||
|
||||
// iterate enum fiels
|
||||
|
|
|
@ -28,7 +28,7 @@ struct function_declaration_generator
|
|||
|
||||
return as_generator
|
||||
(eolian_mono::type(true) << " " << string << "(" << (parameter % ", ") << ");\n")
|
||||
.generate(sink, std::make_tuple(f.return_type, name_helpers::managed_method_name(f.name), f.parameters), context);
|
||||
.generate(sink, std::make_tuple(f.return_type, name_helpers::managed_method_name(f), f.parameters), context);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -105,7 +105,7 @@ struct native_function_definition_generator
|
|||
.generate(sink, std::make_tuple(f.return_type, escape_keyword(f.name), f.parameters
|
||||
, /***/f.c_name/***/
|
||||
, f
|
||||
, managed_method_name(f.name)
|
||||
, name_helpers::managed_method_name(f)
|
||||
, f.parameters
|
||||
, f
|
||||
, f.c_name
|
||||
|
@ -175,7 +175,7 @@ struct function_definition_generator
|
|||
<< *(", " << argument_invocation ) << ");\n"
|
||||
<< eolian_mono::function_definition_epilogue()
|
||||
<< " }\n")
|
||||
.generate(sink, std::make_tuple(managed_method_name(f.name), f.parameters, f, f.c_name, f.parameters, f), context))
|
||||
.generate(sink, std::make_tuple(name_helpers::managed_method_name(f), f.parameters, f, f.c_name, f.parameters, f), context))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
|
|
|
@ -34,7 +34,7 @@ static bool generate_static_cast_method(OutputIterator sink, grammar::attributes
|
|||
{
|
||||
return as_generator(
|
||||
scope_tab << "///<summary>Casts obj into an instance of this type.</summary>\n"
|
||||
<< scope_tab << "public static " << name_helpers::klass_interface_name(cls) << " static_cast(efl.Object obj)\n"
|
||||
<< scope_tab << "public static " << name_helpers::klass_interface_name(cls) << " static_cast(efl.IObject obj)\n"
|
||||
<< scope_tab << "{\n"
|
||||
<< scope_tab << scope_tab << "if (obj == null)\n"
|
||||
<< scope_tab << scope_tab << scope_tab << "throw new System.ArgumentNullException(\"obj\");\n"
|
||||
|
@ -50,7 +50,7 @@ static bool generate_equals_method(OutputIterator sink, Context const &context)
|
|||
scope_tab << "///<summary>Verifies if the given object is equals to this.</summary>\n"
|
||||
<< scope_tab << "public override bool Equals(object obj)\n"
|
||||
<< scope_tab << "{\n"
|
||||
<< scope_tab << scope_tab << "var other = obj as efl.Object;\n"
|
||||
<< scope_tab << scope_tab << "var other = obj as efl.IObject;\n"
|
||||
<< scope_tab << scope_tab << "if (other == null)\n"
|
||||
<< scope_tab << scope_tab << scope_tab << "return false;\n"
|
||||
<< scope_tab << scope_tab << "return this.raw_handle == other.raw_handle;\n"
|
||||
|
@ -126,7 +126,7 @@ struct klass
|
|||
(
|
||||
"public " /*<< class_type*/ "interface" /*<<*/ " " << string << " : "
|
||||
)
|
||||
.generate(sink, cls.cxx_name, iface_cxt))
|
||||
.generate(sink, name_helpers::klass_interface_name(cls), iface_cxt))
|
||||
return false;
|
||||
for(auto first = std::begin(cls.immediate_inherits)
|
||||
, last = std::end(cls.immediate_inherits); first != last; ++first)
|
||||
|
@ -186,7 +186,7 @@ struct klass
|
|||
<< scope_tab << "///<summary>Creates a new instance.</summary>\n"
|
||||
<< scope_tab << "///<param>Parent instance.</param>\n"
|
||||
<< scope_tab << "///<param>Delegate to call constructing methods that should be run inside the constructor.</param>\n"
|
||||
<< scope_tab << "public " << concrete_name << "(efl.Object parent = null, ConstructingMethod init_cb=null)\n"
|
||||
<< scope_tab << "public " << concrete_name << "(efl.IObject parent = null, ConstructingMethod init_cb=null)\n"
|
||||
<< scope_tab << "{\n"
|
||||
<< scope_tab << scope_tab << "System.IntPtr klass = " << name_helpers::klass_get_name(cls) << "();\n"
|
||||
<< scope_tab << scope_tab << "System.IntPtr parent_ptr = System.IntPtr.Zero;\n"
|
||||
|
@ -293,7 +293,7 @@ struct klass
|
|||
<< scope_tab << "///<summary>Creates a new instance.</summary>\n"
|
||||
<< scope_tab << "///<param>Parent instance.</param>\n"
|
||||
<< scope_tab << "///<param>Delegate to call constructing methods that should be run inside the constructor.</param>\n"
|
||||
<< scope_tab << "public " << inherit_name << "(efl.Object parent = null, ConstructingMethod init_cb=null)\n"
|
||||
<< scope_tab << "public " << inherit_name << "(efl.IObject parent = null, ConstructingMethod init_cb=null)\n"
|
||||
<< scope_tab << "{\n"
|
||||
<< scope_tab << scope_tab << "if (klass == System.IntPtr.Zero) {\n"
|
||||
<< scope_tab << scope_tab << scope_tab << "lock (klassAllocLock) {\n"
|
||||
|
|
|
@ -172,13 +172,19 @@ inline std::string managed_namespace(std::string const& ns)
|
|||
return utils::to_lowercase(escape_keyword(ns));
|
||||
}
|
||||
|
||||
inline std::string managed_method_name(std::string const& underscore_name)
|
||||
inline std::string managed_method_name(attributes::function_def const& f)
|
||||
{
|
||||
std::vector<std::string> names = utils::split(underscore_name, '_');
|
||||
std::vector<std::string> names = utils::split(f.name, '_');
|
||||
|
||||
name_helpers::reorder_verb(names);
|
||||
|
||||
return escape_keyword(utils::to_pascal_case(names));
|
||||
std::string candidate = escape_keyword(utils::to_pascal_case(names));
|
||||
|
||||
// Some eolian methods have the same name as their parent class
|
||||
if (candidate == f.klass.eolian_name)
|
||||
candidate = "Do" + candidate;
|
||||
|
||||
return candidate;
|
||||
}
|
||||
|
||||
inline std::string function_ptr_full_eolian_name(attributes::function_def const& func)
|
||||
|
@ -201,6 +207,11 @@ inline std::string struct_full_eolian_name(attributes::struct_def const& struct_
|
|||
return join_namespaces(struct_.namespaces, '.') + struct_.cxx_name;
|
||||
}
|
||||
|
||||
inline std::string enum_managed_name(attributes::enum_def const& enum_)
|
||||
{
|
||||
return enum_.cxx_name;
|
||||
}
|
||||
|
||||
inline std::string to_field_name(std::string const& in)
|
||||
{
|
||||
return utils::capitalize(in);
|
||||
|
@ -210,7 +221,7 @@ inline std::string to_field_name(std::string const& in)
|
|||
template<typename T>
|
||||
inline std::string klass_interface_name(T const& klass)
|
||||
{
|
||||
return klass.eolian_name;
|
||||
return "I" + klass.eolian_name;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
|
@ -222,7 +233,7 @@ inline std::string klass_full_interface_name(T const& klass)
|
|||
template<typename T>
|
||||
inline std::string klass_concrete_name(T const& klass)
|
||||
{
|
||||
return klass.eolian_name + "Concrete";
|
||||
return klass.eolian_name;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
|
|
|
@ -25,7 +25,7 @@ struct part_definition_generator
|
|||
<< scope_tab << "{\n"
|
||||
<< scope_tab << scope_tab << "get\n"
|
||||
<< scope_tab << scope_tab << "{\n"
|
||||
<< scope_tab << scope_tab << scope_tab << "efl.Object obj = efl_part(raw_handle, \"" << part.name << "\");\n"
|
||||
<< scope_tab << scope_tab << scope_tab << "efl.IObject obj = efl_part(raw_handle, \"" << part.name << "\");\n"
|
||||
<< scope_tab << scope_tab << scope_tab << "return " << part_klass_name << ".static_cast(obj);\n"
|
||||
<< scope_tab << scope_tab << "}\n"
|
||||
<< scope_tab << "}\n"
|
||||
|
|
|
@ -29,9 +29,9 @@ public class EcoreEvas
|
|||
ecore_evas_show(handle);
|
||||
}
|
||||
|
||||
public efl.canvas.Object canvas
|
||||
public efl.canvas.IObject canvas
|
||||
{
|
||||
get { return new efl.canvas.ObjectConcrete(ecore_evas_get(handle)); }
|
||||
get { return new efl.canvas.Object(ecore_evas_get(handle)); }
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#pragma warning disable 1591
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Collections.Generic;
|
||||
|
||||
|
@ -522,19 +523,41 @@ public static class TraitFunctions
|
|||
|
||||
private static IDictionary<System.Type, object> register = new Dictionary<System.Type, object>();
|
||||
|
||||
private static System.Type AsEflInstantiableType(System.Type type)
|
||||
{
|
||||
if (!IsEflObject(type))
|
||||
return null;
|
||||
|
||||
if (type.IsInterface)
|
||||
{
|
||||
string[] names = type.FullName.Split('.');
|
||||
names[names.Count() - 1] = names.Last().Substring(1); // Remove the leading 'I' (What about user-defined interfaces?)
|
||||
|
||||
string fullName = string.Join(".", names);
|
||||
return type.Assembly.GetType(fullName); // That was our best guess...
|
||||
}
|
||||
|
||||
|
||||
System.Type current = type;
|
||||
while (current != null)
|
||||
{
|
||||
if (current.Name.EndsWith("Inherit"))
|
||||
throw new Exception("Inherit-based classes are not currently supported.");
|
||||
current = current.BaseType;
|
||||
}
|
||||
|
||||
return type; // Not inherited neither interface, so it should be a concrete.
|
||||
}
|
||||
|
||||
public static object RegisterTypeTraits<T>()
|
||||
{
|
||||
object traits;
|
||||
var type = typeof(T);
|
||||
if (IsEflObject(type))
|
||||
{
|
||||
System.Type concrete = type;
|
||||
if (!type.Name.EndsWith("Concrete"))
|
||||
{
|
||||
var c = type.Assembly.GetType(type.FullName + "Concrete");
|
||||
if (c != null && type.IsAssignableFrom(c))
|
||||
concrete = c;
|
||||
}
|
||||
System.Type concrete = AsEflInstantiableType(type);
|
||||
if (concrete == null || !type.IsAssignableFrom(concrete))
|
||||
throw new Exception("Failed to get a suitable concrete class for this type.");
|
||||
traits = new EflObjectElementTraits<T>(concrete);
|
||||
}
|
||||
else if (IsString(type))
|
||||
|
|
|
@ -95,7 +95,7 @@ public class Globals {
|
|||
eina.Log.Debug("Registered?");
|
||||
return klass;
|
||||
}
|
||||
public static IntPtr instantiate_start(IntPtr klass, efl.Object parent)
|
||||
public static IntPtr instantiate_start(IntPtr klass, efl.IObject parent)
|
||||
{
|
||||
eina.Log.Debug("Instantiating");
|
||||
System.IntPtr parent_ptr = System.IntPtr.Zero;
|
||||
|
|
Loading…
Reference in New Issue