Guest User

Untitled

a guest
Sep 11th, 2018
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Vala 6.19 KB | None | 0 0
  1. diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
  2. index 9102e70..d8bafb9 100644
  3. --- a/codegen/valaccodebasemodule.vala
  4. +++ b/codegen/valaccodebasemodule.vala
  5. @@ -2449,6 +2449,19 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
  6.     public CCodeExpression get_type_id_expression (DataType type, bool is_chainup = false) {
  7.         if (type is GenericType) {
  8.             string var_name = "%s_type".printf (type.type_parameter.name.down ());
  9. +           if (type.type_parameter.parent_symbol is Interface) {
  10. +               Interface iface = type.type_parameter.parent_symbol as Interface;
  11. +               if (iface.get_attribute("GenericAccessors") == null) {
  12. +                   Report.error (iface.source_reference,
  13. +                                 "missing generic type for interface `%s', add GenericAccessors attribute to interface declaration"
  14. +                                 .printf (iface.get_full_name ()));
  15. +               }
  16. +               else {
  17. +                   string method_name = "get_" + type.type_parameter.name.down () + "_type";
  18. +                   return new CCodeFunctionCall (new CCodeMemberAccess.pointer (get_result_cexpression (iface.get_full_name()), method_name));
  19. +               }
  20. +           }
  21. +
  22.             if (is_in_generic_type (type) && !is_chainup && !in_creation_method) {
  23.                 return new CCodeMemberAccess.pointer (new CCodeMemberAccess.pointer (get_result_cexpression ("self"), "priv"), var_name);
  24.             } else {
  25. diff --git a/codegen/valagtypemodule.vala b/codegen/valagtypemodule.vala
  26. index eca78af..199322d 100644
  27. --- a/codegen/valagtypemodule.vala
  28. +++ b/codegen/valagtypemodule.vala
  29. @@ -1277,6 +1277,34 @@ public class Vala.GTypeModule : GErrorModule {
  30.         pop_context ();
  31.     }
  32.  
  33. +   private void connect_inherited_implementations (Class cl, Interface iface, Method m) {
  34. +       if (m.is_abstract) {
  35. +           Method cl_method = null;
  36. +           var base_class = cl;
  37. +           while (base_class != null && cl_method == null) {
  38. +               cl_method = base_class.scope.lookup (m.name) as Method;
  39. +               base_class = base_class.base_class;
  40. +           }
  41. +           if (base_class != null && cl_method.parent_symbol != cl) {
  42. +               // method inherited from base class
  43. +  
  44. +               var base_method = cl_method;
  45. +               if (cl_method.base_method != null) {
  46. +                   base_method = cl_method.base_method;
  47. +               } else if (cl_method.base_interface_method != null) {
  48. +                   base_method = cl_method.base_interface_method;
  49. +               }
  50. +  
  51. +               generate_method_declaration (base_method, cfile);
  52. +  
  53. +               CCodeExpression cfunc = new CCodeIdentifier (get_ccode_name (base_method));
  54. +               cfunc = cast_method_pointer (base_method, cfunc, iface);
  55. +               var ciface = new CCodeIdentifier ("iface");
  56. +               ccode.add_assignment (new CCodeMemberAccess.pointer (ciface, get_ccode_vfunc_name (m)), cfunc);
  57. +           }
  58. +       }
  59. +   }
  60. +
  61.     private void add_class_init_function (Class cl) {
  62.         cfile.add_function (class_init_context.ccode);
  63.     }
  64. @@ -1333,33 +1361,19 @@ public class Vala.GTypeModule : GErrorModule {
  65.         }
  66.  
  67.         // connect inherited implementations
  68. -       foreach (Method m in iface.get_methods ()) {
  69. -           if (m.is_abstract) {
  70. -               Method cl_method = null;
  71. -               var base_class = cl;
  72. -               while (base_class != null && cl_method == null) {
  73. -                   cl_method = base_class.scope.lookup (m.name) as Method;
  74. -                   base_class = base_class.base_class;
  75. -               }
  76. -               if (base_class != null && cl_method.parent_symbol != cl) {
  77. -                   // method inherited from base class
  78. -
  79. -                   var base_method = cl_method;
  80. -                   if (cl_method.base_method != null) {
  81. -                       base_method = cl_method.base_method;
  82. -                   } else if (cl_method.base_interface_method != null) {
  83. -                       base_method = cl_method.base_interface_method;
  84. -                   }
  85. -
  86. -                   generate_method_declaration (base_method, cfile);
  87. -
  88. -                   CCodeExpression cfunc = new CCodeIdentifier (get_ccode_name (base_method));
  89. -                   cfunc = cast_method_pointer (base_method, cfunc, iface);
  90. -                   var ciface = new CCodeIdentifier ("iface");
  91. -                   ccode.add_assignment (new CCodeMemberAccess.pointer (ciface, get_ccode_vfunc_name (m)), cfunc);
  92. -               }
  93. +       if (iface.get_attribute("GenericAccessors") != null) {
  94. +           foreach (TypeParameter p in iface.get_type_parameters()) {
  95. +               string method_name = "get_" + p.name.down() + "_type";
  96. +               Method m = new Method (method_name, get_data_type_for_symbol (gtype_type));
  97. +               m.is_virtual = true;
  98. +               m.is_abstract = true;
  99. +               connect_inherited_implementations (cl, iface, m);
  100.             }
  101.         }
  102. +  
  103. +       foreach (Method m in iface.get_methods ()) {
  104. +           connect_inherited_implementations (cl, iface, m);
  105. +       }
  106.  
  107.         foreach (Property prop in cl.get_properties ()) {
  108.             if (prop.base_interface_property == null) {
  109. @@ -1894,6 +1908,18 @@ public class Vala.GTypeModule : GErrorModule {
  110.  
  111.         type_struct.add_field ("GTypeInterface", "parent_iface");
  112.  
  113. +       if (iface.get_attribute("GenericAccessors") != null) {
  114. +           foreach (TypeParameter p in iface.get_type_parameters()) {
  115. +               string method_name = "get_" + p.name.down() + "_type";
  116. +               DataType return_type = get_data_type_for_symbol (gtype_type);
  117. +               var vdeclarator = new CCodeFunctionDeclarator (method_name);
  118. +               string creturn_type = get_ccode_name (return_type);
  119. +               var vdecl = new CCodeDeclaration (creturn_type);
  120. +               vdecl.add_declarator (vdeclarator);
  121. +               type_struct.add_declaration (vdecl);
  122. +           }
  123. +       }
  124. +
  125.         foreach (Method m in iface.get_methods ()) {
  126.             generate_virtual_method_declaration (m, decl_space, type_struct);
  127.         }
  128. @@ -1993,6 +2019,24 @@ public class Vala.GTypeModule : GErrorModule {
  129.  
  130.         add_interface_base_init_function (iface);
  131.  
  132. +       if (iface.get_attribute ("GenericAccessors") != null) {
  133. +           foreach (TypeParameter p in iface.get_type_parameters()) {
  134. +               string method_name = iface.name + "_get_" + p.name.down() + "_type";
  135. +               DataType return_type = get_data_type_for_symbol (gtype_type);
  136. +               string creturn_type = get_ccode_name (return_type);
  137. +               var function = new CCodeFunction (method_name, creturn_type);
  138. +              
  139. +               push_function (function);
  140. +               var ccall = new CCodeFunctionCall (new CCodeIdentifier ("typeof"));
  141. +               ccall.add_argument (new CCodeIdentifier (p.name));
  142. +               ccode.add_return (ccall);
  143. +               pop_function ();
  144. +              
  145. +               cfile.add_function_declaration (function);
  146. +               cfile.add_function (function);
  147. +           }
  148. +       }
  149. +      
  150.         if (iface.comment != null) {
  151.             cfile.add_type_member_definition (new CCodeComment (iface.comment.content));
  152.         }
Add Comment
Please, Sign In to add comment