[vala/staging] codegen: Reduce code duplications when generation base-access



commit af8fcf8ef745ab9cce20e1ee1806612d515e50de
Author: Rico Tzschichholz <ricotz ubuntu com>
Date:   Fri Oct 18 15:41:30 2019 +0200

    codegen: Reduce code duplications when generation base-access

 codegen/valaccodebasemodule.vala         | 24 ++++++------------
 codegen/valaccodememberaccessmodule.vala | 43 ++++++++++++--------------------
 codegen/valaccodemethodcallmodule.vala   | 17 ++++++-------
 3 files changed, 32 insertions(+), 52 deletions(-)
---
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index 7c1c2290c..993355b7e 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -6039,24 +6039,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);
diff --git a/codegen/valaccodememberaccessmodule.vala b/codegen/valaccodememberaccessmodule.vala
index 2a37ceb5c..3b8933d04 100644
--- a/codegen/valaccodememberaccessmodule.vala
+++ b/codegen/valaccodememberaccessmodule.vala
@@ -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;
                                }
@@ -201,26 +200,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 ()) {
diff --git a/codegen/valaccodemethodcallmodule.vala b/codegen/valaccodemethodcallmodule.vala
index fc0561dd7..5d28ee365 100644
--- a/codegen/valaccodemethodcallmodule.vala
+++ b/codegen/valaccodemethodcallmodule.vala
@@ -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));
                                }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]