summaryrefslogtreecommitdiff
path: root/src/bin/eolian
diff options
context:
space:
mode:
authorMarcel Hollerbach <mail@marcel-hollerbach.de>2019-02-09 18:45:27 +0100
committerMarcel Hollerbach <mail@marcel-hollerbach.de>2019-02-13 16:59:58 +0100
commit37d2d378ec2e2d1f9a3941372ef4d818996291c7 (patch)
treee100879fbdc9ce0d2ce810be81977be97125603b /src/bin/eolian
parent3b2a5a429be16e5b8e5d322b7a077a2c849586b8 (diff)
eolian: drop class function overriding
Until this commit eo did class functions as part of the vtable, which enabled those functions to be overwritten in classes inheriting another class. However in task T7675 we decided that this is not really good for bindings, as most OOP languages do not support this sort of feature. After this commit eolian realizes class function completly outside of the vtable, the c-symbol that is the class funciton is now just directly redirecting to a implementation, without the involvement of the vtable. This also means a change to the syntax created by eo: Calling before: class_function(CLASS_A); Calling after: class_function(); Implementation before: class_function(const Eo *obj, void *pd) { ... } Implementation after: class_function(void) { ... } This fixes T7675. Co-authored-by: lauromauro <lauromoura@expertisesolutions.com.br> Reviewed-by: Daniel Kolesa <daniel@octaforge.org> Differential Revision: https://phab.enlightenment.org/D7901
Diffstat (limited to 'src/bin/eolian')
-rw-r--r--src/bin/eolian/headers.c2
-rw-r--r--src/bin/eolian/sources.c94
2 files changed, 60 insertions, 36 deletions
diff --git a/src/bin/eolian/headers.c b/src/bin/eolian/headers.c
index 4ebf9a7..70520fc 100644
--- a/src/bin/eolian/headers.c
+++ b/src/bin/eolian/headers.c
@@ -125,7 +125,7 @@ _gen_func(const Eolian_State *state, const Eolian_Function *fid,
125 eina_stringshare_del(fcn); 125 eina_stringshare_del(fcn);
126 126
127 Eina_Strbuf *flagbuf = NULL; 127 Eina_Strbuf *flagbuf = NULL;
128 int nidx = !legacy || !eolian_function_is_class(fid); 128 int nidx = !eolian_function_is_class(fid);
129 129
130 eina_strbuf_append_char(buf, '('); 130 eina_strbuf_append_char(buf, '(');
131 if (nidx) 131 if (nidx)
diff --git a/src/bin/eolian/sources.c b/src/bin/eolian/sources.c
index eb2ad41..493ec1a 100644
--- a/src/bin/eolian/sources.c
+++ b/src/bin/eolian/sources.c
@@ -386,8 +386,14 @@ _gen_func(const Eolian_Class *cl, const Eolian_Function *fid,
386 eina_strbuf_append(params, ", "); 386 eina_strbuf_append(params, ", ");
387 eina_strbuf_append(params, prn); 387 eina_strbuf_append(params, prn);
388 388
389 eina_strbuf_append_printf(params_full, ", %s", ptn); 389 if (eina_strbuf_length_get(params_full) || !eolian_function_is_class(fid))
390 eina_strbuf_append_printf(params_full_imp, ", %s", ptn); 390 {
391 eina_strbuf_append(params_full, ", ");
392 eina_strbuf_append(params_full_imp, ", ");
393 }
394 eina_strbuf_append_printf(params_full, "%s", ptn);
395 eina_strbuf_append_printf(params_full_imp, "%s", ptn);
396
391 if (ptn[strlen(ptn) - 1] != '*') 397 if (ptn[strlen(ptn) - 1] != '*')
392 { 398 {
393 eina_strbuf_append_char(params_full, ' '); 399 eina_strbuf_append_char(params_full, ' ');
@@ -470,7 +476,8 @@ _gen_func(const Eolian_Class *cl, const Eolian_Function *fid,
470 if (eina_strbuf_length_get(params)) 476 if (eina_strbuf_length_get(params))
471 eina_strbuf_append(params, ", "); 477 eina_strbuf_append(params, ", ");
472 478
473 eina_strbuf_append(params_full_imp, ", "); 479 if (eina_strbuf_length_get(params_full_imp) || !eolian_function_is_class(fid))
480 eina_strbuf_append(params_full_imp, ", ");
474 eina_strbuf_append(params_full_imp, ptn); 481 eina_strbuf_append(params_full_imp, ptn);
475 if (!had_star) 482 if (!had_star)
476 eina_strbuf_append_char(params_full_imp, ' '); 483 eina_strbuf_append_char(params_full_imp, ' ');
@@ -480,7 +487,8 @@ _gen_func(const Eolian_Class *cl, const Eolian_Function *fid,
480 eina_strbuf_append(params_full_imp, " EINA_UNUSED"); 487 eina_strbuf_append(params_full_imp, " EINA_UNUSED");
481 eina_strbuf_append(params, prn); 488 eina_strbuf_append(params, prn);
482 489
483 eina_strbuf_append(params_full, ", "); 490 if (eina_strbuf_length_get(params_full) || !eolian_function_is_class(fid))
491 eina_strbuf_append(params_full, ", ");
484 eina_strbuf_append(params_full, ptn); 492 eina_strbuf_append(params_full, ptn);
485 if (!had_star) 493 if (!had_star)
486 eina_strbuf_append_char(params_full, ' '); 494 eina_strbuf_append_char(params_full, ' ');
@@ -559,12 +567,17 @@ _gen_func(const Eolian_Class *cl, const Eolian_Function *fid,
559 eina_strbuf_append(buf, func_suffix); 567 eina_strbuf_append(buf, func_suffix);
560 /* ([const ]Eo *obj, Data_Type *pd, impl_full_params); */ 568 /* ([const ]Eo *obj, Data_Type *pd, impl_full_params); */
561 eina_strbuf_append_char(buf, '('); 569 eina_strbuf_append_char(buf, '(');
562 if ((ftype == EOLIAN_PROP_GET) || eolian_function_object_is_const(fid)) 570 if (!eolian_function_is_class(fid))
563 eina_strbuf_append(buf, "const "); 571 {
564 eina_strbuf_append(buf, "Eo *obj, "); 572 if ((ftype == EOLIAN_PROP_GET) || eolian_function_object_is_const(fid))
565 eina_strbuf_append(buf, dt); 573 eina_strbuf_append(buf, "const ");
566 eina_strbuf_append(buf, " *pd"); 574 eina_strbuf_append(buf, "Eo *obj, ");
575 eina_strbuf_append(buf, dt);
576 eina_strbuf_append(buf, " *pd");
577 }
567 eina_strbuf_append(buf, eina_strbuf_string_get(params_full_imp)); 578 eina_strbuf_append(buf, eina_strbuf_string_get(params_full_imp));
579 if (eina_strbuf_length_get(params_full_imp) == 0 && eolian_function_is_class(fid))
580 eina_strbuf_append(buf, "void");
568 eina_strbuf_append(buf, ");\n\n"); 581 eina_strbuf_append(buf, ");\n\n");
569 } 582 }
570 583
@@ -635,7 +648,7 @@ _gen_func(const Eolian_Class *cl, const Eolian_Function *fid,
635 eina_stringshare_del(dt); 648 eina_stringshare_del(dt);
636 } 649 }
637 650
638 if (impl_same_class) 651 if (impl_same_class && !eolian_function_is_class(fid))
639 { 652 {
640 void *data; 653 void *data;
641 Eina_Iterator *itr = eolian_property_keys_get(fid, ftype); 654 Eina_Iterator *itr = eolian_property_keys_get(fid, ftype);
@@ -746,6 +759,36 @@ _gen_func(const Eolian_Class *cl, const Eolian_Function *fid,
746 eina_stringshare_del(lfn); 759 eina_stringshare_del(lfn);
747 eina_stringshare_del(eofn); 760 eina_stringshare_del(eofn);
748 } 761 }
762 if (impl_same_class && eolian_function_is_class(fid))
763 {
764 eina_strbuf_append(buf, "EOAPI ");
765 if (rtp)
766 eina_strbuf_append(buf, eolian_type_c_type_get(rtp, EOLIAN_C_TYPE_RETURN));
767 else
768 eina_strbuf_append(buf, "void");
769 eina_strbuf_append(buf, " ");
770 eina_strbuf_append(buf, eolian_function_full_c_name_get(fid, ftype, EINA_FALSE));
771 eina_strbuf_append(buf, "(");
772 if (eina_strbuf_length_get(params_full) == 0)
773 eina_strbuf_append(buf, "void");
774 else
775 eina_strbuf_append_buffer(buf, params_full);
776 eina_strbuf_append(buf, ")\n");
777 eina_strbuf_append(buf, "{\n");
778 eina_strbuf_append_printf(buf, " %s();\n", eolian_class_c_get_function_name_get(cl));
779 if (rtp)
780 eina_strbuf_append(buf, " return ");
781 else
782 eina_strbuf_append(buf, " ");
783 eina_strbuf_append_printf(buf, "_%s", ocnamel);
784 eina_strbuf_append_char(buf, '_');
785 eina_strbuf_append(buf, eolian_function_name_get(fid));
786 eina_strbuf_append(buf, func_suffix);
787 eina_strbuf_append(buf, "(");
788 eina_strbuf_append_buffer(buf, params);
789 eina_strbuf_append(buf, ");\n");
790 eina_strbuf_append(buf, "}\n");
791 }
749 792
750 free(cname); 793 free(cname);
751 free(cnamel); 794 free(cnamel);
@@ -797,9 +840,9 @@ _gen_initializer(const Eolian_Class *cl, Eina_Strbuf *buf)
797 eina_strbuf_append(buf, "\nstatic Eina_Bool\n_"); 840 eina_strbuf_append(buf, "\nstatic Eina_Bool\n_");
798 eina_strbuf_append(buf, cnamel); 841 eina_strbuf_append(buf, cnamel);
799 eina_strbuf_append(buf, "_class_initializer(Efl_Class *klass)\n{\n"); 842 eina_strbuf_append(buf, "_class_initializer(Efl_Class *klass)\n{\n");
800 eina_strbuf_append(buf, " const Efl_Object_Ops *opsp = NULL, *copsp = NULL;\n\n"); 843 eina_strbuf_append(buf, " const Efl_Object_Ops *opsp = NULL;\n\n");
801 844
802 Eina_Strbuf *ops = eina_strbuf_new(), *cops = eina_strbuf_new(); 845 Eina_Strbuf *ops = eina_strbuf_new();
803 846
804 /* start over with clean itearator */ 847 /* start over with clean itearator */
805 const Eolian_Implement *imp; 848 const Eolian_Implement *imp;
@@ -810,13 +853,12 @@ _gen_initializer(const Eolian_Class *cl, Eina_Strbuf *buf)
810 Eolian_Function_Type ftype; 853 Eolian_Function_Type ftype;
811 const Eolian_Function *fid = eolian_implement_function_get(imp, &ftype); 854 const Eolian_Function *fid = eolian_implement_function_get(imp, &ftype);
812 855
856 if (eolian_function_is_class(fid)) continue;
857
813 Eina_Strbuf *obuf = ops; 858 Eina_Strbuf *obuf = ops;
814 if (eolian_function_is_class(fid))
815 obuf = cops;
816 859
817 if (!eina_strbuf_length_get(obuf)) 860 if (!eina_strbuf_length_get(obuf))
818 eina_strbuf_append_printf(obuf, " EFL_OPS_DEFINE(%s,\n", 861 eina_strbuf_append_printf(obuf, " EFL_OPS_DEFINE(ops,\n");
819 (obuf == ops) ? "ops" : "cops");
820 862
821 Eina_Bool found_get = !!eina_hash_find(_funcs_params_init_get, &imp); 863 Eina_Bool found_get = !!eina_hash_find(_funcs_params_init_get, &imp);
822 Eina_Bool found_set = !!eina_hash_find(_funcs_params_init_set, &imp); 864 Eina_Bool found_set = !!eina_hash_find(_funcs_params_init_set, &imp);
@@ -864,28 +906,10 @@ _gen_initializer(const Eolian_Class *cl, Eina_Strbuf *buf)
864 eina_strbuf_append(buf, " opsp = &ops;\n"); 906 eina_strbuf_append(buf, " opsp = &ops;\n");
865 eina_strbuf_append(buf, "#endif\n\n"); 907 eina_strbuf_append(buf, "#endif\n\n");
866 } 908 }
867 if (eina_strbuf_length_get(cops))
868 {
869 eina_strbuf_append_printf(buf, "#ifndef %s_EXTRA_CLASS_OPS\n", cnameu);
870 eina_strbuf_append_printf(buf, "#define %s_EXTRA_CLASS_OPS\n", cnameu);
871 eina_strbuf_append(buf, "#endif\n\n");
872
873 eina_strbuf_append_printf(cops, " %s_EXTRA_CLASS_OPS\n );\n", cnameu);
874 eina_strbuf_append(buf, eina_strbuf_string_get(cops));
875 eina_strbuf_append(buf, " copsp = &cops;\n\n");
876 }
877 else
878 {
879 eina_strbuf_append_printf(buf, "#ifdef %s_EXTRA_CLASS_OPS\n", cnameu);
880 eina_strbuf_append_printf(buf, " EFL_OPS_DEFINE(cops, %s_EXTRA_CLASS_OPS);\n", cnameu);
881 eina_strbuf_append(buf, " copsp = &cops;\n");
882 eina_strbuf_append(buf, "#endif\n\n");
883 }
884 909
885 eina_strbuf_append(buf, " return efl_class_functions_set(klass, opsp, copsp, NULL);\n"); 910 eina_strbuf_append(buf, " return efl_class_functions_set(klass, opsp, NULL, NULL);\n");
886 911
887 eina_strbuf_free(ops); 912 eina_strbuf_free(ops);
888 eina_strbuf_free(cops);
889 913
890 eina_strbuf_append(buf, "}\n\n"); 914 eina_strbuf_append(buf, "}\n\n");
891 915