Skip to content

Commit

Permalink
codegen: Reduce code duplications when generation base-access
Browse files Browse the repository at this point in the history
  • Loading branch information
ricotz committed Nov 7, 2019
1 parent 6c8eff3 commit 47d5fd7
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 52 deletions.
24 changes: 8 additions & 16 deletions codegen/valaccodebasemodule.vala
Expand Up @@ -6167,24 +6167,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);
Expand Down
43 changes: 16 additions & 27 deletions codegen/valaccodememberaccessmodule.vala
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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 ()) {
Expand Down
17 changes: 8 additions & 9 deletions codegen/valaccodemethodcallmodule.vala
Expand Up @@ -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));
}
Expand Down

0 comments on commit 47d5fd7

Please sign in to comment.