Commit e97db761 authored by Jürg Billeter's avatar Jürg Billeter

codegen: Small refactoring in property accessor generation

parent f37c74e4
...@@ -1416,10 +1416,6 @@ public class Vala.CCodeBaseModule : CodeGenerator { ...@@ -1416,10 +1416,6 @@ public class Vala.CCodeBaseModule : CodeGenerator {
acc.result_var.accept (this); acc.result_var.accept (this);
} }
if (acc.body != null) {
acc.body.emit (this);
}
var t = (TypeSymbol) prop.parent_symbol; var t = (TypeSymbol) prop.parent_symbol;
if (acc.construction && !t.is_subtype_of (gobject_type)) { if (acc.construction && !t.is_subtype_of (gobject_type)) {
...@@ -1465,6 +1461,7 @@ public class Vala.CCodeBaseModule : CodeGenerator { ...@@ -1465,6 +1461,7 @@ public class Vala.CCodeBaseModule : CodeGenerator {
} }
if (prop.is_abstract || prop.is_virtual) { if (prop.is_abstract || prop.is_virtual) {
CCodeFunction function;
if (acc.readable && !returns_real_struct) { if (acc.readable && !returns_real_struct) {
function = new CCodeFunction (acc.get_cname (), current_return_type.get_cname ()); function = new CCodeFunction (acc.get_cname (), current_return_type.get_cname ());
} else { } else {
...@@ -1562,6 +1559,7 @@ public class Vala.CCodeBaseModule : CodeGenerator { ...@@ -1562,6 +1559,7 @@ public class Vala.CCodeBaseModule : CodeGenerator {
cname = acc.get_cname (); cname = acc.get_cname ();
} }
CCodeFunction function;
if (acc.writable || acc.construction || returns_real_struct) { if (acc.writable || acc.construction || returns_real_struct) {
function = new CCodeFunction (cname, "void"); function = new CCodeFunction (cname, "void");
} else { } else {
...@@ -1608,12 +1606,18 @@ public class Vala.CCodeBaseModule : CodeGenerator { ...@@ -1608,12 +1606,18 @@ public class Vala.CCodeBaseModule : CodeGenerator {
} }
} }
function.block = (CCodeBlock) acc.body.ccodenode; var init_fragment = new CCodeFragment ();
if (is_virtual) { if (prop.binding == MemberBinding.INSTANCE && !is_virtual) {
var cdecl = new CCodeDeclaration (this_type.get_cname ()); CCodeStatement check_stmt;
cdecl.add_declarator (new CCodeVariableDeclarator ("self", transform_expression (new CCodeIdentifier ("base"), base_type, this_type))); if (!acc.readable || returns_real_struct) {
function.block.prepend_statement (cdecl); check_stmt = create_property_type_check_statement (prop, false, t, true, "self");
} else {
check_stmt = create_property_type_check_statement (prop, true, t, true, "self");
}
if (check_stmt != null) {
init_fragment.append (check_stmt);
}
} }
if (acc.readable && !returns_real_struct) { if (acc.readable && !returns_real_struct) {
...@@ -1621,26 +1625,25 @@ public class Vala.CCodeBaseModule : CodeGenerator { ...@@ -1621,26 +1625,25 @@ public class Vala.CCodeBaseModule : CodeGenerator {
if (acc.return_block == null || acc.return_block.get_predecessors ().size > 0) { if (acc.return_block == null || acc.return_block.get_predecessors ().size > 0) {
var cdecl = new CCodeDeclaration (acc.value_type.get_cname ()); var cdecl = new CCodeDeclaration (acc.value_type.get_cname ());
cdecl.add_declarator (new CCodeVariableDeclarator ("result")); cdecl.add_declarator (new CCodeVariableDeclarator ("result"));
function.block.prepend_statement (cdecl); init_fragment.append (cdecl);
} }
} }
if (current_method_inner_error) { if (is_virtual) {
var cdecl = new CCodeDeclaration ("GError *"); var cdecl = new CCodeDeclaration (this_type.get_cname ());
cdecl.add_declarator (new CCodeVariableDeclarator ("_inner_error_", new CCodeConstant ("NULL"))); cdecl.add_declarator (new CCodeVariableDeclarator ("self", transform_expression (new CCodeIdentifier ("base"), base_type, this_type)));
function.block.prepend_statement (cdecl); init_fragment.append (cdecl);
} }
if (prop.binding == MemberBinding.INSTANCE && !is_virtual) { acc.body.emit (this);
CCodeStatement check_stmt;
if (!acc.readable || returns_real_struct) { function.block = (CCodeBlock) acc.body.ccodenode;
check_stmt = create_property_type_check_statement (prop, false, t, true, "self"); function.block.prepend_statement (init_fragment);
} else {
check_stmt = create_property_type_check_statement (prop, true, t, true, "self"); if (current_method_inner_error) {
} var cdecl = new CCodeDeclaration ("GError *");
if (check_stmt != null) { cdecl.add_declarator (new CCodeVariableDeclarator.zero ("_inner_error_", new CCodeConstant ("NULL")));
function.block.prepend_statement (check_stmt); function.block.add_statement (cdecl);
}
} }
// notify on property changes // notify on property changes
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment