]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
codegen: Reduce code duplications when generation base-access
authorRico Tzschichholz <ricotz@ubuntu.com>
Fri, 18 Oct 2019 13:41:30 +0000 (15:41 +0200)
committerRico Tzschichholz <ricotz@ubuntu.com>
Thu, 7 Nov 2019 10:53:07 +0000 (11:53 +0100)
codegen/valaccodebasemodule.vala
codegen/valaccodememberaccessmodule.vala
codegen/valaccodemethodcallmodule.vala

index c9362387ed4aa54ee69330db3d7a47630a0f8ae9..776562087fac3ce49c8b6d66c51a224ba9276aa7 100644 (file)
@@ -6185,24 +6185,16 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
 
        public void store_property (Property prop, Expression? instance, TargetValue value) {
                if (instance is BaseAccess) {
+                       CCodeExpression? vcast = null;
                        if (prop.base_property != null) {
-                               var base_class = (Class) prop.base_property.parent_symbol;
-                               var vcast = new CCodeFunctionCall (new CCodeIdentifier (get_ccode_class_type_function (base_class)));
-                               vcast.add_argument (new CCodeIdentifier ("%s_parent_class".printf (get_ccode_lower_case_name (current_class, null))));
-
-                               var ccall = new CCodeFunctionCall (new CCodeMemberAccess.pointer (vcast, "set_%s".printf (prop.name)));
-                               ccall.add_argument ((CCodeExpression) get_ccodenode (instance));
-                               var cexpr = get_cvalue_ (value);
-                               if (prop.property_type.is_real_non_null_struct_type ()) {
-                                       cexpr = new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, cexpr);
-                               }
-                               ccall.add_argument (cexpr);
-
-                               ccode.add_expression (ccall);
+                               unowned Class base_class = (Class) prop.base_property.parent_symbol;
+                               vcast = new CCodeFunctionCall (new CCodeIdentifier (get_ccode_class_type_function (base_class)));
+                               ((CCodeFunctionCall) vcast).add_argument (new CCodeIdentifier ("%s_parent_class".printf (get_ccode_lower_case_name (current_class))));
                        } else if (prop.base_interface_property != null) {
-                               var base_iface = (Interface) prop.base_interface_property.parent_symbol;
-                               var vcast = get_this_interface_cexpression (base_iface);
-
+                               unowned Interface base_iface = (Interface) prop.base_interface_property.parent_symbol;
+                               vcast = get_this_interface_cexpression (base_iface);
+                       }
+                       if (vcast != null) {
                                var ccall = new CCodeFunctionCall (new CCodeMemberAccess.pointer (vcast, "set_%s".printf (prop.name)));
                                ccall.add_argument ((CCodeExpression) get_ccodenode (instance));
                                var cexpr = get_cvalue_ (value);
index 2359f4ba80eeb12f5f1e04533067fa71a5e86c34..e08d75ee178df56ed53ecccea0e646531e68e0f6 100644 (file)
@@ -49,17 +49,16 @@ public abstract class Vala.CCodeMemberAccessModule : CCodeControlFlowModule {
                        }
 
                        if (expr.inner is BaseAccess) {
+                               CCodeExpression? vcast = null;
                                if (m.base_method != null) {
-                                       var base_class = (Class) m.base_method.parent_symbol;
-                                       var vcast = new CCodeFunctionCall (new CCodeIdentifier (get_ccode_class_type_function (base_class)));
-                                       vcast.add_argument (new CCodeIdentifier ("%s_parent_class".printf (get_ccode_lower_case_name (current_class, null))));
-
-                                       set_cvalue (expr, new CCodeMemberAccess.pointer (vcast, get_ccode_vfunc_name (m)));
-                                       return;
+                                       unowned Class base_class = (Class) m.base_method.parent_symbol;
+                                       vcast = new CCodeFunctionCall (new CCodeIdentifier (get_ccode_class_type_function (base_class)));
+                                       ((CCodeFunctionCall) vcast).add_argument (new CCodeIdentifier ("%s_parent_class".printf (get_ccode_lower_case_name (current_class))));
                                } else if (m.base_interface_method != null) {
-                                       var base_iface = (Interface) m.base_interface_method.parent_symbol;
-                                       var vcast = get_this_interface_cexpression (base_iface);
-
+                                       unowned Interface base_iface = (Interface) m.base_interface_method.parent_symbol;
+                                       vcast = get_this_interface_cexpression (base_iface);
+                               }
+                               if (vcast != null) {
                                        set_cvalue (expr, new CCodeMemberAccess.pointer (vcast, get_ccode_vfunc_name (m)));
                                        return;
                                }
@@ -188,26 +187,16 @@ public abstract class Vala.CCodeMemberAccessModule : CCodeControlFlowModule {
                                } else if (prop.base_interface_property != null) {
                                        base_prop = prop.base_interface_property;
                                }
+                               CCodeExpression? vcast = null;
                                if (base_prop.parent_symbol is Class) {
-                                       var base_class = (Class) base_prop.parent_symbol;
-                                       var vcast = new CCodeFunctionCall (new CCodeIdentifier (get_ccode_class_type_function (base_class)));
-                                       vcast.add_argument (new CCodeIdentifier ("%s_parent_class".printf (get_ccode_lower_case_name (current_class, null))));
-
-                                       var ccall = new CCodeFunctionCall (new CCodeMemberAccess.pointer (vcast, "get_%s".printf (prop.name)));
-                                       ccall.add_argument (get_cvalue (expr.inner));
-                                       if (prop.property_type.is_real_non_null_struct_type ()) {
-                                               var temp_value = (GLibValue) create_temp_value (prop.get_accessor.value_type, false, expr);
-                                               expr.target_value = load_temp_value (temp_value);
-                                               var ctemp = get_cvalue_ (temp_value);
-                                               ccall.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, ctemp));
-                                               ccode.add_expression (ccall);
-                                       } else {
-                                               set_cvalue (expr, ccall);
-                                       }
+                                       unowned Class base_class = (Class) base_prop.parent_symbol;
+                                       vcast = new CCodeFunctionCall (new CCodeIdentifier (get_ccode_class_type_function (base_class)));
+                                       ((CCodeFunctionCall) vcast).add_argument (new CCodeIdentifier ("%s_parent_class".printf (get_ccode_lower_case_name (current_class))));
                                } else if (base_prop.parent_symbol is Interface) {
-                                       var base_iface = (Interface) base_prop.parent_symbol;
-                                       var vcast = get_this_interface_cexpression (base_iface);
-
+                                       unowned Interface base_iface = (Interface) base_prop.parent_symbol;
+                                       vcast = get_this_interface_cexpression (base_iface);
+                               }
+                               if (vcast != null) {
                                        var ccall = new CCodeFunctionCall (new CCodeMemberAccess.pointer (vcast, "get_%s".printf (prop.name)));
                                        ccall.add_argument (get_cvalue (expr.inner));
                                        if (prop.property_type.is_real_non_null_struct_type ()) {
index 3a698d61211f56829511934d268b69d0238f63c5..60bc43097d47720eed040d98750c5e04ff3339a3 100644 (file)
@@ -95,17 +95,16 @@ public class Vala.CCodeMethodCallModule : CCodeAssignmentModule {
                        finish_call = new CCodeFunctionCall (new CCodeIdentifier (get_ccode_finish_name (m)));
 
                        if (ma.inner is BaseAccess) {
+                               CCodeExpression? vcast = null;
                                if (m.base_method != null) {
-                                       var base_class = (Class) m.base_method.parent_symbol;
-                                       var vcast = new CCodeFunctionCall (new CCodeIdentifier (get_ccode_class_type_function (base_class)));
-                                       vcast.add_argument (new CCodeIdentifier ("%s_parent_class".printf (get_ccode_lower_case_name (current_class, null))));
-
-                                       async_call.call = new CCodeMemberAccess.pointer (vcast, get_ccode_vfunc_name (m));
-                                       finish_call.call = new CCodeMemberAccess.pointer (vcast, get_ccode_finish_vfunc_name (m));
+                                       unowned Class base_class = (Class) m.base_method.parent_symbol;
+                                       vcast = new CCodeFunctionCall (new CCodeIdentifier (get_ccode_class_type_function (base_class)));
+                                       ((CCodeFunctionCall) vcast).add_argument (new CCodeIdentifier ("%s_parent_class".printf (get_ccode_lower_case_name (current_class))));
                                } else if (m.base_interface_method != null) {
-                                       var base_iface = (Interface) m.base_interface_method.parent_symbol;
-                                       var vcast = get_this_interface_cexpression (base_iface);
-
+                                       unowned Interface base_iface = (Interface) m.base_interface_method.parent_symbol;
+                                       vcast = get_this_interface_cexpression (base_iface);
+                               }
+                               if (vcast != null) {
                                        async_call.call = new CCodeMemberAccess.pointer (vcast, get_ccode_vfunc_name (m));
                                        finish_call.call = new CCodeMemberAccess.pointer (vcast, get_ccode_finish_vfunc_name (m));
                                }