Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
- index 9102e70..d8bafb9 100644
- --- a/codegen/valaccodebasemodule.vala
- +++ b/codegen/valaccodebasemodule.vala
- @@ -2449,6 +2449,19 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
- public CCodeExpression get_type_id_expression (DataType type, bool is_chainup = false) {
- if (type is GenericType) {
- string var_name = "%s_type".printf (type.type_parameter.name.down ());
- + if (type.type_parameter.parent_symbol is Interface) {
- + Interface iface = type.type_parameter.parent_symbol as Interface;
- + if (iface.get_attribute("GenericAccessors") == null) {
- + Report.error (iface.source_reference,
- + "missing generic type for interface `%s', add GenericAccessors attribute to interface declaration"
- + .printf (iface.get_full_name ()));
- + }
- + else {
- + string method_name = "get_" + type.type_parameter.name.down () + "_type";
- + return new CCodeFunctionCall (new CCodeMemberAccess.pointer (get_result_cexpression (iface.get_full_name()), method_name));
- + }
- + }
- +
- if (is_in_generic_type (type) && !is_chainup && !in_creation_method) {
- return new CCodeMemberAccess.pointer (new CCodeMemberAccess.pointer (get_result_cexpression ("self"), "priv"), var_name);
- } else {
- diff --git a/codegen/valagtypemodule.vala b/codegen/valagtypemodule.vala
- index eca78af..199322d 100644
- --- a/codegen/valagtypemodule.vala
- +++ b/codegen/valagtypemodule.vala
- @@ -1277,6 +1277,34 @@ public class Vala.GTypeModule : GErrorModule {
- pop_context ();
- }
- + private void connect_inherited_implementations (Class cl, Interface iface, Method m) {
- + if (m.is_abstract) {
- + Method cl_method = null;
- + var base_class = cl;
- + while (base_class != null && cl_method == null) {
- + cl_method = base_class.scope.lookup (m.name) as Method;
- + base_class = base_class.base_class;
- + }
- + if (base_class != null && cl_method.parent_symbol != cl) {
- + // method inherited from base class
- +
- + var base_method = cl_method;
- + if (cl_method.base_method != null) {
- + base_method = cl_method.base_method;
- + } else if (cl_method.base_interface_method != null) {
- + base_method = cl_method.base_interface_method;
- + }
- +
- + generate_method_declaration (base_method, cfile);
- +
- + CCodeExpression cfunc = new CCodeIdentifier (get_ccode_name (base_method));
- + cfunc = cast_method_pointer (base_method, cfunc, iface);
- + var ciface = new CCodeIdentifier ("iface");
- + ccode.add_assignment (new CCodeMemberAccess.pointer (ciface, get_ccode_vfunc_name (m)), cfunc);
- + }
- + }
- + }
- +
- private void add_class_init_function (Class cl) {
- cfile.add_function (class_init_context.ccode);
- }
- @@ -1333,33 +1361,19 @@ public class Vala.GTypeModule : GErrorModule {
- }
- // connect inherited implementations
- - foreach (Method m in iface.get_methods ()) {
- - if (m.is_abstract) {
- - Method cl_method = null;
- - var base_class = cl;
- - while (base_class != null && cl_method == null) {
- - cl_method = base_class.scope.lookup (m.name) as Method;
- - base_class = base_class.base_class;
- - }
- - if (base_class != null && cl_method.parent_symbol != cl) {
- - // method inherited from base class
- -
- - var base_method = cl_method;
- - if (cl_method.base_method != null) {
- - base_method = cl_method.base_method;
- - } else if (cl_method.base_interface_method != null) {
- - base_method = cl_method.base_interface_method;
- - }
- -
- - generate_method_declaration (base_method, cfile);
- -
- - CCodeExpression cfunc = new CCodeIdentifier (get_ccode_name (base_method));
- - cfunc = cast_method_pointer (base_method, cfunc, iface);
- - var ciface = new CCodeIdentifier ("iface");
- - ccode.add_assignment (new CCodeMemberAccess.pointer (ciface, get_ccode_vfunc_name (m)), cfunc);
- - }
- + if (iface.get_attribute("GenericAccessors") != null) {
- + foreach (TypeParameter p in iface.get_type_parameters()) {
- + string method_name = "get_" + p.name.down() + "_type";
- + Method m = new Method (method_name, get_data_type_for_symbol (gtype_type));
- + m.is_virtual = true;
- + m.is_abstract = true;
- + connect_inherited_implementations (cl, iface, m);
- }
- }
- +
- + foreach (Method m in iface.get_methods ()) {
- + connect_inherited_implementations (cl, iface, m);
- + }
- foreach (Property prop in cl.get_properties ()) {
- if (prop.base_interface_property == null) {
- @@ -1894,6 +1908,18 @@ public class Vala.GTypeModule : GErrorModule {
- type_struct.add_field ("GTypeInterface", "parent_iface");
- + if (iface.get_attribute("GenericAccessors") != null) {
- + foreach (TypeParameter p in iface.get_type_parameters()) {
- + string method_name = "get_" + p.name.down() + "_type";
- + DataType return_type = get_data_type_for_symbol (gtype_type);
- + var vdeclarator = new CCodeFunctionDeclarator (method_name);
- + string creturn_type = get_ccode_name (return_type);
- + var vdecl = new CCodeDeclaration (creturn_type);
- + vdecl.add_declarator (vdeclarator);
- + type_struct.add_declaration (vdecl);
- + }
- + }
- +
- foreach (Method m in iface.get_methods ()) {
- generate_virtual_method_declaration (m, decl_space, type_struct);
- }
- @@ -1993,6 +2019,24 @@ public class Vala.GTypeModule : GErrorModule {
- add_interface_base_init_function (iface);
- + if (iface.get_attribute ("GenericAccessors") != null) {
- + foreach (TypeParameter p in iface.get_type_parameters()) {
- + string method_name = iface.name + "_get_" + p.name.down() + "_type";
- + DataType return_type = get_data_type_for_symbol (gtype_type);
- + string creturn_type = get_ccode_name (return_type);
- + var function = new CCodeFunction (method_name, creturn_type);
- +
- + push_function (function);
- + var ccall = new CCodeFunctionCall (new CCodeIdentifier ("typeof"));
- + ccall.add_argument (new CCodeIdentifier (p.name));
- + ccode.add_return (ccall);
- + pop_function ();
- +
- + cfile.add_function_declaration (function);
- + cfile.add_function (function);
- + }
- + }
- +
- if (iface.comment != null) {
- cfile.add_type_member_definition (new CCodeComment (iface.comment.content));
- }
Add Comment
Please, Sign In to add comment